Previous Page Next Page Contents

<, <=, >, >= -- 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

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




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000