Documentation Center

  • Trial Software
  • Product Updates

<, >, _less

Inequalities "less than" and "greater than"

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

x < y
x > y
_less(x, y)

Description

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 floating-point intervals, these operators are interpreted as "strictly smaller than" and so on, 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 hand side and the right hand side. One may use lhs and rhs to extract these operands.

Examples

Example 1

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.5 <= 3/2; bool(%)

Note that bool may fail to handle Boolean expressions that involve exact expressions, even if they represent real numbers:

_less(PI,  sqrt(2) + 17/10); bool(%)

bool(sqrt(6) < sqrt(2)*sqrt(3))
Error: Cannot evaluate to Boolean. [_less]

Example 2

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)

bool(0...1 <= 2...3), bool(0...2 <= 1...3),
bool(0...1 <= 1...2)

Example 3

This examples demonstrates how character strings can be compared:

if "text" < "t"."e"."x"."t"."book" then "yes" else "no" end

bool("a" >= "b")

Example 4

Note that bool does not perform symbolic simplification and therefore cannot handle some combinations of symbolic expressions; the function is does perform symbolic simplification:

bool(sqrt(6) < sqrt(2)*sqrt(3))
Error: Cannot evaluate to Boolean. [_less]
is(sqrt(6) < sqrt(2)*sqrt(3))

Example 5

Inequalities are valid input objects for the system function solve:

solve(x^2 - 2*x < 3, x)

solve(x^2 - 2*x >= 3, x)

Example 6

The operators < and <= can be overloaded by user-defined 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, a slot"_less" is defined. It is called, when an inequality of type "_less" is evaluated by bool. The slot compares floating-point 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:

Parameters

x, y

Arbitrary MuPAD® objects

Return Values

Expression of type "_less".

Overloaded By

x, y

See Also

MuPAD Functions

Was this topic helpful?