# Issue with Pattern

In the ip6a box - it is grading as correct when the standard form is written as an expression (no y=) but not when written as an equation (with the y=).

How do I change the pattern to require the equation instead of the expression?

Thanks so much for your help!

You could use parseEquation( ).differenceFunction( ) to graph instead of simpleFunction( ). You’d use `0=f(x,y)` to graph it.

This would check if it’s an equation at all:

``````when isUndefined(parseEquation(this.latex)) "Not an equation"
``````

As to the pattern matching, you can use parseEquation( ).lhs or .rhs to pattern match one side of the equation.

There may also be an issue with the answer being a combination of sum and difference. I haven’t worked enough with it to give you a definite though.

Thanks for your help! I haven’t used parseEquation before, could you tell me how to add that to the code I have?

submitLabel: “Check my Standard Form equation”

p=patterns

standard=p.anyOf(
p.difference(p.expression,p.expression,p.expression),
p.difference(p.expression,p.expression),
p.sum(p.expression,p.expression,p.expression),
p.sum(p.expression,p.expression)
)

errorMessage: when not(standard.matches(this.latex)) “Did you write your equation in standard form?” otherwise “”

fn1 = simpleFunction(this.latex)

disableEvaluation: true

checkfunction = fn1.evaluateAt(-2) = -10 and fn1.evaluateAt(2) = -6 and fn1.evaluateAt(1) = -10

correct = checkfunction and standard.matches(this.latex)
correct: checkfunction and standard.matches(this.latex)

This checks if y= is entered on the left hand side, although Daniel’s suggestion would work too. This wouldn’t work if a student enters f(x) though, which is why it might be better to check if the equation is defined. To alleviate that, you could just put in the errorMessage to enter a standard form equation starting with y=.

``````submitLabel: "Check my Standard Form equation"

left = parseEquation(this.latex).lhs
right = parseEquation(this.latex).rhs

p=patterns

matchLeft = p.literal("y").matches(left)

standard=p.anyOf(
p.difference(p.expression,p.expression,p.expression),
p.difference(p.expression,p.expression),
p.sum(p.expression,p.expression,p.expression),
p.sum(p.expression,p.expression)
)

matchRight = standard.matches(right)

errorMessage: when not(matchRight) or not(matchLeft) "Did you write your equation in standard form?" otherwise ""

fn1 = simpleFunction(this.latex)

disableEvaluation: true

correct = fn1.evaluateAt(-2) = -10 and fn1.evaluateAt(2) = -6 and fn1.evaluateAt(1) = -10

correct: correct
``````
``````errorMessage: when isUndefined(parseEquation(this.latex)) or
not(standard.matches(parseEquation(this.latex).lhs)) "Did you write your equation in standard form?"
otherwise ""
``````

Then change this:

``````fn1= parseEquation(this.latex).differenceFunction("x","y")
``````

In the graph component:

``````function(`f`): ip6a.script.fn1
``````

In the graph

``````0=f(x,y)
``````

I sincerely appreciate all of the help. I tried both of your ideas (on pages 2 and 3, attached). On one I am getting an error in the computation layer, and in the other it still isn’t “grading” correctly when typed in and is still getting a red x instead of a green check.

I was wondering if you could help me finish this up?

Thank you SO much!

The error in ip6a is that since the difference function (which is lhs - rhs) is in terms of x and y you need to put both x and y in evaluateAt. Solutions to the differenceFunction should always equal 0:

``````checkfunction = fn1.evaluateAt(-2,-10) = 0 and fn1.evaluateAt(2,-6) = 0 and fn1.evaluateAt(1,-10) = 0
``````