Pattern Matching Equations

Hello,

I’m trying to check an input equation for the proper coefficients and units on each side–we’re solving equations with the variable on both sides, and I want them to do just the first step of combining like terms. Since I specifically don’t want it solved yet, I can’t use parseEquation.differenceFunction, so I’m using patterns instead.

I have the left-hand side working, but the right-hand side is giving me grief for some reason. I’m pretty new to patterns, so I’m hoping I’ve just overlooked something obvious.

TIA!

The subtraction on the right-hand side is what’s throwing things off right now - the sum pattern specifically looks for an addition sign. You can use p.anyOf with your original pattern and then a similar pattern that swaps out p.sum for p.difference. Here’s your original activity with that tweak in place -

1 Like

Excellent! Thank you so much!