The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V32. Logic, model theory and computability

Mathlib.Computability.Primrec.Basic

173 declarations and 2 deprecated aliases. Mathlib docs · Source

The primitive recursive functions

The primitive recursive functions are the least collection of functions ℕ → ℕ which are closed under projections (using the pair pairing function), composition, zero, successor, and primitive recursion (i.e. Nat.rec where the motive is C n := ℕ).

We can extend this definition to a large class of basic types by using canonical encodings of types as natural numbers (Gödel numbering), which we implement through the type class Encodable. (More precisely, we need that the composition of encode with decode yields a primitive recursive function, so we have the Primcodable type class for this.)

In the above, the pairing function is primitive recursive by definition. This deviates from the textbook definition of primitive recursive functions, which instead work with n-ary functions. We formalize the textbook definition in Nat.Primrec'. Nat.Primrec'.prim_iff then proves it is equivalent to our chosen formulation. For more discussion of this and other design choices in this formalization, see [carneiro2019].

Main definitions

  • Nat.Primrec f: f is primitive recursive, for functions f : ℕ → ℕ
  • Primrec f: f is primitive recursive, for functions between Primcodable types
  • Primcodable α: well-behaved encoding of α into ℕ, i.e. one such that roundtripping through the encoding functions adds no computational power

References

  • [Mario Carneiro, Formalizing computability theory via partial recursive functions][carneiro2019]

ctor Nat.Primrec.below.pair E0 #

∀ {motive : (a : ℕ → ℕ) → Nat.Primrec a → Prop} {f g : ℕ → ℕ} (a : Nat.Primrec f) (a_1 : Nat.Primrec g),
  Nat.Primrec.below a → motive f a → Nat.Primrec.below a_1 → motive g a_1 → Nat.Primrec.below ⋯

ctor Nat.Primrec.below.prec E0 #

∀ {motive : (a : ℕ → ℕ) → Nat.Primrec a → Prop} {f g : ℕ → ℕ} (a : Nat.Primrec f) (a_1 : Nat.Primrec g),
  Nat.Primrec.below a → motive f a → Nat.Primrec.below a_1 → motive g a_1 → Nat.Primrec.below ⋯

ctor Nat.Primrec.below.left E0 #

∀ {motive : (a : ℕ → ℕ) → Nat.Primrec a → Prop}, Nat.Primrec.below Nat.Primrec.left

ctor Nat.Primrec.below.zero E0 #

∀ {motive : (a : ℕ → ℕ) → Nat.Primrec a → Prop}, Nat.Primrec.below Nat.Primrec.zero

def Primcodable.ctorIdx E1 #

{α : Type u_1} → Primcodable α → ℕ

ctor Nat.Primrec.below.succ E0 #

∀ {motive : (a : ℕ → ℕ) → Nat.Primrec a → Prop}, Nat.Primrec.below Nat.Primrec.succ

ctor Nat.Primrec.below.right E0 #

∀ {motive : (a : ℕ → ℕ) → Nat.Primrec a → Prop}, Nat.Primrec.below Nat.Primrec.right

ctor Nat.Primrec.below.comp E0 #

∀ {motive : (a : ℕ → ℕ) → Nat.Primrec a → Prop} {f g : ℕ → ℕ} (a : Nat.Primrec f) (a_1 : Nat.Primrec g),
  Nat.Primrec.below a → motive f a → Nat.Primrec.below a_1 → motive g a_1 → Nat.Primrec.below ⋯

def Nat.unpaired E1 #

{α : Sort u_1} → (ℕ → ℕ → α) → ℕ → α

Calls the given function on a pair of entries n, encoded via the pairing function.

inductive Nat.Primrec E1 #

(ℕ → ℕ) → Prop

The primitive recursive functions ℕ → ℕ.

ctor Nat.Primrec.zero E0 #

Nat.Primrec fun x ↦ 0

ctor Nat.Primrec.succ E0 #

Nat.Primrec Nat.succ

ctor Nat.Primrec.left E0 #

