Check Algebraic Expression Answer

I’d like students to input an algebraic expression and tell them it is right or wrong in the note. I don’t think this isn’t too complicated but I’m getting tangled up with latex.

Thanks,
Reggie

You can have problems trying to match the input. It needs to be exactly the same. Any extra spaces and whatnot renders it incorrect. Often, it’s best to evaluate the expressions for a few values to see if it’s correct, but that doesn’t tell if something is simplified or in some particular form. Example for correct answer “2x+4”:

exp1=yourInputName (OR for a table) =yourTableName.cellContent(1,2)
check1= simpleFunction(exp1.latex).evaluateAt(0)=4 and simpleFunction(exp1.latex).evaluateAt(1)=6

check1 will output true or false

1 Like

Thanks for this answer, Daniel. It was helpful for my own activity.

What if the expression evaluates to an inconvenient number (i.e., a non-terminating decimal)? Is there a way to include a check that evaluates a fraction, or do I have to enter an expanded decimal of some kind? If it’s the latter, how many significant figures should I include?

Thanks for this response Daniel. The activity I was creating was asking them to factor a polynomial. With this method won’t they get it “right” if they just repeat the question? I also want to check that they factored completely and every step along the way is equivalent to the original question. I should have been more clear in my question. I’m really looking for a way to check an algebraic expression written in equation form (I think it is called latex)
.

Can you share your activity? It’s a lot easier to figure out and troubleshoot your expectations. However, two ways of checking “equality” are (1) comparing text to text and (2) numeric value. LaTex is a essentially a typesetting program for documentation, a code that includes mathematical notations.

The problem with trying to compare latex in desmos is that even an extra space will render a comparison invalid.

“2x+4” and “2x + 4” (with spaces) are not equivalent as far as the code is concerned. You can teach your students not to use spaces, but there can still be valid expressions it won’t consider equivalent. For example, 2(3x+5) and 2·(3x+5) or 2x+4 and 4+2x

B_Kirk,
I think as far as computation goes, Desmos compares decimals, though I don’t know to how many decimal places. I think it’s around 10, but you could use round() and choose however many decimal places you feel is acceptable or appropriate.

If you want something in fraction form, or for ThinMint’s purposes, a particular expression, you could use countNumberUsage() for part of your check. For example, if you wanted “5x - 3x + 4”

check2= simpleFunction(exp1.latex).evaluateAt(0)=4 and simpleFunction(exp1.latex).evaluateAt(1)=6 and countNumberUsage(exp1,5)=1 and countNumberUsage(exp1,3)=1

Here, check2 would be false if “2x+4” were entered. It evaluates as desired, but doesn’t have one 5 and one 3 in the expression.

Thank you for this response. This is what I ended up doing. I had a help session with John Rowe and he showed me something very similar to this. Thanks again!
Reggie

I want my students to enter “x=4” or “y=2” or some asymptote equation. What does the script look like to check for that?

For x=4

#this creates a function equivalent to the left side of an equation minus the right.
eq1=parseEquation(yourInputName.latex).differenceFunction("x")
#this evaluates eq1 for x=4 and x=5
#if it equals 0 and 5 respectively correct = true
correct = eq1.evaluateAt(4)=0 and eq1.evaluateAt(5)=1

For y=2

#creates a function in terms of x
eq1=simpleFunction(yourInputName.latex)
#checks that evaluating at x=0 and 1 equals 2
correct = eq1.evaluateAt(0)=2 and eq1.evaluateAt(1)=2
1 Like

Hi Desmos,
I am wondering if I am using the countNumberUsage feature correctly in the following activity:

In a simpler instance on slide 2 table 2 of this activity, I use it to determine whether the number 3 has been written in the cell of that table that already has a parentheses and several spaces. Is there a reason why the code does not produce a checkmark when I type “3” in row 1 column 4 of the table?

In a more complicated instance on slide 1 table 1 of this activity, I am using countNumberUsage to check the steps of solving an equation 5x-4=3x-2.

The second step in row 3 of this table should produce a checkmark for 2x-4=-2. If I take away the countUsage line I am using for the cellSuffix of row 3 column 1 and row 3 column 3, it works. However, if I take away the countUsage line, the green checkmark also appears for row 3 if I write 2x = 2 prematurely (this expression should be saved for the next step in solving the equation, which should be put in row 5).

I am using the countNumberUsage feature in row 3 to count whether a value for “b” (in an equation such as y=mx+b) has been included in the student’s input into the table for row 3. If not, then they are moving too fast in solving the equation. I want this to be flexible in case b=0 for one of the 2 initial equations, as this is a template.

Have I used countNumberUsage incorrectly in the “or” statement to count whether a form of “b” is present? Is it possible to fix this?

