mitodl / mitx-grading-library

The MITx Grading Library, a python grading library for edX
https://edge.edx.org/courses/course-v1:MITx+grading-library+examples/
BSD 3-Clause "New" or "Revised" License
14 stars 9 forks source link

Exponentiation issue in calc.py #43

Closed jolyonb closed 6 years ago

jolyonb commented 6 years ago

There is an issue with calc.py whereby exponentiation doesn't parse in the correct order. I can't remember exactly what the issue is, but I remember that we haven't fixed it.

ChristopherChudzicki commented 6 years ago

The bug is that calc.py interprets 2^-2^2 as 2^(-2)^2 = 16, whereas it seems standard (Google, Mathematica, Python) interpret to interpret as 2^-(2^2) = 1/16. EdX display also suggests should be interpretted as 2^-(2^2):

evaluator('2^-2^2', {'x':2}, {}, {}) # 16, same as 2^(-2)^2
screen shot 2017-08-20 at 4 21 41 pm

Note that this only happens with numerical nested exponents with a negative sign in the exponent... so that's probably pretty rare.

It does NOT happen with symbolic exponents because the parser requires parentheses:

evaluator('2^(-x^2)', {'x':2}, {}, {}) # 1/16
evaluator('2^-x^2', {'x':2}, {}, {}) # raises InvalidInput
jolyonb commented 6 years ago

Ok, good to have this documented. I looked at calc.py to see why this is happening... and it's baked somewhat strongly into the tree parser. We'd have to refactor that algorithm significantly :-(

ChristopherChudzicki commented 6 years ago

Resolved by #59