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).

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).