Nat.Primrec fun n ↦ (Nat.unpair n).1

ctor Nat.Primrec.right E0 #

Nat.Primrec fun n ↦ (Nat.unpair n).2

ctor Nat.Primrec.pair E0 #

∀ {f g : ℕ → ℕ}, Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n ↦ Nat.pair (f n) (g n)

ctor Nat.Primrec.comp E0 #

∀ {f g : ℕ → ℕ}, Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n ↦ f (g n)

ctor Nat.Primrec.prec E0 #

∀ {f g : ℕ → ℕ},
  Nat.Primrec f →
    Nat.Primrec g → Nat.Primrec (Nat.unpaired fun z n ↦ Nat.rec (f z) (fun y IH ↦ g (Nat.pair z (Nat.pair y IH))) n)

theorem Nat.Primrec.of_eq E0 #

∀ {f g : ℕ → ℕ}, Nat.Primrec f → (∀ (n : ℕ), f n = g n) → Nat.Primrec g

theorem Nat.Primrec.const E1 #

∀ (n : ℕ), Nat.Primrec fun x ↦ n

theorem Nat.Primrec.id E1 #

Nat.Primrec id

theorem Nat.Primrec.prec1 E1 #

∀ {f : ℕ → ℕ} (m : ℕ), Nat.Primrec f → Nat.Primrec fun n ↦ Nat.rec m (fun y IH ↦ f (Nat.pair y IH)) n

theorem Nat.Primrec.casesOn1 E1 #

∀ {f : ℕ → ℕ} (m : ℕ), Nat.Primrec f → Nat.Primrec fun x ↦ Nat.casesOn x m f

theorem Nat.Primrec.casesOn' E1 #

∀ {f g : ℕ → ℕ},
  Nat.Primrec f → Nat.Primrec g → Nat.Primrec (Nat.unpaired fun z n ↦ Nat.casesOn n (f z) fun y ↦ g (Nat.pair z y))

theorem Nat.Primrec.swap E1 #

Nat.Primrec (Nat.unpaired (Function.swap Nat.pair))

theorem Nat.Primrec.swap' E1 #

∀ {f : ℕ → ℕ → ℕ}, Nat.Primrec (Nat.unpaired f) → Nat.Primrec (Nat.unpaired (Function.swap f))

theorem Nat.Primrec.pred E1 #

Nat.Primrec Nat.pred

theorem Nat.Primrec.add E1 #

Nat.Primrec (Nat.unpaired fun x1 x2 ↦ x1 + x2)

theorem Nat.Primrec.sub E1 #

Nat.Primrec (Nat.unpaired fun x1 x2 ↦ x1 - x2)

theorem Nat.Primrec.mul E1 #

Nat.Primrec (Nat.unpaired fun x1 x2 ↦ x1 * x2)

theorem Nat.Primrec.pow E1 #

Nat.Primrec (Nat.unpaired fun x1 x2 ↦ x1 ^ x2)

class Primcodable E3 #

Type u_1 → Type u_1

A Primcodable type is, essentially, an Encodable type for which the encode/decode functions are primitive recursive. However, such a definition is circular.

Instead, we ask that the composition of decode : ℕ → Option α with encode : Option α → ℕ is primitive recursive. Said composition is the identity function, restricted to the image of encode. Thus, in a way, the added requirement ensures that no predicates can be smuggled in through a cunning choice of the subset of ℕ into which the type is encoded.

ctor Primcodable.mk E0 #

{α : Type u_1} →
  [toEncodable : Encodable α] → (Nat.Primrec fun n ↦ Encodable.encode (Encodable.decode n)) → Primcodable α

instance Primcodable.toEncodable E0 #

{α : Type u_1} → [self : Primcodable α] → Encodable α

theorem Primcodable.prim E1 #

∀ (α : Type u_1) [self : Primcodable α], Nat.Primrec fun n ↦ Encodable.encode (Encodable.decode n)

instance Primcodable.ofDenumerable E0 #

(α : Type u_1) → [Denumerable α] → Primcodable α

def Primcodable.ofEquiv E1 #

