Section Substitution.
Fixpoint substituteTerm (s : fol.Term L) (x : nat)
(t : fol.Term L) {struct s} : fol.Term L :=
match s with
| fol.var v =>
match eq_nat_dec x v with
| left _ => t
| right _ => var v
end
| fol.apply f ts => apply f (substituteTerms _ ts x t)
end
with substituteTerms (n : nat) (ss : fol.Terms L n)
(x : nat) (t : fol.Term L) {struct ss} : fol.Terms L n :=
match ss in (fol.Terms _ n0) return (fol.Terms L n0) with
| Tnil => Tnil L
| Tcons m s ts =>
Tcons L m (substituteTerm s x t) (substituteTerms m ts x t)
end.
Definition newVar (l : list nat) : nat := fold_right max 0 (map S l).

Lemma newVar1 : forall l : list nat, ~ In (newVar l) l.