Prefixes, suffixes, infixes #
This file proves properties about
List.isPrefix
:l₁
is a prefix ofl₂
ifl₂
starts withl₁
.List.isSuffix
:l₁
is a suffix ofl₂
ifl₂
ends withl₁
.List.isInfix
:l₁
is an infix ofl₂
ifl₁
is a prefix of some suffix 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 Mathlib.Data.List.Defs
.
Notation #
l₁ <+: l₂
:l₁
is a prefix ofl₂
.l₁ <:+ l₂
:l₁
is a suffix ofl₂
.l₁ <:+: l₂
:l₁
is an infix ofl₂
.
prefix, suffix, infix #
theorem
List.isSuffix.reverse :
∀ {α : Type u_1} {l₁ l₂ : List α}, l₁ <:+ l₂ → List.reverse l₁ <+: List.reverse l₂
Alias of the reverse direction of List.reverse_prefix
.
theorem
List.isPrefix.reverse :
∀ {α : Type u_1} {l₁ l₂ : List α}, l₁ <+: l₂ → List.reverse l₁ <:+ List.reverse l₂
Alias of the reverse direction of List.reverse_suffix
.
theorem
List.isInfix.reverse :
∀ {α : Type u_1} {l₁ l₂ : List α}, l₁ <:+: l₂ → List.reverse l₁ <:+: List.reverse l₂
Alias of the reverse direction of List.reverse_infix
.
Alias of the forward direction of List.infix_nil
.
Alias of the forward direction of List.prefix_nil
.
Alias of the forward direction of List.suffix_nil
.
theorem
List.eq_of_infix_of_length_eq
{α : Type u_1}
{l₁ : List α}
{l₂ : List α}
(h : l₁ <:+: l₂)
:
List.length l₁ = List.length l₂ → l₁ = l₂
theorem
List.eq_of_prefix_of_length_eq
{α : Type u_1}
{l₁ : List α}
{l₂ : List α}
(h : l₁ <+: l₂)
:
List.length l₁ = List.length l₂ → l₁ = l₂
theorem
List.eq_of_suffix_of_length_eq
{α : Type u_1}
{l₁ : List α}
{l₂ : List α}
(h : l₁ <:+ l₂)
:
List.length l₁ = List.length l₂ → l₁ = l₂
theorem
List.dropSlice_sublist
{α : Type u_1}
(n : ℕ)
(m : ℕ)
(l : List α)
:
List.Sublist (List.dropSlice n m l) l
theorem
List.mem_of_mem_dropSlice
{α : Type u_1}
{n : ℕ}
{m : ℕ}
{l : List α}
{a : α}
(h : a ∈ List.dropSlice n m l)
:
a ∈ l
theorem
List.drop_sublist_drop_left
{α : Type u_1}
(l : List α)
{m : ℕ}
{n : ℕ}
(h : m ≤ n)
:
List.Sublist (List.drop n l) (List.drop m l)
theorem
List.mem_of_mem_dropLast
{α : Type u_1}
{l : List α}
{a : α}
(h : a ∈ List.dropLast l)
:
a ∈ l
theorem
List.Sublist.drop
{α : Type u_1}
{l₁ : List α}
{l₂ : List α}
:
List.Sublist l₁ l₂ → ∀ (n : ℕ), List.Sublist (List.drop n l₁) (List.drop n l₂)
theorem
List.suffix_iff_eq_append
{α : Type u_1}
{l₁ : List α}
{l₂ : List α}
:
l₁ <:+ l₂ ↔ List.take (List.length l₂ - List.length l₁) l₂ ++ l₁ = l₂
theorem
List.prefix_iff_eq_take
{α : Type u_1}
{l₁ : List α}
{l₂ : List α}
:
l₁ <+: l₂ ↔ l₁ = List.take (List.length l₁) l₂
theorem
List.concat_get_prefix
{α : Type u_1}
{x : List α}
{y : List α}
(h : x <+: y)
(hl : List.length x < List.length y)
:
x ++ [List.get y { val := List.length x, isLt := hl }] <+: y
theorem
List.suffix_iff_eq_drop
{α : Type u_1}
{l₁ : List α}
{l₂ : List α}
:
l₁ <:+ l₂ ↔ l₁ = List.drop (List.length l₂ - List.length l₁) l₂
Equations
- List.decidablePrefix [] x = isTrue ⋯
- List.decidablePrefix (a :: l₁) [] = isFalse ⋯
- List.decidablePrefix (a :: l₁) (b :: l₂) = if h : a = b then decidable_of_decidable_of_iff ⋯ else isFalse ⋯
Equations
- List.decidableSuffix [] x = isTrue ⋯
- List.decidableSuffix (a :: l₁) [] = isFalse ⋯
- List.decidableSuffix x (b :: l₂) = decidable_of_decidable_of_iff ⋯
Equations
- List.decidableInfix [] x = isTrue ⋯
- List.decidableInfix (a :: l₁) [] = isFalse ⋯
- List.decidableInfix x (b :: l₂) = decidable_of_decidable_of_iff ⋯
theorem
List.IsPrefix.filterMap
{α : Type u_1}
{β : Type u_2}
{l₁ : List α}
{l₂ : List α}
(h : l₁ <+: l₂)
(f : α → Option β)
:
List.filterMap f l₁ <+: List.filterMap f l₂
@[deprecated List.IsPrefix.filterMap]
theorem
List.IsPrefix.filter_map
{α : Type u_1}
{β : Type u_2}
{l₁ : List α}
{l₂ : List α}
(h : l₁ <+: l₂)
(f : α → Option β)
:
List.filterMap f l₁ <+: List.filterMap f l₂
Alias of List.IsPrefix.filterMap
.
instance
List.instIsPartialOrderListIsPrefix
{α : Type u_1}
:
IsPartialOrder (List α) fun (x x_1 : List α) => x <+: x_1
Equations
- ⋯ = ⋯
instance
List.instIsPartialOrderListIsSuffix
{α : Type u_1}
:
IsPartialOrder (List α) fun (x x_1 : List α) => x <:+ x_1
Equations
- ⋯ = ⋯
instance
List.instIsPartialOrderListIsInfix
{α : Type u_1}
:
IsPartialOrder (List α) fun (x x_1 : List α) => x <:+: x_1
Equations
- ⋯ = ⋯
@[simp]
@[simp]
theorem
List.inits_cons
{α : Type u_1}
(a : α)
(l : List α)
:
List.inits (a :: l) = [] :: List.map (fun (t : List α) => a :: t) (List.inits l)
theorem
List.tails_cons
{α : Type u_1}
(a : α)
(l : List α)
:
List.tails (a :: l) = (a :: l) :: List.tails l
@[simp]
theorem
List.inits_append
{α : Type u_1}
(s : List α)
(t : List α)
:
List.inits (s ++ t) = List.inits s ++ List.map (fun (l : List α) => s ++ l) (List.tail (List.inits t))
@[simp]
theorem
List.tails_append
{α : Type u_1}
(s : List α)
(t : List α)
:
List.tails (s ++ t) = List.map (fun (l : List α) => l ++ t) (List.tails s) ++ List.tail (List.tails t)
theorem
List.inits_eq_tails
{α : Type u_1}
(l : List α)
:
List.inits l = List.reverse (List.map List.reverse (List.tails (List.reverse l)))
theorem
List.tails_eq_inits
{α : Type u_1}
(l : List α)
:
List.tails l = List.reverse (List.map List.reverse (List.inits (List.reverse l)))
theorem
List.inits_reverse
{α : Type u_1}
(l : List α)
:
List.inits (List.reverse l) = List.reverse (List.map List.reverse (List.tails l))
theorem
List.tails_reverse
{α : Type u_1}
(l : List α)
:
List.tails (List.reverse l) = List.reverse (List.map List.reverse (List.inits l))
theorem
List.map_reverse_inits
{α : Type u_1}
(l : List α)
:
List.map List.reverse (List.inits l) = List.reverse (List.tails (List.reverse l))
theorem
List.map_reverse_tails
{α : Type u_1}
(l : List α)
:
List.map List.reverse (List.tails l) = List.reverse (List.inits (List.reverse l))
@[simp]
theorem
List.length_tails
{α : Type u_1}
(l : List α)
:
List.length (List.tails l) = List.length l + 1
@[simp]
theorem
List.length_inits
{α : Type u_1}
(l : List α)
:
List.length (List.inits l) = List.length l + 1
@[simp]
theorem
List.get_tails
{α : Type u_1}
(l : List α)
(n : Fin (List.length (List.tails l)))
:
List.get (List.tails l) n = List.drop (↑n) l
@[simp]
theorem
List.get_inits
{α : Type u_1}
(l : List α)
(n : Fin (List.length (List.inits l)))
:
List.get (List.inits l) n = List.take (↑n) l
@[simp, deprecated List.get_tails]
theorem
List.nth_le_tails
{α : Type u_1}
(l : List α)
(n : ℕ)
(hn : n < List.length (List.tails l))
:
List.nthLe (List.tails l) n hn = List.drop n l
@[simp, deprecated List.get_inits]
theorem
List.nth_le_inits
{α : Type u_1}
(l : List α)
(n : ℕ)
(hn : n < List.length (List.inits l))
:
List.nthLe (List.inits l) n hn = List.take n l
insert #
@[simp]
theorem
List.suffix_insert
{α : Type u_1}
[DecidableEq α]
(a : α)
(l : List α)
:
l <:+ List.insert a l
theorem
List.infix_insert
{α : Type u_1}
[DecidableEq α]
(a : α)
(l : List α)
:
l <:+: List.insert a l
theorem
List.sublist_insert
{α : Type u_1}
[DecidableEq α]
(a : α)
(l : List α)
:
List.Sublist l (List.insert a l)