Basic properties of lists
Equations
Equations
Equations
mem
length
set-theoretic notation of lists
bounded quantifiers over lists
list subset
append
repeat
pure
bind
concat
reverse
is_nil
init
last
last'
head(') and tail
Induction from the right
Induction principle from the right for lists: if a property holds for the empty list, and
for l ++ [a] if it holds for l, then it holds for all lists. The principle is given for
a Sort-valued predicate, i.e., it can also be used to construct data.
Bidirectional induction principle for lists: if a property holds for the empty list, the
singleton list, and a :: (l ++ [b]) from l, then it holds for all lists. This can be used to
prove statements about palindromes. The principle is given for a Sort-valued predicate, i.e., it
can also be used to construct data.
Equations
- list.bidirectional_rec H0 H1 Hn (a :: b :: l) = let l' : list α := (b :: l).init, b' : α := (b :: l).last _ in _.mpr (Hn a l' b' (list.bidirectional_rec H0 H1 Hn l'))
- list.bidirectional_rec H0 H1 Hn [a] = H1 a
- list.bidirectional_rec H0 H1 Hn list.nil = H0
Like bidirectional_rec, but with the list parameter placed first.
Equations
- l.bidirectional_rec_on H0 H1 Hn = list.bidirectional_rec H0 H1 Hn l
sublists
Equations
- (a :: l₁).decidable_sublist (b :: l₂) = dite (a = b) (λ (h : a = b), decidable_of_decidable_of_iff (l₁.decidable_sublist l₂) _) (λ (h : ¬a = b), decidable_of_decidable_of_iff ((a :: l₁).decidable_sublist l₂) _)
- (a :: l₁).decidable_sublist list.nil = decidable.is_false _
- list.nil.decidable_sublist (hd :: tl) = decidable.is_true _
- list.nil.decidable_sublist list.nil = decidable.is_true list.decidable_sublist._main._proof_1
index_of
nth element
If one has nth_le L i hi in a formula and h : L = L', one can not rw h in the formula as
hi gives i < L.length and not i < L'.length. The lemma nth_le_of_eq can be used to make
such a rewrite, with rw (nth_le_of_eq h).
map
map₂
take, drop
foldl, foldr
mfoldl, mfoldr
prod and sum
A list with sum not zero must have positive length.
A list with positive sum must have positive length.
join
In a join, taking the first elements up to an index which is the sum of the lengths of the
first i sublists, is the same as taking the join of the first i sublists.
In a join, dropping all the elements up to an index which is the sum of the lengths of the
first i sublists, is the same as taking the join after dropping the first i sublists.
Taking only the first i+1 elements in a list, and then dropping the first i ones, one is
left with a list of length 1 made of the i-th element of the original list.
In a join of sublists, taking the slice between the indices A and B - 1 gives back the
original sublist of index i if A is the sum of the lenghts of sublists of index < i, and
B is the sum of the lengths of sublists of index ≤ i.
The n-th element in a join of sublists is the j-th element of the ith sublist,
where n can be obtained in terms of i and j by adding the lengths of all the sublists
of index < i, and adding j.
Two lists of sublists are equal iff their joins coincide, as well as the lengths of the sublists.
lexicographic ordering
- nil : ∀ {α : Type u} (r : α → α → Prop) {a : α} {l : list α}, list.lex r list.nil (a :: l)
- cons : ∀ {α : Type u} (r : α → α → Prop) {a : α} {l₁ l₂ : list α}, list.lex r l₁ l₂ → list.lex r (a :: l₁) (a :: l₂)
- rel : ∀ {α : Type u} (r : α → α → Prop) {a₁ : α} {l₁ : list α} {a₂ : α} {l₂ : list α}, r a₁ a₂ → list.lex r (a₁ :: l₁) (a₂ :: l₂)
Given a strict order < on α, the lexicographic strict order on list α, for which
[a0, ..., an] < [b0, ..., b_k] if a0 < b0 or a0 = b0 and [a1, ..., an] < [b1, ..., bk].
The definition is given for any relation r, not only strict orders.
Equations
Equations
- list.lex.decidable_rel r (a :: l₁) (b :: l₂) = decidable_of_iff (r a b ∨ a = b ∧ list.lex r l₁ l₂) _
- list.lex.decidable_rel r (hd :: tl) list.nil = decidable.is_false _
- list.lex.decidable_rel r list.nil (b :: l₂) = decidable.is_true list.lex.nil
- list.lex.decidable_rel r list.nil list.nil = decidable.is_false _
Equations
Equations
all & any
Equations
- l.decidable_forall_mem = decidable_of_iff ↥(l.all (λ (a : α), decidable.to_bool (p a))) _
Equations
- l.decidable_exists_mem = decidable_of_iff ↥(l.any (λ (a : α), decidable.to_bool (p a))) _
map for partial functions
Partial map. If f : Π a, p a → β is a partial function defined on
a : α satisfying p, then pmap f l h is essentially the same as map f l
but is defined only when all members of l satisfy p, using the proof
to apply f.
"Attach" the proof that the elements of l are in l to produce a new list
with the same elements but in the type {x // x ∈ l}.
Equations
- l.attach = list.pmap subtype.mk l _
find
lookmap
filter_map
filter
count
prefix, suffix, infix
Equations
- (a :: l₁).decidable_prefix (b :: l₂) = dite (a = b) (λ (h : a = b), decidable_of_iff (l₁ <+: l₂) _) (λ (h : ¬a = b), decidable.is_false _)
- (a :: l₁).decidable_prefix list.nil = decidable.is_false _
- list.nil.decidable_prefix l₂ = decidable.is_true _
Equations
- (hd :: tl).decidable_suffix (hd_1 :: tl_1) = let len1 : ℕ := (hd :: tl).length, len2 : ℕ := (hd_1 :: tl_1).length in dite (len1 ≤ len2) (λ (hl : len1 ≤ len2), decidable_of_iff' (hd :: tl = list.drop (len2 - len1) (hd_1 :: tl_1)) _) (λ (hl : ¬len1 ≤ len2), decidable.is_false _)
- (a :: l₁).decidable_suffix list.nil = decidable.is_false _
- list.nil.decidable_suffix l₂ = decidable.is_true _
Equations
- (hd :: tl).decidable_infix (hd_1 :: tl_1) = decidable_of_decidable_of_iff (list.decidable_bex (λ (t : list α), hd :: tl <+: t) (hd_1 :: tl_1).tails) _
- (a :: l₁).decidable_infix list.nil = decidable.is_false _
- list.nil.decidable_infix l₂ = decidable.is_true _
sublists
sublists_len
Auxiliary function to construct the list of all sublists of a given length. Given an
integer n, a list l, a function f and an auxiliary list L, it returns the list made of
of f applied to all sublists of l of length n, concatenated with L.
Equations
- list.sublists_len_aux (n + 1) (a :: l) f r = list.sublists_len_aux (n + 1) l f (list.sublists_len_aux n l (f ∘ list.cons a) r)
- list.sublists_len_aux (n + 1) list.nil f r = r
- list.sublists_len_aux 0 (hd :: tl) f r = f list.nil :: r
- list.sublists_len_aux 0 list.nil f r = f list.nil :: r
The list of all sublists of a list l that are of length n. For instance, for
l = [0, 1, 2, 3] and n = 2, one gets
[[2, 3], [1, 3], [1, 2], [0, 3], [0, 2], [0, 1]].