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 varcouples_subst_snd n (ts : trms L n) (ts' : trms L n)
: subst_trms (trms_map n ts ts') (snd (varcouples n)) = ts'.