(α : Type u_1) → {β : Type u_2} → [Primcodable α] → β ≃ α → Primcodable β

Builds a Primcodable instance from an equivalence to a Primcodable type.

instance Primcodable.empty E0 #

Primcodable Empty

instance Primcodable.unit E0 #

Primcodable PUnit.{u_1 + 1}

instance Primcodable.option E0 #

{α : Type u_1} → [h : Primcodable α] → Primcodable (Option α)

instance Primcodable.bool E0 #

Primcodable Bool

def Primrec E3 #

{α : Type u_1} → {β : Type u_2} → [Primcodable α] → [Primcodable β] → (α → β) → Prop

Primrec f means f is primitive recursive (after encoding its input and output as natural numbers).

theorem Primrec.encode E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec Encodable.encode

theorem Primrec.decode E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec Encodable.decode

theorem Primrec.dom_denumerable E1 #

∀ {α : Type u_4} {β : Type u_5} [inst : Denumerable α] [inst_1 : Primcodable β] {f : α → β},
  Primrec f ↔ Nat.Primrec fun n ↦ Encodable.encode (f (Denumerable.ofNat α n))

theorem Primrec.nat_iff E0 #

∀ {f : ℕ → ℕ}, Primrec f ↔ Nat.Primrec f

theorem Primrec.encdec E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec fun n ↦ Encodable.encode (Encodable.decode n)

theorem Primrec.option_some E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec some

theorem Primrec.of_eq E0 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {f g : α → σ},
  Primrec f → (∀ (n : α), f n = g n) → Primrec g

theorem Primrec.const E1 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] (x : σ), Primrec fun x_1 ↦ x

theorem Primrec.id E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec id

theorem Primrec.comp E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : β → σ} {g : α → β}, Primrec f → Primrec g → Primrec fun a ↦ f (g a)

theorem Primrec.succ E1 #

Primrec Nat.succ

theorem Primrec.pred E1 #

Primrec Nat.pred

theorem Primrec.encode_iff E0 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {f : α → σ},
  (Primrec fun a ↦ Encodable.encode (f a)) ↔ Primrec f

theorem Primrec.ofNat_iff E0 #

∀ {α : Type u_4} {β : Type u_5} [inst : Denumerable α] [inst_1 : Primcodable β] {f : α → β},
  Primrec f ↔ Primrec fun n ↦ f (Denumerable.ofNat α n)

theorem Primrec.ofNat E1 #

∀ (α : Type u_4) [inst : Denumerable α], Primrec (Denumerable.ofNat α)

theorem Primrec.option_some_iff E0 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {f : α → σ},
  (Primrec fun a ↦ some (f a)) ↔ Primrec f

theorem Primrec.of_equiv E1 #

∀ {α : Type u_1} [inst : Primcodable α] {β : Type u_4} {e : β ≃ α}, Primrec ⇑e

theorem Primrec.of_equiv_symm E1 #

∀ {α : Type u_1} [inst : Primcodable α] {β : Type u_4} {e : β ≃ α}, Primrec ⇑e.symm

theorem Primrec.of_equiv_iff E0 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {β : Type u_4} (e : β ≃ α) {f : σ → β},
  (Primrec fun a ↦ e (f a)) ↔ Primrec f

theorem Primrec.of_equiv_symm_iff E0 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {β : Type u_4} (e : β ≃ α) {f : σ → α},
  (Primrec fun a ↦ e.symm (f a)) ↔ Primrec f

instance Primcodable.prod E0 #

{α : Type u_1} → {β : Type u_2} → [Primcodable α] → [Primcodable β] → Primcodable (α × β)

theorem Primrec.fst E1 #

∀ {α : Type u_2} {β : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β], Primrec Prod.fst

theorem Primrec.snd E1 #

∀ {α : Type u_2} {β : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β], Primrec Prod.snd

theorem Primrec.pair E1 #

∀ {α : Type u_2} {β : Type u_3} {γ : Type u_4} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable γ]
  {f : α → β} {g : α → γ}, Primrec f → Primrec g → Primrec fun a ↦ (f a, g a)

