maths / moodle-qtype_stack

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

Typeset noun form of basic arithmetic operators as regular infix operators. #1199

Open mrseanman opened 4 weeks ago

mrseanman commented 4 weeks ago

The STACK documentation recommends using simp: false for cases where you don't want certain expressions to be evaluated. I find this works OK, but it is often useful to have finer control of exactly what is and isn't evaluated. Also, having simp: false looming around has obvious undesirable effects.

I think using nouns and the ' prefix would be a good alternative to simp:false. Unfortunately, the only way to access the noun form of basic arithmetic operators is to use them as prefix functions, e.g. '"+"(1,2).

In maxima itself, using the noun form of simple arithmetic operators typesets nicely (in the command line). E.g. '"+"(1,2) returns 1 + 2. However the latex is typeset as {\it mplus}\left(1 , 2\right).

This prefix tex typesetting is the only thing stopping me from using this as an alternative to simp:false. The slight added difficulty of using prefix functions is not so bad. I think this would be a nice feature, depending on how difficult it would be to change how '"+" etc are typeset.

LukeLongworth commented 4 weeks ago

This idea is interesting to me! I like having finer control over how things are displayed, and I prefer to avoid having to construct my own tex strings.

Another two examples that feel relevant/similar to me are:

I'm not even sure either of these would be fixed by something like Sean has suggested, but I like the spirit anyway!

sangwinc commented 4 weeks ago

The substantive issue here is better support for selective simplification. I wrote a parallel elementary simplifier to support this answer test: https://docs.stack-assessment.org/en/Authoring/Answer_Tests/Rule_based/ The code is here https://github.com/maths/moodle-qtype_stack/blob/master/stack/maxima/noun_simp.mac

This creates parallel "noun" forms of all the elementary operations, e.g. noun+ is a parallel infix +. This is to avoid the use of "+"(1,2) as a prefix notation.

@mrseanman, sorry but I have no plans to typeset '"+"(1,2) as infix notation (as requested). I think that's a work-around, but that's not the right direction to go in. Instead, the plan is to expand the rule-based answer test functionality to expose this as a selective simplifier. Please look at that functionality first.

Note that the parser we have in PHP does not currently allow teachers to use the (parallel) noun+ operators. That's by design, because the 1st draft of the rule-based simplifier was not designed for end-user use, rather it was designed to support internal computation in the answer test. We may change those decisions and expose the simplifier.

Thanks for the comments @LukeLongworth but now we're conflating a lot of separate display requests into a single issue about selective simplification! You probably have no idea how difficult it was to get Maxima to display sin(x)^2 as sin^2(x), but I was persuaded to do this by a number of people to follow common practice in typesetting! The code starts here https://github.com/maths/moodle-qtype_stack/blob/master/stack/maxima/stacktex.lisp#L240 @LukeLongworth you're in good company in rejecting f^2(x) as did Babbage in the 1830s. Well, we could add an option to choose between the two....

STACK already defines an nth root function https://github.com/maths/moodle-qtype_stack/blob/master/stack/maxima/assessment.mac#L363 so let's not duplicate that functionality please. We just need to add in a texput() rule for unevaluated 'root(x,n). That should be easy enough to do...

LukeLongworth commented 4 weeks ago

Thanks for the response Chris, I did suspect that I was jumping around a few different things here. None of those issues were particularly important to me, I mostly commented because I was interested in the discussion here! I've not used those noun_simp.mac functions before and this has got me interested to play around with them.

I'd happily have a look at writing a flag to switch between f^2(x) and f(x)^2, and write the texput for 'root. Should the latter live in assessment.mac?

sangwinc commented 4 weeks ago

@LukeLongworth, I'll sort out the display of "root" should only be a few lines, and changes to existing unit tests.

mrseanman commented 3 weeks ago

@sangwinc Many thanks for your reply. I would argue that maxima already has some sort of selective simplification, in the form of the ' prefix. Influence over specific nouns (rather than algebraic properties, such as commutativity) is more appealing to me. But I understand if that's not the plan. My intended use case is for dynamic feedback and question-text content.

sangwinc commented 3 weeks ago

@mrseanman, that's fair enough comment: maxima does have it's ' prefix system for noun forms of operators. We're gradually moving in that direction for functions. I don't know how to convert the '"+"(a,b) prefix forms into the infix a+b form in maxima. I've done a little digging, but I can't figure it out! Similarly, we could add in new rules to texput for these prefix functions, but I don't know how to do that.