I am still trying to wrap my head around patterns. I created a slide that creates a random trinomial to be factored, a not equal to 1.

If there is a GCF, it looks for an answer with 3 factors. The problem is, the answer might have a 2 factored out, but it should be a 4.
How can I compare the “integer” in the answer “pattern” with the GCF?
Is there a way to parse the student answer pattern to grab the integer?

You can call the parse method on a latex string and then run that through the matches method of a different pattern. A good thing to know is the .satisfies method. It works with number and integer (and maybe other things). So if you wanted only positive integers you could have:

valid = p.integer.satisfies("x>0")

To make sure it matches your gcf you could have:

valid = p.integer.satisfies("x=${gcf}")

Here is what I put together for checking a factored form trinomial. It seems a bit convoluted and there may be a better way… but my goal was to make something that works even if there are negatives in the problem, and that would also prevent an answer like (1)(original problem) as being marked correct.

I see what you’re saying about the 1*problem getting marked correctly. I really don’t have a good grasp of patterns.
I was hoping that changing the code you had in yours would fix that:

your code
p=patterns
sum = p.sum(p.repeat(p.expression))
prod2=p.product(sum,sum).matches(sa) and gcf=1

Patterns really took me a lot of practice to get solid on, and I still have trouble getting them right at times.

The code I have won’t mark correct for (1)(problem). I was trying to explain a common error and what I was trying to do in my code. Basically making sure that the expression matches a product of two-term expressions.

Overall, I think my code will do what you want, even if the original problem has negatives in it. If it doesn’t, or if you want me to clarify what some piece of it is doing, just let me know. I’m happy to help.

I made a different version. I got more specific with the expressions instead of p.expression. I also added in a pattern that includes use of an exponent instead of just product for situations like (x+1)^{2}. Let me know if anything is glitchy. I tried to keep it close to yours. Adding .satisfies(`x=${gcf}) to the integer makes it specific to the intended factor. [Copy of] factoring a not 1 • Activity Builder by Desmos

So I am just wondering why the third box on this slide will not work.

box 1: any monomial with an x

box 2: any linear binomial

box3: a product of the two…

What am I missing…

Thanks for your help. The last code you sent me really got me on my way towards figuring this out!
Here is the cut and paste of the code that is used for all three inputs. I just changed the match for each one.

Patterns won’t allow you to nest product patterns, which is what’s happening with a piece of the monomial pattern within the term pattern. I think this should cover your expected monomial*binomial products.