theorem Primrec.unpair E1 #

Primrec Nat.unpair

theorem Primrec.list_getElem?₁ E1 #

∀ {α : Type u_1} [inst : Primcodable α] (l : List α), Primrec fun x ↦ l[x]?

def Primrec₂ E1 #

{α : Type u_1} →
  {β : Type u_2} → {σ : Type u_3} → [Primcodable α] → [Primcodable β] → [Primcodable σ] → (α → β → σ) → Prop

Primrec₂ f means f is a binary primitive recursive function. This is technically unnecessary since we can always curry all the arguments together, but there are enough natural two-arg functions that it is convenient to express this directly.

def PrimrecPred E1 #

{α : Type u_1} → [Primcodable α] → (α → Prop) → Prop

PrimrecPred p means p : α → Prop is a primitive recursive predicate, which is to say that decide ∘ p : α → Bool is primitive recursive.

def PrimrecRel E1 #

{α : Type u_1} → {β : Type u_2} → [Primcodable α] → [Primcodable β] → (α → β → Prop) → Prop

PrimrecRel p means p : α → β → Prop is a primitive recursive relation, which is to say that decide ∘ p : α → β → Bool is primitive recursive.

theorem Primrec₂.mk E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → σ}, (Primrec fun p ↦ f p.1 p.2) → Primrec₂ f

theorem Primrec₂.of_eq E0 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f g : α → β → σ}, Primrec₂ f → (∀ (a : α) (b : β), f a b = g a b) → Primrec₂ g

theorem Primrec₂.const E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  (x : σ), Primrec₂ fun x_1 x_2 ↦ x

theorem Primrec₂.pair E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β], Primrec₂ Prod.mk

theorem Primrec₂.left E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β], Primrec₂ fun a x ↦ a

theorem Primrec₂.right E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β], Primrec₂ fun x b ↦ b

theorem Primrec₂.natPair E1 #

Primrec₂ Nat.pair

theorem Primrec₂.unpaired E1 #

∀ {α : Type u_1} [inst : Primcodable α] {f : ℕ → ℕ → α}, Primrec (Nat.unpaired f) ↔ Primrec₂ f

theorem Primrec₂.unpaired' E1 #

∀ {f : ℕ → ℕ → ℕ}, Nat.Primrec (Nat.unpaired f) ↔ Primrec₂ f

theorem Primrec₂.encode_iff E0 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → σ}, (Primrec₂ fun a b ↦ Encodable.encode (f a b)) ↔ Primrec₂ f

theorem Primrec₂.option_some_iff E0 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → σ}, (Primrec₂ fun a b ↦ some (f a b)) ↔ Primrec₂ f

theorem Primrec₂.ofNat_iff E0 #

∀ {α : Type u_4} {β : Type u_5} {σ : Type u_6} [inst : Denumerable α] [inst_1 : Denumerable β] [inst_2 : Primcodable σ]
  {f : α → β → σ}, Primrec₂ f ↔ Primrec₂ fun m n ↦ f (Denumerable.ofNat α m) (Denumerable.ofNat β n)

theorem Primrec₂.uncurry E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → σ}, Primrec (Function.uncurry f) ↔ Primrec₂ f

theorem Primrec₂.curry E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α × β → σ}, Primrec₂ (Function.curry f) ↔ Primrec f

theorem Primrec.comp₂ E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {σ : Type u_5} [inst : Primcodable α] [inst_1 : Primcodable β]
  [inst_2 : Primcodable γ] [inst_3 : Primcodable σ] {f : γ → σ} {g : α → β → γ},
  Primrec f → Primrec₂ g → Primrec₂ fun a b ↦ f (g a b)

theorem Primrec₂.comp E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {σ : Type u_5} [inst : Primcodable α] [inst_1 : Primcodable β]
  [inst_2 : Primcodable γ] [inst_3 : Primcodable σ] {f : β → γ → σ} {g : α → β} {h : α → γ},
  Primrec₂ f → Primrec g → Primrec h → Primrec fun a ↦ f (g a) (h a)

