I'd like to look into making a "plus/minus" operator. I know that I could make "+-" or "pm" be an operator in a MathObjects context. But I'd want it to take numeric operands and returns a list (of two numbers). So that:

Compute("1 +- 2")

would be equal to

Compute("-1, 3");

Also, an operator like this comes up with solutions to quadratic equations, so you might want to use it like:

Compute("(1 +- sqrt(5)) / 2")

So then the list resulting from the +- would have to permit division by a scalar, interpreted as applying the division to each member of the list (and similarly other operations). I think Points and Vectors permit multiplication and division, but not lists. And I think adding or subtracting a scalar to a list is not permitted anywhere.

So it would be that

Compute("(1 +- sqrt(5)) / 2")

is equal to

Compute("(1 - sqrt(5), 1 + sqrt(5)) / 2")

is equal to

Compute("(1 - sqrt(5)) / 2, (1 + sqrt(5)) / 2")

Note that to work with lists this way, they need to use delimiters and not be the delimiter-free variety. The middle of these three above would be interpreted as a Point by the parser, but I would change the delimiter settings to make "(" open regular lists.

Is there anything fundamental with MathObjects that would make this impossible? Such as an binary operator on number that outputs a list? Or extending arithmetic operators to make sense when one operand is a scalar and the other is a list?

(And... "+-" or "pm" would ideally also exist as a unary operator.)

In reply to Alex Jordan
Tuesday, 27 February 2018, 4:03 PM

### Re: Plus/Minus operator

by Davide Cervone -
This all looks doable, but I don't have time at the moment to say much more. Instead of making the result be a list, you could also make an object that is a single "number" that includes the two values, but prints with a plus/minus and acts as a single unit rather than a list. We could discuss this if you want to get some ideas from me about how this might work.

In reply to Davide Cervone
Tuesday, 27 February 2018, 6:51 PM

### Re: Plus/Minus operator

by Alex Jordan -
I'd like it to be so that one student could enter "1 pm sqrt(2)" but another could enter "1 + sqrt(2), 1 - sqrt(2)". But you have me thinking now. What to do with things like "1 pm 0" and "1 pm 2 pm 3"? (Some reasonable answers are apparent.)

I'm building a context that attempts to address the common complaints (from our faculty and our students) about answer format being too picky or not in agreement with what is modeled in whatever textbook is used. In particular, with entering the solutions to some equation in one variable. I've got a test problem up at:

https://webwork.pcc.edu/webwork2/html2xml?&answersSubmitted=0&sourceFilePath=local/FiniteSolutionSetsTesting.pg&problemSeed=1&displayMode=MathJax&courseID=anonymous&userID=anonymous&course_password=anonymous&outputformat=simple

It's piecing together various tricks I've learned for dealing with pre-college level math over the years, where format is paradoxically inflexible in some ways and must be very flexible in others.

I will slowly convert all our problems to use this new context. If, one day, it understands "pm", that will just be a silent improvement across the board, added to the context file. Maybe we can chat some time in the future.

Next up, I'm going to experiment with a cousin of bizarroArithmetic that will swap the precedence of things like addition with things like multiplication. I'm hoping I can identify when the student wanted to enter "(a+b)/c", but they typed "a+b/c".

I'm building a context that attempts to address the common complaints (from our faculty and our students) about answer format being too picky or not in agreement with what is modeled in whatever textbook is used. In particular, with entering the solutions to some equation in one variable. I've got a test problem up at:

https://webwork.pcc.edu/webwork2/html2xml?&answersSubmitted=0&sourceFilePath=local/FiniteSolutionSetsTesting.pg&problemSeed=1&displayMode=MathJax&courseID=anonymous&userID=anonymous&course_password=anonymous&outputformat=simple

It's piecing together various tricks I've learned for dealing with pre-college level math over the years, where format is paradoxically inflexible in some ways and must be very flexible in others.

I will slowly convert all our problems to use this new context. If, one day, it understands "pm", that will just be a silent improvement across the board, added to the context file. Maybe we can chat some time in the future.

Next up, I'm going to experiment with a cousin of bizarroArithmetic that will swap the precedence of things like addition with things like multiplication. I'm hoping I can identify when the student wanted to enter "(a+b)/c", but they typed "a+b/c".