Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
seancanobrien opened this issue Jun 5, 2024 · 9 comments

Comments

@seancanobrien
Copy link

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
Copy link
Contributor

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:

  • Even with simp: false, sin(x)^2 will display as \\sin ^2\\left(x\\right) rather than the (in my opinion) preferred \\sin\\left(x\\right)^2. Perhaps '"^"(sin(x),2) could display the latter?
  • Maxima has the frustrating habit of displaying variables in reverse alphabetical order in sums and normal alphabetical order in products. I would personally prefer expand((x+y)^2) to print as x^2 + 2*x*y + y^2 but with or without ordergreat(x,y), one of those orders will be reversed. If I instead had expand((a*x + b*y)^2) then with simp:false even ev(a^2*x^2,simp) + ev(2*a*b,simp)*x*y + ev(b^2*x^2,simp) causes sign-related headaches for the middle term. Perhaps this functionality could let me use ordergreat(x,y) with simp:true and the expression a^2*x^2 + '"*"(2*a*b*x,y) + b^2*y^2 would display as I hope?
  • I would really love to be able to use n-th root notation as an alternative to fractional powers too. That feels related, though I can't think of how it fits in exactly

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

@sangwinc
Copy link
Member

sangwinc commented Jun 6, 2024

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
Copy link
Contributor

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
Copy link
Member

sangwinc commented Jun 6, 2024

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

@seancanobrien
Copy link
Author

@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
Copy link
Member

@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.

@sangwinc
Copy link
Member

Just reviewing issues. I'm happy to add in code to STACK which would display noun prefix operators such as '"+"(a,b) with TeX which uses infix operations. But, I don't have time to figure out the Maxima code to do this! If someone else (e.g. @mrseanman ) can figure out what Maxima code will convert these noun prefix operators into infx operators then I'll do the work adding this to STACK.

@seancanobrien
Copy link
Author

Hi @sangwinc, happy to have a look in to that. I'll first look in to a way to texput the prefix operator. In your first comment you seemed to hope to have something like a '+ b, this seems much more difficult, but I can have a go at that as well.

@sangwinc
Copy link
Member

Thanks @mrseanman, this kind of contribution to STACK is very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants