Documentation

Mathlib.Computability.Primrec.List

Primitive recursive functions on Lists #

The primitive recursive functions are defined in Mathlib.Computability.Primrec.Basic. This file contains definitions and theorems about primitive recursive functions that relate to operation on lists.

References #

instance Primcodable.list {α : Type u_1} [Primcodable α] :
Equations
theorem Primrec.list_casesOn {α : Type u_1} {β : Type u_2} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αList β} {g : ασ} {h : αβ × List βσ} :
Primrec fPrimrec gPrimrec₂ hPrimrec fun (a : α) => List.casesOn (f a) (g a) fun (b : β) (l : List β) => h a (b, l)
theorem Primrec.list_foldl {α : Type u_1} {β : Type u_2} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αList β} {g : ασ} {h : ασ × βσ} :
Primrec fPrimrec gPrimrec₂ hPrimrec fun (a : α) => List.foldl (fun (s : σ) (b : β) => h a (s, b)) (g a) (f a)
theorem Primrec.list_foldr {α : Type u_1} {β : Type u_2} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αList β} {g : ασ} {h : αβ × σσ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) :
Primrec fun (a : α) => List.foldr (fun (b : β) (s : σ) => h a (b, s)) (g a) (f a)
theorem Primrec.list_rec {α : Type u_1} {β : Type u_2} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αList β} {g : ασ} {h : αβ × List β × σσ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) :
Primrec fun (a : α) => List.recOn (f a) (g a) fun (b : β) (l : List β) (IH : σ) => h a (b, l, IH)
theorem Primrec.list_getElem? {α : Type u_1} [Primcodable α] :
Primrec₂ fun (x1 : List α) (x2 : ) => x1[x2]?
theorem Primrec.list_getD {α : Type u_1} [Primcodable α] (d : α) :
Primrec₂ fun (l : List α) (n : ) => l.getD n d
theorem Primrec.list_append {α : Type u_1} [Primcodable α] :
Primrec₂ fun (x1 x2 : List α) => x1 ++ x2
theorem Primrec.list_concat {α : Type u_1} [Primcodable α] :
Primrec₂ fun (l : List α) (a : α) => l ++ [a]
theorem Primrec.list_map {α : Type u_1} {β : Type u_2} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αList β} {g : αβσ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec fun (a : α) => List.map (g a) (f a)
theorem Primrec.list_flatMap {α : Type u_1} {β : Type u_2} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αList β} {g : αβList σ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec fun (a : α) => List.flatMap (g a) (f a)
theorem Primrec.listFilterMap {α : Type u_1} {β : Type u_2} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αList β} {g : αβOption σ} (hf : Primrec f) (hg : Primrec₂ g) :
Primrec fun (a : α) => List.filterMap (g a) (f a)
theorem Primrec.listFilter {α : Type u_1} [Primcodable α] {p : αProp} [DecidablePred p] (hf : PrimrecPred p) :
Primrec fun (L : List α) => List.filter (fun (x : α) => decide (p x)) L

Filtering a list for elements that satisfy a decidable predicate is primitive recursive.

