\(\text{Sort}\)

You can use the \(\text{Sort}\) function to sort an iterable value in ascending order.

You can use the \sort backslash command to insert this function.

The following variants of this function are available:

  • \(\text{tuple } \text{Sort} \left ( \text{<set>} \right )\)

  • \(\text{tuple } \text{Sort} \left ( \text{<tuple>} \right )\)

  • \(\text{matrix } \text{Sort} \left ( \text{<matrix>} \right )\)

The \(\text{Sort}\) function accepting a set will return a tuple containing the set members sorted based on the implicit ordering of the members. This variant of the \(\text{Sort}\) function operates very quickly with \(N\) complexity due to the internal implementation of Aion sets.

The \(\text{Sort}\) function accepting a tuple will return a tuple containing the members sorted based on the implicit ordering of the tuple elements. This variant of the \(\text{Sort}\) function has \(\text{O}\left( N \log N \right )\) complexity.

The \(\text{Sort}\) function accepting a matrix will return a column matrix of the same type. When boolean, integer, or real matrices are provided, this function will sort the values in ascending order. Complex matrices containing just real values will be sorted in ascending order. Complex matrices containing one or more complex values will be sorted based on the magnitude of the values. The boolean matrix variant of the \(\text{Sort}\) function has \(\text{O}\left( N \right )\) complexity. The integer, real, and complex matrix variant of the \(\text{Sort}\) function has \(\text{O}\left ( N log N \right )\) complexity.

Implicitly ordered elements will be driven by the rules documented in Table 43.

Table 43 Implicit Ordering

Data Type (Sorted First)

Sorting Within This Type

Boolean

false < true

Integer

Ascending numerical order.

Real

Ascending numerical order.

Complex

Sort based on the magnitude of the values.

Sets

Sorted based on the number of elements then the implicit ordering of elements within the set.

Tuples

Sorted based on the implicit ordering of the members then by tuple length.

Boolean matrices

Sorted based on the internal representation of the matrix.

Integer matrices

Real matrices

Complex matrices

Figure 207 shows the basic use of the \(\text{Sort}\) function.

../_images/sort_example.png

Figure 207 Example Use Of The Sort Function