solvelib::conditionalSort -- possible
sortings of a list depending on parameters
Introductionsolvelib::conditionalSort(l) sorts the
list l in ascending order. Unlike for sort, only the usual order on the real
numbers and not the internal order (see sysorder) is used.
solvelib::conditionalSort does a case analysis if list
elements contain indeterminates.
Call(s)solvelib::conditionalSort(l)
Parametersl |
- | list of arithmetical expressions |
ReturnsA list if the sorting is the same for all possible parameter values;
or an object of type piecewise if some case analysis is
necessary.
Side
Effectssolvelib::conditionalSort takes into account the
assumptions on all occurring identifiers.
Related
Functions
Detailssolvelib::conditionalSort invokes the inequality
solver to get simple conditions in the case analysis. The ability of
solvelib::conditionalSort to recognize sortings as
impossible is thus limited by the ability of the inequality solver to
recognize an inequality as unsolvable. See Example 2.
Example
1In the simplest case, sorting a two-element list
[a,b] just amounts to solving the inequation
a<=b w.r.t. all occuring parameters.
>> solvelib::conditionalSort([x,x^2])
2
piecewise([x , x] if 0 <= x and x <= 1,
2
[x, x ] if (x < 0 or 1 < x))
Example
2Sometimes cases are not recognized as impossible.
>> assume(x>5): solvelib::conditionalSort([x,exp(x)])
piecewise([exp(x), x] if - x + exp(x) <= 0,
[x, exp(x)] if x - exp(x) < 0)
Background