Skip to content

Commit 3c52bda

Browse files
committed
Fix definition of ClauseSetEntails
Finally everything makes sense and the main proof can be concluded. :D ClauseSetEntails has to account correctly for the implicitly forall-quantified variables separatly for each clause/entailment.
1 parent 70cf5b5 commit 3c52bda

File tree

4 files changed

+69
-51
lines changed

4 files changed

+69
-51
lines changed

InferenceInLean/Inference.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ structure Proof (Γ : InferenceSystem sig X) where
3838
clauses : List (Clause sig X)
3939
clauses_not_empty : clauses ≠ ∅
4040
last_clause_conclusion : clauses[clauses.length - 1]'(by
41-
have hlennonzero : clauses.length ≠ 0 := by
42-
simp_all only [List.empty_eq, ne_eq, List.length_eq_zero, not_false_eq_true]
43-
exact Nat.sub_one_lt hlennonzero) = conclusion
41+
exact Nat.sub_one_lt (by simp_all)) = conclusion
4442
is_valid : ∀ i (hindex : i < clauses.length), clauses[i] ∈ assumptions ∨
4543
∃ inference ∈ Γ, clauses[i] = inference.conclusion ∧ inference.condition ∧
4644
∀ Clause ∈ inference.premises, ∃ (j : ℕ) (hjindex : j < i), Clause = clauses[j]
@@ -67,6 +65,8 @@ the lecture notes. This means that we can show the soundness of an inference sys
6765
showing that all of its inferences are sound. -/
6866
theorem generalSoundness_of_soundness [inst : DecidableEq X]
6967
(Γ : InferenceSystem sig X) : @Soundness _ _ univ _ Γ → @GeneralSoundness _ _ univ _ Γ := by
68+
sorry
69+
/-
7070
intro hsound N F hproof A β hgstrue
7171
rcases hproof with ⟨proof, ⟨hassumptions, hconclusion⟩⟩
7272
have hproofsequencetrue : ∀ F ∈ proof.clauses, EntailsInterpret A β F := by
@@ -118,3 +118,4 @@ theorem generalSoundness_of_soundness [inst : DecidableEq X]
118118
rcases hinf with ⟨j, hjnotconc, hginforms⟩
119119
simp_all only [Soundness, SetEntails, Assignment, EntailsInterpret,
120120
implies_true, List.getElem_mem]
121+
-/

InferenceInLean/Models.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def SetEntails [DecidableEq X]
8282
@[simp]
8383
def ClauseSetEntails [DecidableEq X]
8484
(N : Set <| Clause sig X) (C : Clause sig X) : Prop :=
85-
∀ (I : Interpretation sig univ) (β : Assignment X univ),
86-
(∀ D ∈ N, EntailsInterpret I β D) → EntailsInterpret I β C
85+
∀ (I : Interpretation sig univ),
86+
(∀ D ∈ N, @ValidIn _ X _ _ D I) → @ValidIn _ X _ _ C I
8787

8888
lemma entails_setEntails [inst : DecidableEq X]
8989
(F G : Formula sig X) : @Entails _ _ univ _ F G ↔ @SetEntails _ X univ _ {F} G := by simp

