@@ -27,6 +27,10 @@ theorem not_entails_not [DecidableEq X]
2727 EntailsInterpret I β F → ¬EntailsInterpret I β (Formula.neg F) :=
2828 fun a a_1 ↦ a_1 a
2929
30+ @[simp]
31+ def ValidIn [DecidableEq X] (F : Formula sig X) (I : Interpretation sig univ) : Prop :=
32+ ∀ (β : Assignment X univ), EntailsInterpret I β F
33+
3034/- ### Validity / Tautology
3135> ⊨ F :⇔ A |= F for all A ∈ Σ-Alg
3236 -/
@@ -160,104 +164,206 @@ theorem setEntails_iff_union_not_unsat [inst : DecidableEq X]
160164 cases hGornegN I β
161165 aesop
162166
167+ /- lemma term_eval_of_closed {sig : Signature} {X : Variables} [inst : DecidableEq X]
168+ (I : Interpretation sig univ) (F : Formula sig X) (hclosed : Formula.closed F) : -/
169+
170+ /- lemma validIn_of_entails_closed {sig : Signature} {X : Variables} [inst : DecidableEq X]
171+ (I : Interpretation sig univ) (F : Formula sig X) (hclosed : Formula.closed F) :
172+ (∃ (β : Assignment X univ), EntailsInterpret I β F) → ValidIn F I := by -/
173+
174+ lemma validIn_of_entails_closed {sig : Signature} {X : Variables} [inst : DecidableEq X]
175+ (I : Interpretation sig univ) (F : Formula sig X) (hclosed : Formula.closed F) :
176+ (∃ (β : Assignment X univ), EntailsInterpret I β F) → ValidIn F I := by
177+ intro hβ β
178+ rcases hβ with ⟨γ, hγ⟩
179+ have heval := Formula.eval_of_closed _ I F hclosed β γ
180+ rw [EntailsInterpret, heval, ← EntailsInterpret]
181+ exact hγ
182+
163183/- ### 3.3.4 Substitution Lemma -/
164184@[simp]
165185def Assignment.compose [DecidableEq X] (I : Interpretation sig univ) (β : Assignment X univ)
186+ (σ : Substitution sig X) : Assignment X univ :=
187+ fun x ↦ Term.eval I β (σ x)
188+
189+ @[simp]
190+ def Assignment.compose_term [DecidableEq X] (I : Interpretation sig univ) (β : Assignment X univ)
166191 (σ : Substitution sig X) (t : Term sig X) :
167192 univ :=
168193 match t with
169194 | Term.var x => Term.eval I β (σ x)
170- | Term.func f args => I.functions f <| args.attach.map (fun ⟨a, _⟩ => Assignment.compose I β σ a)
195+ | Term.func f args => I.functions f <| args.attach.map (fun ⟨a, _⟩ =>
196+ Assignment.compose_term I β σ a)
197+
198+ lemma Assignment.compose_term_eq_eval_compose [DecidableEq X] (I : Interpretation sig univ)
199+ (β : Assignment X univ) (σ : Substitution sig X) (t : Term sig X) :
200+ Assignment.compose_term I β σ t = Term.eval I (Assignment.compose I β σ) t := by
201+ induction' t using Term.induction with x args ih f
202+ · simp_all only [compose_term, Term.eval.eq_1, compose]
203+ · simp_all only [compose_term, List.map_subtype, List.unattach_attach, Term.eval.eq_2]
171204
172205theorem substitution_lemma [DecidableEq X]
173206 (I : Interpretation sig univ) (β : Assignment X univ) (σ : Substitution _ _) (t : Term _ _) :
174- Term.eval I β (t.substitute σ) = Assignment.compose I β σ t := by
175- match t with
176- | .var x => simp_all only [Term.substitute, Assignment.compose]
177- | .func f args =>
178- simp only [Term.substitute, List.map_subtype, List.unattach_attach, Term.eval,
179- List.mem_map, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, List.map_map,
180- Assignment.compose]
181- have hargsareequal :
182- List.map (Term.eval I β ∘ .substitute σ) args = .map (Assignment.compose I β σ) args := by
183- simp only [List.map_inj_left, Function.comp_apply]
184- intro t hargs
185- have h := substitution_lemma I β σ t
186- simp_all only
187- rw [hargsareequal]
188-
189- -- equivalent proof to show that the induction lemma we defined for terms actually works
190- theorem substitution_lemma' [DecidableEq X]
191- (I : Interpretation sig univ) (β : Assignment X univ) (σ : Substitution _ _) (t : Term _ _) :
192- Term.eval I β (t.substitute σ) = Assignment.compose I β σ t := by
207+ Term.eval I β (t.substitute σ) = Term.eval I (Assignment.compose I β σ) t := by
208+ rw [← Assignment.compose_term_eq_eval_compose]
193209 induction' t using Term.induction with x args ih f
194- · simp only [Term.substitute, Assignment.compose ]
195- · rw [Assignment.compose , Term.substitute]
210+ · simp_all only [Term.substitute.eq_1 , Assignment.compose_term ]
211+ · rw [Assignment.compose_term , Term.substitute]
196212 simp only [List.map_subtype, List.unattach_attach, Term.eval,
197213 List.mem_map, forall_exists_index, and_imp,
198214 forall_apply_eq_imp_iff₂, List.map_map]
199215 have hargsarequal :
200- List.map (Assignment.compose I β σ) args = .map (Term.eval I β ∘ .substitute σ) args := by
216+ List.map (Assignment.compose_term I β σ) args =
217+ List.map (Term.eval I β ∘ Term.substitute σ) args := by
201218 simp_all only [List.map_inj_left, Function.comp_apply, implies_true]
202219 rw [hargsarequal]
203220
221+ theorem three_three_five [DecidableEq X]
222+ (I : Interpretation sig univ) (β : Assignment X univ) (σ : Substitution _ _) (C : Clause _ _) :
223+ Formula.eval I β (C.substitute σ) = Formula.eval I (Assignment.compose I β σ) C := by
224+ simp_all only [Clause.substitute, eq_iff_iff]
225+ apply Iff.intro
226+ · intro heval
227+ induction' C with lit lits ih
228+ · simp_all only [List.map_nil, Clause.toFormula, Formula.eval]
229+ · match lit with
230+ | .pos a =>
231+ rw [List.map, Literal.substitute, Clause.toFormula, Formula.eval] at *
232+ rcases heval with ha | hrest
233+ · left
234+ induction' a with p args
235+ rw [Formula.eval, Atom.substitute, Atom.eval, List.map_map] at *
236+ have hargsarequal :
237+ List.map (Term.eval I β ∘ Term.substitute σ) args =
238+ List.map (Term.eval I (Assignment.compose I β σ)) args := by
239+ simp_all only [List.map_inj_left, Function.comp_apply]
240+ intro arg hargs
241+ rw [substitution_lemma]
242+ rw [← hargsarequal]
243+ exact ha
244+ · right
245+ exact ih hrest
246+ | .neg a =>
247+ rw [List.map, Literal.substitute, Clause.toFormula, Formula.eval] at *
248+ rcases heval with ha | hrest
249+ · left
250+ induction' a with p args
251+ rw [Formula.eval, Atom.substitute] at *
252+ simp_all only [Formula.eval, Atom.eval, List.map_map]
253+ apply Aesop.BuiltinRules.not_intro
254+ intro f
255+ have hargsarequal :
256+ List.map (Term.eval I β ∘ Term.substitute σ) args =
257+ List.map (Term.eval I (Assignment.compose I β σ)) args := by
258+ simp_all only [List.map_inj_left, Function.comp_apply]
259+ intro arg hargs
260+ rw [substitution_lemma]
261+ simp_all only [not_true_eq_false]
262+ · right
263+ exact ih hrest
264+ · intro heval
265+ induction' C with lit lits ih
266+ · simp_all only [List.map_nil, Clause.toFormula, Formula.eval]
267+ · match lit with
268+ | .pos a =>
269+ rw [List.map, Literal.substitute, Clause.toFormula, Formula.eval] at *
270+ rcases heval with ha | hrest
271+ · left
272+ induction' a with p args
273+ rw [Formula.eval, Atom.substitute, Atom.eval, List.map_map] at *
274+ have hargsarequal :
275+ List.map (Term.eval I β ∘ Term.substitute σ) args =
276+ List.map (Term.eval I (Assignment.compose I β σ)) args := by
277+ simp_all only [List.map_inj_left, Function.comp_apply]
278+ intro arg hargs
279+ rw [substitution_lemma]
280+ rw [hargsarequal]
281+ exact ha
282+ · right
283+ exact ih hrest
284+ | .neg a =>
285+ rw [List.map, Literal.substitute, Clause.toFormula, Formula.eval] at *
286+ rcases heval with ha | hrest
287+ · left
288+ induction' a with p args
289+ rw [Formula.eval, Atom.substitute] at *
290+ simp_all only [Formula.eval, Atom.eval, List.map_map]
291+ apply Aesop.BuiltinRules.not_intro
292+ intro f
293+ have hargsarequal :
294+ List.map (Term.eval I β ∘ Term.substitute σ) args =
295+ List.map (Term.eval I (Assignment.compose I β σ)) args := by
296+ simp_all only [List.map_inj_left, Function.comp_apply]
297+ intro arg hargs
298+ rw [substitution_lemma]
299+ simp_all only [not_true_eq_false]
300+ · right
301+ exact ih hrest
302+
303+ -- corollary
304+ theorem three_three_six [DecidableEq X]
305+ (I : Interpretation sig univ) (β : Assignment X univ) (σ : Substitution _ _) (C : Clause _ _) :
306+ EntailsInterpret I β (C.substitute σ) ↔ EntailsInterpret I (Assignment.compose I β σ) C := by
307+ rw [EntailsInterpret, EntailsInterpret, ← eq_iff_iff]
308+ exact three_three_five I β σ C
309+
204310/- ### Lemma 3.3.7 -/
205- --(hfree : ∀ x ∈ xs, x ∈ F.freeVars)
206- lemma three_three_seven [DecidableEq X] (n : ℕ)
207- (F : Formula sig X) (xs : List X) (huniq : xs.Nodup) (hn : xs.length = n) :
208- @Valid _ _ univ _ (Formula.bigForall _ _ xs F) ↔ @Valid _ _ univ _ F := by
311+ lemma three_three_seven [DecidableEq X] (n : ℕ) (F : Formula sig X) (I : Interpretation sig univ)
312+ (xs : List X) (huniq : xs.Nodup) (hn : xs.length = n) :
313+ ValidIn (F.bigForall _ _ xs) I ↔ ValidIn F I := by
209314 apply Iff.intro
210- · intro hvalid I γ
211- specialize hvalid I
315+ · intro hvalid γ
212316 have hlemma (as : List univ) (hlen : xs.length = as.length) :
213317 Formula.eval I (Assignment.bigModify γ xs as) F := by
214- induction' n with n ih generalizing γ xs as
215- · have h : xs = [] := by exact List.length_eq_zero.mp hn
216- have h2 : as = [] := by rw [h] at hlen; exact List.length_eq_zero.mp (id (Eq.symm hlen))
217- rw [h, h2]
218- subst h2 h
219- simp_all only [List.nodup_nil, List.length_nil, Assignment,
220- Formula.bigForall, Assignment.bigModify]
318+ induction' n with n ih generalizing γ xs as F
319+ · aesop
221320 · match xs, as with
222321 | x :: xs, a :: as =>
223322 rw [Assignment.bigModify]
224323 have hstillvalid :
225324 ∀ (β : Assignment X univ), Formula.eval I β (Formula.bigForall _ _ xs F) := by
226325 intro β
227- rw [Formula.bigForall] at hvalid
326+ rw [Formula.bigForall, ValidIn ] at hvalid
228327 specialize hvalid β
229- rw [Formula.eval] at hvalid
328+ rw [EntailsInterpret, Formula.eval] at hvalid
230329 specialize hvalid (β x)
231330 rw [Assignment.modify_rfl] at hvalid
232331 exact hvalid
233- specialize ih xs (List.Nodup.of_cons huniq) (by exact Nat.succ_inj'.mp hn)
234- (γ.modify x a) hstillvalid as (Nat.succ_inj'.mp hlen)
235- exact ih
332+ simp_all only [ValidIn, Assignment, EntailsInterpret, List.nodup_cons, List.length_cons,
333+ Nat.add_right_cancel_iff, Formula.bigForall, Formula.eval, implies_true]
236334 | [], [] =>
237- simp_all only [List.nodup_nil , Assignment, Formula.bigForall , List.length_nil,
238- Assignment.bigModify, implies_true , Nat.add_one_ne_zero]
335+ simp_all only [ValidIn , Assignment, EntailsInterpret, List.nodup_nil , List.length_nil,
336+ Nat.self_eq_add_left , Nat.add_one_ne_zero]
239337 set as : List univ := List.map γ xs with has
240338 have hsubequal : γ = Assignment.bigModify γ xs as := by
241339 exact Assignment.substitute_equality γ xs
242340 rw [hsubequal]
243341 apply hlemma as (Eq.symm (List.length_map xs γ))
244- · intro hvalid I β
245- specialize hvalid I
342+ · intro hvalid β
246343 induction' xs with x xs ih generalizing β n
247- · simp_all only [Valid, Assignment, List.nodup_nil, Formula.bigForall]
248- · rw [Formula.bigForall]
249- rw [Formula.eval]
344+ · simp_all only [ValidIn, Valid, Assignment, List.nodup_nil, Formula.bigForall]
345+ · rw [EntailsInterpret, Formula.bigForall, Formula.eval]
250346 intro a
251- specialize ih (n - 1 ) (List.Nodup.of_cons huniq) (Nat.eq_sub_of_add_eq hn) (β.modify x a)
252- exact ih
347+ exact ih (n - 1 ) (List.Nodup.of_cons huniq) (Nat.eq_sub_of_add_eq hn) (β.modify x a)
348+
349+ lemma valid_sub_of_valid {I : Interpretation sig univ} [DecidableEq X] (C : Clause sig X)
350+ (σ : Substitution sig X) :
351+ ValidIn (Clause.toFormula sig X C) I →
352+ ValidIn (Clause.toFormula sig X (Clause.substitute σ C)) I := by
353+ intro hvalid γ
354+ specialize hvalid (Assignment.compose I γ σ)
355+ rw [EntailsInterpret] at *
356+ rw [three_three_five]
357+ exact hvalid
253358
254359/- ### Lemma 3.3.8 -/
255- lemma three_three_eight {sig : Signature} {X : Variables} [DecidableEq X] (n m : ℕ)
256- (C : Clause sig X) (xs : List X) (hxuniq : xs.Nodup) (hn : xs.length = n)
257- (σ : Substitution sig X) (ys : List X) (hyuniq : ys.Nodup) (hm : ys.length = m) :
258- @Valid _ _ univ _ (Formula.bigForall _ _ xs C.toFormula) →
259- @Valid _ _ univ _ (Formula.bigForall _ _ ys (C.substitute σ).toFormula) := by
360+ lemma three_three_eight {sig : Signature} {X : Variables} [DecidableEq X] (C : Clause sig X)
361+ (I : Interpretation sig univ) (σ : Substitution sig X) (n m : ℕ)
362+ (xs ys : List X) (hxuniq : xs.Nodup) (hn : xs.length = n)
363+ (hyuniq : ys.Nodup) (hm : ys.length = m) :
364+ ValidIn (Formula.bigForall _ _ xs C.toFormula) I →
365+ ValidIn (Formula.bigForall _ _ ys (C.substitute σ).toFormula) I := by
260366 intro h
261- have := (three_three_seven n C.toFormula xs hxuniq hn).mp h
262- apply (three_three_seven m (C.substitute σ).toFormula ys hyuniq hm).mpr
263- sorry -- use 3.3.5 (see lecture notes)
367+ have hl := (three_three_seven n C.toFormula I xs hxuniq hn).mp h
368+ apply (three_three_seven m (C.substitute σ).toFormula I ys hyuniq hm).mpr
369+ exact valid_sub_of_valid C σ hl
0 commit comments