theorem Primrec₂.comp₂ E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {σ : Type u_5} [inst : Primcodable α]
  [inst_1 : Primcodable β] [inst_2 : Primcodable γ] [inst_3 : Primcodable δ] [inst_4 : Primcodable σ] {f : γ → δ → σ}
  {g : α → β → γ} {h : α → β → δ}, Primrec₂ f → Primrec₂ g → Primrec₂ h → Primrec₂ fun a b ↦ f (g a b) (h a b)

theorem PrimrecPred.decide E1 #

∀ {α : Type u_1} [inst : Primcodable α] {p : α → Prop} [inst_1 : DecidablePred p],
  PrimrecPred p → Primrec fun a ↦ decide (p a)

theorem Primrec.primrecPred E1 #

∀ {α : Type u_1} [inst : Primcodable α] {p : α → Prop} [inst_1 : DecidablePred p],
  (Primrec fun a ↦ decide (p a)) → PrimrecPred p

theorem primrecPred_iff_primrec_decide E1 #

∀ {α : Type u_1} [inst : Primcodable α] {p : α → Prop} [inst_1 : DecidablePred p],
  PrimrecPred p ↔ Primrec fun a ↦ decide (p a)

theorem PrimrecPred.comp E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {p : β → Prop} {f : α → β},
  PrimrecPred p → Primrec f → PrimrecPred fun a ↦ p (f a)

theorem PrimrecRel.decide E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {R : α → β → Prop}
  [inst_2 : DecidableRel R], PrimrecRel R → Primrec₂ fun a b ↦ decide (R a b)

theorem Primrec₂.primrecRel E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {R : α → β → Prop}
  [inst_2 : DecidableRel R], (Primrec₂ fun a b ↦ decide (R a b)) → PrimrecRel R

theorem primrecRel_iff_primrec_decide E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {R : α → β → Prop}
  [inst_2 : DecidableRel R], PrimrecRel R ↔ Primrec₂ fun a b ↦ decide (R a b)

theorem PrimrecRel.comp E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable γ]
  {R : β → γ → Prop} {f : α → β} {g : α → γ}, PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a ↦ R (f a) (g a)

theorem PrimrecRel.comp₂ E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} [inst : Primcodable α] [inst_1 : Primcodable β]
  [inst_2 : Primcodable γ] [inst_3 : Primcodable δ] {R : γ → δ → Prop} {f : α → β → γ} {g : α → β → δ},
  PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b ↦ R (f a b) (g a b)

theorem PrimrecPred.of_eq E0 #

∀ {α : Type u_1} [inst : Primcodable α] {p q : α → Prop}, PrimrecPred p → (∀ (a : α), p a ↔ q a) → PrimrecPred q

theorem PrimrecRel.of_eq E0 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {r s : α → β → Prop},
  PrimrecRel r → (∀ (a : α) (b : β), r a b ↔ s a b) → PrimrecRel s

theorem Primrec₂.swap E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → σ}, Primrec₂ f → Primrec₂ (Function.swap f)

theorem PrimrecRel.swap E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {r : α → β → Prop},
  PrimrecRel r → PrimrecRel (Function.swap r)

theorem Primrec₂.nat_iff E0 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → σ},
  Primrec₂ f ↔
    Nat.Primrec
      (Nat.unpaired fun m n ↦
        Encodable.encode ((Encodable.decode m).bind fun a ↦ Option.map (f a) (Encodable.decode n)))

theorem Primrec₂.nat_iff' E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → σ},
  Primrec₂ f ↔ Primrec₂ fun m n ↦ (Encodable.decode m).bind fun a ↦ Option.map (f a) (Encodable.decode n)

theorem Primrec.to₂ E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α × β → σ}, Primrec f → Primrec₂ fun a b ↦ f (a, b)

theorem PrimrecPred.primrecRel E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {p : α × β → Prop},
  PrimrecPred p → PrimrecRel fun a b ↦ p (a, b)