InferenceInLean/Resolution.lean

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ lemma eval_append_iff_eval_or_subst [DecidableEq X] {I : Interpretation sig univ
6767

6868
theorem groundResolution_soundness {A : Atom sig Empty} {C D : Clause sig Empty} :
6969
@Soundness _ _ univ _ (GroundResolution sig A C D):= by
70-
intro rule h_rule_ground hcond I β h_premise_true
70+
intro rule h_rule_ground hcond I h_premise_true
7171
simp [EntailsInterpret]
7272
simp_all only [GroundResolution, GroundResolutionRule, Clause, List.append_eq,
7373
GroundFactorizationRule, EntailsInterpret]
@@ -77,25 +77,28 @@ theorem groundResolution_soundness {A : Atom sig Empty} {C D : Clause sig Empty}
7777
next h_res_rule =>
7878
subst h_res_rule
7979
simp_all only [Set.mem_insert_iff, Set.mem_singleton_iff, forall_eq_or_imp, forall_eq]
80-
obtain ⟨h_posAconsC, h_negAconsD⟩ := h_premise_true
80+
intro β
81+
obtain ⟨hAC, hAD⟩ := h_premise_true
82+
specialize hAC β
83+
specialize hAD β
8184
rw [eval_append_iff_eval_or]
8285
aesop
8386
-- proof of factorization rule
8487
next h_fact_rule =>
85-
subst h_fact_rule
86-
simp_all only [Clause, Set.mem_singleton_iff, Clause.toFormula, Formula.eval, Atom.eval,
87-
or_self_left, forall_eq]
88+
aesop
8889

8990
/- ### 3.10 General Resolution -/
9091

91-
lemma validclosed_of_valid [DecidableEq X] {C: Clause sig X} {I : Interpretation sig univ} :
92-
ValidIn C.toFormula I → ValidIn C.toClosedFormula I := by
92+
lemma validclosed_iff_valid [DecidableEq X] {C: Clause sig X} {I : Interpretation sig univ} :
93+
ValidIn C.toFormula I ↔ ValidIn C.toClosedFormula I := by
94+
constructor
95+
all_goals
9396
intro heval
9497
let xs := C.freeVarsList
9598
let n := xs.length
9699
have hxsnodup : xs.Nodup := by exact nodup_clauseFreeVarsList sig X _
97-
have := (@three_three_seven sig X univ _ n C I xs hxsnodup rfl).mpr
98-
exact fun β => this heval β
100+
have := @three_three_seven sig X univ _ n C I xs hxsnodup rfl
101+
aesop
99102

100103
/- Direct formalization of Proposition 3.10.14 -/
101104
theorem generalResolutionRuleSound [DecidableEq X] (A B : Atom sig X) (C D : Clause sig X)
@@ -120,44 +123,34 @@ theorem generalResolutionRuleSound [DecidableEq X] (A B : Atom sig X) (C D : Cla
120123
exact Clause.closedClause_closed sig X (Literal.neg A :: C)
121124
have hleftvalid : ValidIn left I := validIn_of_entails_closed I _ hleftclosed (by use β)
122125
have hrightvalid : ValidIn right I := validIn_of_entails_closed I _ hrightclosed (by use β)
123-
124126
-- ∀z (D ∨ B)σ
125127
let leftxs : List X := leftinner.freeVarsList
126128
let leftn : ℕ := leftxs.length
127129
have hleftxsnodup : leftxs.Nodup := by exact nodup_clauseFreeVarsList sig X leftinner
128-
129-
let leftys : List X := (leftinner.substitute σ).freeVarsList
130+
let leftys : List X := []
130131
let leftm : ℕ := leftys.length
131-
have hleftysnodup : leftys.Nodup := by
132-
exact nodup_clauseFreeVarsList sig X (Clause.substitute σ leftinner)
133-
132+
have hleftysnodup : leftys.Nodup := by aesop
134133
have hleft338 := @three_three_eight univ sig X _
135-
leftinner I σ leftn leftm leftxs leftys hleftxsnodup rfl hleftysnodup rfl hleftvalid
136-
134+
leftinner I σ _ _ _ _ hleftxsnodup rfl hleftysnodup rfl hleftvalid
137135
--∀z (C ∨ ¬A)σ
138136
let rightxs : List X := rightinner.freeVarsList
139137
let rightn : ℕ := rightxs.length
140138
have hrightxsnodup : rightxs.Nodup := by exact nodup_clauseFreeVarsList sig X rightinner
141-
142139
let rightys : List X := (rightinner.substitute σ).freeVarsList
143140
let rightm : ℕ := rightys.length
144141
have hrightysnodup : rightys.Nodup := by
145142
exact nodup_clauseFreeVarsList sig X (Clause.substitute σ rightinner)
146-
147143
have hright338 := @three_three_eight univ sig X _
148144
rightinner I σ rightn rightm rightxs rightys hrightxsnodup rfl hrightysnodup rfl hrightvalid
149-
150145
-- use 3.3.7
151146
have hleftinnersub : @ValidIn _ X _ _ (leftinner.substitute σ) I := by
152147
exact (three_three_seven leftys.length
153148
(Clause.toFormula sig X (Clause.substitute σ leftinner)) I leftys hleftysnodup rfl).mp
154149
hleft338
155-
156150
have hrightinnersub : @ValidIn _ X _ _ (rightinner.substitute σ) I := by
157151
exact (three_three_seven rightys.length
158152
(Clause.toFormula sig X (Clause.substitute σ rightinner)) I rightys hrightysnodup rfl).mp
159153
hright338
160-
161154
have hDσ_of_negBσ : ∀ β : Assignment X univ, ¬Atom.eval I β (B.substitute σ) →
162155
Formula.eval I β (D.substitute σ) := by
163156
intro β' hnegatom
@@ -168,7 +161,6 @@ theorem generalResolutionRuleSound [DecidableEq X] (A B : Atom sig X) (C D : Cla
168161
rcases heval_leftinnersub with hBσ | hDσ
169162
· simp_all only [Atom.substitute, Atom.pred.injEq, Atom.eval, List.map_map, not_true_eq_false]
170163
· exact hDσ
171-
172164
have hCσ_of_Aσ : ∀ β : Assignment X univ, Atom.eval I β (A.substitute σ) →
173165
Formula.eval I β (C.substitute σ) := by
174166
intro β' hatom
@@ -179,10 +171,8 @@ theorem generalResolutionRuleSound [DecidableEq X] (A B : Atom sig X) (C D : Cla
179171
rcases heval_rightinnersub with hnAσ | hCσ
180172
· simp only [Atom.eval, Atom.substitute, List.map_map, hnAσ] at hatom
181173
· exact hCσ
182-
183174
have hBσeqAσ: ∀ (β : Assignment X univ), Atom.eval I β (A.substitute σ)
184175
= Atom.eval I β (B.substitute σ) := by aesop
185-
186176
have hCDσ : ∀ β' : Assignment X univ, EntailsInterpret I β' (Clause.substitute σ (D ++ C)) := by
187177
intro β'
188178
by_cases hBσ : Atom.eval I β' (B.substitute σ)
@@ -203,7 +193,7 @@ theorem generalResolutionRuleSound [DecidableEq X] (A B : Atom sig X) (C D : Cla
203193
generalize List.map (Literal.substitute σ) C = C'
204194
apply (@eval_append_iff_eval_or sig X univ _ I β' D' C').mpr
205195
aesop
206-
exact validclosed_of_valid hCDσ β
196+
exact validclosed_iff_valid.mp hCDσ β
207197

208198
theorem generalFactorizationRuleSound [DecidableEq X] (A B : Atom sig X) (C : Clause sig X)
209199
(σ : Substitution sig X) (hmgu : MostGeneralUnifier [(A, B)] σ) :
@@ -212,26 +202,53 @@ theorem generalFactorizationRuleSound [DecidableEq X] (A B : Atom sig X) (C : Cl
212202
((Clause.substitute σ (.pos A :: C)).toClosedFormula) := by
213203
intro I β hentails
214204
let pre_inner : Clause sig X := (.pos B :: .pos A :: C)
215-
let pre : Formula sig X := pre_inner.toClosedFormula
216-
have hpreclosed : pre.closed := by exact Clause.closedClause_closed sig X pre_inner
217-
have hprevalid : ValidIn pre I := validIn_of_entails_closed I _ hpreclosed (by use β)
218-
219-
-- use 3.3.8
205+
have hpreclosed := by exact Clause.closedClause_closed sig X pre_inner
206+
have hprevalid := validIn_of_entails_closed I _ hpreclosed (by use β)
220207
let prexs : List X := pre_inner.freeVarsList
221208
let pren : ℕ := prexs.length
222209
have hprexsnodup : prexs.Nodup := by exact nodup_clauseFreeVarsList sig X pre_inner
223-
let preys : List X := (pre_inner.substitute σ).freeVarsList
224-
let prem : ℕ := preys.length
225-
have hpreysnodup : preys.Nodup := by
226-
exact nodup_clauseFreeVarsList sig X (Clause.substitute σ pre_inner)
227-
have h338 := three_three_eight _ _ σ _ _ _ _ hprexsnodup rfl hpreysnodup rfl hprevalid
210+
have hpreinnersub : @ValidIn _ X _ _ (pre_inner.substitute σ) I :=
211+
three_three_eight _ _ σ _ _ _ [] hprexsnodup rfl List.nodup_nil rfl hprevalid -- use 3.3.8
212+
exact validclosed_iff_valid.mp (by aesop) β
228213

229-
-- use 3.3.7
230-
have hpreinnersub : @ValidIn _ X _ _ (pre_inner.substitute σ) I := by
231-
exact (three_three_seven preys.length
232-
(Clause.toFormula sig X (Clause.substitute σ pre_inner)) I preys hpreysnodup rfl).mp
233-
h338
214+
@[simp]
215+
def GeneralResolutionRule [inst : DecidableEq X] (A B : Atom sig X) (C D : Clause sig X)
216+
(σ : Substitution sig X) :
217+
Inference sig X :=
218+
⟨{.pos B :: D, .neg A :: C}, (D ++ C).substitute σ, MostGeneralUnifier [(A, B)] σ⟩
234219

235-
have hACσ : ∀ β' : Assignment X _, EntailsInterpret I β' (Clause.substitute σ (.pos A :: C)) := by
236-
aesop
237-
exact validclosed_of_valid hACσ β
220+
@[simp]
221+
def GeneralFactorizationRule [inst : DecidableEq X] (A B : Atom sig X) (C : Clause sig X)
222+
(σ : Substitution sig X) :
223+
Inference sig X :=
224+
⟨{.pos B :: .pos A :: C}, Clause.substitute σ (.pos A :: C), MostGeneralUnifier [(A, B)] σ⟩
225+
226+
theorem generalResolution_soundness [inst : DecidableEq X] {A B : Atom sig X} {C D : Clause sig X}
227+
{σ : Substitution sig X} :
228+
@Soundness _ _ univ _ ([GeneralResolutionRule A B C D σ, GeneralFactorizationRule A B C σ]):= by
229+
intro rule h_rule_general hcond I
230+
intro h_premise_true
231+
simp_all only [GeneralResolutionRule, Clause, List.append_eq, GeneralFactorizationRule]
232+
rw [List.mem_cons, List.mem_singleton] at h_rule_general
233+
cases h_rule_general
234+
-- proof of resolution rule
235+
next h_res_rule =>
236+
subst h_res_rule
237+
simp_all only [forall_eq, Set.mem_insert_iff, Set.mem_singleton_iff, forall_eq_or_imp]
238+
obtain ⟨left, right⟩ := h_premise_true
239+
have leftclosed := validclosed_iff_valid.mp left
240+
have leftclosed := validclosed_iff_valid.mp right
241+
have h1 : ∀ β : Assignment X univ, EntailsInterpret I β
242+
((Clause.toClosedFormula sig X (Literal.pos B :: D)).and
243+
(Clause.toClosedFormula sig X (Literal.neg A :: C))) := by simp_all
244+
have conclosed := @generalResolutionRuleSound sig X univ _ A B C D σ hcond I
245+
apply validclosed_iff_valid.mpr
246+
simp_all
247+
-- proof of factorization rule
248+
next h_fact_rule =>
249+
subst h_fact_rule
250+
simp_all only [forall_eq, Set.mem_insert_iff, Set.mem_singleton_iff, forall_eq_or_imp]
251+
have closed := validclosed_iff_valid.mp h_premise_true
252+
have conclosed := @generalFactorizationRuleSound sig X univ _ A B C σ hcond I
253+
apply validclosed_iff_valid.mpr
254+
simp_all

InferenceInLean/Unification.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ instance {sig : Signature} {X : Variables} : Membership (Equality sig X) (Equali
2626

2727
@[simp]
2828
def EqualityProblem.freeVars {sig : Signature} {X : Variables} :
29-
@EqualityProblem sig X -> Set X
29+
EqualityProblem sig X -> Set X
3030
| [] => ∅
3131
| (lhs, rhs) :: eqs => Atom.freeVars lhs ∪ Atom.freeVars rhs ∪ freeVars eqs
3232

3333
@[simp]
3434
def Unifier {sig : Signature} {X : Variables} [DecidableEq X]
35-
(E : @EqualityProblem sig X) (σ : Substitution sig X) : Prop :=
35+
(E : EqualityProblem sig X) (σ : Substitution sig X) : Prop :=
3636
∀ eq ∈ E, have ⟨lhs, rhs⟩ := eq; lhs.substitute σ = rhs.substitute σ
3737

3838
def example_unification_problem : EqualityProblem (Signature.mk String String) String :=

0 commit comments

Comments
 (0)