Section EQUATIONS. (* Reference: "https://github.com/princeton-vl/CoqGym/blob/master/coq_projects/goedel/folLogic3.v" *)
Fixpoint pairwise_equal {n : nat} (Gamma : ensemble (frm L)) {struct n} : trms L n -> trms L n -> Prop :=
match n with
| O => fun ts => fun ts' => True
| S n' => fun ts => fun ts' => Gamma \proves (Eqn_frm (head ts) (head ts')) /\ pairwise_equal (n := n') Gamma (tail ts) (tail ts')
end.
Definition trms_map : forall n, trms L n -> trms L n -> subst L :=
nat_rec (fun n => trms L n -> trms L n -> ivar -> trm L) (fun _ => fun _ => fun z => Var_trm z) (fun n => fun ACC => fun ts => fun ts' => fun z => if eq_dec z (n + n) then head ts else if eq_dec z (S (n + n)) then head ts' else ACC (tail ts) (tail ts') z).

Lemma add_pairwise_equals n (ts : trms L n) (ts' : trms L n) (s : subst L) (Gamma : ensemble (frm L)) (p : frm L)
(EQs : pairwise_equal Gamma ts ts')
(BOUND : forall z : ivar, z < n + n -> s z = trms_map n ts ts' z)
(PROVE : Gamma \proves subst_frm s (nat_rec (fun _ => frm L) p (fun m : nat => fun ACC : frm L => Imp_frm (Eqn_frm (Var_trm (m + m)) (Var_trm (S (m + m)))) ACC) n))
: Gamma \proves subst_frm s p.