Require Vector.
Section Code_Substitute_Term.
Variable L : Language.
Variable codeF : Functions L -> nat.
Let Formula := Formula L.
Let Formulas := Formulas L.
Let System := System L.
Let Term := Term L.
Let Terms := Terms L.
Let var := var L.
Let apply := apply L.
Definition codeSubTermTerms : nat -> nat -> nat -> nat :=
evalStrongRec 2
(fun t recs v s : nat =>
cPair
(switchPR (cPairPi1 t)
(cPair (cPairPi1 t) (cPairPi2 (codeNth (t - S (cPairPi2 t)) recs)))
(switchPR (charFunction 2 beq_nat (cPairPi2 t) v) s t))
(switchPR t
(S
(cPair (cPairPi1 (codeNth (t - S (cPairPi1 (pred t))) recs))
(cPairPi2 (codeNth (t - S (cPairPi2 (pred t))) recs)))) 0)).
Definition codeSubTerm (t s v : nat) : nat :=
cPairPi1 (codeSubTermTerms t s v).
Definition codeSubTerms (t s v : nat) : nat :=
cPairPi2 (codeSubTermTerms t s v).

(* Specifications: *)
Lemma codeSubTermCorrect :
forall (t : Term) (v : nat) (s : Term),
codeSubTerm (codeTerm L codeF t) v (codeTerm L codeF s) =
codeTerm L codeF (substituteTerm L t v s).
Lemma codeSubTermsCorrect :
forall (n : nat) (ts : Terms n) (v : nat) (s : Term),
codeSubTerms (codeTerms L codeF n ts) v (codeTerm L codeF s) =
codeTerms L codeF n (substituteTerms L n ts v s).
Lemma codeSubTermTermsIsPR : isPR 3 codeSubTermTerms.
Lemma codeSubTermIsPR : isPR 3 codeSubTerm.
Lemma codeSubTermsIsPR : isPR 3 codeSubTerms.
End Code_Substitute_Term.