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

[Problematic] Vector multiplication is not associative #108

Closed ChristopherChudzicki closed 6 years ago

ChristopherChudzicki commented 6 years ago

Since * multiplies vectors as a dot product, * is not associative when used with vectors.

from mitxgraders.helpers.calc import evaluator, MathArray

variables = {
    'i': MathArray([1, 0]),
    'j': MathArray([0, 1]),
}

evaluator("i*i*j", variables)[0]        # result: [0, 1, 0]
evaluator("i*(i*j)", variables)[0]      # result: [0, 0, 0]

This seems like it could cause confusion, especially since edX renders multiplication with dot product symbols.

Edit: In particular, students might not know above whether i*i*j is equivalent to (i*i)*j or i*(i*j).

ChristopherChudzicki commented 6 years ago

One idea to reduce the confusion is to disallow expressions like i*i*j all together: Parser.eval_product could raise an error if three of its children are vectors. The error might say something like "Multiplication of three vectors without parentheses is ambiguous. Please add parentheses around dot products."

jolyonb commented 6 years ago

Ah. Good catch. We don't usually run into this problem on paper because we have different symbols for dot produt vs normal multiplication. I agree that this is ambiguous. I see two options:

Given that multiplication is rendered as a dot product, I don't really like the second... Let's go with warning that an ambiguous product was detected.