Section fot_word_var.
(* when arity of symbols is 1, terms have the shape s1(s2(...sn(i)...)) where [s1,...,sn] is a list of symbols and i is a variable *)
Variable (X : Type).
Implicit Type t : fo_term (fun _ : X => 1).
Fixpoint fot_var t :=
match t with
| in_var i   => i
| in_fot s v => fot_var (vec_pos v pos0)
end.
Fixpoint fot_word t :=
match t with
| in_var i   => nil
| in_fot s v => s::fot_word (vec_pos v pos0)
end.
Fixpoint fot_word_var w i : fo_term (fun _ : X => 1) :=
match w with
| nil  => in_var i
| s::w => in_fot s (fot_word_var w i##ø)
end.
Fact fot_word_var_eq t : t = fot_word_var (fot_word t) (fot_var t).
Fact fot_word_eq w i : fot_word (fot_word_var w i) = w.
Let lwY := proj1_sig YwY_fin.
Let HlwY p : In p lwY.
Variable (A : fol_form Σ) (HwA : forall w, In w (Σ11_words A) -> length w < S m).
(* Equations P_r(£0) <-> Q_(nil,r) (£0) and Q_(s::w,r) (£0) <-> Q_(w,r) (s(£0)) *)
Let Eq (p : Yw * Y) :=
let (w,r) := p  in
let (w,_) := w in
match w with
| nil   => @fol_atom Σ' (inl (nil,r)) (£0##ø)
↔ @fol_atom Σ' (inr r) (£0##ø)
| s::w' => @fol_atom Σ' (inl (w',r)) (@in_fot _ (ar_syms Σ') s (£0##ø)##ø)
↔ @fol_atom Σ' (inl (w,r)) (£0##ø)
end.
(* The previous equation but skolemized by s(£0) <-> £(s) *)
Let Eq' (p : Yw * Y) :=
let (w,r) := p  in
let (w,_) := w in
match w with
| nil   => @fol_atom Σ' (inl (nil,r)) (£n##ø)
↔ @fol_atom Σ' (inr r) (£n##ø)
| s::w' => @fol_atom Σ' (inl (w',r)) (£(pos2nat s)##ø)
↔ @fol_atom Σ' (inl (w,r)) (£n##ø)
end.
(* We first deals with the non-skolemized reduction *)
Definition Σfull_mon_red : fol_form Σ' :=
Σfull_mon_rec A ⟑ ∀ fol_lconj (map Eq lwY).
Variable (K : Type).
Let Fixpoint f (M : fo_model Σ K) w x :=
match w with
| nil  => x
| s::w => f M w (fom_syms M s (x##ø))
end.
Let f_app M w1 w2 x : f M (w1++w2) x = f M w2 (f M w1 x).
Variable (Kfin : finite_t K)
(Mdec : fo_model_dec M)
(φ : nat -> K)
(HA : fol_sem M φ A).

Theorem Σfull_mon_rem_sound : fo_form_fin_dec_SAT_in Σfull_mon_red K.