# Patterns product

**URL:** <https://cl.desmos.com/t/patterns-product/4801>\
**Category:** Questions\
**Tags:** patterns\
**Created:** [March 24, 2023, 2:18pm UTC](https://cl.desmos.com/t/patterns-product/4801 "2023-03-24T14:18:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbrigida](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/rbrigida/32/1449_2.png) [@rbrigida](https://cl.desmos.com/u/rbrigida)\
**Post date:** [March 24, 2023, 2:18pm UTC](https://cl.desmos.com/t/patterns-product/4801/1 "2023-03-24T14:18:26Z")

</div>

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?

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/6/6f663598688b844044f0e4bdacc0adae95c17386.png)

> **[factoring a not 1 • Activity by Robert Brigida](https://classroom.amplify.com/activity/641cfe23075b571885686273)**
>
> by Robert Brigida

---

<div class="post-metadata">

**Author:** ![SteinSchreiber](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/steinschreiber/32/2267_2.png) [@SteinSchreiber](https://cl.desmos.com/u/SteinSchreiber)\
**Post date:** [March 24, 2023, 3:16pm UTC](https://cl.desmos.com/t/patterns-product/4801/2 "2023-03-24T15:16:23Z")

</div>

Is this what you are looking for?

 ![Screen Shot 2023-03-24 at 10.14.16 AM](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/6/6b0d40c72da73c4f071d5148b2405ed4850403f0.png)  
 ![Screen Shot 2023-03-24 at 10.14.29 AM](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/a/a39f0a82d09a9b7a4fe5a3fdff0320e9a8cb77f6.png)  
 ![Screen Shot 2023-03-24 at 10.17.00 AM](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/d/de4b096f3da4ed1bbc693d4038d9cb7ca5d0a56e.png)

> **[\[Copy of\] factoring a not 1 • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/641db9c968c8e70f4de044b2)**
>
> by Stein Schreiber

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [March 24, 2023, 4:26pm UTC](https://cl.desmos.com/t/patterns-product/4801/3 "2023-03-24T16:26:27Z")

</div>

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:

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

```

To make sure it matches your gcf you could have:

```auto
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.

> **[patterns - factoring trinomial with a not 1 • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/641dca4f16370ef1e54ebffa)**
>
> by Daniel Wekselgreene

---

<div class="post-metadata">

**Author:** ![rbrigida](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/rbrigida/32/1449_2.png) [@rbrigida](https://cl.desmos.com/u/rbrigida)\
**Post date:** [March 24, 2023, 5:57pm UTC](https://cl.desmos.com/t/patterns-product/4801/4 "2023-03-24T17:57:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [March 24, 2023, 6:42pm UTC](https://cl.desmos.com/t/patterns-product/4801/5 "2023-03-24T18:42:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [March 25, 2023, 6:59pm UTC](https://cl.desmos.com/t/patterns-product/4801/6 "2023-03-25T18:59:28Z")

</div>

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](https://teacher.desmos.com/activitybuilder/custom/641f3ea788ed117928bcb476)

---

<div class="post-metadata">

**Author:** ![rbrigida](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/rbrigida/32/1449_2.png) [@rbrigida](https://cl.desmos.com/u/rbrigida)\
**Post date:** [April 12, 2023, 12:09pm UTC](https://cl.desmos.com/t/patterns-product/4801/7 "2023-04-12T12:09:55Z")

</div>

I am starting to grasp patterns much better.

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.

sa=this.latex

p=patterns  
X=p.literal(`x`)  
monomial=p.anyOf(X,p.number,p.product(p.number,X))  
binomial=p.sum(monomial,p.number).allowNegativeTerms  
term=p.product(monomial,binomial)

correct=term.matches(sa)

suffix: when correct “Yes”  
otherwise “no”

> **[Using patterns • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/64369d30a3d120e0935756c5)**
>
> by Robert Brigida

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [April 13, 2023, 1:56am UTC](https://cl.desmos.com/t/patterns-product/4801/8 "2023-04-13T01:56:59Z")

</div>

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.

```auto
term= p.anyOf(p.product(p.number,X,binomial), p.product( p.anyOf(p.number, X), binomial) )

```

---

<div class="post-metadata">

**Author:** ![willow01nb](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/willow01nb/32/762_2.png) [@willow01nb](https://cl.desmos.com/u/willow01nb)\
**Post date:** [February 11, 2024, 4:54am UTC](https://cl.desmos.com/t/patterns-product/4801/9 "2024-02-11T04:54:17Z")

</div>

Hi,

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:

> **[2.12 Factoring Quadratics using the Area Model/Box Method • Activity Builder...](https://teacher.desmos.com/activitybuilder/custom/65c7da20eaa4df3c2c35b244)**
>
> https://docs.google.com/document/d/1e9T\_FMfG2mJ9GUeI11J4vNwAAwdI\_rfkSTythmCKgLs/edit?usp=sharing

Thanks.

---

<div class="post-metadata">

**Author:** ![ianmcmeek](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/ianmcmeek/32/3966_2.png) [@ianmcmeek](https://cl.desmos.com/u/ianmcmeek)\
**Post date:** [February 13, 2024, 2:34pm UTC](https://cl.desmos.com/t/patterns-product/4801/10 "2024-02-13T14:34:42Z")

</div>

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!
