## `<, <=, >, >=` -- inequalities

#### Introduction

`x < y`, `x <= y`, `x > y`, and `x >= y` define inequalities.

#### Call(s)

x < y `_less(x, y)`
x <= y `_leequal(x, y)`
x > y `_less(y, x)`
x >= y `_leequal(y, x)`

#### Parameters

`x, y` | - | arbitrary MuPAD objects

#### Returns

an expression of type `"_less"` or `"_leequal`, respectively.

### Overloadable:

`x`, `y`

#### Related Functions

`<>`, `=`, `and`, `bool`, `FALSE`, `if`, `lhs`, `not`, `or`, `repeat`, `rhs`, `solve`, `TRUE`, `while`, `UNKNOWN`

#### Details

- `x > y` and `x >= y` are always converted to `y < x` and `y <= x`, respectively.
- `x < y` is equivalent to the function call `_less(x,y)`. It represents the Boolean statement ```x` is smaller than `y`''.
- `x <= y` is equivalent to the function call `_leequal(x,y)`. It represents the Boolean statement ```x` is smaller than or equal to `y`''.
- 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.

  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. Cf. example 3.

- `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.
- `_less` is a function of the system kernel.
- `_leequal` is a function of the system kernel.

#### 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(%)

                                    1.5 <= 3/2

                                       TRUE

Note that `bool` does not handle Boolean expressions that involve exact expressions, even if they represent real numbers:

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

                                       1/2
                                 PI < 2    + 17/10
          Error: Can't evaluate to boolean [_less]

#### Example 2

This examples demonstrates how character strings can be compared:

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

                                       "yes"

    >> bool("aa" >= "b")

                                       FALSE

#### Example 3

Note that `bool` only compares numbers of type `Type::Real`, whereas `is` can also compare exact constant expressions:

    >> bool(10 < PI^2 + sqrt(2)/10)

          Error: Can't evaluate to boolean [_less]

    >> is(10 < PI^2 + sqrt(2)/10)

                                       TRUE

#### Example 4

Inequalities are valid input objects for the system function `solve`:

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

                                      ]-1, 3[

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

                        ]-infinity, -1] union [3, infinity[

#### Example 5

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: Can't 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)

                                    1/2
                              PI, 10   , TRUE, FALSE

    >> bool(new(myDom, I) < new(myDom, PI))

          Error: cannot compare [myDom::_less]

    >> delete myDom, x, y:

#### Changes

- no changes

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000