Section Formula_Depth_Induction.
Fixpoint depth (A : Formula) : nat :=
match A with
| equal _ _ => 0
| atomic _ _ => 0
| impH A B => S (max (depth A) (depth B))
| notH A => S (depth A)
| forallH _ A => S (depth A)
end.
Definition lt_depth (A B : Formula) : Prop := depth A < depth B.
Definition Formula_depth_rec_rec :
forall P : Formula -> Set,
(forall a : Formula, (forall b : Formula, lt_depth b a -> P b) -> P a) ->
forall (n : nat) (b : Formula), depth b <= n -> P b.
intros P H n.
induction n as [| n Hrecn].
intros.
apply H.
intros.
unfold lt_depth in H1.
rewrite <- (le_n_O_eq _ H0) in H1.
elim (lt_n_O _ H1).
intros.
apply H.
intros.
apply Hrecn.
apply lt_n_Sm_le.
apply lt_le_trans with (depth b).
apply H1.
apply H0.
Defined.
Definition Formula_depth_rec (P : Formula -> Set)
(rec : forall a : Formula, (forall b : Formula, lt_depth b a -> P b) -> P a)
(a : Formula) : P a :=
Formula_depth_rec_rec P rec (depth a) a (le_n (depth a)).
Definition Formula_depth_rec2rec (P : Formula -> Set)
(f1 : forall t t0 : Term, P (equal t t0))
(f2 : forall (r : Relations L) (t : Terms (arity L (inl (Functions L) r))),
P (atomic r t))
(f3 : forall f : Formula, P f -> forall f0 : Formula, P f0 -> P (impH f f0))
(f4 : forall f : Formula, P f -> P (notH f))
(f5 : forall (v : nat) (a : Formula),
(forall b : Formula, lt_depth b (forallH v a) -> P b) ->
P (forallH v a)) (a : Formula) :
(forall b : Formula, lt_depth b a -> P b) -> P a :=
match a return ((forall b : Formula, lt_depth b a -> P b) -> P a) with
| equal t s => fun _ => f1 t s
| atomic r t => fun _ => f2 r t
| impH f g =>
fun hyp => f3 f (hyp f (depthImp1 f g)) g (hyp g (depthImp2 f g))
| notH f => fun hyp => f4 f (hyp f (depthNot f))
| forallH n f => fun hyp => f5 n f hyp
end.
Definition Formula_depth_rec2 (P : Formula -> Set)
(f1 : forall t t0 : Term, P (equal t t0))
(f2 : forall (r : Relations L) (t : Terms (arity L (inl (Functions L) r))),
P (atomic r t))
(f3 : forall f : Formula, P f -> forall f0 : Formula, P f0 -> P (impH f f0))
(f4 : forall f : Formula, P f -> P (notH f))
(f5 : forall (v : nat) (a : Formula),
(forall b : Formula, lt_depth b (forallH v a) -> P b) ->
P (forallH v a)) (a : Formula) : P a :=
Formula_depth_rec P (Formula_depth_rec2rec P f1 f2 f3 f4 f5) a.
Remark Formula_depth_rec2rec_nice :
forall (Q P : Formula -> Set)
(f1 : forall t t0 : Term, Q (equal t t0) -> P (equal t t0))
(f2 : forall (r : Relations L) (t : Terms (arity L (inl (Functions L) r))),
Q (atomic r t) -> P (atomic r t))
(f3 : forall f : Formula,
(Q f -> P f) ->
forall f0 : Formula,
(Q f0 -> P f0) -> Q (impH f f0) -> P (impH f f0)),
(forall (f g : Formula) (z1 z2 : Q f -> P f),
(forall q : Q f, z1 q = z2 q) ->
forall z3 z4 : Q g -> P g,
(forall q : Q g, z3 q = z4 q) ->
forall q : Q (impH f g), f3 f z1 g z3 q = f3 f z2 g z4 q) ->
forall f4 : forall f : Formula, (Q f -> P f) -> Q (notH f) -> P (notH f),
(forall (f : Formula) (z1 z2 : Q f -> P f),
(forall q : Q f, z1 q = z2 q) ->
forall q : Q (notH f), f4 f z1 q = f4 f z2 q) ->
forall
f5 : forall (v : nat) (a : Formula),
(forall b : Formula, lt_depth b (forallH v a) -> Q b -> P b) ->
Q (forallH v a) -> P (forallH v a),
(forall (v : nat) (a : Formula)
(z1 z2 : forall b : Formula, lt_depth b (forallH v a) -> Q b -> P b),
(forall (b : Formula) (q : lt_depth b (forallH v a)) (r : Q b),
z1 b q r = z2 b q r) ->
forall q : Q (forallH v a), f5 v a z1 q = f5 v a z2 q) ->
forall (a : Formula)
(z1 z2 : forall b : Formula, lt_depth b a -> Q b -> P b),
(forall (b : Formula) (p : lt_depth b a) (q : Q b), z1 b p q = z2 b p q) ->
forall q : Q a,
Formula_depth_rec2rec (fun x : Formula => Q x -> P x) f1 f2 f3 f4 f5 a z1 q =
Formula_depth_rec2rec (fun x : Formula => Q x -> P x) f1 f2 f3 f4 f5 a z2 q.

Lemma Formula_depth_rec2_not :
forall (Q P : Formula -> Set)
(f1 : forall t t0 : Term, Q (equal t t0) -> P (equal t t0))
(f2 : forall (r : Relations L) (t : Terms (arity L (inl (Functions L) r))),
Q (atomic r t) -> P (atomic r t))
(f3 : forall f : Formula,
(Q f -> P f) ->
forall f0 : Formula,
(Q f0 -> P f0) -> Q (impH f f0) -> P (impH f f0)),
(forall (f g : Formula) (z1 z2 : Q f -> P f),
(forall q : Q f, z1 q = z2 q) ->
forall z3 z4 : Q g -> P g,
(forall q : Q g, z3 q = z4 q) ->
forall q : Q (impH f g), f3 f z1 g z3 q = f3 f z2 g z4 q) ->
forall f4 : forall f : Formula, (Q f -> P f) -> Q (notH f) -> P (notH f),
(forall (f : Formula) (z1 z2 : Q f -> P f),
(forall q : Q f, z1 q = z2 q) ->
forall q : Q (notH f), f4 f z1 q = f4 f z2 q) ->
forall
f5 : forall (v : nat) (a : Formula),
(forall b : Formula, lt_depth b (forallH v a) -> Q b -> P b) ->
Q (forallH v a) -> P (forallH v a),
(forall (v : nat) (a : Formula)
(z1 z2 : forall b : Formula, lt_depth b (forallH v a) -> Q b -> P b),
(forall (b : Formula) (q : lt_depth b (forallH v a)) (r : Q b),
z1 b q r = z2 b q r) ->
forall q : Q (forallH v a), f5 v a z1 q = f5 v a z2 q) ->
forall (a : Formula) (q : Q (notH a)),
Formula_depth_rec2 (fun x : Formula => Q x -> P x) f1 f2 f3 f4 f5 (notH a) q =
f4 a (Formula_depth_rec2 (fun x : Formula => Q x -> P x) f1 f2 f3 f4 f5 a) q.