Fixpoint closeFrom (a n : nat) (f : fol.Formula L) {struct n} :
 fol.Formula L :=
  match n with
  | O => f
  | S m => fol.forallH L (a + m) (closeFrom a m f)
  end.

(* Specifications: *)
Lemma liftCloseFrom : forall (n : nat) (f : fol.Formula L) (T : fol.System L) (m : nat), (forall v : nat, In v (freeVarFormula L f) -> v < m) -> n <= m -> folProof.SysPrf L T (closeFrom 0 n f) -> folProof.SysPrf L T (closeFrom m n (subAllFormula f (fun x : nat => match le_lt_dec n x with | left _ => fol.var L x | right _ => fol.var L (m + x) end))).
Lemma subAllCloseFrom1 : forall (n m : nat) (map : nat -> fol.Term L) (f : fol.Formula L) (T : fol.System L), (forall v : nat, v < n -> forall w : nat, In w (freeVarTerm L (map (m + v))) -> w < m) -> folProof.SysPrf L T (closeFrom m n f) -> folProof.SysPrf L T (subAllFormula f (fun x : nat => match le_lt_dec m x with | left _ => match le_lt_dec (m + n) x with | left _ => fol.var L x | right _ => map x end | right _ => fol.var L x end)).
Lemma subAllCloseFrom : forall (n : nat) (m : nat -> fol.Term L) (f : fol.Formula L) (T : fol.System L), folProof.SysPrf L T (closeFrom 0 n f) -> folProof.SysPrf L T (subAllFormula f (fun x : nat => match le_lt_dec n x with | left _ => fol.var L x | right _ => m x end)).
Lemma reduceSubAll : forall (T : fol.System L) (map : nat -> fol.Term L) (A B : fol.Formula L), (forall v : nat, ~ In_freeVarSys L v T) -> folProof.SysPrf L T (fol.iffH L A B) -> folProof.SysPrf L T (fol.iffH L (subAllFormula A map) (subAllFormula B map)).
Lemma subToSubAll : forall (T : fol.System L) (A : fol.Formula L) (v : nat) (s : fol.Term L), folProof.SysPrf L T (fol.iffH L (substituteFormula L A v s) (subAllFormula A (fun x : nat => match eq_nat_dec v x with | left _ => s | right _ => fol.var L x end))).
Lemma subAllSubFormula : forall (T : fol.System L) (A : fol.Formula L) (v : nat) (s : fol.Term L) (map : nat -> fol.Term L), folProof.SysPrf L T (fol.iffH L (subAllFormula (substituteFormula L A v s) map) (subAllFormula A (fun x : nat => match eq_nat_dec v x with | left _ => subAllTerm s map | right _ => map x end))).