Skip to content

Commit 6af6640

Browse files
committed
Adjust and finish proofs for 3.3.5-3.3.8
1 parent 28be8c9 commit 6af6640

File tree

4 files changed

+236
-83
lines changed

4 files changed

+236
-83
lines changed

InferenceInLean/Basic.lean

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ lemma eval_append_iff_eval_or [DecidableEq X]
5858
rw [ih]
5959
aesop
6060

61+
lemma eval_append_iff_eval_or_subst [DecidableEq X] {I : Interpretation sig univ}
62+
(β : Assignment X univ) (C D : Clause sig X) (σ : Substitution sig X):
63+
Formula.eval I β ↑((C ++ D).substitute σ) ↔
64+
Formula.eval I β (Formula.or ↑(C.substitute σ) ↑(D.substitute σ)) := by
65+
induction' C with c cs ih generalizing D
66+
· simp_all only [Clause.substitute, Clause, List.nil_append, Formula.eval, List.map_nil,
67+
Clause.toFormula, false_or]
68+
· match c with
69+
| .pos a => aesop
70+
| .neg a => aesop
71+
6172
theorem groundResolution_soundness {A : Atom sig Empty} {C D : Clause sig Empty} :
6273
@Soundness _ _ univ _ (GroundResolution sig A C D):= by
6374
intro rule h_rule_ground hcond I β h_premise_true
@@ -83,34 +94,49 @@ theorem groundResolution_soundness {A : Atom sig Empty} {C D : Clause sig Empty}
8394

8495
-- TODO: do we need to add that freeVars ∩ freeVars = ∅?
8596
@[simp]
86-
def GeneralResolutionRule [inst : DecidableEq X] (A B : Atom sig X) (C D : Clause sig X) :
97+
def GeneralResolutionRule [inst : DecidableEq X] (A B : Atom sig X) (C D : Clause sig X)
98+
(σ : Substitution sig X) :
8799
Inference sig X :=
88-
⟨{.pos A :: C, .neg B :: D}, C ++ D, ∃ σ : Substitution sig X, MostGeneralUnifier [(A, B)] σ⟩
100+
⟨{.neg A :: C, .pos B :: D}, (C ++ D).substitute σ, MostGeneralUnifier [(A, B)] σ⟩
89101

90102
@[simp]
91-
def GeneralFactorizationRule [inst : DecidableEq X] (A B : Atom sig X) (C : Clause sig X) :
103+
def GeneralFactorizationRule [inst : DecidableEq X] (A B : Atom sig X) (C : Clause sig X)
104+
(σ : Substitution sig X) :
92105
Inference sig X :=
93-
⟨{.pos A :: .pos B :: C}, .pos A :: C, ∃ σ : Substitution sig X, MostGeneralUnifier [(A, B)] σ⟩
106+
⟨{.pos A :: .pos B :: C}, Clause.substitute σ (.pos A :: C), MostGeneralUnifier [(A, B)] σ⟩
94107

