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 multiple_subst_simultaneous_subst (m : nat) (n : nat) (p : frm L)
(LE : n <= m)
(BOUND : forall z : ivar, is_free_in_frm z p = true -> z < m)
: multiple_subst m n p ≡ subst_frm (fun x : ivar => if le_lt_dec n x then Var_trm x else Var_trm (m + x)) p.