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

Implicit product for terms ? #319

Closed drhodes closed 2 years ago

drhodes commented 2 years ago

Hi everyone! This is a feature proposal for introducing implicit products for numeric literals adjacent with other expressions, for example:

2x would parse as 2 * x
2sin(x) would parse as 2 * sin(x)

For what it's worth the julia programming language manages to allow this (so perhaps, at least, it's not a bad idea for some unknown reason), but more importantly for users of openedx, forgetting the * character is one of the most common entry mistakes.

jolyonb commented 2 years ago

This is a massive can of worms... The parser is easily the most complicated part of this library, and I'm loathe to change it. We already have excellent error messages if students forget a * character in an expression; I'm not sure this is really worth the effort?

jolyonb commented 2 years ago

Elaborating a bit... Remember that 2e3 is treated as a valid number. How would you handle that in your proposed syntax, especially if e3 is a defined function?

drhodes commented 2 years ago
julia> 2e3
2000.0

julia> 22e3
22000.0

julia> 2222e3
2.222e6

julia just interprets it as a float64.

What about e3 as a defined function? Well..

julia> e3(x) = x^2
e3 (generic function with 1 method)

julia> 2e3(2)
4000.0

I thoroughly understand your concern about the can of worms, what's going to break, for whom, etc..

jolyonb commented 2 years ago

What happens if you also set e3=6 as a variable?

drhodes commented 2 years ago

julia> e4 = 6
6

julia> 2e4
20000.0
jolyonb commented 2 years ago

There we go... I'd really like to avoid something like that happening in the parser.

Another reason I'd like to avoid this is backwards compatibility with edX. Basically, anything that your stock standard edX math input box accepts, we need to handle in exactly the same way (with the sole exception of an order-of-precedence bug in the edX parser regarding exponentials). This hamstrings us somewhat; there are certainly decisions I'd make differently if I could be freed from that constraint. I don't know if it precludes what you're requesting, but it certainly doesn't make it easy.

drhodes commented 2 years ago

Ok Jolyon, thanks for taking time out to consider the issue, I appreciate it!