Evaluating inequalities in the Desmos Computation Layer (CL) is a bit more complicated than evaluating equations, but it’s pretty straightforward when you understand how to use the two conditions of parseInequality evaluation.

*click this link to see a Desmos activity that demonstrates the code used in this post*

## The two conditions

The one thing that you should know about evaluating inequalities in the CL is that there are always two conditions that you have to write: **.isStrict** and **.differenceFunction**

**.isStrict** describes whether the inequality is strict (< or >), or is not strict (≤ or ≥).

**.differenceFunction** for inequalities subtracts the greater than side of the inequality from the less than side of the inequality. This differs from using .differenceFunction with parseEquation, which subtracts the left side of the equation from the right side of the equation.

Here’s a basic setup, with a “Note” item asking the question and a “Math Input” item for student input:

To evaluate the correctness of the inequality, I would use the following code in the CL of the “Math Input” item:

```
correct:
not(parseInequality(input1.latex).isStrict) and
parseInequality(input1.latex).differenceFunction("x","y").evaluateAt(7,11)=1
```

The first part of the correct condition, `not(parseInequality(input1.latex).isStrict)`

, defines that this is not a strict inequality.

The second part of the correct condition, `parseInequality(input1.latex).differenceFunction("x","y").evaluateAt(7,11)=1`

says to separate the inequalities into left and right sides, to substitute 7 for x and substitute 11 for y, and then to subtract the “greater than” side from the “less than” side to get the difference of 1.

One of the correct answers for this problem, 3+x≤y would be evaluated by this .differenceFunction as 11-(3+7)=1 – therefore correct.

The biggest benefit of this type of evaluation is that any equivalent inequality would be evaluated as correct, such as 0≤y-x-3 (.differenceFunction evaluates this as 11-7-3-0=1) or -3≥x-y (.differenceFunction evaluates this as -3-(7-11)=1).

## how to graph an inequality using parseInequality

You can graph an inequality in a Desmos activity from a “Math Input” with variations on the code. Here’s a example setup with a “Note” item, a “Math Input” item, and a “Graph” item:

In this example, I am going to put the following code in the CL of the graph:

```
function("a"): parseInequality(input2.latex).differenceFunction("x","y")
number("z"):
when parseInequality(input2.latex).isStrict 1
when not(parseInequality(input2.latex).isStrict) 2
otherwise 0
```

This code starts by defining a function, “a.” Notice that the .differenceFunction terminates after identifying the variables (instead of evaluating using the .evaluateAt command as we did to identify the correct condition). This is because we want the graph to show every possible solution to this inequality.

The second part of the code defines a number, “z.” This number determine whether we graph the inequality as strict (when z=1) or not strict (z=2). When there is no inequality, the otherwise condition is z=0. These will make more sense when we look at the graph input.

In the graph inputs, we’ll put two inequalities: one for a strict inequality and one for an inequality that is not strict.

The first input in the graph, `0<a(x,y){z=1}`

evaluates the input inequality for all values where the result of the “greater than” side minus the “less than” side is greater than 0, or more simply: it graphs all of the possible solutions to this inequality. The `{z=1}`

restricts this graph only to appear when the inequality is strict (recall that we defined the z=1 as the value when the inequality is strict).

The second input in the graph, ` 0≤a(x,y){z=2}`

evaluates the input inequality for all values where the result of the “greater than” side minus the “less than” side is greater than or equal to 0. The `{z=2}`

restricts this graph only to appear when the inequality is not strict.

## Leave a Reply