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.

Bruce Rhodewalt says

I have two questions about your first example:

1. Why (7,11)? I see this point is in the true region, but so is (7,12), and when I change the CL to check for (7,12), this doesn’t work.

2. Where in the code is the equation of the boundary line?

A general question: Where is the documentation for the methods of parseInequality?

Thanks!

jimdougherty says

Hi Bruce,

1. In that parseInequality evaluation I wrote it such that 7 is substituted for x and 11 is substituted for y (evaluateAt(7,11)=1) – the 1 is the difference between the greater than side and the lesser than side, in the example I give the new equation would be 3+7 /le 11, and 11-(3+7)=1. It’s not a gauge of whether the point given is correct, it is actually an evaluation of greater side minus lesser side.

2. Re the boundary line: the =1 actually identifies the boundary line. For example, (7,10) would be the solution that lies on the boundary line (3+7=10), but you wouldn’t want to evaluate a difference function that equals zero because that would show the incorrect inequality 3+7 /ge 11 to be true as well as 3+7 /le 11. So the =1 in this example identifies the side of the inequality that is correct and also identifies that the solution y is 1 unit from the boundary line when x=7. I hope that makes sense?

General question: here is the specific link to the desmos documentation: https://teacher.desmos.com/computation-layer/documentation#function:parseInequality