Definition newVar (l : list nat) : nat := fold_right max 0 (map S l).

Lemma newVar1 : forall l : list nat, ~ In (newVar l) l.
Definition substituteFormulaImp (f : fol.Formula L)
(frec : nat * fol.Term L -> {y : fol.Formula L | depth L y = depth L f})
(g : fol.Formula L)
(grec : nat * fol.Term L -> {y : fol.Formula L | depth L y = depth L g})
(p : nat * fol.Term L) :
{y : fol.Formula L | depth L y = depth L (impH f g)} :=
match frec p with
| exist f' prf1 =>
match grec p with
| exist g' prf2 =>
exist
(fun y : fol.Formula L =>
depth L y = S (max (depth L f) (depth L g)))
(impH f' g')
(eq_ind_r
(fun n : nat =>
S (max n (depth L g')) = S (max (depth L f) (depth L g)))
(eq_ind_r
(fun n : nat =>
S (max (depth L f) n) = S (max (depth L f) (depth L g)))
(refl_equal (S (max (depth L f) (depth L g)))) prf2) prf1)
end
end.