Split a list at an index.
split_at 2 [a, b, c] = ([a, b], [c])
Split a list at every element satisfying a predicate.
Split a list at every occurrence of an element.
[1,1,2,3,2,4,4].split_on 2 = [[1,1],[3],[4,4]]
Concatenate an element at the end of a list.
concat [a, b] c = [a, b, c]
Convert a list into an array (whose length is the length of l).
"inhabited" nth function: returns default instead of none in the case that the index is out of bounds.
Apply a function to the nth tail of l. Returns the input without using f if the index is larger than the length of the list.
modify_nth_tail f 2 [a, b, c] = [a, b] ++ f [c]
Apply f to the head of the list, if it exists.
Apply f to the nth element of the list, if it exists.
Get the longest initial segment of the list whose members all satisfy p.
take_while (λ x, x < 3) [0, 2, 5, 1] = [0, 2]
Fold a function f over the list from the left, returning the list of partial results.
scanl (+) 0 [1, 2, 3] = [0, 1, 3, 6]
Fold a function f over the list from the right, returning the list of partial results.
scanr (+) 0 [1, 2, 3] = [6, 5, 3, 0]
Product of a list.
prod [a, b, c] = ((1 * a) * b) * c
Sum of a list.
sum [a, b, c] = ((0 + a) + b) + c
find p l is the first element of l satisfying p, or none if no such element exists.
find_indexes p l is the list of indexes of elements of l that satisfy p.
lookmap is a combination of lookup and filter_map. lookmap f l will apply f : α → option α to each element of the list, replacing a → b at the first value a in the list such that f a = some b.
indexes_of a l is the list of all indexes of a in l.
indexes_of a [a, b, a, a] = [0, 2, 3]
countp p l is the number of elements of l that satisfy p.
count a l is the number of occurrences of a in l.
is_prefix l₁ l₂, or l₁ <+: l₂, means that l₁ is a prefix of l₂, that is, l₂ has the form l₁ ++ t for some t.
is_suffix l₁ l₂, or l₁ <:+ l₂, means that l₁ is a suffix of l₂, that is, l₂ has the form t ++ l₁ for some t.
is_infix l₁ l₂, or l₁ <:+: l₂, means that l₁ is a contiguous substring of l₂, that is, l₂ has the form s ++ l₁ ++ t for some s, t.
inits l is the list of initial segments of l.
inits [1, 2, 3] = [[], [1], [1, 2], [1, 2, 3]]
tails l is the list of terminal segments of l.
tails [1, 2, 3] = [[1, 2, 3], [2, 3], [3], []]
sublists' l is the list of all (non-contiguous) sublists of l. It differs from sublists only in the order of appearance of the sublists; sublists' uses the first element of the list as the MSB, sublists uses the first element of the list as the LSB.
sublists' [1, 2, 3] = [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]
sublists l is the list of all (non-contiguous) sublists of l; cf. sublists' for a different ordering.
sublists [1, 2, 3] = [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]
transpose of a list of lists, treated as a matrix.
transpose [[1, 2], [3, 4], [5, 6]] = [[1, 3, 5], [2, 4, 6]]
List of all sections through a list of lists. A section of [L₁, L₂, ..., Lₙ] is a list whose first element comes from L₁, whose second element comes from L₂, and so on.
List of all permutations of l.
permutations [1, 2, 3] =
[[1, 2, 3], [2, 1, 3], [3, 2, 1],
[2, 3, 1], [3, 1, 2], [1, 3, 2]]
product l₁ l₂ is the list of pairs (a, b) where a ∈ l₁ and b ∈ l₂.
product [1, 2] [5, 6] = [(1, 5), (1, 6), (2, 5), (2, 6)]
sigma l₁ l₂ is the list of dependent pairs (a, b) where a ∈ l₁ and b ∈ l₂ a.
sigma [1, 2] (λ_, [(5 : ℕ), 6]) = [(1, 5), (1, 6), (2, 5), (2, 6)]
disjoint l₁ l₂ means that l₁ and l₂ have no elements in common.
pairwise R l means that all the elements with earlier indexes are R-related to all the elements with later indexes.
pairwise R [1, 2, 3] ↔ R 1 2 ∧ R 1 3 ∧ R 2 3
For example if R = (≠) then it asserts l has no duplicates, and if R = (<) then it asserts that l is (strictly) sorted.
pw_filter R l is a maximal sublist of l which is pairwise R. pw_filter (≠) is the erase duplicates function (cf. erase_dup), and pw_filter (<) finds a maximal increasing subsequence in l. For example,
pw_filter (<) [0, 1, 5, 2, 6, 3, 4] = [0, 1, 2, 3, 4]
chain R a l means that R holds between adjacent elements of a::l.
chain R a [b, c, d] ↔ R a b ∧ R b c ∧ R c d
chain' R l means that R holds between adjacent elements of l.
chain' R [a, b, c, d] ↔ R a b ∧ R b c ∧ R c d
nodup l means that l has no duplicates, that is, any element appears at most once in the list. It is defined as pairwise (≠).
erase_dup l removes duplicates from l (taking only the first occurrence). Defined as pw_filter (≠).
erase_dup [1, 0, 2, 2, 1] = [0, 2, 1]
range' s n is the list of numbers [s, s+1, ..., s+n-1]. It is intended mainly for proving properties of range and iota.
ilast' x xs returns the last element of xs if xs is non-empty; it returns x otherwise
last' xs returns the last element of xs if xs is non-empty; it returns none otherwise
rotate l n rotates the elements of l to the left by n
rotate [0, 1, 2, 3, 4, 5] 2 = [2, 3, 4, 5, 0, 1]
rotate' is the same as rotate, but slower. Used for proofs about rotate
Filters and maps elements of a list
get_rest l l₁ returns some l₂ if l = l₁ ++ l₂. If l₁ is not a prefix of l, returns none