theorem Primrec.nat_rec E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {f : α → β} {g : α → ℕ × β → β},
  Primrec f → Primrec₂ g → Primrec₂ fun a n ↦ Nat.rec (f a) (fun n IH ↦ g a (n, IH)) n

theorem Primrec.nat_rec' E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {f : α → ℕ} {g : α → β}
  {h : α → ℕ × β → β}, Primrec f → Primrec g → Primrec₂ h → Primrec fun a ↦ Nat.rec (g a) (fun n IH ↦ h a (n, IH)) (f a)

theorem Primrec.nat_rec₁ E1 #

∀ {α : Type u_1} [inst : Primcodable α] {f : ℕ → α → α} (a : α), Primrec₂ f → Primrec fun t ↦ Nat.rec a f t

theorem Primrec.nat_casesOn' E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {f : α → β} {g : α → ℕ → β},
  Primrec f → Primrec₂ g → Primrec₂ fun a n ↦ Nat.casesOn n (f a) (g a)

theorem Primrec.nat_casesOn E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {f : α → ℕ} {g : α → β} {h : α → ℕ → β},
  Primrec f → Primrec g → Primrec₂ h → Primrec fun a ↦ Nat.casesOn (f a) (g a) (h a)

theorem Primrec.nat_casesOn₁ E1 #

∀ {α : Type u_1} [inst : Primcodable α] {f : ℕ → α} (a : α), Primrec f → Primrec fun n ↦ Nat.casesOn n a f

theorem Primrec.nat_iterate E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {f : α → ℕ} {g : α → β} {h : α → β → β},
  Primrec f → Primrec g → Primrec₂ h → Primrec fun a ↦ (h a)^[f a] (g a)

theorem Primrec.option_casesOn E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {o : α → Option β} {f : α → σ} {g : α → β → σ},
  Primrec o → Primrec f → Primrec₂ g → Primrec fun a ↦ Option.casesOn (o a) (f a) (g a)

theorem Primrec.option_bind E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → Option β} {g : α → β → Option σ}, Primrec f → Primrec₂ g → Primrec fun a ↦ (f a).bind (g a)

theorem Primrec.option_bind₁ E1 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {f : α → Option σ},
  Primrec f → Primrec fun o ↦ o.bind f

theorem Primrec.option_map E1 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → Option β} {g : α → β → σ}, Primrec f → Primrec₂ g → Primrec fun a ↦ Option.map (g a) (f a)

theorem Primrec.option_map₁ E1 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {f : α → σ},
  Primrec f → Primrec (Option.map f)

theorem Primrec.option_getD E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec₂ Option.getD

theorem Primrec.option_getD_default E1 #

∀ {α : Type u_1} [inst : Primcodable α] [inst_1 : Inhabited α], Primrec fun o ↦ o.getD default

theorem Primrec.option_isSome E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec Option.isSome

theorem Primrec.bind_decode_iff E0 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → Option σ}, (Primrec₂ fun a n ↦ (Encodable.decode n).bind (f a)) ↔ Primrec₂ f

theorem Primrec.map_decode_iff E0 #

∀ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable β] [inst_2 : Primcodable σ]
  {f : α → β → σ}, (Primrec₂ fun a n ↦ Option.map (f a) (Encodable.decode n)) ↔ Primrec₂ f

theorem Primrec.nat_add E1 #

Primrec₂ fun x1 x2 ↦ x1 + x2

theorem Primrec.nat_sub E1 #

Primrec₂ fun x1 x2 ↦ x1 - x2

theorem Primrec.nat_mul E1 #

Primrec₂ fun x1 x2 ↦ x1 * x2

theorem Primrec.cond E1 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {c : α → Bool} {f g : α → σ},
  Primrec c → Primrec f → Primrec g → Primrec fun a ↦ bif c a then f a else g a

theorem Primrec.ite E1 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] {c : α → Prop}
  [inst_2 : DecidablePred c] {f g : α → σ},
  PrimrecPred c → Primrec f → Primrec g → Primrec fun a ↦ if c a then f a else g a

