maths / moodle-qtype_stack

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

Incorrect display in input validation field #347

Closed timlowe closed 6 years ago

timlowe commented 6 years ago

Hi, (I think is is a general STACK issue, rather than one with the OU display filter).

In a question with "insert stars for implied multiplication" turned on (it doesn't seem to matter which variant of that):

If the input is "2sqrt(2)/3" the validation field correctly displays $$\frac{2\sqrt{2}}/3$$.

But if the input is "2sqrt(+2)/3" [note the + within the square root] the validation field wrongly displays $\frac{2+\sqrt{2}}/3$ (ie, moves the + out of the root, to where the implied multiplication should be), yet the internal value of the ans1 variable is still correct $\frac{2\sqrt{2}}/3$.

Putting a negative inside the root works fine.

It doesn't seem to matter what the actual numbers are.

Tim

sangwinc commented 6 years ago

This is a Maxima issue. For a minimal example in Maxima (i.e. no STACK code) try

simp:false; p:sqrt(+2); tex(p);

sangwinc commented 6 years ago

In fact, I think just about any function has this behaviour, e.g the following is just a bit wrong!

simp:false; p:1/sin(+x) tex(p);

sangwinc commented 6 years ago

I'm unit testing a fix to this, but my fix involves removing all expressions where we have a single argument to the plus function. That is +x will from now on be displayed as "x" and not "+x".

This changes the behaviour of the LaTeX output for a number of existing functions around here:https://github.com/maths/moodle-qtype_stack/blob/master/tests/fixtures/inputfixtures.class.php#L251

I always felt these were very odd indeed https://github.com/maths/moodle-qtype_stack/blob/master/tests/fixtures/inputfixtures.class.php#L251 and under the new code the output becomes "a+b" rather than "a+++((b))" which is, I think, a substantial improvement.

Does anyone object to the proposed change to drop all display of "+a" where we have only one summand?

christianp commented 6 years ago

The only wrinkle I can think of is to differentiate +0 from -0 for numerical purposes (Numbas doesn't do this - one of its most basic rules is to strip out all unary pluses, like you're suggesting)

timhunt commented 6 years ago

Seems like a good idea to me.

timlowe commented 6 years ago

Sounds good to me. Thanks for looking into this.

sangwinc commented 6 years ago

Christian, I think if we needed a +0 and -0 we'd introduce an "infinitesimal" atom perhaps to play that role? Chris