Section Code_PA.
Let codeTerm := codeTerm LNT codeLNTFunction.
Let codeFormula := codeFormula LNT codeLNTFunction codeLNTRelation.
Let codeFormulaInj :=
codeFormulaInj LNT codeLNTFunction codeLNTRelation codeLNTFunctionInj
codeLNTRelationInj.
Definition codeOpen : nat -> nat :=
evalStrongRec 0
(fun f recs : nat =>
switchPR (cPairPi1 f)
(switchPR (pred (cPairPi1 f))
(switchPR (pred (pred (cPairPi1 f)))
(switchPR (pred (pred (pred (cPairPi1 f)))) f
(codeNth (f - S (cPairPi2 (cPairPi2 f))) recs)) f) f) f).

(* Specifications: *)
Lemma codeOpenCorrect :
forall f : Formula, codeOpen (codeFormula f) = codeFormula (open f).
Lemma codeOpenIsPR : isPR 1 codeOpen.
Definition codeInductionSchema (f : nat) : bool :=
let n :=
cPairPi1
(cPairPi2 (cPairPi2 (cPairPi2 (cPairPi2 (cPairPi2 (codeOpen f)))))) in
let g :=
cPairPi2
(cPairPi2 (cPairPi2 (cPairPi2 (cPairPi2 (cPairPi2 (codeOpen f)))))) in
beq_nat
(codeClose
(codeImp (codeSubFormula g n (codeTerm Zero))
(codeImp
(codeForall n
(codeImp g (codeSubFormula g n (codeTerm (Succ (var n))))))
(codeForall n g)))) f.
Lemma codeInductionSchemaCorrect1 :
forall f : Formula,
InductionSchema f -> codeInductionSchema (codeFormula f) = true.
Lemma codeInductionSchemaCorrect2 :
forall f : Formula,
codeInductionSchema (codeFormula f) = true -> InductionSchema f.
Lemma codeInductionSchemaCorrect3 :
forall f : Formula,
~ InductionSchema f -> codeInductionSchema (codeFormula f) = false.
Lemma codeInductionSchemaIsPR : isPRrel 1 codeInductionSchema.
Definition codePA : nat -> bool :=
orRel 1 (beq_nat (codeFormula PA6))
(orRel 1 (beq_nat (codeFormula PA5))
(orRel 1 (beq_nat (codeFormula PA4))
(orRel 1 (beq_nat (codeFormula PA3))
(orRel 1 (beq_nat (codeFormula PA2))
(orRel 1 (beq_nat (codeFormula PA1)) codeInductionSchema))))).
Lemma codePAcorrect1 :
forall f : Formula,
codePA (codeFormula f) = true -> mem Formula PA f.
Lemma codePAcorrect2 :
forall f : Formula,
~ mem Formula PA f -> codePA (codeFormula f) = false.
Lemma codePAcorrect3 :
forall f : Formula,
mem Formula PA f -> codePA (codeFormula f) = true.
Lemma codePAIsPR : isPRrel 1 codePA.
End Code_PA.