Documentation

Mathlib.Data.Vector.Snoc

This file establishes a snoc : Vector α n → α → Vector α (n+1) operation, that appends a single element to the back of a vector.

It provides a collection of lemmas that show how different Vector operations reduce when their argument is snoc xs x.

Also, an alternative, reverse, induction principle is added, that breaks down a vector into snoc xs x for its inductive case. Effectively doing induction from right-to-left

def Vector.snoc {α : Type u_1} {n : } :
Vector α nαVector α (n + 1)

Append a single element to the end of a vector

Equations
Instances For

    Simplification lemmas #

    @[simp]
    theorem Vector.snoc_cons {α : Type u_1} {n : } (xs : Vector α n) {x : α} {y : α} :
    @[simp]
    theorem Vector.snoc_nil :
    ∀ {α : Type u_1} {x : α}, Vector.snoc Vector.nil x = x ::ᵥ Vector.nil
    @[simp]
    theorem Vector.reverse_cons {α : Type u_1} {n : } (xs : Vector α n) {x : α} :
    @[simp]
    theorem Vector.reverse_snoc {α : Type u_1} {n : } (xs : Vector α n) {x : α} :
    theorem Vector.replicate_succ_to_snoc {α : Type u_1} {n : } (val : α) :

    Reverse induction principle #

    def Vector.revInductionOn {α : Type u_2} {C : {n : } → Vector α nSort u_1} {n : } (v : Vector α n) (nil : C Vector.nil) (snoc : {n : } → (xs : Vector α n) → (x : α) → C xsC (Vector.snoc xs x)) :
    C v

    Define C v by reverse induction on v : Vector α n. That is, break the vector down starting from the right-most element, using snoc

    This function has two arguments: nil handles the base case on C nil, and snoc defines the inductive step using ∀ x : α, C xs → C (xs.snoc x).

    This can be used as induction v using Vector.revInductionOn.

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      def Vector.revInductionOn₂ {α : Type u_2} {β : Type u_3} {C : {n : } → Vector α nVector β nSort u_1} {n : } (v : Vector α n) (w : Vector β n) (nil : C Vector.nil Vector.nil) (snoc : {n : } → (xs : Vector α n) → (ys : Vector β n) → (x : α) → (y : β) → C xs ysC (Vector.snoc xs x) (Vector.snoc ys y)) :
      C v w

      Define C v w by reverse induction on a pair of vectors v : Vector α n and w : Vector β n.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        def Vector.revCasesOn {α : Type u_2} {C : {n : } → Vector α nSort u_1} {n : } (v : Vector α n) (nil : C Vector.nil) (snoc : {n : } → (xs : Vector α n) → (x : α) → C (Vector.snoc xs x)) :
        C v

        Define C v by reverse case analysis, i.e. by handling the cases nil and xs.snoc x separately

        Equations
        Instances For

          More simplification lemmas #

          @[simp]
          theorem Vector.map_snoc {α : Type u_2} {n : } (xs : Vector α n) :
          ∀ {α_1 : Type u_1} {f : αα_1} {x : α}, Vector.map f (Vector.snoc xs x) = Vector.snoc (Vector.map f xs) (f x)
          @[simp]
          theorem Vector.mapAccumr_nil :
          ∀ {α : Type u_1} {α_1 : Type} {β : Type u_2} {f : αα_1α_1 × β} {s : α_1}, Vector.mapAccumr f Vector.nil s = (s, Vector.nil)
          @[simp]
          theorem Vector.mapAccumr_snoc {α : Type u_2} {n : } (xs : Vector α n) :
          ∀ {α_1 : Type} {β : Type u_1} {f : αα_1α_1 × β} {x : α} {s : α_1}, Vector.mapAccumr f (Vector.snoc xs x) s = let q := f x s; let r := Vector.mapAccumr f xs q.1; (r.1, Vector.snoc r.2 q.2)
          @[simp]
          theorem Vector.map₂_snoc {α : Type u_2} {n : } {β : Type u_3} (xs : Vector α n) (ys : Vector β n) :
          ∀ {α_1 : Type u_1} {f : αβα_1} {x : α} {y : β}, Vector.map₂ f (Vector.snoc xs x) (Vector.snoc ys y) = Vector.snoc (Vector.map₂ f xs ys) (f x y)
          @[simp]
          theorem Vector.mapAccumr₂_nil :
          ∀ {α β α_1 β_1 : Type} {f : αβα_1α_1 × β_1} {s : α_1}, Vector.mapAccumr₂ f Vector.nil Vector.nil s = (s, Vector.nil)
          @[simp]
          theorem Vector.mapAccumr₂_snoc {α : Type} {n : } {β : Type} (xs : Vector α n) (ys : Vector β n) {σ : Type} {φ : Type} {c : σ} (f : αβσσ × φ) (x : α) (y : β) :
          Vector.mapAccumr₂ f (Vector.snoc xs x) (Vector.snoc ys y) c = let q := f x y c; let r := Vector.mapAccumr₂ f xs ys q.1; (r.1, Vector.snoc r.2 q.2)