NAME

Context("Inequalities"), Context("Inequalities-Only") - Provides contexts that allow intervals to be specified as inequalities.

DESCRIPTION

Implements contexts that provides for inequalities that produce the cooresponding Interval, Set or Union MathObjects. There are two such contexts: Context("Inequalities"), in which both intervals and inequalities are defined, and Context("Inequalities-Only"), which allows only inequalities as a means of producing intervals.

USAGE

loadMacros("contextInequalities.pl");

Context("Inequalities");
$S1 = Compute("1 < x <= 4");
$S2 = Inequality("(1,4]");     # force interval to be inequality

Context("Inequalities-Only");
$S1 = Compute("1 < x <= 4");
$S2 = Inequality("(1,4]");     # generates an error

$S3 = Compute("x < -2 or x > 2");  # forms the Union (-inf,-2) U (2,inf)
$S4 = Compute("x > 2 and x <= 4"); # forms the Interval (2,4]
$S5 = Compute("x = 1");            # forms the Set
$S6 = Compute("x != 1");           # forms the Union (-inf,1) U (1,inf)

You can set the "noneWord" flag to specify the string to use when the inequalities specify the empty set. By default, it is "NONE", but you can change it to other strings. Be sure that you use a string that is defined in the Context, however, if you expect the student to be able to enter it. For example

Context("Inequalities");
Context()->constants->add(EmptySet => Set());
Context()->flags->set(noneWord=>"EmptySet");

creates an empty set as a named constant and uses that name.

In addition to the noneWord flag, the inequality contexts accept the following additional flags:

showNotEquals

This controls whether intervals of the form (-inf,a) U (a,inf) are displayed as x != a or not. The default is 1, meaning convert to x != a.

allowSloppyInequalities

This controls whether <= and >= can also be represented by =< and => or not. By default, both forms are allowed, to allow maximum flexibility in student answers, but if set to 0, only the first forms are allowed.

Inequalities and interval notation both can coexist side by side, but you may wish to convert from one to the other. Use Inequality() to convert from an Interval, Set or Union to an Inequality, and use Interval(), Set(), or Union() to convert from an Inequality object to one in interval notation. For example:

$I0 = Compute("(1,2]");            # the interval (1,2]
$I1 = Inequality($I1);             # the inequality 1 < x <= 2

$I0 = Compute("1 < x <= 2");       # the inequality 1 < x <= 2
$I1 = Interval($I0);               # the interval (1,2]

Note that ineqaulities and inervals can be compared and combined regardless of the format, so $I0 == $I1 is true in either example above.

Since Inequality objects are actually Interval objects, the variable used to create them doesn't matter. That is,

$I0 = Compute("1 < x <= 2");
$I1 = Compute("1 < y <= 2");

would both produce the same interval, so $I0 == $I1 would be true in this case. If you need to distinguish between these two, use

$I0 == $I1 && $I0->{varName} eq $I1->{varName}

instead.