|
113 | 113 | Depatternize[pattern_] := MapAll[DepatternizePattern, pattern] |
114 | 114 |
|
115 | 115 | (*StandardizeEquation: a function that automatically converts all instances |
116 | | -of the equals sign to the repeated equals sign, so that anything WL would |
117 | | -parse as an assignment gets parsed instead as an equu |
118 | | -ation*) |
| 116 | +of the equals sign in a string to the repeated equals sign, so that anything WL |
| 117 | +would parse as an assignment gets parsed instead as an equation*) |
119 | 118 |
|
120 | | -StandardizeEquation[str_]:=FixedPoint[StringReplace["==="->"=="],StringReplace[str,"="->"=="]] |
| 119 | +StandardizeEquation[str_String]:=FixedPoint[StringReplace["==="->"=="],StringReplace[str,"="->"=="]] |
121 | 120 |
|
122 | 121 | (*StructureMatchQ: a function that checks whether a user's response \ |
123 | 122 | has the same structure as a given answer template, given a set of \ |
|
156 | 155 |
|
157 | 156 | Options[StructureMatchQ] = {Atomic -> False}; |
158 | 157 |
|
159 | | -StructureMatchQ[response_,answerTemplate_,namedVariables_] := |
| 158 | +StructureMatchQ[answerTemplate_String,response_String,namedVariables_List] := |
160 | 159 | Module[{response2,answerTemplate2},response2=MapAll[CanonicComplex,ReplaceAll[response,inertFunctionRules]]; |
161 | 160 | answerTemplate2=ReplaceAll[answerTemplate,inertFunctionRules]; |
162 | 161 | MatchQ[response2,Patternize[answerTemplate2,namedVariables]]] |
163 | 162 |
|
164 | | -equalQStructure[answer_, response_, params_] := Module[{namedVariables,correctQ}, |
| 163 | +equalQStructure[answer_String, response_String, params_Association] := Module[{namedVariables,correctQ}, |
165 | 164 | Print["Evaluating Structure"]; |
166 | | - namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
| 165 | + namedVariables = FullForm[ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]]; |
167 | 166 | correctQ = StructureMatchQ[ |
168 | | - ToExpression[StandardizeEquation[ToString[response]],TraditionalForm], |
169 | | - ToExpression[StandardizeEquation[ToString[answer]],TraditionalForm], |
| 167 | + ToString[ToExpression[StandardizeEquation[answer],TraditionalForm],InputForm], |
| 168 | + response, |
170 | 169 | namedVariables]; |
171 | 170 |
|
172 | 171 | <| |
|
191 | 190 | arccoth -> ArcCoth, acoth -> ArcCoth, |
192 | 191 | exp -> Exp, log -> Log, ln -> Log}; |
193 | 192 |
|
194 | | -SemanticMatchQ[response_,answer_] := Simplify[(response-answer)/.activeFunctionRules] == 0 |
| 193 | +SemanticMatchQ[answer_,response_] := Simplify[(response-answer)/.activeFunctionRules] == 0 |
| 194 | + |
| 195 | +SemanticMatchQ[answer_Equal, response_Equal] := |
| 196 | + SemanticMatchQ[answer[[1]]-answer[[2]], response[[1]]-response[[2]]]|| |
| 197 | + SemanticMatchQ[answer[[1]]-answer[[2]], response[[2]]-response[[1]]] |
195 | 198 |
|
196 | | -SemanticMatchQ[response_Equal, answer_Equal] := |
197 | | - SemanticMatchQ[response[[1]]-response[[2]], answer[[1]]-answer[[2]]]|| |
198 | | - SemanticMatchQ[response[[1]]-response[[2]], answer[[2]]-answer[[1]]] |
| 199 | +SemanticMatchQ[answer_String,response_String] := |
| 200 | + SemanticMatchQ[ |
| 201 | + ToExpression[answer], |
| 202 | + ToExpression[response] |
| 203 | + ] |
199 | 204 |
|
200 | | -SemanticAndStructureMatchQ[response_,answer_,answerTemplate_,namedVariables_] := |
201 | | - TrueQ[SemanticMatchQ[response,answer]&&StructureMatchQ[response,answerTemplate,namedVariables]] |
| 205 | +SemanticAndStructureMatchQ[answer_String,response_String,answerTemplate_String,namedVariables_List] := |
| 206 | + TrueQ[SemanticMatchQ[answer,response]&&StructureMatchQ[answerTemplate,response,namedVariables]] |
202 | 207 |
|
203 | | -equalQSemantic[answer_, response_, params_] := Module[{correctQ}, |
| 208 | +equalQSemantic[answer_String, response_String, params_Association] := Module[{correctQ}, |
204 | 209 | Print["Evaluating Semantic"]; |
205 | 210 | correctQ = SemanticMatchQ[ |
206 | | - ToExpression[StandardizeEquation[ToString[response]],TraditionalForm], |
207 | | - ToExpression[StandardizeEquation[ToString[answer]],TraditionalForm]]; |
| 211 | + ToString[ToExpression[StandardizeEquation[answer],TraditionalForm],InputForm], |
| 212 | + response]; |
208 | 213 |
|
209 | 214 | <| |
210 | 215 | "error" -> Null, |
211 | 216 | "is_correct" -> correctQ |
212 | 217 | |> |
213 | 218 | ] |
214 | 219 |
|
215 | | -equalQSemanticAndStructure[answer_, response_, params_] := Module[{namedVariables,answerTemplate,correctQ}, |
| 220 | +equalQSemanticAndStructure[answer_String, response_String, params_Association] := Module[{namedVariables,answerTemplate,correctQ}, |
216 | 221 | Print["Evaluating SemanticAndStructure"]; |
217 | 222 | namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
218 | | - answerTemplate = ToExpression[Lookup[params,"answer_template",{}],TraditionalForm]; |
| 223 | + answerTemplate = Lookup[params,"answer_template",{}]; |
219 | 224 | correctQ = SemanticAndStructureMatchQ[ |
220 | | - ToExpression[StandardizeEquation[ToString[response]],TraditionalForm], |
221 | | - ToExpression[StandardizeEquation[ToString[answer]],TraditionalForm], |
222 | | - ToExpression[StandardizeEquation[ToString[answerTemplate]],TraditionalForm], |
| 225 | + ToString[ToExpression[StandardizeEquation[answer],TraditionalForm],InputForm], |
| 226 | + response, |
| 227 | + ToString[ToExpression[StandardizeEquation[answerTemplate],TraditionalForm],InputForm], |
223 | 228 | namedVariables |
224 | 229 | ]; |
225 | 230 |
|
|
242 | 247 |
|
243 | 248 | (* IN PARTICULAR, THE COMPARISON OF THE LENGTHS OF THE SYMBOL LISTS IS VERY HAMFISTED *) |
244 | 249 |
|
245 | | -StrictStructureMatchQ[response_,answerTemplate_,namedVariables_] := |
246 | | - StructureMatchQ[response,answerTemplate,namedVariables]&& |
| 250 | +StrictStructureMatchQ[answerTemplate_String,response_String,namedVariables_List] := |
| 251 | + StructureMatchQ[answerTemplate,response,namedVariables]&& |
247 | 252 | TrueQ[ |
248 | | - (Length[Union[UnnamedSymbols[response,namedVariables]]]== |
249 | | - Length[Union[UnnamedSymbols[answerTemplate,namedVariables]]])] |
| 253 | + (Length[Union[UnnamedSymbols[ToExpression[response],namedVariables]]]== |
| 254 | + Length[Union[UnnamedSymbols[ToExpression[StandardizeEquation[answerTemplate],TraditionalForm],namedVariables]]])] |
250 | 255 |
|
251 | 256 | (* SemanticAndStrictStructureMatchQ: a function that combines a strict structure comparison with a test of |
252 | 257 | mathematical equivalence *) |
253 | 258 |
|
254 | | -SemanticAndStrictStructureMatchQ[response_,answer_,answerTemplate_,namedVariables_] := |
255 | | - TrueQ[SemanticMatchQ[response,answer]&&StrictStructureMatchQ[response,answerTemplate,namedVariables]] |
| 259 | +SemanticAndStrictStructureMatchQ[answer_String,response_String,answerTemplate_String,namedVariables_List] := |
| 260 | + TrueQ[SemanticMatchQ[answer,response]&&StrictStructureMatchQ[answerTemplate,response,namedVariables]] |
256 | 261 |
|
257 | | -equalQStrictStructure[answer_, response_, params_] := Module[{namedVariables,correctQ}, |
| 262 | +equalQStrictStructure[answer_String, response_String, params_Association] := Module[{namedVariables,correctQ}, |
258 | 263 | Print["Evaluating Structure"]; |
259 | 264 | namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
260 | 265 | correctQ = StrictStructureMatchQ[ |
261 | | - ToExpression[StandardizeEquation[ToString[response]],TraditionalForm], |
262 | | - ToExpression[StandardizeEquation[ToString[answer]],TraditionalForm], |
| 266 | + ToString[ToExpression[StandardizeEquation[answer],TraditionalForm],InputForm], |
| 267 | + response, |
263 | 268 | namedVariables]; |
264 | 269 |
|
265 | 270 | <| |
|
268 | 273 | |> |
269 | 274 | ] |
270 | 275 |
|
271 | | -equalQSemanticAndStrictStructure[answer_, response_, params_] := Module[{namedVariables,answerTemplate,correctQ}, |
| 276 | +equalQSemanticAndStrictStructure[answer_String, response_String, params_Association] := Module[{namedVariables,answerTemplate,correctQ}, |
272 | 277 | Print["Evaluating SemanticAndStructure"]; |
273 | 278 | namedVariables = ToExpression[Lookup[params,"named_variables",{}],TraditionalForm]; |
274 | | - answerTemplate = ToExpression[Lookup[params,"answer_template",{}],TraditionalForm]; |
| 279 | + answerTemplate = Lookup[params,"answer_template",{}]; |
275 | 280 | correctQ = SemanticAndStrictStructureMatchQ[ |
276 | | - ToExpression[ToString[response],TraditionalForm], |
277 | | - ToExpression[ToString[answer],TraditionalForm], |
278 | | - ToExpression[ToString[answerTemplate],TraditionalForm], |
| 281 | + ToString[ToExpression[StandardizeEquation[answer],TraditionalForm],InputForm], |
| 282 | + response, |
| 283 | + answerTemplate, |
279 | 284 | namedVariables |
280 | 285 | ]; |
281 | 286 |
|
|
290 | 295 | evalQ[type_, answer_, response_, params_] := Module[{}, |
291 | 296 | Which[ |
292 | 297 | type == "structure", |
293 | | - equalQStructure[answer,response,params], |
| 298 | + equalQStructure[answer, response, params], |
294 | 299 | type == "semantic", |
295 | | - equalQSemantic[answer,response,params], |
| 300 | + equalQSemantic[answer, response, params], |
296 | 301 | type == "semantic_and_structure", |
297 | | - equalQSemanticAndStructure[answer,response,params], |
| 302 | + equalQSemanticAndStructure[answer, response, params], |
298 | 303 | type == "strict_structure", |
299 | | - equalQStrictStructure[answer,response,params], |
| 304 | + equalQStrictStructure[answer, response, params], |
300 | 305 | type == "semantic_and_strict_structure", |
301 | | - equalQSemanticAndStrictStructure[answer,response,params], |
| 306 | + equalQSemanticAndStrictStructure[answer, response, params], |
302 | 307 | NumericQ[answer], |
303 | 308 | equalQNumeric[answer, response, params], |
304 | 309 | True, |
|
0 commit comments