# solvelib::conditionalSort

Possible sortings of a list depending on parameters

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```solvelib::conditionalSort(`l`)
```

## Description

`solvelib::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.

`solvelib::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 3.

Only expressions representing real numbers can be sorted. It is an error if non-real numbers occur in the list; it is implicitly assumed that all parameters take on only such values that cause all list elements to be real.

Sorting is unstable, i.e. equal elements may be placed in any order in the resulting list; these cases may be listed separately in the case analysis.

The usual simplifications for piecewise defined objects are applied, e.g., equalities that can be derived from a condition are applied (by substitution) to the list.

## Environment Interactions

`solvelib::conditionalSort` takes into account the assumptions on all occurring identifiers.

## Examples

### Example 1

In the simplest case, sorting a two-element list `[a,b]` just amounts to solving the inequality `a<=b` w.r.t. all occurring parameters.

`solvelib::conditionalSort([x,x^2])`

### Example 2

If, by implicit or explicit assumptions on the parameters, no different sortings can occur, the result is just a list.

According to the implicit assumption that all list elements are real, `x` must be nonnegative.

`solvelib::conditionalSort([sqrt(x), -3])`

### Example 3

Sometimes cases are not recognized as impossible.

`assume(x>5): solvelib::conditionalSort([x,gamma(x)])`

## Parameters

 `l` List of arithmetical expressions

## Return Values

List if the sorting is the same for all possible parameter values; or an object of type `piecewise` if some case analysis is necessary.

## Algorithms

The complexity of sorting a list of n elements is up to .