maths / moodle-qtype_stack

Stack question type for Moodle
GNU General Public License v3.0
138 stars 147 forks source link

complex_exponentialp predicate function doesn't check for -(...) #1136

Closed LukeLongworth closed 3 months ago

LukeLongworth commented 3 months ago

Hi again,

Another small issue from me today: I have a complex numbers question where I generate rec_form: -aa - bb*i and then ask students to convert this to polar form. My model answer is generated with ev(polarform(rec_form),simp), which produces answers of the form -(r*exp(i*atan(bb/aa))).

When I then use the complex_exponentialp to check whether the answer is in the correct form, it rejects this answer, because the leading operation is "-" rather than "" and there is no check for this. Simply removing the brackets and giving the answer `-rexp(iatan(bb/aa))fixes the problem (or even better, givingrexp(i*(atan(bb/aa) + pi))`), but I don't like that the brackets change the answer from correct to incorrect.

After some fiddling I came up with the solution to include the line if safe_op(ex)="-" then return(complex_exponentialp(first(ex))) after checking whether ex is real (i.e. after line 465 of assessment.mac), and this has worked fine.

I haven't made this a pull request because I'm not 100% convinced that this is a sensible approach, but it seems to work fine on the small handful of checks I ran locally. It feels vaguely correct to me that -(expr) must be in complex exponential form if and only if expr is in complex exponential form.

As an aside, is this the best place to make small suggestions/raise questions like this? I am aware I've posted lots of small issues the last couple of weeks, and I will happily move this to Zulip if that would be a better place.

sangwinc commented 3 months ago

These small fixes and improvements really do add up over time and are much appreciated. Thanks @LukeLongworth, it's appreciated.