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_1 (n : nat) (p : frm L) (m : nat) (s : subst L)
(BOUND : forall y, y < n -> forall z : ivar, is_free_in_trm z (s (m + y)) = true -> z < m)
: E.empty \proves Imp_frm (close_from m n p) (subst_frm (fun x : ivar => if le_lt_dec m x then if le_lt_dec (m + n) x then Var_trm x else s x else Var_trm x) p).