1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
from sympy import *
from latex2sympy import process_sympy
#
# Equality Testing
#
answer_sets = [
{
'correct_answer': '(x-y)(x+2y)',
'student_answers': [
'x^2+xy-2y^2',
'(x-y)(x+2y)',
'(x+2y)(x-y)',
'(2\\times y+x)(-y+x)',
'(y\\cdot 2+x)(-y+x)'
]
},
{
'correct_answer': '2\\pi \\variable{r}^2',
'student_answers': [
'2\\pi \\variable{r}^2',
'\\pi 2\\variable{r}^2',
'2\\times \\pi \\times \\variable{r}^2',
'2\\pi \\variable{r} \\times \\variable{r}'
]
},
{
'correct_answer': '2x - 3y',
'student_answers': [
'-3y + 2x'
]
},
{
'correct_answer': 'x\\times x',
'student_answers': [
'x\\times x',
'x\\cdot x',
'x^2',
'(\\sqrt{x})^{4}'
]
},
{
'correct_answer': '23e^{-1\\times \\sqrt{t^2}}',
'student_answers': [
'23e^{-t}'
]
},
{
'correct_answer': 'a=x^2+1',
'student_answers': [
'x^2+1=a'
]
}
]
for answer_set in answer_sets:
correct_answer = answer_set['correct_answer']
correct_answer_parsed = process_sympy(answer_set['correct_answer'])
for student_answer in answer_set['student_answers']:
student_answer_parsed = process_sympy(student_answer)
print('correct_answer (c): ', correct_answer, correct_answer_parsed)
print('student_answer (a): ', student_answer, student_answer_parsed)
print('')
print('Expression Tree (srepr(c) == srepr(a)) =>', srepr(correct_answer_parsed) == srepr(student_answer_parsed))
print('srepr(c) =>', srepr(correct_answer_parsed))
print('srepr(a) =>', srepr(student_answer_parsed))
print('')
# print('Structural (c == a) =>', correct_answer_parsed == student_answer_parsed)
print('Symbolic (simplify(c - s) == 0) =>', simplify(correct_answer_parsed - student_answer_parsed) == 0)
print('simplified =>', simplify(correct_answer_parsed - student_answer_parsed))
print('')
print('Numeric Substitution (c.equals(s)) =>', correct_answer_parsed.equals(student_answer_parsed))
print('-----------------------------------------------------')
|