Commit b9af428b by ichuang

formula.py handle imaginary correctly; symmath_check add numerical option

parent f1e5d697
......@@ -409,8 +409,7 @@ class formula(object):
if 'hat' in usym:
sym = my_sympify(usym)
else:
if usym == 'i': print "options=", self.options
if usym == 'i' and 'imaginary' in self.options: # i = sqrt(-1)
if usym == 'i' and self.options is not None and 'imaginary' in self.options: # i = sqrt(-1)
sym = sympy.I
else:
sym = sympy.Symbol(str(usym))
......
......@@ -175,6 +175,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
do_matrix = 'matrix' in (options or '')
do_qubit = 'qubit' in (options or '')
do_imaginary = 'imaginary' in (options or '')
do_numerical = 'numerical' in (options or '')
# parse expected answer
try:
......@@ -196,6 +197,13 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None
msg += '<p>You entered: %s</p>' % to_latex(fans)
return {'ok': False, 'msg': msg}
if do_numerical: # numerical answer expected - force numerical comparison
if abs(abs(fans - fexpect) / fexpect) < threshold:
return {'ok': True, 'msg': msg}
else:
msg += '<p>You entered: %s (note that a numerical answer is expected)</p>' % to_latex(fans)
return {'ok': False, 'msg': msg}
if fexpect == fans:
msg += '<p>You entered: %s</p>' % to_latex(fans)
return {'ok': True, 'msg': msg}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment