Section SUBST. (* Reference: "https://github.com/princeton-vl/CoqGym/blob/master/coq_projects/goedel/subAll.v" *)
Fixpoint close_from (a : nat) (n : nat) (p : frm L) {struct n} : frm L :=
match n with
| O => p
| S m => All_frm (a + m) (close_from a m p)
end.
#[global]
Add Parametric Morphism
: close_from with signature (eq ==> eq ==> alpha_equiv ==> alpha_equiv)
as close_from_compat_with_alpha.
#[local] Opaque le_lt_dec.
Fixpoint multiple_subst (m : nat) (n : nat) (p : frm L) : frm L :=
match n with
| O => p
| S n' => subst1 n' (Var_trm (m + n')) (multiple_subst m n' p)
end.

Lemma subst_frm_close_frm (n : nat) (s : subst L) (p : frm L)
: E.empty \proves Imp_frm (close_from 0 n p) (subst_frm (fun x : ivar => if le_lt_dec n x then Var_trm x else s x) p).