Thanks for any help.

Right now the two columns (for 2 and 3) are formatted as text. countNumberUsage only accepts latex, so you either need to format them as math, or in your CL code put backticks around table.cellContent(1,2).

Thank you! It works now.

Is there a reason it is not working in slide 1 of the activity in table 1? I am specifically looking at cellSuffix(3,1) and cellSuffix(3,3). It’s not working in the “or” statement that I created for row 3.

Found it. So, countNumberUsage doesn’t take negative values, so you’d need to use absolute values of your various b’s.

Just a suggestion. You could avoid a lot of your or's by using one column for the whole equation. That would only require one set of countNumberUsage. Then, you could use parseEquation(yourCell).differenceFunction("x").evaluateAt(value) = 0 for a few values to check correctness.
Also, trying using “this” to identify the component you’re in, instead of “table”. It makes copying slides easier.

Thank you! I may have to implement your suggestion in order to get this to work. I like the table with the equal sign in the middle because sometimes my students have issues with seeing both sides of the equation. When I say “what you do to one side, do to the other” I love how it is so clear in this table format.

I will create your version for more advanced students.

I have just switched over to replacing each “b” with its absolute value as defined in the graph. I had also tried this method before. It did not work either time. I have updated the attached slides with the absolute values, however, the checkmark is still not appearing for row 3. I will work on creating your version and see if the countUsage function works then.

With your help on understanding the countNumberUsage function, on slide 4 of the activity, I was able to create an alternate version of the above activity that ensures students are solving an equation step by step. I did that by ensuring that either the left side or right side of the equation in row 3 has a “b” variable using the cellNumericValue function- a very easy fix compared to what I was trying to do. This allows for multiple types of equations (including of the type mx+b = b2).
Thank you so much for your help.

1 Like

Hi Daniel,

First, thank you to you and entire Desmos team for building such an amazing learning tool.

I had the same request as ThinMint. Being able to check for a student’s input of the correct algebraic expression would be incredibly useful.

I understand the points you have made in this thread and others:

  1. It is a losing battle to try to match latex input directly due to spaces and other differences such as (x+2)*(x+1) vs. (x+2)(x+1) etc.
  2. A possible solution is to use simpleFunction to compare a few evaluations of the algebraic expression entered by the user vs. the correct algebraic expression.

As was mentioned already, one issue with this possible solution is that for any problem that involves rewriting an algebraic in a different way, this solution will say that a student’s expression is correct, even if the student just enters the same expression they were given.

Given that simpleFunction creates a “function object”, my question is:
is there no way to compare two function objects for equivalence? If there is no way currently, would it be possible to add one?

Such an equivalence relation would return TRUE for the two function objects generated from the following two latex strings, for example:

Latex1 Latex2
(x + 1) (x+1) (only difference is spaces)
(x+1) x+1 (only difference is unneeded parentheses)
(x+2)(x) (x+2)*(x) (only difference is unneeded multiplication symbol)

Such an equivalence relation would return FALSE for function objects generated from the following two latex strings, for example:

Latex1 Latex2
(1+x) (x+1) (Desmos should not need to know commutative property )
3(x+1) 3x+3 (Desmos should not need to know distributive property )
x^2 x*x (Desmos should not need to compare diff. forms of repeated multiplication.)

One positive here is that the requested behavior to return FALSE (above) is that:

  • the behavior could be useful for teachers who are trying to teach the commutative and distributive properties etc. and are looking for algebraic expressions (as answers) in a specific form.
  • the behavior would presumably make this feature easier for Desmos to implement, if it does not exist already.

Thanks. I’m not actually part of the Desmos team, just a user who enjoys the coding puzzles and helping people out.

First, you can use countNumberUsage to identify specific expressions. (See post 6 in this thread).

Second, if you have equivalent expressions, you could just create a function that is the difference of the two. Being equivalent, any value of x should evaluate to zero.
Say you want a student to simplify exp1 in a math input.

exp1=`4x-2x+5`
f= simpleFunction("${exp1} - (${this.latex})")
correct: f.evaluateAt(0)=0 and f.evaluateAt(1)=0 and f.evaluateAt(2)=0
           and countNumberUsage(this.latex,2)=1 
           and countNumberUsage(this.latex,5)=1
           and countNumberUsage(this.latex)=2

It’s also easier to check more values using a table in a graph than to use evaluateAt in the CL.

1 Like

Hi Daniel,
Thank you for the suggestions.
I will send my query to the Desmos team to see what they say.

Hello, I am having a hard time with my correct answer being “-2x^3+4x”. I know it is a simple, but for whatever reason I cannot get it! I just want my content to say “Good Job” for correct answers and “Maybe next time” for wrong answers. HELP!

1 Like