theorem Primrec.list_findIdx {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {f : αList β} {p : αβBool} (hf : Primrec f) (hp : Primrec₂ p) :
Primrec fun (a : α) => List.findIdx (p a) (f a)
theorem Primrec.nat_strong_rec {α : Type u_1} {σ : Type u_4} [Primcodable α] [Primcodable σ] (f : ασ) {g : αList σOption σ} (hg : Primrec₂ g) (H : ∀ (a : α) (n : ), g a (List.map (f a) (List.range n)) = some (f a n)) :
theorem Primrec.nat_omega_rec' {β : Type u_2} {σ : Type u_4} [Primcodable β] [Primcodable σ] (f : βσ) {m : β} {l : βList β} {g : βList σOption σ} (hm : Primrec m) (hl : Primrec l) (hg : Primrec₂ g) (Ord : ∀ (b b' : β), b' l bm b' < m b) (H : ∀ (b : β), g b (List.map f (l b)) = some (f b)) :
theorem Primrec.nat_omega_rec {α : Type u_1} {β : Type u_2} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable σ] (f : αβσ) {m : αβ} {l : αβList β} {g : αβ × List σOption σ} (hm : Primrec₂ m) (hl : Primrec₂ l) (hg : Primrec₂ g) (Ord : ∀ (a : α) (b b' : β), b' l a bm a b' < m a b) (H : ∀ (a : α) (b : β), g a (b, List.map (f a) (l a b)) = some (f a b)) :
theorem PrimrecPred.exists_mem_list {α : Type u_1} {p : αProp} [Primcodable α] (hf : PrimrecPred p) :
PrimrecPred fun (L : List α) => aL, p a

Checking if any element of a list satisfies a decidable predicate is primitive recursive.

theorem PrimrecPred.forall_mem_list {α : Type u_1} {p : αProp} [Primcodable α] (hf : PrimrecPred p) :
PrimrecPred fun (L : List α) => aL, p a

Checking if every element of a list satisfies a decidable predicate is primitive recursive.

theorem PrimrecPred.exists_lt {p : Prop} (hf : PrimrecPred p) :
PrimrecPred fun (n : ) => x < n, p x

Bounded existential quantifiers are primitive recursive.

theorem PrimrecPred.forall_lt {p : Prop} (hf : PrimrecPred p) :
PrimrecPred fun (n : ) => x < n, p x

Bounded universal quantifiers are primitive recursive.

theorem PrimrecPred.listFilter_listRange {R : Prop} (s : ) [DecidableRel R] (hf : PrimrecRel R) :
Primrec fun (n : ) => List.filter (fun (y : ) => decide (R y n)) (List.range s)

A helper lemma for proofs about bounded quantifiers on decidable relations.

theorem PrimrecRel.listFilter {α : Type u_1} {β : Type u_2} {R : αβProp} [Primcodable α] [Primcodable β] (hf : PrimrecRel R) [DecidableRel R] :
Primrec₂ fun (L : List α) (b : β) => List.filter (fun (a : α) => decide (R a b)) L

If R a b is decidable, then given L : List α and b : β, it is primitive recursive to filter L for elements a with R a b

theorem PrimrecRel.exists_mem_list {α : Type u_1} {β : Type u_2} {R : αβProp} [Primcodable α] [Primcodable β] (hf : PrimrecRel R) :
PrimrecRel fun (L : List α) (b : β) => aL, R a b

If R a b is decidable, then given L : List α and b : β, g L b ↔ ∃ a L, R a b is a primitive recursive relation.

theorem PrimrecRel.forall_mem_list {α : Type u_1} {β : Type u_2} {R : αβProp} [Primcodable α] [Primcodable β] (hf : PrimrecRel R) :
PrimrecRel fun (L : List α) (b : β) => aL, R a b

If R a b is decidable, then given L : List α and b : β, g L b ↔ ∀ a L, R a b is a primitive recursive relation.

theorem PrimrecRel.exists_lt {R : Prop} (hf : PrimrecRel R) :
PrimrecRel fun (n y : ) => x < n, R x y

If R a b is decidable, then for any fixed n and y, g n y ↔ ∃ x < n, R x y is a primitive recursive relation.

theorem PrimrecRel.forall_lt {R : Prop} (hf : PrimrecRel R) :
PrimrecRel fun (n y : ) => x < n, R x y

If R a b is decidable, then for any fixed n and y, g n y ↔ ∀ x < n, R x y is a primitive recursive relation.

theorem Primrec.vector_toList_iff {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {n : } {f : αList.Vector β n} :
(Primrec fun (a : α) => (f a).toList) Primrec f
theorem Primrec.list_ofFn {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {n : } {f : Fin nασ} :
(∀ (i : Fin n), Primrec (f i))Primrec fun (a : α) => List.ofFn fun (i : Fin n) => f i a
theorem Primrec.vector_ofFn {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {n : } {f : Fin nασ} (hf : ∀ (i : Fin n), Primrec (f i)) :
Primrec fun (a : α) => List.Vector.ofFn fun (i : Fin n) => f i a
theorem Primrec.fin_app {σ : Type u_3} [Primcodable σ] {n : } :
theorem Primrec.fin_curry₁ {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {n : } {f : Fin nασ} :
Primrec₂ f ∀ (i : Fin n), Primrec (f i)
theorem Primrec.fin_curry {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {n : } {f : αFin nσ} :
inductive Nat.Primrec' {n : } :
(List.Vector n)Prop

An alternative inductive definition of Primrec which does not use the pairing function on ℕ, and so has to work with n-ary functions on ℕ instead of unary functions. We prove that this is equivalent to the regular notion in to_prim and of_prim.

Instances For
    theorem Nat.Primrec'.to_prim {n : } {f : List.Vector n} (pf : Primrec' f) :
    theorem Nat.Primrec'.of_eq {n : } {f g : List.Vector n} (hf : Primrec' f) (H : ∀ (i : List.Vector n), f i = g i) :
    theorem Nat.Primrec'.const {n : } (m : ) :
    Primrec' fun (x : List.Vector n) => m
    theorem Nat.Primrec'.tail {n : } {f : List.Vector n} (hf : Primrec' f) :
    Primrec' fun (v : List.Vector n.succ) => f v.tail

    A function from vectors to vectors is primitive recursive when all of its projections are.

    Equations
    Instances For
      theorem Nat.Primrec'.cons {n m : } {f : List.Vector n} {g : List.Vector nList.Vector m} (hf : Primrec' f) (hg : Vec g) :
      Vec fun (v : List.Vector n) => f v ::ᵥ g v
      theorem Nat.Primrec'.comp' {n m : } {f : List.Vector m} {g : List.Vector nList.Vector m} (hf : Primrec' f) (hg : Vec g) :
      Primrec' fun (v : List.Vector n) => f (g v)
      theorem Nat.Primrec'.comp₁ (f : ) (hf : Primrec' fun (v : List.Vector 1) => f v.head) {n : } {g : List.Vector n} (hg : Primrec' g) :
      Primrec' fun (v : List.Vector n) => f (g v)
      theorem Nat.Primrec'.comp₂ (f : ) (hf : Primrec' fun (v : List.Vector 2) => f v.head v.tail.head) {n : } {g h : List.Vector n} (hg : Primrec' g) (hh : Primrec' h) :
      Primrec' fun (v : List.Vector n) => f (g v) (h v)
      theorem Nat.Primrec'.prec' {n : } {f g : List.Vector n} {h : List.Vector (n + 2)} (hf : Primrec' f) (hg : Primrec' g) (hh : Primrec' h) :
      Primrec' fun (v : List.Vector n) => Nat.rec (g v) (fun (y IH : ) => h (y ::ᵥ IH ::ᵥ v)) (f v)
      theorem Nat.Primrec'.if_lt {n : } {a b f g : List.Vector n} (ha : Primrec' a) (hb : Primrec' b) (hf : Primrec' f) (hg : Primrec' g) :
      Primrec' fun (v : List.Vector n) => if a v < b v then f v else g v
      theorem Nat.Primrec'.unpair₁ {n : } {f : List.Vector n} (hf : Primrec' f) :
      Primrec' fun (v : List.Vector n) => (unpair (f v)).1
      theorem Nat.Primrec'.unpair₂ {n : } {f : List.Vector n} (hf : Primrec' f) :
      Primrec' fun (v : List.Vector n) => (unpair (f v)).2
      theorem Nat.Primrec'.of_prim {n : } {f : List.Vector n} :
      theorem Nat.Primrec'.prim_iff₁ {f : } :
      (Primrec' fun (v : List.Vector 1) => f v.head) Primrec f
      theorem Nat.Primrec'.prim_iff₂ {f : } :
      (Primrec' fun (v : List.Vector 2) => f v.head v.tail.head) Primrec₂ f