sysorder -- compare objects
according to the internal order
Introductionsysorder(object1, object2) returns
TRUE if MuPAD's
internal order of object1 is less than or equal to the
order of object2. Otherwise, FALSE is
returned.
Call(s)sysorder(object1, object2)
Parametersobject1, object2 |
- | arbitrary MuPAD objects |
Returns
Related
Functions_less, listlib::removeDupSorted,
sort
Detailssysorder compares two
objects according to this internal order.
The exceptions are sets and tables. They do not have a unique internal order. This implies that also objects containing sets or tables as (sub)operands do not have an unique internal order. Cf. example 3.
The only feature one may rely upon is its uniqueness. Cf. example 4.
sysorder is a function of the system kernel.
Example
1We give some examples how sysorder behaves
in the current MuPAD version. For nonnegative integer numbers,
the internal order is equal to the natural order. However, for rational
numbers or negative integers, this is not true:
>> sysorder(3, 4) = bool(3 <= 4), sysorder(45, 33) = bool(45 <= 33), sysorder(0, 4) = bool(0 <= 4)
TRUE = TRUE, FALSE = FALSE, TRUE = TRUE
>> sysorder(1/3, 1/4) <> bool(1/3 <= 1/4), sysorder(-4, 2) <> bool(-4 <= 2), sysorder(-4, -2) <> bool(-4 <= -2)
TRUE <> FALSE, FALSE <> TRUE, FALSE <> TRUE
Example
2For character strings or names of identifiers, the internal order is not lexicographical:
>> sysorder("abc", "baa"), sysorder("abc", "bab"),
sysorder("abc", "bac")
FALSE, FALSE, TRUE
>> sysorder(abc, baa), sysorder(abc, bab), sysorder(abc, bac)
FALSE, FALSE, TRUE
Example
3There is no unique internal order for sets and tables:
>> sysorder({1, 2, 3}, {4, 5, 6}), sysorder({4, 5, 6}, {1, 2, 3})
FALSE, FALSE
>> sysorder(table("a" = 42), table("a" = 43)),
sysorder(table("a" = 43), table("a" = 42))
FALSE, FALSE
Example
4We give a simple application of sysorder.
Suppose, we want to implement a function f, say, whose
only known property is its skewness f(-x) = -f(x).
Expressions involving f should be simplified
automatically, e.g., f(x) + f(-x) should yield zero for
any argument x. To achieve this, we use
sysorder to decide, whether a call f(x)
should return f(x) or -f(-x):
>> f := proc(x) begin
if sysorder(x, -x) then
return(-procname(-x))
else return(procname(x))
end_if;
end_proc:
For numerical arguments, f prefers to
rewrite itself with positive arguments:
>> f(-3), f(3), f(-4.5), f(4.5), f(-2/3), f(2/3)
-f(3), f(3), -f(4.5), f(4.5), -f(2/3), f(2/3)
For other arguments, the result is difficult to predict:
>> f(x), f(-x), f(sqrt(2) + 1), f(-sqrt(2) - 1)
1/2 1/2
-f(-x), f(-x), - f(- 2 - 1), f(- 2 - 1)
With this implementation, expressions involving
f simplify automatically:
>> f(x) + f(-x) - f(3)*f(x) + f(-3)*f(-x) + sin(f(7)) + sin(f(-7))
0
>> delete f: