Check Algebraic Expression Answer

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!

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.
#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
#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.

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

If you’re just trying to compare latex, use backticks instead of quotes. If you’re using computation, it’s probably a good idea to use a graph.

Hi Casey,

Not sure if you already figured this out or not. But you can check out my slides 8, 9 or 10 for the CL to fit what you are looking for. I hope it helps you out.

1 Like

Mr. Grubbs, not sure if this old post is active or monitored in any way, but still trying. Completely novice questions here, but I assume the code you gave is entered in the computation layer for the graph (seems to accept it there for me). Then how and where do you use the “true” or “false” value that you get for check1? I’m not sure on the syntax to turn that “true” into a “correct” for the graph or how to use that variable (check1) in the computation layer for the math input box where the student enters the formula. Any suggestions? Thanks

When setting a correct: sink in a component, you can either put explicit conditions directly after:

correct: this.numericValue=3.5 and this.submitted

or you can use Booleans that have been defined elsewhere:

check= this.numericValue=3.5 and this.submitted
correct: check

In both cases (this being the only component), the dashboard will show a checkmark when correct is true, or an X when false. Since check is a true or false value, correct will always be either true or false, and the dashboard reflects that.

It’s not possible to check equality between 2 or more equal signs is it?

An example is, in one cell writing "2^(6-1)+7=2^(5)+7=(2)(2)(2)(2)(2)+7=32+7 and having a cell suffix that was a checkmark.

There is the activity I will be updating.