Section Sign_Sig2_encoding.
Variable (n : nat).
Notation Σ2 := (Σrel 2).
Notation Σn := (Σrel n).
Infix "∈" := Σ2_mem.
Infix "≈" := Σ2_equiv.
Infix "⊆" := Σ2_incl.
(* We bound quantification inside hf-set l ∈ p and r ∈ p represent a set of ordered triples corresponding to M3 *)
Fixpoint Σn_Σ2 (d r : nat) (A : fol_form Σn) : fol_form Σ2 :=
match A with
| ⊥             => ⊥
| fol_atom _  v => Σ2_is_tuple_in r (vec_map (@Σrel_var _) v)
| fol_bin b A B => fol_bin b (Σn_Σ2 d r A) (Σn_Σ2 d r B)
| fol_quant fol_fa A  => ∀ 0 ∈ (S d) ⤑ Σn_Σ2 (S d) (S r) A
| fol_quant fol_ex A  => ∃ 0 ∈ (S d) ⟑ Σn_Σ2 (S d) (S r) A
end.
Variable (X : Type) (M2 : fo_model Σ2 X).
Variable (Y : Type) (Mn : fo_model Σn Y).
Let mem a b := fom_rels M2 tt (a##b##ø).
Infix "∈m" := mem (at level 59, no associativity).
Notation P := (fun v => fom_rels Mn tt v).
Variable R : Y -> X -> Prop.
(* R represent a relation  Mn <~> M2 = { x | x ∈ p } which ensures the soundness & completeness of the encoding These are the conditions for correctness  HR1 : R is onto from Mn to { x | x ∈ l } HR2 : R is onto from { x | x ∈ l } to Mn HR3 : R relates the n-ary relation in Mn and the n-ary relation <_,...,_> ∈ r in M2  *)
Let HR1 (d r : X) := forall y, exists x, x ∈m d /\ R y x.
Let HR2 (d r : X) := forall x, x ∈m d -> exists y, R y x.
Let HR3 (d r : X) := forall v w, (forall p, R (vec_pos v p) (vec_pos w p))
-> P v <-> mb_is_tuple_in mem r w.
Notation "⟪ A ⟫" := (fun ψ => fol_sem M2 ψ A).
Notation "⟪ A ⟫'" := (fun φ => fol_sem Mn φ A) (at level 1, format "⟪ A ⟫'").
(* The correctness lemma *)

Lemma Σn_Σ2_correct (A : fol_form Σn) d r φ ψ :
HR1 (ψ d) (ψ r)
-> HR2 (ψ d) (ψ r)
-> HR3 (ψ d) (ψ r)
-> (forall x, In x (fol_vars A) -> R (φ x) (ψ x))
-> ⟪ A ⟫' φ <-> ⟪Σn_Σ2 d r A⟫ ψ.