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.

My goal is to ensure that a student enters an expression such as:
-30x^2 divided by -3x
There must be an integer (the “a” times “c” value in ax^2+bx+c) before the x-squared, there must be a division or fraction sign, and there must be an integer before the x.

I also want to check the left hand side of the equation once they enter:

-30x^2 divided by -3x= 10x

to ensure the pattern is still matching after they put what it equals.

Here is the code I have used for the 1st part of just checking -30x^2 div -3x

New: divisio1n=p.division((p.integer, p.exponent(p.literal(“x”),p.literal(“2”))), p.product(p.integer,p.literal(“x”)))
(there is an error after the 3rd parentheses in p.literal(“2”))) for the above code that says “syntax error: Expected =>”

Old (after realizing you cannot put nested patterns in the product pattern):
divisio1n=patterns.division(patterns.product(patterns.integer,patterns.exponent(patterns.literal(“x”),patterns.literal(“2”))), patterns.product(patterns.integer,patterns.literal(“x”)))

match=divisio1n.matches(g1.labelLatex(“d_8”))
feedback=when match “yes” otherwise “no”
diviso1nexpression=divisio1n.parse(g1.labelLatex(“d_8”)).dividend.latex

However, the “feedback” is saying an expression like -30x^2 divided by -3x is not matching the pattern. How can I edit the code?

Here is the activity I am working on (slide 1, graph p1 is the code), but it is currently in disarray:

Hi! It looks like your old version was correct. The expression you shared registers as a match if you put parentheses around -3x to clarify order of operations (without parentheses Desmos interprets your expression as dividing by -3 and then multiplying by x). One possible way around this would be to have students enter their answer in the form of a fraction and use the fraction pattern instead of the division pattern. I hope that helps!