diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-04 22:15:24 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-02-04 22:16:24 -0500 |
| commit | ea4d30020926bd2cb790c11aa311b4722d1fda75 (patch) | |
| tree | a475f15f32334f6d0e887198b79764fbdf61d9f4 /spec/primitive.md | |
| parent | e185843aad2dcf233270fa2932ee2200d94acec5 (diff) | |
Require sort to be stable for fill elements of elements
Diffstat (limited to 'spec/primitive.md')
| -rw-r--r-- | spec/primitive.md | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/spec/primitive.md b/spec/primitive.md index 829729f8..24f98e6d 100644 --- a/spec/primitive.md +++ b/spec/primitive.md @@ -183,7 +183,7 @@ Dyadic search functions check whether major cells of the *principal argument* (w Sorting functions are those that depend on BQN's array ordering. There are three kinds of sorting function, with two functions of each kind: one with an upward-pointing glyph that uses an ascending ordering (these function names are suffixed with "Up"), and one with a downward-pointing glyph and the reverse, descending, ordering ("Down"). Below, these three kinds of function are described, then the ordering rules. Except for the right argument of Bins, all arguments must have rank at least 1. -**Sort** (`∧∨`) reorders the major cells of its argument so that a major cell with a lower index comes earlier in the ordering than a major cell with a higher index, or matches it. +**Sort** (`∧∨`) reorders the major cells of its argument so that a major cell with a lower index comes earlier in the ordering than a major cell with a higher index, or matches it. If it's possible for matching arrays to differ in behavior because of different (including undefined versus defined) fill elements, then these arrays must maintain their ordering (a stable sort is required). **Grade** (`⍋⍒`) returns a permutation describing the way the argument array would be sorted. For this reason the reference implementations simply define Sort to be selection by the grade. One way to define Grade is as a sorted version of the index list `↕≠𝕩`. An index `i` is ordered according to the corresponding major cell `i⊏𝕩`. However, ties in the ordering are broken by ordering the index values themselves, so that no two indices are ever considered equal, and the result of sorting is well-defined (for Sort this is not an issue—matching cells are truly interchangeable). This property means that a stable sorting algorithm must be used to implement Grade functions. While cells might be ordered ascending or descending, indices are always ordered ascending, so that for example index `i` is placed before index `j` if either `i⊏𝕩` comes earlier in the ordering than `j⊏𝕩`, or if they match and `i<j`. |
