Pattern Match the +- symbol

Hello,

I have not been able to pattern match for the plusminus symbol. Can anyone help me?

Eg I would like students to have to include it in their answer to the final slide of this activity:

Changing the Subject • Activity by Amplify Classroom?

Thank you! Hande

1 Like

The latex for the +- symbol is \pm. You can use simpleFunction or parseEquation to match it, but if you are making a simple equation checker using the Math Response element, just use simpleFunction.

1 Like

Unfortunately, desmos calculator (and consequently patterns) does not recognize +/- as an operation, so you can’t use any evaluative methods like simpleFunction().

You can pattern match the presence of the symbol:

p = patterns
exp = this.latex
hasPlusMinus = p.contains(p.literal(`\pm`)).matches(exp)

If you further want to check for form or use an evaluative method, you can use substituteLatexVariable() to replace the +/- symbol.

expWithPlus =  substituteLatexVariable(exp, `\pm`, `+`)
expWithMinus = substituteLatexVariable(exp, `\pm`, `-`)

You could then use those latex expressions for pattern matching or evaluation.

1 Like

Sorry I was not aware of this, that simpleFunction does not support the \pm thing. Does p.literal only allow one argument, or can I do p.literal(‘\pm’, ‘\mul’)? Also, how would I use substituteLatexVariable if \pm represents a + and a -? I saw you used two variables, but I feel like that’s a little shaky.

1 Like

p.literal() only takes a single argument, matching the latex expression “literally”, so it can be more than just a character, but the more complexity you add, the more variations you need to consider and code separately.

Not sure how you mean “shaky”. \pm is an essentially unrecognized symbol, I’m converting it to exactly what it means, which is two separate expressions, one with + and one with -. They are now in a form that the calculator can understand and I can utilize as I would normally, so I can now use them in simpleFunction() or patterns.

2 Likes