Inequalities "less than" and "greater than"
This functionality does not run in MATLAB.
x < y
x > y
_less(x
,y
)
x < y
and x > y
define
inequalities.
x < y
represents the Boolean statement
"x
is less than y
".
It is equivalent to the function call _less(x,y)
.
x > y
represents the Boolean statement
"x
is greater than y
".
It is always converted to y < x
, which is equivalent
to the function call _less(y,x)
.
These operators return symbolic Boolean expressions. If only
real numbers of Type::Real
are
involved, these expressions can be evaluated to TRUE
or FALSE
by
the function bool
.
They also serve as control conditions in if
, repeat
, and while
statements. For floatingpoint intervals, these operators
are interpreted as "strictly less than" and "strictly
greater than". See Example 2. Further, Boolean expressions can be evaluated to TRUE
, FALSE
,
or UNKNOWN
by
the function is
.
Tests using is
can
also be applied to constant symbolic expressions. See Example 4.
bool
also
handles inequalities involving character strings. It compares them
with respect to the lexicographical ordering.
Inequalities have two operands: the left side and the right
side. Use lhs
and rhs
to extract these
operands.
The operators <
and >
produce
symbolic inequalities. They can be evaluated to TRUE
or FALSE
by
the function bool
if
only real numbers of type Type::Real
(integers,
rationals, and floats) are involved:
1.4 < 3/2; bool(%)
Comparison of intervals is interpreted as "strict", that is, all combinations of numbers in the intervals must fulfill the relation:
bool(0...1 < 2...3), bool(0...2 < 1...3), bool(0...1 < 1...2)
Compare character strings:
if "text" < "t"."e"."x"."t"."book" then "yes" else "no" end
bool("a" > "b")
Note that bool
does not perform symbolic
simplification and therefore cannot handle some combinations of symbolic
expressions. Use the function is
for comparisons requiring symbolic
simplification:
bool(sqrt(6) < sqrt(2)*sqrt(3))
Error: Cannot evaluate to Boolean. [_less]
is(sqrt(6) < sqrt(2)*sqrt(3))
Inequalities are valid input objects for the system function solve
:
solve(x^2  2*x < 3, x)
The operator <
can be overloaded by
userdefined domains:
myDom := newDomain("myDom"): myDom::print := x > extop(x):
Without overloading _less
or _leequal
,
elements of this domain cannot be compared:
x := new(myDom, PI): y := new(myDom, sqrt(10)): bool(x < y)
Error: Cannot evaluate to Boolean. [_less]
Now, define a slot"_less"
.
This slot is called when an inequality of type "_less"
is
evaluated by bool
.
The slot compares floatingpoint approximations if the arguments are
not of type Type::Real
:
myDom::_less := proc(x, y) begin x := extop(x, 1): y := extop(y, 1): if not testtype(x, Type::Real) then x := float(x): if not testtype(x, Type::Real) then error("cannot compare") end_if end_if: if not testtype(y, Type::Real) then y := float(y): if not testtype(y, Type::Real) then error("cannot compare") end_if end_if: bool(x < y) end_proc:
x, y, bool(x < y), bool(x > y)
bool(new(myDom, I) < new(myDom, PI))
Error: cannot compare [myDom::_less]
delete myDom, x, y:

Arbitrary MuPAD^{®} objects 
Expression of type "_less"
.
x
, y