theorem Primrec.nat_le E1 #

PrimrecRel fun x1 x2 ↦ x1 ≤ x2

theorem Primrec.nat_min E1 #

Primrec₂ min

theorem Primrec.nat_max E1 #

Primrec₂ max

theorem Primrec.dom_bool E1 #

∀ {α : Type u_1} [inst : Primcodable α] (f : Bool → α), Primrec f

theorem Primrec.dom_bool₂ E1 #

∀ {α : Type u_1} [inst : Primcodable α] (f : Bool → Bool → α), Primrec₂ f

theorem Primrec.not E1 #

Primrec not

theorem Primrec.and E1 #

Primrec₂ and

theorem Primrec.or E1 #

Primrec₂ or

theorem PrimrecPred.not E1 #

∀ {α : Type u_1} [inst : Primcodable α] {p : α → Prop}, PrimrecPred p → PrimrecPred fun a ↦ ¬p a

theorem PrimrecPred.and E1 #

∀ {α : Type u_1} [inst : Primcodable α] {p q : α → Prop}, PrimrecPred p → PrimrecPred q → PrimrecPred fun a ↦ p a ∧ q a

theorem PrimrecPred.or E1 #

∀ {α : Type u_1} [inst : Primcodable α] {p q : α → Prop}, PrimrecPred p → PrimrecPred q → PrimrecPred fun a ↦ p a ∨ q a

theorem Primrec.eq E1 #

∀ {α : Type u_1} [inst : Primcodable α], PrimrecRel Eq

theorem Primrec.beq E1 #

∀ {α : Type u_1} [inst : Primcodable α] [inst_1 : DecidableEq α], Primrec₂ BEq.beq

theorem Primrec.nat_lt E1 #

PrimrecRel fun x1 x2 ↦ x1 < x2

theorem Primrec.option_guard E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {p : α → β → Prop}
  [inst_2 : DecidableRel p],
  PrimrecRel p → ∀ {f : α → β}, Primrec f → Primrec fun a ↦ Option.guard (fun b ↦ decide (p a b)) (f a)

theorem Primrec.option_orElse E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec₂ fun x1 x2 ↦ x1 <|> x2

theorem Primrec.decode₂ E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec (Encodable.decode₂ α)

theorem Primrec.list_findIdx₁ E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {p : α → β → Bool},
  Primrec₂ p → ∀ (l : List β), Primrec fun a ↦ List.findIdx (p a) l

theorem Primrec.list_idxOf₁ E1 #

∀ {α : Type u_1} [inst : Primcodable α] [inst_1 : DecidableEq α] (l : List α), Primrec fun a ↦ List.idxOf a l

theorem Primrec.dom_finite E1 #

∀ {α : Type u_1} {σ : Type u_3} [inst : Primcodable α] [inst_1 : Primcodable σ] [Finite α] (f : α → σ), Primrec f

def Primrec.PrimrecBounded E1 #

{α : Type u_1} → {β : Type u_2} → [Primcodable α] → [Primcodable β] → (α → β) → Prop

A function is PrimrecBounded if its size is bounded by a primitive recursive function

theorem Primrec.nat_findGreatest E1 #

∀ {α : Type u_1} [inst : Primcodable α] {f : α → ℕ} {p : α → ℕ → Prop} [inst_1 : DecidableRel p],
  Primrec f → PrimrecRel p → Primrec fun x ↦ Nat.findGreatest (p x) (f x)

theorem Primrec.of_graph E1 #

∀ {α : Type u_1} [inst : Primcodable α] {f : α → ℕ},
  Primrec.PrimrecBounded f → (PrimrecRel fun a b ↦ f a = b) → Primrec f

To show a function f : α → ℕ is primitive recursive, it is enough to show that the function is bounded by a primitive recursive function and that its graph is primitive recursive

theorem Primrec.nat_div E1 #

Primrec₂ fun x1 x2 ↦ x1 / x2

theorem Primrec.nat_mod E1 #

