# CL correct for writing equations of a line in specific forms

I have some understanding of writing CL for checking if a student is correct on writing an equation in any form:
#for y=0.5x+10
f = parseEquation(this.cellContent(1,1)).differenceFunction(“x”,“y”)
correct: (f.evaluateAt(0,10)=0 and f.evaluateAt(-20,0)=0)

Is there a way to check if the student has written a correct equation in a very specific form (ie point slope form). I want to make sure they know how to write the different forms and be able to convert to another specified form like to slope intercept or to standard.

This is where pattern matching comes into its own. It takes a bit of getting your head around and is not fully documented yet, but essentially something like this should work:

``````p=patterns
x=p.literal(`x`)
y=p.literal(`y`)
lhs=p.anyOf(p.sum(y,p.number),p.difference(y,p.number))
rhs=p.product(p.anyOf(p.number,p.fraction(p.number,p.number)),p.anyOf(p.sum(x,p.number),p.difference(x,p.number)))

expr=parseEquation(this.latex)
lhsmatch=lhs.matches(expr.lhs)
rhsmatch=rhs.matches(expr.rhs)

errorMessage: when lhsmatch and rhsmatch "" otherwise "Not in correct form"
``````

It takes some getting your head around if you’ve not used it before, so let us know if there’s anything there that doesn’t make sense or you can’t work out how to implement it into your activity.

Thank you for such a fast reply!

Some of this makes sense but I’m still learning here. I’m assuming “number” is where I am putting an actual number? Let’s try something specific. I want the student to enter `y=x+2`. How would I program this so that this is the specific form of an answer without writing all the various latex forms? And I would like this to show a check on the teacher dashboard if it is correct.

Thank you!

In all cases (forgot to mention this originally), I would still use simpleFunction to handle the checking that the equation itself is correct - pattern matching is only really to verify the correct form. So p.number doesn’t get replaced with an actual number - it’s just telling the pattern matcher to make sure there’s some number there.

For `y=x+2`, you’d use simpleFunction to make sure it evaluated correctly, then something like:

``````p=patterns
lhs=p.literal(`y`)
rhs=p.sum(p.literal(`x`),p.number)

expr=parseEquation(this.latex)
lhsmatch=lhs.matches(expr.lhs)
rhsmatch=rhs.matches(expr.rhs)

errorMessage: when lhsmatch and rhsmatch "" otherwise "Not in correct form"
``````

Instead of p.number on the third line, you could use `p.literal("2")` or `p.number.satisfies(`x=2`)` to force it to check for the sum of x and 2… but like I say, I much prefer to use pattern matching to check the form, and simpleFunction to check the values.

Thank you.

I have tried adding this to my CL after my parseEquation check and it doesn’t seem to be working.

Here is the link to my activity. I am only focused on slide 2, very last question. I will also have to try to figure out the CL for writing the equation in point slope form.

Thank you, again for your assistance.

I think you forgot the link. If you can let us have it, I’m happy to have a look and see what I can spot.

What do you mean precisely by “not working”?

I can’t believe I forgot the link! 4.3: Investigation 8 • Activity Builder by Desmos

This morning I tackled the problem again and I was able to get it to work! I used the CL from another post. This is what I have:

myLine = xyLine(this.latex)

slope = myLine.slope

yInt = myLine.yIntercept

check = (slope = -1 and yInt = 2 and slopeIntForm)

correct: check

f=simpleFunction(parseEquation(this.latex).lhs,“y”)

slopeIntForm = f.evaluateAt(0)=0 and f.evaluateAt(2)=2

disableEvaluation: true

showSubmitButton: true

resetLabel: when this.submitted (when check “” otherwise “”) otherwise “”

This CL checks for slope-intercept form. Is there a way to get point-slope form and standard form?

The bulk of the code I gave in post 2 checks for point-slope form - you just need to add `and lhsmatch and rhsmatch` to your correct condition.

Something like, in full:

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

p=patterns
x=p.literal(`x`)
y=p.literal(`y`)
lhs=p.anyOf(p.sum(y,p.number),p.difference(y,p.number))
rhs=p.product(p.anyOf(p.number,p.fraction(p.number,p.number)),p.anyOf(p.sum(x,p.number),p.difference(x,p.number)))

expr=parseEquation(this.latex)
lhsmatch=lhs.matches(expr.lhs)
rhsmatch=rhs.matches(expr.rhs)

isCorrect = f.evaluateAt(0,2)=0 and f.evaluateAt(2,0)=0 and lhsmatch and rhsmatch
correct: isCorrect

disableEvaluation: true

showSubmitButton: true

resetLabel: when this.submitted (when isCorrect "✅" otherwise "❌") otherwise ""
``````

I’m not sure what “standard form” of an equation of a line is - what does this look like? (I don’t think we use that expression over here in the UK…)

1 Like

Standard Form is Ax+By=C, where A, B, and C are integers.

1 Like

standard form is ax+by=c

1 Like

Thanks both. Every day’s a school day!

This works wonderfully for the point-slope form!!! Thank you!!!