Langlib

Langlib.Utilities.ListUtils

List Utilities #

This file collects list lemmas and auxiliary definitions used in grammar constructions and derivation arguments.

Main declarations #

theorem List.length_append_append {α : Type u_1} {x y z : List α} :
(x ++ y ++ z).length = x.length + y.length + z.length
theorem List.map_append_append {α : Type u_1} {β : Type u_2} {x y z : List α} {f : αβ} :
map f (x ++ y ++ z) = map f x ++ map f y ++ map f z
theorem List.filter_map_append_append {α : Type u_1} {β : Type u_2} {x y z : List α} {f : αOption β} :
filterMap f (x ++ y ++ z) = filterMap f x ++ filterMap f y ++ filterMap f z
theorem List.reverse_append_append {α : Type u_1} {x y z : List α} :
theorem List.forall_mem_append_append {α : Type u_1} {x y z : List α} {p : αProp} :
(∀ ax ++ y ++ z, p a) (∀ ax, p a) (∀ ay, p a) az, p a
def List.n_times {α : Type u_1} (l : List α) (n : ) :
List α
Equations
Instances For
    def List.count_in {α : Type u_1} [DecidableEq α] (l : List α) (a : α) :
    Equations
    Instances For
      theorem List.count_in_nil {α : Type u_1} [DecidableEq α] (a : α) :
      theorem List.count_in_cons {α : Type u_1} {x : List α} [DecidableEq α] (a b : α) :
      (b :: x).count_in a = (if b = a then 1 else 0) + x.count_in a
      theorem List.count_in_append {α : Type u_1} {x y : List α} [DecidableEq α] (a : α) :
      (x ++ y).count_in a = x.count_in a + y.count_in a
      theorem List.count_in_replicate_eq {α : Type u_1} [DecidableEq α] (a : α) (n : ) :
      (replicate n a).count_in a = n
      theorem List.count_in_replicate_neq {α : Type u_1} [DecidableEq α] {a b : α} (hyp : a b) (n : ) :
      (replicate n a).count_in b = 0
      theorem List.count_in_singleton_eq {α : Type u_1} [DecidableEq α] (a : α) :
      theorem List.count_in_singleton_neq {α : Type u_1} [DecidableEq α] {a b : α} (hyp : a b) :
      theorem List.count_in_pos_of_in {α : Type u_1} {x : List α} [DecidableEq α] {a : α} (hyp : a x) :
      x.count_in a > 0
      theorem List.count_in_zero_of_notin {α : Type u_1} {x : List α} [DecidableEq α] {a : α} (hyp : ax) :
      x.count_in a = 0
      theorem List.count_in_flatten {α : Type u_1} [DecidableEq α] (L : List (List α)) (a : α) :
      L.flatten.count_in a = (map (fun (w : List α) => w.count_in a) L).sum
      theorem split_at_separator {α : Type} {a b u mid v : List α} {sep : α} (h_sep_not_in_mid : sepmid) (h_eq : a ++ [sep] ++ b = u ++ mid ++ v) :
      (∃ (u' : List α), a = u ++ mid ++ u' v = u' ++ [sep] ++ b) ∃ (v' : List α), u = a ++ [sep] ++ v' b = v' ++ mid ++ v

      If a ++ [sep] ++ b = u ++ mid ++ v and sep ∉ mid, then the separator falls either entirely within a or entirely within b.

      theorem head_unique_elem {α : Type} {s : List α} {elem : α} {u rest : List α} (_h_head : s = elem :: s.tail) (h_not_in_tail : elems.tail) (h_eq : s = u ++ [elem] ++ rest) :
      u = []

      If elem appears only at the head of s, and s = u ++ [elem] ++ rest, then u = [].

      def List.nth {α : Type} (l : List α) (n : ) :
      Equations
      Instances For
        def List.nthLe {α : Type} (l : List α) (n : ) :
        n < l.lengthα
        Equations
        Instances For
          theorem List.get?_eq_nth {α : Type} {l : List α} {n : } :
          l[n]? = l.nth n
          theorem List.nthLe_nth {α : Type} {l : List α} {n : } (h : n < l.length) :
          l.nth n = some (l.nthLe n h)
          theorem List.nthLe_mem {α : Type} {l : List α} {n : } (h : n < l.length) :
          l.nthLe n h l
          theorem List.nthLe_map {α β : Type} {f : αβ} {l : List α} {n : } (h : n < (map f l).length) :
          (map f l).nthLe n h = f (l.nthLe n )
          theorem List.nthLe_append_right {α : Type} {l₁ l₂ : List α} {n : } (h₁ : l₁.length n) (h₂ : n < (l₁ ++ l₂).length) :
          (l₁ ++ l₂).nthLe n h₂ = l₂.nthLe (n - l₁.length)
          theorem List.nthLe_congr {α : Type} {l : List α} {n : } {h₁ h₂ : n < l.length} :
          l.nthLe n h₁ = l.nthLe n h₂
          theorem List.nthLe_of_eq {α : Type} {l₁ l₂ : List α} (h : l₁ = l₂) {n : } (hn : n < l₁.length) :
          l₁.nthLe n hn = l₂.nthLe n
          theorem List.nthLe_append {α : Type} {l₁ l₂ : List α} {n : } (h₁ : n < l₁.length) (h₂ : n < (l₁ ++ l₂).length) :
          (l₁ ++ l₂).nthLe n h₂ = l₁.nthLe n h₁
          theorem List.nthLe_of_mem {α : Type} {l : List α} {a : α} (h : a l) :
          ∃ (n : ) (h' : n < l.length), l.nthLe n h' = a
          theorem List.nthLe_replicate {α : Type} (a : α) {n i : } (h : i < (replicate n a).length) :
          (replicate n a).nthLe i h = a
          theorem List.nth_eq_none_iff {α : Type} {l : List α} {n : } :
          theorem List.nth_take {α : Type} {l : List α} {m n : } (h : n < m) :
          (take m l).nth n = l.nth n
          theorem List.nth_drop {α : Type} {l : List α} {m n : } :
          (drop m l).nth n = l.nth (m + n)
          theorem List.nth_append_right {α : Type} {l₁ l₂ : List α} {n : } (h : l₁.length n) :
          (l₁ ++ l₂).nth n = l₂.nth (n - l₁.length)
          theorem List.nth_append {α : Type} {l₁ l₂ : List α} {n : } (h : n < l₁.length) :
          (l₁ ++ l₂).nth n = l₁.nth n