Pattern Matching

Try using term1 or term2 instead of minuend or subtrahend. This works for sum and product patterns. This code would parse the denominator of the second fraction that is added.

frac = patterns.fraction(patterns.number, patterns.expression)
diff = patterns.difference(frac,frac)
den = sum.parse(this.cellContent(1,1)).term2.denominator.latex
1 Like

Hi Jay,

This looks really cool and powerful. I’m trying to parse something like this:
4f(1/3(x-5))+7

But, currently I’m having issues with

I guess it is a:
sum(product(number,“f”,number,(difference(x,number))))

But, it appears to not care what order the product comes in. So, 4f(x), f*4x 4(x-3)f" would all parse fine, and I can just make the assumption that they are entering it correctly, but I’m struggling to get it to recognize the difference between 3f(x) and f(3x).

This is what I have so far, look at tab 7, in the nTransformed CL:

Is support for function notation coming soon?

I’m no expert. There are some issues with product patterns and parentheses. I think there’s a way to parse each term of a product or sum, which would let you get more specific.
Maybe look at this one.

Yeah, I’m using term1 and term2 in my product. But it appears that the order the products appear don’t matter, so if I want a product of the form “f”, number, “x”. It recognizes them in any order:

f(4x)
4f(x)
x4f

all seem to match

F = p.literal(“f”)
X = p.literal(“x”)
Number = p.anyOf(p.number,p.fraction(p.number,p.number),p.negative(p.fraction(p.number,p.number)))

patterns.product(F, number, X)

(edit, I realized that my work in on tab 5, not tab 7.)

I mean you might be able to parse term1 and term2 and check that they are what you want them to be. I just haven’t played with it much so I’m not sure exactly how it works.

This is a result of the calculator interpreting f() as function notation and not as a product. It’s something we’ve been looking into ways of improving.

Except in this situation it is exactly the opposite, it is treating it as a product when I want it to recognize it as function notation.

Is there a way to truly enforce that the order is recognized? I guess maybe I could do some extra comparisons to find out if term 2 is p.literal(“f”) and then determine if the number is a or b based on that.

Oooh! Looks like the change went through! Apologies, sometimes I’m not aware when the switch is flipped.

In this case you can use .strictOrder to make sure that the product matches the order in which the terms are listed. e.g.
p.product(p.number,p.literal(f)).strictOrder
looks specifically for a number followed by f.

4 Likes

Awesome! Thanks, I’ll try that.

Beautiful! I got this working:

Again, look at slide 5. The one issue that I still seem to be having is that if I do -f(x+4)-3. The flip at the front is not interpreted and it breaks the rest of the interpretations. Do I need to include a p.literal("-") as an option?

Could you use the p.negative pattern?

What I’ve done right now is just tell students that they need to include -1 not just -.

Nevermind. I found it…

Never mind, found it.