// Specification of `sort_desc`: the result lists every index of `keys` once, // highest version first, ties in their original order. ///| predicate same_length(keys : FixedArray[Key], idx : FixedArray[Int32]) { idx.length() == keys.length() } ///| /// The first `n` entries are all below `n`. predicate below(idx : FixedArray[Int32], n : Int32) { ∀ p : Int32, (0 <= p && p < n) → (0 <= idx[p] && idx[p] < n) } ///| predicate distinct(idx : FixedArray[Int32], n : Int32) { ∀ p : Int32, ∀ q : Int32, (0 <= p && p < q && q < n) → idx[p] != idx[q] } ///| /// Index `i` comes before index `j` in the result. predicate before(keys : FixedArray[Key], i : Int32, j : Int32) { key_lt(keys[j], keys[i]) || (key_eq(keys[j], keys[i]) && i < j) } ///| predicate ordered(keys : FixedArray[Key], idx : FixedArray[Int32], n : Int32) { ∀ p : Int32, ∀ q : Int32, (0 <= p && p < q && q < n) → before(keys, idx[p], idx[q]) } ///| /// Everything in `(j, n]` comes after the entry being inserted at `j`. predicate after_hole( keys : FixedArray[Key], idx : FixedArray[Int32], j : Int32, n : Int32, ) { ∀ q : Int32, (j < q && q <= n) → before(keys, idx[j], idx[q]) } ///| /// The first `n + 1` entries are ordered, ignoring the one at `j`. predicate ordered_except( keys : FixedArray[Key], idx : FixedArray[Int32], j : Int32, n : Int32, ) { ∀ p : Int32, ∀ q : Int32, (0 <= p && p < q && q <= n && p != j && q != j) → before(keys, idx[p], idx[q]) } ///| predicate sort_post(keys : FixedArray[Key], idx : FixedArray[Int32]) { sorted_prefix(keys, idx, keys.length()) } ///| /// The first `n` entries are `0..