`contextInequailities.pl`

macro file.
To answer your questions:

- Yes, you can use
`Compute("p < $r")`

(provided you have added the variable "p" to your context).

Yes you can use

`Compute("$r1 < p < $r2")`

or `Compute("$r1 <= p < $r2")`

and so on. You can even use `Compute("$r1 <= p and p < $r2")`

, or `Compute("p < $r1 or p > $r2")`

.
No,

`p < $r1`

is equivalent to the interval `(-infinity,$r1)`

, while `0 <= p`

is the interval `[0,$r1)`

. These are not equal.
There are a couple of things to keep in mind. First, inequalities are a special way of specifying intervals, so the variable used is not taken into account (so `x > 2`

is the same as `y > 2`

). If you want the variable to count, you need to use a custom checker, such as

Context("Inequalities-Only"); Context()->variables->add(y => 'Real'); $I = Compute("x < 5"); ... ANS($I->cmp(checker => sub { my ($correct,$student,$ans) = @_; return $correct == $student && $correct->{varName} eq $student->{varName}; }));Here

`x < 5`

will be marked correct, but `y < 5`

will not. You could add code to give a hint like "You variable is not the correct one" if the variables don't match rather than just marking it incorrect.
Of course, it is not all that convenient to have to add that to each inequality, so you could use

Context("Inequalities-Only"); Context()->{cmpDefaults}{Inequality}{checker} = sub { my ($correct,$student,$ans) = @_; return $correct == $student && ($correct->{varName}||"") eq ($student->{varName}||""); }; Context()->{cmpDefaults}{Inequality}{list_checker} = sub { my ($correct,$student,$ans) = ($_[2]->{correct_value},$_[2]->{student_value},$_[2]); my ($score,@errors) = $correct->cmp_list_compare(@_); $score = 0 if $score && $correct->{varName} ne $student->{varName}; return ($score,@errors); }; Context()->{cmpDefaults}{Inequality}{list_type} = "an Inequality";so that every inequality uses the custom checker. Here we also add a

`list_checker`

since sets and unions are implemented as lists, so this is needed for answers like `x = 5`

, or `x < 1 or x > 5`

.
This stuff probably should be made available in the `contextInequalities.pl`

file, but they currently aren't, but you could make your own macro file that does this (or better creates a copy of the Inequalities-Only context and modifies that).

To handle the issue of negative numbers, you could use

Context()->{cmpDefaults}{Inequality}{checker} = sub { my ($correct,$student,$ans) = @_; return $correct == $student unless $correct->type eq "Interval"; $correct = $correct->intersect("$correct->{varName} >= 0") if $correct->{leftInfinite} && $correct->{data}[1]->value > 0; $student = $student->intersect("$student->{varName} >= 0") if $student->{leftInfinite} && $student->{data}[1]->value > 0; return $correct == $student && $correct->{varName} eq $student->{varName}; };instead, which prevents intervals from extending past 0.