95-
theorem generalResolution_soundness [inst : DecidableEq X] {A B : Atom sig X} {C D : Clause sig X} :
96-
@Soundness _ _ univ _ ([GeneralResolutionRule A B C D, GeneralFactorizationRule A B C]):= by
108+
theorem generalResolution_soundness [inst : DecidableEq X] {A B : Atom sig X} {C D : Clause sig X}
109+
{σ : Substitution sig X} :
110+
@Soundness _ _ univ _ ([GeneralResolutionRule A B C D σ, GeneralFactorizationRule A B C σ]):= by
97111
rw [Soundness]
98-
intro rule h_rule_ground hcond I β h_premise_true
99-
simp_all only [GeneralResolutionRule, Clause, List.append_eq, GeneralFactorizationRule,
100-
EntailsInterpret]
101-
rw [List.mem_cons, List.mem_singleton] at h_rule_ground
102-
cases h_rule_ground
112+
intro rule h_rule_general hcond I
113+
114+
intro β h_premise_true
115+
simp_all only [GeneralResolutionRule, Clause, List.append_eq, GeneralFactorizationRule]
116+
rw [List.mem_cons, List.mem_singleton] at h_rule_general
117+
cases h_rule_general
103118
-- proof of resolution rule
104119
next h_res_rule =>
105120
subst h_res_rule
106121
simp only [GeneralResolutionRule] at h_premise_true
107122
simp_all only [Clause, GeneralResolutionRule, List.append_eq, Substitution.eq_1,
108123
MostGeneralUnifier, Unifier, Equality.eq_1, EqualityProblem.eq_1, List.mem_singleton,
109124
forall_eq, MoreGeneral, Set.mem_insert_iff, Set.mem_singleton_iff,
110-
EntailsInterpret, forall_eq_or_imp, Clause.toFormula, Formula.eval]
111-
rcases hcond with ⟨σ, hunif, hmgu⟩
125+
EntailsInterpret, forall_eq_or_imp]
126+
rcases hcond with ⟨hunif, hmgu⟩
127+
repeat rw [← EntailsInterpret] at h_premise_true
112128
clear hmgu
113-
sorry
129+
rw [eval_append_iff_eval_or_subst, Formula.eval]
130+
obtain ⟨first, second⟩ := h_premise_true
131+
have hclosed : Formula.closed (Clause.toFormula sig X (Literal.neg A :: C)) := sorry
132+
have hclosed₂ : Formula.closed (Clause.toFormula sig X (Literal.pos B :: D)) := sorry
133+
have s := validIn_of_entails_closed I _ hclosed (by use β)
134+
have t := validIn_of_entails_closed I _ hclosed₂ (by use β)
135+
apply valid_sub_of_valid _ σ at s
136+
apply valid_sub_of_valid _ σ at t
137+
specialize s β
138+
specialize t β
139+
aesop
114140
next h_fact_rule =>
115141
sorry
116142

InferenceInLean/Models.lean

Lines changed: 164 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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]
165185
def 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

172205
theorem 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

InferenceInLean/Semantics.lean

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,23 @@ def Formula.eval {sig : Signature} {X : Variables} {univ : Universes} [Decidable
7676
| Formula.all x f => ∀ a : univ, Formula.eval I (β.modify x a) f
7777
| Formula.ex x f => ∃ a : univ, Formula.eval I (β.modify x a) f
7878

79+
lemma Formula.eval_of_closed {sig : Signature} {X : Variables} [inst : DecidableEq X]
80+
(I : Interpretation sig univ) (F : Formula sig X) (hclosed : Formula.closed F) :
81+
(∀ (β γ : Assignment X univ), Formula.eval I β F = Formula.eval I γ F) := by
82+
intro β γ
83+
sorry
84+
7985
@[simp]
80-
def Formula.freeVars {sig : Signature} {X : Variables} : @Formula sig X -> Set X
81-
| Formula.falsum => ∅
82-
| Formula.verum => ∅
83-
| Formula.atom a => Atom.freeVars a
84-
| Formula.neg f => Formula.freeVars f
85-
| Formula.and f g => Formula.freeVars f ∪ Formula.freeVars g
86-
| Formula.or f g => Formula.freeVars f ∪ Formula.freeVars g
87-
| Formula.imp f g => Formula.freeVars f ∪ Formula.freeVars g
88-
| Formula.iff f g => Formula.freeVars f ∪ Formula.freeVars g
89-
| Formula.all x f => Formula.freeVars f \ {x}
90-
| Formula.ex x f => Formula.freeVars f \ {x}
86+
def Term.eval_without_free {sig : Signature} {X : Variables} [DecidableEq X] (t : Term sig X) :
87+
t.freeVars = {} → ¬∃ (x : X), t = Term.var x := by
88+
intro a
89+
simp_all only [not_exists]
90+
intro x
91+
apply Aesop.BuiltinRules.not_intro
92+
intro a_1
93+
subst a_1
94+
simp_all only [Term.freeVars.eq_1, Set.singleton_ne_empty]
95+
9196

9297
-- β[x1 ↦ a1, ..., xn ↦ an]
9398
@[simp]

0 commit comments

Comments
 (0)