Prefixes, subfixes, infixes #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This file proves properties about
list.prefix
:l₁
is a prefix ofl₂
ifl₂
starts withl₁
.list.subfix
:l₁
is a subfix ofl₂
ifl₂
ends withl₁
.list.infix
:l₁
is an infix ofl₂
ifl₁
is a prefix of some subfix ofl₂
.list.inits
: The list of prefixes of a list.list.tails
: The list of prefixes of a list.insert
on lists
All those (except insert
) are defined in data.list.defs
.
Notation #
l₁ <+: l₂
: l₁
is a prefix of l₂
.
l₁ <:+ l₂
: l₁
is a subfix of l₂
.
l₁ <:+: l₂
: l₁
is an infix of l₂
.
prefix, suffix, infix #
Alias of the reverse direction of list.reverse_prefix
.
Alias of the reverse direction of list.reverse_suffix
.
Alias of the reverse direction of list.reverse_infix
.
Alias of the forward direction of list.prefix_nil_iff
.
Alias of the forward direction of list.suffix_nil_iff
.
theorem
list.mem_of_mem_slice
{α : Type u_1}
{n m : ℕ}
{l : list α}
{a : α}
(h : a ∈ list.slice n m l) :
a ∈ l
theorem
list.take_while_prefix
{α : Type u_1}
{l : list α}
(p : α → Prop)
[decidable_pred p] :
list.take_while p l <+: l
theorem
list.drop_while_suffix
{α : Type u_1}
{l : list α}
(p : α → Prop)
[decidable_pred p] :
list.drop_while p l <:+ l
@[protected, instance]
Equations
- (a :: l₁).decidable_prefix (b :: l₂) = dite (a = b) (λ (h : a = b), decidable_of_decidable_of_iff (l₁.decidable_prefix l₂) _) (λ (h : ¬a = b), decidable.is_false _)
- (a :: l₁).decidable_prefix list.nil = decidable.is_false _
- list.nil.decidable_prefix l₂ = decidable.is_true _
@[protected, instance]
Equations
- (hd :: tl).decidable_suffix (b :: l₂) = decidable_of_decidable_of_iff or.decidable _
- (a :: l₁).decidable_suffix list.nil = decidable.is_false _
- list.nil.decidable_suffix (hd :: tl) = decidable.is_true _
- list.nil.decidable_suffix list.nil = decidable.is_true list.decidable_suffix._main._proof_1
@[protected, instance]
Equations
- (hd :: tl).decidable_infix (b :: l₂) = decidable_of_decidable_of_iff or.decidable _
- (a :: l₁).decidable_infix list.nil = decidable.is_false _
- list.nil.decidable_infix (hd :: tl) = decidable.is_true _
- list.nil.decidable_infix list.nil = decidable.is_true list.decidable_infix._main._proof_1
theorem
list.is_prefix.filter_map
{α : Type u_1}
{β : Type u_2}
{l₁ l₂ : list α}
(h : l₁ <+: l₂)
(f : α → option β) :
list.filter_map f l₁ <+: list.filter_map f l₂
theorem
list.is_prefix.reduce_option
{α : Type u_1}
{l₁ l₂ : list (option α)}
(h : l₁ <+: l₂) :
l₁.reduce_option <+: l₂.reduce_option
theorem
list.is_prefix.filter
{α : Type u_1}
(p : α → Prop)
[decidable_pred p]
⦃l₁ l₂ : list α⦄
(h : l₁ <+: l₂) :
list.filter p l₁ <+: list.filter p l₂
theorem
list.is_suffix.filter
{α : Type u_1}
(p : α → Prop)
[decidable_pred p]
⦃l₁ l₂ : list α⦄
(h : l₁ <:+ l₂) :
list.filter p l₁ <:+ list.filter p l₂
theorem
list.is_infix.filter
{α : Type u_1}
(p : α → Prop)
[decidable_pred p]
⦃l₁ l₂ : list α⦄
(h : l₁ <:+: l₂) :
list.filter p l₁ <:+: list.filter p l₂
@[protected, instance]
@[protected, instance]
@[protected, instance]
insert #
@[simp]
theorem
list.insert_nil
{α : Type u_1}
[decidable_eq α]
(a : α) :
has_insert.insert a list.nil = [a]
theorem
list.insert.def
{α : Type u_1}
[decidable_eq α]
(a : α)
(l : list α) :
has_insert.insert a l = ite (a ∈ l) l (a :: l)
@[simp]
theorem
list.insert_of_mem
{α : Type u_1}
{l : list α}
{a : α}
[decidable_eq α]
(h : a ∈ l) :
has_insert.insert a l = l
@[simp]
theorem
list.insert_of_not_mem
{α : Type u_1}
{l : list α}
{a : α}
[decidable_eq α]
(h : a ∉ l) :
has_insert.insert a l = a :: l
@[simp]
@[simp]
theorem
list.suffix_insert
{α : Type u_1}
[decidable_eq α]
(a : α)
(l : list α) :
l <:+ has_insert.insert a l
theorem
list.infix_insert
{α : Type u_1}
[decidable_eq α]
(a : α)
(l : list α) :
l <:+: has_insert.insert a l
theorem
list.sublist_insert
{α : Type u_1}
[decidable_eq α]
(a : α)
(l : list α) :
l <+ list.insert a l
theorem
list.subset_insert
{α : Type u_1}
[decidable_eq α]
(a : α)
(l : list α) :
l ⊆ list.insert a l
@[simp]
theorem
list.mem_insert_self
{α : Type u_1}
[decidable_eq α]
(a : α)
(l : list α) :
a ∈ list.insert a l
theorem
list.mem_insert_of_mem
{α : Type u_1}
{l : list α}
{a b : α}
[decidable_eq α]
(h : a ∈ l) :
a ∈ has_insert.insert b l
theorem
list.eq_or_mem_of_mem_insert
{α : Type u_1}
{l : list α}
{a b : α}
[decidable_eq α]
(h : a ∈ has_insert.insert b l) :
@[simp]
theorem
list.length_insert_of_mem
{α : Type u_1}
{l : list α}
{a : α}
[decidable_eq α]
(h : a ∈ l) :
(has_insert.insert a l).length = l.length
@[simp]
theorem
list.length_insert_of_not_mem
{α : Type u_1}
{l : list α}
{a : α}
[decidable_eq α]
(h : a ∉ l) :
(has_insert.insert a l).length = l.length + 1