numbas / Numbas

A completely browser-based e-assessment/e-learning system, with an emphasis on mathematics
http://www.numbas.org.uk
Apache License 2.0
207 stars 122 forks source link

When identifying the variables used in the answer to a mathematical expression part, use the unsimplified expression #782

Closed christianp closed 3 years ago

christianp commented 3 years ago

I have a mathematical expression part whose correct answer is something like {cx}*x + {cy}*y = {cz}*z. I need to pick z to satisfy the equation half of the time.

When cy = 0, the y term is cancelled, so it's not in the list of variables to pick, and the value generator for z gives an error "`y is not defined." It doesn't matter what valuey` takes, since it'll cancel out, but it needs to be defined. So we should use the unsimplified form of the expected answer to find variable names.

christianp commented 3 years ago

This is really hard, because of the "part of expression to mark" option. We can only identify the variables to evaluate after finding the matching group. The expression might have to be simplified in order to match the pattern restriction. I suppose it's true that simplifying can't introduce new variable names, and there's no harm in generating unused variables, so maybe this isn't really a problem.

For now, I fixed the part by setting the correctVariables marking note to a fixed set("x","y","z"), but I'm not happy about having to do that.