Evaluate a student expression using inputs from the graph

I feel like I’m reaching my question quota limit over these last two days so my apologies…

Is there a way to take an expression like “x>5” that was given by a student through an input and test variables from the graph within the expression? [It almost feels like I’d need some kind of “find and replace” function to use on the student input.]
Like student moves points (a,0), (b,0) and (c,0) on the number line to 4, 5, and 6 and I check to see that all values work within the student expression. Right now I have the student expression graphing with the points showing so visually a student could see it isn’t working but that’s it.
My goal is to have some response text if the values on the number line don’t mesh with the inequality a student is entering. Essentially I’m wanting a way to compare the student entered inequality with the correct inequality.

1 Like

I know it uses rawExpression but in the past I’ve (1) used raw expression to graph x>? (2) created a simple function (in your case 0x) and set the restriction to the expression latex (3) created each point as a part of that function (a,f(a)) (b,f(b) (c,f© or whatever you are planning. That way the points only show up when they fall within the solution of the inequality. You can make hollow points or something to show where they are before submitting and then have them fill in after if you’d like.

1 Like

There’s no question quota - keep it up.

We’d like to have better support for inequalities, but one thing you can do now is something like this:

studentInput = input.latex
a = graph.number("a")

f = simpleFunction("\\{${studentInput}:1,0\\}")
testResult = f.evaluateAt(a)
content:
when isUndefined(f) "Please enter an inequality, like x>0"
when testResult = 1 "Your test point, ${a} satisfies your inequality"
otherwise "Your test point, ${a} does not satisfy your inequality"

You can see this at Inequality demo • Activity Builder by Desmos

2 Likes

Eric,
This is perfect and very helpful. Thank you so much!

1 Like

What am I doing wrong with this code? I get an error on my second “when” statement that says --syntax error: expected token ‘=’

studentInput = exp1.latex
a = graph1.number("a")
b = graph1.number("b")
c = graph1.number("c")
d = graph1.number("d")

f = simpleFunction("\\{${studentInput}:1,0\\}")
testResult1 = f.evaluateAt(a)
testResult2 = f.evaluateAt(b)
testResult3 = f.evaluateAt(c)
testResult4 = f.evaluateAt(d)
content:
"1. Move the four points to represent represent four different numbers that are more than 5."
when isUndefined(f) "2. Write an inequality that works for all points that are more than 5, like x>0"
when testResult1 = 1 and testResult2 = 1 and testResult3 = 1 and testResult4 = 1 "Your test points all satisfy your inequality."
otherwise "Not all your test points satisfy your inequality."
1 Like

You can’t just put the “when” in the middle of the message you’re writing. You need to do something to build it up from pieces like:

step2instructions =
when isUndefined(f) "Please define f"
otherwise "Thanks for defining f"

and then you can include it in the text like:

content: "Move the four points.  ${step2instructions}"
1 Like

Ok, that makes sense. Thank you!

1 Like

That’s just our conditional syntax. So if the studentInput evaluates to a true statement, the result of that expression is 1, otherwise it’s 0. That lets you check truthiness of some calculation simply by looking at a numeric value.

2 Likes

How would this work if you wanted the test point to be of the form (0, a) rather than (a, 0)?

I tried adapting it, but it didn’t work. Thanks.

I am making an activity guiding students through domain and range, and I need to be able to check inequalities using “y” rather than “x” in order to do the range.

Here is an example of the kind of thing I want to do. I am able to use

f = simpleFunction("\\{${studentInput}:1,0\\}")

to check correctness of the domain questions, but cannot use the same script to check correctness of the range questions, because the range uses the variable y.

Is there a way to compute correctness using y, or to replace all instances of “y” in the latex to an “x” and then compute correctness?

f = simpleFunction("\\{${studentInput}:1,0\\}","y")

will make a function of y

additionally: f = simpleFunction("\\{${studentInput}:1,0\\}","x","y") will make a function of x and y

Thanks, I was not putting separate quote marks around the “${StudentInput}” part and the “y”. That was my problem.