negative numbers in brackets

negative numbers in brackets

by Björn Gerß -
Number of replies: 4

Hello,

for many randomised questions numbers can be either positive or negative.

I´d like to have negative numbers in brackets, but no brackets for positive ones.

For example with \({@z1@}+{@z2@}\), the output should be 3+7, but 3+(-7).

Any ideas how to do that?

Björn


Average of ratings: -
In reply to Björn Gerß

Re: negative numbers in brackets

by Stephan Bach -
Hi,
you could do something like this: texput(dispex, if is (z2>=0) then tex1(z1+z2) else sconcat( tex1(z1) ,"+(" , tex1(z2) ,")") ); And then inlcude {@dispex@} in your question text.
Stephan
In reply to Stephan Bach

Re: negative numbers in brackets

by Christopher Sangwin -
Picture of Particularly helpful Moodlers Picture of Plugin developers
I don't think the best way to solve this is at the display level with texput. Maxima already does this. There is a section on "unary minus" in the docs here: https://docs.stack-assessment.org/en/CAS/Simplification/
In reply to Christopher Sangwin

Re: negative numbers in brackets

by Stephan Bach -
Hi Chris,
thank's for the hint. I'm not sure though, if this is working here. Because even with simp set to false 2+(-1) is being displayed as 2-1. The question is how to prevent Maxima from very basic simplification of sums.
In reply to Stephan Bach

Re: negative numbers in brackets

by Björn Gerß -
Hi Chris, hi Stephan,
I found the important sentence:
“Note that STACK's display functions automatically apply unary_minus_sort(...) to any expression being displayed.”
But for teaching negative numbers, I like to deactivate this function. The output I’d like to have is 3+(-7)