Combining sum and difference patterns, polynomial pattern matching

I’m writing an activity to help students with the distributive property using area models. I’m using pattern matching to give them feedback, and I’m stuck on how to check a specific polynomial.

The exercise is to multiply (x+5)(2x-3) , which equals 2x^2+7x-15

I am trying to give them a bit of flexibility in writing this, but I actually can’t figure out how to check that the terms are in this order and allow for both the + and the -

I CAN get Desmos to recognize 2x^2+(7x-15) using p.sum and p.difference, but it insists on the parentheses around 7x-15.

I CAN get it to recognize 2x^2+7x-15 by using p.sum().allowNegativeTerms , but then it’s fine with 2x^2-7x-15 , which is mathematically incorrect.

It’s screen 14 in this activity right now! (If I happen to move it around, it’s 3-67c):

Thanks all!

I generally use both pattern for checking the structure and then plugging in test values for checking the value. If it passes both tests then it is correct. I have coded up something like what you want, though I don’t restrict it to be in standard form.

See if this helps you: repeat and allowNegativeTerms patterns to check trinomial or factored form quadratic • Activity Builder by Desmos

Thanks @Daniel_Wekselgreene !

The combination strikes a good balance between flexibility and structure, and solves my problem!