Comparing latex values

I’m getting confused on what the CL views as the latex for an expression entered as |x-1|=3. Can I use that as a string to determine if that is what they’ve entered or is the CL looking for “\left|x-1\right|=3” or something else entirely?
What I’m trying to use this for is with marking something correct in the dashboard. I saw some other questions related to this but what I’m really looking for to be cleared up is what string exactly does .latex return from a student input to background CL operation?
correct: exp1.latex="abs(x-1)=3"
vs
correct: exp1.latex="\left|x-1\right|=3"
vs
correct: exp1.latex="|x-1|=3"

2 Likes

The short answer here is that you shouldn’t rely on a student’s entered LaTeX matching a particular form in order to determine correctness. There are just too many ways to enter something equivalent to the correct answer to enumerate them all with string checking.

The two main purposes of the latex source are to (1) display what the student has entered somewhere else in a nicely typeset form, and (2) put the entered math text into the calculator for use in computation.

That’s why it’s not super important to understand “what CL views as the LaTeX” that gets entered: it’s always a form that the system recognizes for typesetting or for use in the calculator (which are basically the same thing). You should pretty much consider those details to be opaque. Almost anything you try to check about raw LaTeX strings will end up biting you.

In this particular case, I think your best move is probably to use the student input inside of a function that returns a 1 at the values you’re interested in, and a 0 otherwise. That way you’ll catch things like |-1+x|=3 or |x-1|=3+12-10+(-2) or whatever.

f = simpleFunction("\\{${input.latex}:1,0\\}")

firstSoln = (f.evaluateAt(-2) = 1)
secondSoln = (f.evaluateAt(4) = 1)

# Add a check to make sure that *everything* isn't a solution.
# This rules out the case that the student entered an identity like `x=x`.
nonSoln = (f.evaluateAt(0) = 0)

correct: (firstSoln and secondSoln and nonSoln)

I just want to note that this kind of solution has some important limitations to keep in mind. For one thing, it’s possible to get false positives: if a student writes something that matches those three checks, it will be marked as correct, and the target equation isn’t the only one that will pass those checks. (Adding a check that 0 isn’t a solution at least rules out one case where the student entered something trivially true.) The other problem is that you end up using an exact equality check in the condition (checking that something is exactly equal to 3). This works in this relatively simple case because everything ends up being integers. But exact equality checks with decimal values are really unreliable because of floating-point rounding error.

Unfortunately, what you really want here are some better parsing tools that we just don’t provide yet. But having use cases like this from actual users wanting to do actual things helps shape our development.

1 Like

Thanks for the detailed response, that all makes sense. Yes, I can see some issues with the checking three points idea too. Will probably leave that check out of the activity for now.

1 Like

Being able to set the correct flag to false without having to also set it to true is something that would help clarify these limitations.

For instance, if I just substituted three values I could ascertain that the answer provided was “probably correct”, but I could also determine in some cases that an answer was “definitely incorrect”.

For this reason, I would love to be able to do something like

correct:
    when not(firstSoln and secondSoln and nonSoln) false
    otherwise undefined 

The dashboard would then just display a dot whenever the correct flag was undefined (like other ungradable content).

1 Like

Here’s a use case where I’d really like to be able to check the string that students have entered: I want to make sure students can enter an expression for their work, not just calculate a numerical value. That is, I want to see that students can enter 2(5) + 7, not just 17. That’s because arriving at the value of 17 can be done in two separate expressions… 2(5) followed by 10+7…but students have to begin doing the problem in just one expression if they’re going to generalize to an algebraic expression like 2x+7.

1 Like

I am trying to compare students’ expression input to a target expression with 2 variables. I want to be able to check that students have entered w^2 - 2a^2 as their input on the following screen:

Does the strategy you outline above work for multivariable expressions? I’m having trouble with this piece. Thanks.

1 Like

I figured it out. If anyone wants to check it out, you can see here: Mystery Area • Activity Builder by Desmos

2 Likes

I know this was posted 2 years ago, but TeacherLearner thanks so much. This is exactly what I needed (how to evaluate the input expression as correct). Still so new to this. Thanks again.

1 Like

Hi Desmos,

First, thank the entire Desmos team for building such an amazing learning tool.

I have a question that is similar to Andy’s. Being able to check for a student’s input of the correct algebraic expression would be incredibly useful.

I understand the points you and others 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 for the feature request. We don’t have any methods currently to differentiate between two strings that are commutatively equivalent and use the the same numbers. For answers like that we’re big fans of card sorts or even multiple choice.

Personally, I love showing two solutions and asking which is correct. (first, second, both, or neither?)

Hi Jay,

Thank you for the speedy reply. Actually my request was not for a method that compares two latex strings.

My request was for a method that compares the programmatic representation of those latex expressions (the function objects) that Desmos has, which Desmos uses to evaluate the functions. Desmos evaluates the functions using values supplied for the variables (referenced by the functions).

As I mentioned in my original request, this has at least two advantages over the approach (typically recommended by Desmos) of evaluating the functions at multiple values.

I only made the request because I thought it would be relatively “easy” to implement, since the function objects already exist.

Got it. I’ll add this to our feature requests. Thanks!

I’m having an issue where a student types (3,4) (coordinates) into the math input, and I compare that to the string “(3,4)” and Desmos says they don’t match. How do I check students’ coordinates?

checkX= parseOrderedPair(this.latex)=3
checkY= parseOrderedPair(this.latex)=4

Thanks. That worked.

I’m trying to modify the code sample you gave for another example and I was wondering what the purpose of the :1,0 is?

Not sure what you’re looking at, but you’re probably looking at a conditional of the format:
{condition: output1, output2}

If the condition is true, then output1, otherwise output2.

1 Like