Sort
The elements of the collection in increasing order.
✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram Language
Sort!Sort(collection)the elements in increasing numeric order.Sort(collection, comparator)sorted by a custom Function comparator, e.g. descending order.Sort(expr)the operands of any expression, sorted in place — not just a collection's.Typed signatures
| Type | Package | Applies |
|---|---|---|
((T, order: (((character) any -> unknown) | ((character, character) any -> boolean | number))?) -> T where T: string) & ((indexed_collection<T>, order: (((T) any -> unknown) | ((any, any) any -> boolean | number))?) -> list<T> where T: any) | combinatoricsreplaces compute-engine | always |
((T, order: (((character) any -> unknown) | ((character, character) any -> boolean | number))?) -> T where T: string) & ((indexed_collection<T>, order: (((T) any -> unknown) | ((any, any) any -> boolean | number))?) -> list<T> where T: any) | compute-engine | always |
Details
- Idempotent: sorting an already-sorted collection changes nothing.
- . See Ordering and At.
Sort(c, p)putsabeforebwhenp(a, b)holds andp(b, a)does not. Elementspholds both ways (a non-strictp, like<=) keep their input order; elements it holds neither way (a strictp, like<) come out in reverse input order, as Wolfram's does.- Orders numbers numerically, strings in Wolfram's order (letters compare ignoring case, lowercase before uppercase on a tie, numbers before strings), and symbols alphabetically by name.
- The comparator form
Sort(list, p)takes a predicatepreporting whether a pair is already in order. - Works on the operands of any expression, not just a collection's elements.
- Differs from Wolfram: strings sort by code point, so
"B"comes before"a"; Wolfram's canonical order putsa, b, B.
Examples
1 more kept as data, checked against the oraclesScope #
Applications #
live ↗
InOut
Equal sort keys now follow Wolfram's tie order (our own convention changing, not a known value).
live ↗InOut
Equal sort keys now follow Wolfram's tie order (our own convention changing, not a known value).
live ↗InOut
About
| Examples | 29 |
|---|---|
| Checked against | Wolfram Language 26 agree3 differmathlib4 6 agree3 error |
| Crosswalk | Wolfram Language |
Implementation
mapped
mathlib4packages/oracle/src/mappings.tsA stable sort of exact rationals, increasing. Strings, symbols and nested lists fail to elaborate, since ours orders them by Wolfram's canonical order. A comparator is unbound.
See also: Ordering