Basic properties of lists #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
There is only one list of an empty type
Equations
- list.unique_of_is_empty = {to_inhabited := {default := inhabited.default (list.inhabited α)}, uniq := _}
mem #
length #
Alias of list.length_le_of_sublist
.
set-theoretic notation of lists #
bounded quantifiers over lists #
list subset #
append #
replicate #
Alias of the reverse direction of list.eq_replicate_length
.
pure #
bind #
concat #
reverse #
empty #
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 #
Dropping the elements up to n
in l₁ ++ l₂
is the same as dropping the elements up to n
in l₁
, dropping the elements up to n - l₁.length
in l₂
, and appending them.