|
218 | 218 | |> |
219 | 219 | ] |
220 | 220 |
|
| 221 | +(* UnnamedSymbols: a function that takes an expression and a list of named variables, |
| 222 | + and returns all other symbolic quantities in the expression. *) |
| 223 | + |
| 224 | +UnnamedSymbols[expression_,namedVariables_] := |
| 225 | + Cases[Reap[Scan[Sow,expression,{-1}]][[2,1]],a_Symbol/;Not[MemberQ[namedVariables,a]]] |
| 226 | + |
| 227 | +(* StrictStructureMatchQ: a function that matches structures more strictly,taking account of the unnamed symbols |
| 228 | + in each.*) |
| 229 | + |
| 230 | +(* THIS FUNCTION IS FLAWED, AND REPRESENTS A CRUDE FIRST GO *) |
| 231 | + |
| 232 | +(* IN PARTICULAR, THE COMPARISON OF THE LENGTHS OF THE SYMBOL LISTS IS VERY HAMFISTED *) |
| 233 | + |
| 234 | +StrictStructureMatchQ[response_,answerTemplate_,namedVariables_] := |
| 235 | + StructureMatchQ[response,answerTemplate,namedVariables]&& |
| 236 | + TrueQ[ |
| 237 | + (Length[Union[UnnamedSymbols[response,namedVariables]]]== |
| 238 | + Length[Union[UnnamedSymbols[answerTemplate,namedVariables]]])] |
| 239 | + |
| 240 | +(* SemanticAndStrictStructureMatchQ: a function that combines a strict structure comparison with a test of |
| 241 | + mathematical equivalence *) |
| 242 | + |
| 243 | +SemanticAndStrictStructureMatchQ[response_,answer_,answerTemplate_,namedVariables_] := |
| 244 | + TrueQ[SemanticMatchQ[response,answer]&&StrictStructureMatchQ[response,answerTemplate,namedVariables]] |
| 245 | + |
| 246 | +equalQStrictStructure[answer_, response_, params_] := Module[{namedVariables,correctQ}, |
| 247 | + Print["Evaluating Structure"]; |
| 248 | + namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
| 249 | + correctQ = StrictStructureMatchQ[ |
| 250 | + ToExpression[ToString[response],TraditionalForm], |
| 251 | + ToExpression[ToString[answer],TraditionalForm], |
| 252 | + namedVariables]; |
| 253 | + |
| 254 | + <| |
| 255 | + "error" -> Null, |
| 256 | + "is_correct" -> correctQ |
| 257 | + |> |
| 258 | +] |
| 259 | + |
| 260 | +equalQSemanticAndStrictStructure[answer_, response_, params_] := Module[{namedVariables,answerTemplate,correctQ}, |
| 261 | + Print["Evaluating SemanticAndStructure"]; |
| 262 | + namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
| 263 | + answerTemplate = ToExpression[Lookup[params,"answer_template",{}],TraditionalForm]; |
| 264 | + correctQ = SemanticAndStrictStructureMatchQ[ |
| 265 | + ToExpression[ToString[response],TraditionalForm], |
| 266 | + ToExpression[ToString[answer],TraditionalForm], |
| 267 | + ToExpression[ToString[answerTemplate],TraditionalForm], |
| 268 | + namedVariables |
| 269 | + ]; |
| 270 | + |
| 271 | + <| |
| 272 | + "error" -> Null, |
| 273 | + "is_correct" -> correctQ |
| 274 | + |> |
| 275 | +] |
| 276 | + |
221 | 277 | (* The evaluation function itself *) |
222 | 278 |
|
223 | 279 | evalQ[type_, answer_, response_, params_] := Module[{}, |
|
228 | 284 | equalQSemantic[answer,response,params], |
229 | 285 | type = "semantic_and_structure", |
230 | 286 | equalQSemanticAndStructure[answer,response,params], |
| 287 | + type = "strict_structure", |
| 288 | + equalQStrictStructure[answer,response,params], |
| 289 | + type = "semantic_and_strict_structure", |
| 290 | + equalQSemanticAndStrictStructure[answer,response,params], |
231 | 291 | NumericQ[answer], |
232 | 292 | equalQNumeric[answer, response, params], |
233 | 293 | True, |
|
0 commit comments