Primrec₂ fun x1 x2 ↦ x1 % x2

theorem Primrec.nat_bodd E1 #

Primrec Nat.bodd

theorem Primrec.nat_div2 E1 #

Primrec Nat.div2

theorem Primrec.nat_double E1 #

Primrec fun n ↦ 2 * n

theorem Primrec.nat_double_succ E1 #

Primrec fun n ↦ 2 * n + 1

instance Primcodable.sum E0 #

{α : Type u_1} → {β : Type u_2} → [Primcodable α] → [Primcodable β] → Primcodable (α ⊕ β)

theorem Primrec.sumInl E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β], Primrec Sum.inl

theorem Primrec.sumInr E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β], Primrec Sum.inr

theorem Primrec.sumCasesOn E1 #

∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {σ : Type u_4} [inst : Primcodable α] [inst_1 : Primcodable β]
  [inst_2 : Primcodable γ] [inst_3 : Primcodable σ] {f : α → β ⊕ γ} {g : α → β → σ} {h : α → γ → σ},
  Primrec f → Primrec₂ g → Primrec₂ h → Primrec fun a ↦ Sum.casesOn (f a) (g a) (h a)

theorem PrimrecRel.not E1 #

∀ {α : Type u_1} {β : Type u_2} {R : α → β → Prop} [inst : Primcodable α] [inst_1 : Primcodable β],
  PrimrecRel R → PrimrecRel fun a b ↦ ¬R a b

def Primcodable.subtype E1 #

{α : Type u_1} → [inst : Primcodable α] → {p : α → Prop} → [DecidablePred p] → PrimrecPred p → Primcodable (Subtype p)

A subtype of a primitive recursive predicate is Primcodable.

instance Primcodable.fin E0 #

{n : ℕ} → Primcodable (Fin n)

theorem Primcodable.mem_range_encode E0 #

∀ {α : Type u_1} [inst : Primcodable α], PrimrecPred fun n ↦ n ∈ Set.range Encodable.encode

instance Primcodable.ulower E0 #

{α : Type u_1} → [inst : Primcodable α] → Primcodable (ULower α)

theorem Primrec.subtypeVal E1 #

∀ {α : Type u_1} [inst : Primcodable α] {p : α → Prop} [inst_1 : DecidablePred p] {hp : PrimrecPred p},
  Primrec Subtype.val

theorem Primrec.subtypeVal_iff E0 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {p : β → Prop}
  [inst_2 : DecidablePred p] {hp : PrimrecPred p} {f : α → Subtype p}, (Primrec fun a ↦ ↑(f a)) ↔ Primrec f

theorem Primrec.subtype_mk E0 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {p : β → Prop}
  [inst_2 : DecidablePred p] {hp : PrimrecPred p} {f : α → β} {h : ∀ (a : α), p (f a)},
  Primrec f → Primrec fun a ↦ ⟨f a, ⋯⟩

theorem Primrec.option_get E1 #

∀ {α : Type u_1} {β : Type u_2} [inst : Primcodable α] [inst_1 : Primcodable β] {f : α → Option β}
  {h : ∀ (a : α), (f a).isSome = true}, Primrec f → Primrec fun a ↦ (f a).get ⋯

theorem Primrec.ulower_down E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec ULower.down

theorem Primrec.ulower_up E1 #

∀ {α : Type u_1} [inst : Primcodable α], Primrec ULower.up

theorem Primrec.fin_val_iff E0 #

∀ {α : Type u_1} [inst : Primcodable α] {n : ℕ} {f : α → Fin n}, (Primrec fun a ↦ ↑(f a)) ↔ Primrec f

theorem Primrec.fin_val E0 #

∀ {n : ℕ}, Primrec fun i ↦ ↑i

theorem Primrec.fin_succ E1 #

∀ {n : ℕ}, Primrec Fin.succ

Deprecated aliases

NameNew nameSince
Primrec.subtype_valPrimrec.subtypeVal2026-11-10
Primrec.subtype_val_iffPrimrec.subtypeVal_iff2026-11-10