Documentation

Mathlib.Computability.Primrec.Basic

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 [Car19].

Main definitions #

References #

@[reducible]
def Nat.unpaired {α : Sort u_1} (f : α) (n : ) :
α

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

Equations
Instances For
    inductive Nat.Primrec :
    ()Prop

    The primitive recursive functions ℕ → ℕ.

    Instances For
      theorem Nat.Primrec.of_eq {f g : } (hf : Nat.Primrec f) (H : ∀ (n : ), f n = g n) :
      theorem Nat.Primrec.const (n : ) :
      Nat.Primrec fun (x : ) => n
      theorem Nat.Primrec.prec1 {f : } (m : ) (hf : Nat.Primrec f) :
      Nat.Primrec fun (n : ) => Nat.rec m (fun (y IH : ) => f (Nat.pair y IH)) n
      theorem Nat.Primrec.casesOn1 {f : } (m : ) (hf : Nat.Primrec f) :
      Nat.Primrec fun (x : ) => Nat.casesOn x m f
      theorem Nat.Primrec.casesOn' {f g : } (hf : Nat.Primrec f) (hg : Nat.Primrec g) :
      Nat.Primrec (unpaired fun (z n : ) => Nat.casesOn n (f z) fun (y : ) => g (Nat.pair z y))
      theorem Nat.Primrec.add :
      Nat.Primrec (unpaired fun (x1 x2 : ) => x1 + x2)
      theorem Nat.Primrec.sub :
      Nat.Primrec (unpaired fun (x1 x2 : ) => x1 - x2)
      theorem Nat.Primrec.mul :
      Nat.Primrec (unpaired fun (x1 x2 : ) => x1 * x2)
      theorem Nat.Primrec.pow :
      Nat.Primrec (unpaired fun (x1 x2 : ) => x1 ^ x2)
      class Primcodable (α : Type u_1) extends Encodable α :
      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.

      Instances
        @[instance 10]
        Equations
        def Primcodable.ofEquiv (α : Type u_1) {β : Type u_2} [Primcodable α] (e : β α) :

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

        Equations
        Instances For
          instance Primcodable.option {α : Type u_1} [h : Primcodable α] :
          Equations
          def Primrec {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] (f : αβ) :

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

          Equations
          Instances For
            theorem Primrec.dom_denumerable {α : Type u_4} {β : Type u_5} [Denumerable α] [Primcodable β] {f : αβ} :
            theorem Primrec.of_eq {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {f g : ασ} (hf : Primrec f) (H : ∀ (n : α), f n = g n) :
            theorem Primrec.const {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] (x : σ) :
            Primrec fun (x_1 : α) => x
            theorem Primrec.id {α : Type u_1} [Primcodable α] :
            theorem Primrec.comp {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : βσ} {g : αβ} (hf : Primrec f) (hg : Primrec g) :
            Primrec fun (a : α) => f (g a)
            theorem Primrec.encode_iff {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {f : ασ} :
            (Primrec fun (a : α) => Encodable.encode (f a)) Primrec f
            theorem Primrec.ofNat_iff {α : Type u_4} {β : Type u_5} [Denumerable α] [Primcodable β] {f : αβ} :
            Primrec f Primrec fun (n : ) => f (Denumerable.ofNat α n)
            theorem Primrec.option_some_iff {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {f : ασ} :
            (Primrec fun (a : α) => some (f a)) Primrec f
            theorem Primrec.of_equiv {α : Type u_1} [Primcodable α] {β : Type u_4} {e : β α} :
            Primrec e
            theorem Primrec.of_equiv_symm {α : Type u_1} [Primcodable α] {β : Type u_4} {e : β α} :
            theorem Primrec.of_equiv_iff {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {β : Type u_4} (e : β α) {f : σβ} :
            (Primrec fun (a : σ) => e (f a)) Primrec f
            theorem Primrec.of_equiv_symm_iff {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {β : Type u_4} (e : β α) {f : σα} :
            (Primrec fun (a : σ) => e.symm (f a)) Primrec f
            instance Primcodable.prod {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] :
            Primcodable (α × β)
            Equations
            theorem Primrec.fst {α : Type u_2} {β : Type u_3} [Primcodable α] [Primcodable β] :
            theorem Primrec.snd {α : Type u_2} {β : Type u_3} [Primcodable α] [Primcodable β] :
            theorem Primrec.pair {α : Type u_2} {β : Type u_3} {γ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable γ] {f : αβ} {g : αγ} (hf : Primrec f) (hg : Primrec g) :
            Primrec fun (a : α) => (f a, g a)
            theorem Primrec.list_getElem?₁ {α : Type u_1} [Primcodable α] (l : List α) :
            Primrec fun (x : ) => l[x]?
            def Primrec₂ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] (f : αβσ) :

            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.

            Equations
            Instances For
              def PrimrecPred {α : Type u_1} [Primcodable α] (p : αProp) :

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

              Equations
              Instances For
                def PrimrecRel {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] (s : αβProp) :

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

                Equations
                Instances For
                  theorem Primrec₂.mk {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβσ} (hf : Primrec fun (p : α × β) => f p.1 p.2) :
                  theorem Primrec₂.of_eq {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f g : αβσ} (hg : Primrec₂ f) (H : ∀ (a : α) (b : β), f a b = g a b) :
                  theorem Primrec₂.const {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] (x : σ) :
                  Primrec₂ fun (x_1 : α) (x_2 : β) => x
                  theorem Primrec₂.pair {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] :
                  theorem Primrec₂.left {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] :
                  Primrec₂ fun (a : α) (x : β) => a
                  theorem Primrec₂.right {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] :
                  Primrec₂ fun (x : α) (b : β) => b
                  theorem Primrec₂.unpaired {α : Type u_1} [Primcodable α] {f : α} :
                  theorem Primrec₂.encode_iff {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβσ} :
                  (Primrec₂ fun (a : α) (b : β) => Encodable.encode (f a b)) Primrec₂ f
                  theorem Primrec₂.option_some_iff {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβσ} :
                  (Primrec₂ fun (a : α) (b : β) => some (f a b)) Primrec₂ f
                  theorem Primrec₂.ofNat_iff {α : Type u_4} {β : Type u_5} {σ : Type u_6} [Denumerable α] [Denumerable β] [Primcodable σ] {f : αβσ} :
                  theorem Primrec₂.uncurry {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβσ} :
                  theorem Primrec₂.curry {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : α × βσ} :
                  theorem Primrec.comp₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {σ : Type u_5} [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] {f : γσ} {g : αβγ} (hf : Primrec f) (hg : Primrec₂ g) :
                  Primrec₂ fun (a : α) (b : β) => f (g a b)
                  theorem Primrec₂.comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} {σ : Type u_5} [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] {f : βγσ} {g : αβ} {h : αγ} (hf : Primrec₂ f) (hg : Primrec g) (hh : Primrec h) :
                  Primrec fun (a : α) => f (g a) (h a)
                  theorem Primrec₂.comp₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {σ : Type u_5} [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] {f : γδσ} {g : αβγ} {h : αβδ} (hf : Primrec₂ f) (hg : Primrec₂ g) (hh : Primrec₂ h) :
                  Primrec₂ fun (a : α) (b : β) => f (g a b) (h a b)
                  theorem PrimrecPred.decide {α : Type u_1} [Primcodable α] {p : αProp} [DecidablePred p] (hp : PrimrecPred p) :
                  Primrec fun (a : α) => decide (p a)
                  theorem Primrec.primrecPred {α : Type u_1} [Primcodable α] {p : αProp} [DecidablePred p] (hp : Primrec fun (a : α) => decide (p a)) :
                  theorem primrecPred_iff_primrec_decide {α : Type u_1} [Primcodable α] {p : αProp} [DecidablePred p] :
                  PrimrecPred p Primrec fun (a : α) => decide (p a)
                  theorem PrimrecPred.comp {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {p : βProp} {f : αβ} (hp : PrimrecPred p) (hf : Primrec f) :
                  PrimrecPred fun (a : α) => p (f a)
                  theorem PrimrecRel.decide {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {R : αβProp} [DecidableRel R] (hR : PrimrecRel R) :
                  Primrec₂ fun (a : α) (b : β) => decide (R a b)
                  theorem Primrec₂.primrecRel {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {R : αβProp} [DecidableRel R] (hp : Primrec₂ fun (a : α) (b : β) => decide (R a b)) :
                  theorem primrecRel_iff_primrec_decide {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {R : αβProp} [DecidableRel R] :
                  PrimrecRel R Primrec₂ fun (a : α) (b : β) => decide (R a b)
                  theorem PrimrecRel.comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable γ] {R : βγProp} {f : αβ} {g : αγ} (hR : PrimrecRel R) (hf : Primrec f) (hg : Primrec g) :
                  PrimrecPred fun (a : α) => R (f a) (g a)
                  theorem PrimrecRel.comp₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] {R : γδProp} {f : αβγ} {g : αβδ} :
                  PrimrecRel RPrimrec₂ fPrimrec₂ gPrimrecRel fun (a : α) (b : β) => R (f a b) (g a b)
                  theorem PrimrecPred.of_eq {α : Type u_1} [Primcodable α] {p q : αProp} (hp : PrimrecPred p) (H : ∀ (a : α), p a q a) :
                  theorem PrimrecRel.of_eq {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {r s : αβProp} (hr : PrimrecRel r) (H : ∀ (a : α) (b : β), r a b s a b) :
                  theorem Primrec₂.swap {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβσ} (h : Primrec₂ f) :
                  theorem PrimrecRel.swap {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {r : αβProp} (h : PrimrecRel r) :
                  theorem Primrec₂.nat_iff {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβσ} :
                  theorem Primrec₂.nat_iff' {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβσ} :
                  Primrec₂ f Primrec₂ fun (m n : ) => (Encodable.decode m).bind fun (a : α) => Option.map (f a) (Encodable.decode n)
                  theorem Primrec.to₂ {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : α × βσ} (hf : Primrec f) :
                  Primrec₂ fun (a : α) (b : β) => f (a, b)
                  theorem PrimrecPred.primrecRel {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {p : α × βProp} (hp : PrimrecPred p) :
                  PrimrecRel fun (a : α) (b : β) => p (a, b)
                  theorem Primrec.nat_rec {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {f : αβ} {g : α × ββ} (hf : Primrec f) (hg : Primrec₂ g) :
                  Primrec₂ fun (a : α) (n : ) => Nat.rec (f a) (fun (n : ) (IH : (fun (x : ) => β) n) => g a (n, IH)) n
                  theorem Primrec.nat_rec' {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {f : α} {g : αβ} {h : α × ββ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) :
                  Primrec fun (a : α) => Nat.rec (g a) (fun (n : ) (IH : (fun (x : ) => β) n) => h a (n, IH)) (f a)
                  theorem Primrec.nat_rec₁ {α : Type u_1} [Primcodable α] {f : αα} (a : α) (hf : Primrec₂ f) :
                  Primrec fun (t : ) => Nat.rec a f t
                  theorem Primrec.nat_casesOn' {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {f : αβ} {g : αβ} (hf : Primrec f) (hg : Primrec₂ g) :
                  Primrec₂ fun (a : α) (n : ) => Nat.casesOn n (f a) (g a)
                  theorem Primrec.nat_casesOn {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {f : α} {g : αβ} {h : αβ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) :
                  Primrec fun (a : α) => Nat.casesOn (f a) (g a) (h a)
                  theorem Primrec.nat_casesOn₁ {α : Type u_1} [Primcodable α] {f : α} (a : α) (hf : Primrec f) :
                  Primrec fun (n : ) => Nat.casesOn n a f
                  theorem Primrec.nat_iterate {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {f : α} {g : αβ} {h : αββ} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) :
                  Primrec fun (a : α) => (h a)^[f a] (g a)
                  theorem Primrec.option_casesOn {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {o : αOption β} {f : ασ} {g : αβσ} (ho : Primrec o) (hf : Primrec f) (hg : Primrec₂ g) :
                  Primrec fun (a : α) => Option.casesOn (o a) (f a) (g a)
                  theorem Primrec.option_bind {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αOption β} {g : αβOption σ} (hf : Primrec f) (hg : Primrec₂ g) :
                  Primrec fun (a : α) => (f a).bind (g a)
                  theorem Primrec.option_bind₁ {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {f : αOption σ} (hf : Primrec f) :
                  Primrec fun (o : Option α) => o.bind f
                  theorem Primrec.option_map {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αOption β} {g : αβσ} (hf : Primrec f) (hg : Primrec₂ g) :
                  Primrec fun (a : α) => Option.map (g a) (f a)
                  theorem Primrec.option_map₁ {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {f : ασ} (hf : Primrec f) :
                  theorem Primrec.option_getD_default {α : Type u_1} [Primcodable α] [Inhabited α] :
                  Primrec fun (o : Option α) => o.getD default
                  @[deprecated Primrec.option_getD_default (since := "2026-01-05")]
                  theorem Primrec.bind_decode_iff {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβOption σ} :
                  (Primrec₂ fun (a : α) (n : ) => (Encodable.decode n).bind (f a)) Primrec₂ f
                  theorem Primrec.map_decode_iff {α : Type u_1} {β : Type u_2} {σ : Type u_3} [Primcodable α] [Primcodable β] [Primcodable σ] {f : αβσ} :
                  (Primrec₂ fun (a : α) (n : ) => Option.map (f a) (Encodable.decode n)) Primrec₂ f
                  theorem Primrec.nat_add :
                  Primrec₂ fun (x1 x2 : ) => x1 + x2
                  theorem Primrec.nat_sub :
                  Primrec₂ fun (x1 x2 : ) => x1 - x2
                  theorem Primrec.nat_mul :
                  Primrec₂ fun (x1 x2 : ) => x1 * x2
                  theorem Primrec.cond {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {c : αBool} {f g : ασ} (hc : Primrec c) (hf : Primrec f) (hg : Primrec g) :
                  Primrec fun (a : α) => bif c a then f a else g a
                  theorem Primrec.ite {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] {c : αProp} [DecidablePred c] {f g : ασ} (hc : PrimrecPred c) (hf : Primrec f) (hg : Primrec g) :
                  Primrec fun (a : α) => if c a then f a else g a
                  theorem Primrec.nat_le :
                  PrimrecRel fun (x1 x2 : ) => x1 x2
                  theorem Primrec.dom_bool {α : Type u_1} [Primcodable α] (f : Boolα) :
                  theorem Primrec.dom_bool₂ {α : Type u_1} [Primcodable α] (f : BoolBoolα) :
                  theorem PrimrecPred.not {α : Type u_1} [Primcodable α] {p : αProp} (hp : PrimrecPred p) :
                  PrimrecPred fun (a : α) => ¬p a
                  theorem PrimrecPred.and {α : Type u_1} [Primcodable α] {p q : αProp} (hp : PrimrecPred p) (hq : PrimrecPred q) :
                  PrimrecPred fun (a : α) => p a q a
                  theorem PrimrecPred.or {α : Type u_1} [Primcodable α] {p q : αProp} (hp : PrimrecPred p) (hq : PrimrecPred q) :
                  PrimrecPred fun (a : α) => p a q a
                  theorem Primrec.eq {α : Type u_1} [Primcodable α] :
                  theorem Primrec.nat_lt :
                  PrimrecRel fun (x1 x2 : ) => x1 < x2
                  theorem Primrec.option_guard {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {p : αβProp} [DecidableRel p] (hp : PrimrecRel p) {f : αβ} (hf : Primrec f) :
                  Primrec fun (a : α) => Option.guard (fun (b : β) => decide (p a b)) (f a)
                  theorem Primrec.option_orElse {α : Type u_1} [Primcodable α] :
                  Primrec₂ fun (x1 x2 : Option α) => x1 <|> x2
                  theorem Primrec.list_findIdx₁ {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {p : αβBool} (hp : Primrec₂ p) (l : List β) :
                  Primrec fun (a : α) => List.findIdx (p a) l
                  theorem Primrec.list_idxOf₁ {α : Type u_1} [Primcodable α] [DecidableEq α] (l : List α) :
                  Primrec fun (a : α) => List.idxOf a l
                  theorem Primrec.dom_finite {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] [Finite α] (f : ασ) :
                  @[deprecated Primrec.dom_finite (since := "2025-08-23")]
                  theorem Primrec.dom_fintype {α : Type u_1} {σ : Type u_3} [Primcodable α] [Primcodable σ] [Finite α] (f : ασ) :

                  Alias of Primrec.dom_finite.

                  def Primrec.PrimrecBounded {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] (f : αβ) :

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

                  Equations
                  Instances For
                    theorem Primrec.nat_findGreatest {α : Type u_1} [Primcodable α] {f : α} {p : αProp} [DecidableRel p] (hf : Primrec f) (hp : PrimrecRel p) :
                    Primrec fun (x : α) => Nat.findGreatest (p x) (f x)
                    theorem Primrec.of_graph {α : Type u_1} [Primcodable α] {f : α} (h₁ : PrimrecBounded f) (h₂ : PrimrecRel fun (a : α) (b : ) => f a = b) :

                    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 :
                    Primrec₂ fun (x1 x2 : ) => x1 / x2
                    theorem Primrec.nat_mod :
                    Primrec₂ fun (x1 x2 : ) => x1 % x2
                    theorem Primrec.nat_double :
                    Primrec fun (n : ) => 2 * n
                    theorem Primrec.nat_double_succ :
                    Primrec fun (n : ) => 2 * n + 1
                    instance Primcodable.sum {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] :
                    Equations
                    theorem Primrec.sumInl {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] :
                    theorem Primrec.sumInr {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] :
                    theorem Primrec.sumCasesOn {α : Type u_1} {β : Type u_2} {γ : Type u_3} {σ : Type u_4} [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable σ] {f : αβ γ} {g : αβσ} {h : αγσ} (hf : Primrec f) (hg : Primrec₂ g) (hh : Primrec₂ h) :
                    Primrec fun (a : α) => Sum.casesOn (f a) (g a) (h a)
                    theorem PrimrecRel.not {α : Type u_1} {β : Type u_2} {R : αβProp} [Primcodable α] [Primcodable β] (hf : PrimrecRel R) :
                    PrimrecRel fun (a : α) (b : β) => ¬R a b
                    def Primcodable.subtype {α : Type u_1} [Primcodable α] {p : αProp} [DecidablePred p] (hp : PrimrecPred p) :

                    A subtype of a primitive recursive predicate is Primcodable.

                    Equations
                    Instances For
                      theorem Primrec.subtype_val {α : Type u_1} [Primcodable α] {p : αProp} [DecidablePred p] {hp : PrimrecPred p} :
                      theorem Primrec.subtype_val_iff {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {p : βProp} [DecidablePred p] {hp : PrimrecPred p} {f : αSubtype p} :
                      (Primrec fun (a : α) => (f a)) Primrec f
                      theorem Primrec.subtype_mk {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {p : βProp} [DecidablePred p] {hp : PrimrecPred p} {f : αβ} {h : ∀ (a : α), p (f a)} (hf : Primrec f) :
                      Primrec fun (a : α) => f a,
                      theorem Primrec.option_get {α : Type u_1} {β : Type u_2} [Primcodable α] [Primcodable β] {f : αOption β} {h : ∀ (a : α), (f a).isSome = true} :
                      Primrec fPrimrec fun (a : α) => (f a).get
                      theorem Primrec.fin_val_iff {α : Type u_1} [Primcodable α] {n : } {f : αFin n} :
                      (Primrec fun (a : α) => (f a)) Primrec f
                      theorem Primrec.fin_val {n : } :
                      Primrec fun (i : Fin n) => i