Skip to content

Commit 678b3b2

Browse files
committed
Merge branch 'generalresolution'
2 parents 9663517 + f59997a commit 678b3b2

File tree

3 files changed

+216
-18
lines changed

3 files changed

+216
-18
lines changed

InferenceInLean/Basic.lean

Lines changed: 124 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,130 @@ def GeneralFactorizationRule [inst : DecidableEq X] (A B : Atom sig X) (C : Clau
105105
Inference sig X :=
106106
⟨{.pos A :: .pos B :: C}, Clause.substitute σ (.pos A :: C), MostGeneralUnifier [(A, B)] σ⟩
107107

108+
lemma validclosed_of_valid [DecidableEq X] {C: Clause sig X} {I : Interpretation sig univ} :
109+
ValidIn C.toFormula I → ValidIn C.toClosedFormula I := by
110+
intro heval
111+
let xs := C.freeVarsList
112+
let n := xs.length
113+
have hxsnodup : xs.Nodup := by exact nodup_clauseFreeVarsList sig X _
114+
have := (@three_three_seven sig X univ _ n C I xs hxsnodup rfl).mpr
115+
exact fun β => this heval β
116+
117+
theorem generalResolutionRuleSound [DecidableEq X] (A B : Atom sig X) (C D : Clause sig X)
118+
(σ : Substitution sig X) (hmgu : MostGeneralUnifier [(A, B)] σ) :
119+
@Entails _ _ univ _
120+
(Formula.and
121+
(Clause.toClosedFormula sig X (.pos B :: D))
122+
(Clause.toClosedFormula sig X (.neg A :: C)))
123+
(((D ++ C).substitute σ).toClosedFormula) := by
124+
let leftinner : Clause sig X := (.pos B :: D)
125+
let rightinner : Clause sig X := (.neg A :: C)
126+
let left := Clause.toClosedFormula sig X (.pos B :: D)
127+
let right := Clause.toClosedFormula sig X (.neg A :: C)
128+
intro I β h_entails
129+
simp [Formula.and] at h_entails
130+
obtain ⟨hleft, hright⟩ := h_entails
131+
have hleftentails : EntailsInterpret I β left := by exact hleft
132+
have hrightentails : EntailsInterpret I β right := by exact hright
133+
have hleftclosed : Formula.closed left := by
134+
exact Clause.closedClause_closed sig X (Literal.pos B :: D)
135+
have hrightclosed : Formula.closed right := by
136+
exact Clause.closedClause_closed sig X (Literal.neg A :: C)
137+
have hleftvalid : ValidIn left I := validIn_of_entails_closed I _ hleftclosed (by use β)
138+
have hrightvalid : ValidIn right I := validIn_of_entails_closed I _ hrightclosed (by use β)
139+
140+
-- ∀z (D ∨ B)σ
141+
let leftxs : List X := leftinner.freeVarsList
142+
let leftn : ℕ := leftxs.length
143+
have hleftxsnodup : leftxs.Nodup := by exact nodup_clauseFreeVarsList sig X leftinner
144+
145+
let leftys : List X := (leftinner.substitute σ).freeVarsList
146+
let leftm : ℕ := leftys.length
147+
have hleftysnodup : leftys.Nodup := by exact nodup_clauseFreeVarsList sig X (Clause.substitute σ leftinner)
148+
149+
have hleft338 := @three_three_eight univ sig X _
150+
leftinner I σ leftn leftm leftxs leftys hleftxsnodup rfl hleftysnodup rfl hleftvalid
151+
152+
--∀z (C ∨ ¬A)σ
153+
let rightxs : List X := rightinner.freeVarsList
154+
let rightn : ℕ := rightxs.length
155+
have hrightxsnodup : rightxs.Nodup := by exact nodup_clauseFreeVarsList sig X rightinner
156+
157+
let rightys : List X := (rightinner.substitute σ).freeVarsList
158+
let rightm : ℕ := rightys.length
159+
have hrightysnodup : rightys.Nodup := by
160+
exact nodup_clauseFreeVarsList sig X (Clause.substitute σ rightinner)
161+
162+
have hright338 := @three_three_eight univ sig X _
163+
rightinner I σ rightn rightm rightxs rightys hrightxsnodup rfl hrightysnodup rfl hrightvalid
164+
165+
-- use 3.3.7
166+
have hleftinnersub : @ValidIn _ X _ _ (leftinner.substitute σ) I := by
167+
exact (three_three_seven leftys.length (Clause.toFormula sig X (Clause.substitute σ leftinner)) I
168+
leftys hleftysnodup rfl).mp
169+
hleft338
170+
171+
have hrightinnersub : @ValidIn _ X _ _ (rightinner.substitute σ) I := by
172+
exact (three_three_seven rightys.length (Clause.toFormula sig X (Clause.substitute σ rightinner)) I
173+
rightys hrightysnodup rfl).mp
174+
hright338
175+
176+
have hDσ_of_negBσ : ∀ β : Assignment X univ, ¬Atom.eval I β (B.substitute σ) →
177+
Formula.eval I β (D.substitute σ) := by
178+
intro β' hnegatom
179+
simp [*] at hleftinnersub
180+
unfold leftinner at hleftinnersub
181+
have heval_leftinnersub := hleftinnersub β'
182+
simp [List.map_cons] at heval_leftinnersub
183+
rcases heval_leftinnersub with hBσ | hDσ
184+
· simp_all only [Atom.substitute, Atom.pred.injEq, Atom.eval, List.map_map, not_true_eq_false]
185+
· exact hDσ
186+
187+
have hCσ_of_Aσ : ∀ β : Assignment X univ, Atom.eval I β (A.substitute σ) →
188+
Formula.eval I β (C.substitute σ) := by
189+
intro β' hatom
190+
simp [*] at hrightinnersub
191+
unfold rightinner at hrightinnersub
192+
have heval_rightinnersub := hrightinnersub β'
193+
simp [List.map_cons] at heval_rightinnersub
194+
rcases heval_rightinnersub with hnAσ | hCσ
195+
· simp only [Atom.eval, Atom.substitute, List.map_map, hnAσ] at hatom
196+
· exact hCσ
197+
198+
have hBσeqAσ: ∀ (β : Assignment X univ), Atom.eval I β (A.substitute σ)
199+
= Atom.eval I β (B.substitute σ) := by
200+
intro β
201+
have hunif : A.substitute σ = B.substitute σ := by
202+
obtain ⟨hσunif, _⟩ := hmgu
203+
simp only [Unifier, EqualityProblem.eq_1, List.mem_singleton, Atom.substitute,
204+
Atom.pred.injEq, forall_eq] at hσunif
205+
simp only [Atom.substitute, Atom.pred.injEq]
206+
exact hσunif
207+
rw [hunif]
208+
209+
have hCDσ : ∀ β' : Assignment X univ, EntailsInterpret I β' (Clause.substitute σ (D ++ C)) := by
210+
intro β'
211+
by_cases hBσ : Atom.eval I β' (B.substitute σ)
212+
· have hAσ : Atom.eval I β' (A.substitute σ) := by
213+
rw [hBσeqAσ]
214+
exact hBσ
215+
have hCσ := hCσ_of_Aσ β' hAσ
216+
unfold Clause.substitute at hCσ
217+
simp only [EntailsInterpret, Clause.substitute, Clause, List.map_append]
218+
generalize List.map (Literal.substitute σ) D = D'
219+
generalize List.map (Literal.substitute σ) C = C' at *
220+
apply (@eval_append_iff_eval_or sig X univ _ I β' D' C').mpr
221+
aesop
222+
· have hDσ := hDσ_of_negBσ β' hBσ
223+
unfold Clause.substitute at hDσ
224+
simp only [EntailsInterpret, Clause.substitute, Clause, List.map_append]
225+
generalize List.map (Literal.substitute σ) D = D' at *
226+
generalize List.map (Literal.substitute σ) C = C'
227+
apply (@eval_append_iff_eval_or sig X univ _ I β' D' C').mpr
228+
aesop
229+
230+
exact validclosed_of_valid hCDσ β
231+
108232
theorem generalResolution_soundness [inst : DecidableEq X] {A B : Atom sig X} {C D : Clause sig X}
109233
{σ : Substitution sig X} :
110234
@Soundness _ _ univ _ ([GeneralResolutionRule A B C D σ, GeneralFactorizationRule A B C σ]):= by
@@ -139,10 +263,3 @@ theorem generalResolution_soundness [inst : DecidableEq X] {A B : Atom sig X} {C
139263
aesop
140264
next h_fact_rule =>
141265
sorry
142-
143-
144-
/-
145-
## Further stuff:
146-
- Compactness
147-
148-
-/

InferenceInLean/Semantics.lean

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,7 @@ def Formula.eval {sig : Signature} {X : Variables} {univ : Universes} [Decidable
7979

8080
@[simp]
8181
lemma Term.eval_without_free_not_term {sig : Signature} {X : Variables} [DecidableEq X]
82-
(t : Term sig X) : t.freeVars = {} → ¬∃ (x : X), t = Term.var x := by
83-
intro a
84-
simp_all only [not_exists]
85-
intro x
86-
apply Aesop.BuiltinRules.not_intro
87-
intro a_1
88-
subst a_1
89-
simp_all only [Term.freeVars.eq_1, Set.singleton_ne_empty]
82+
(t : Term sig X) : t.freeVars = {} → ¬∃ (x : X), t = Term.var x := by aesop
9083

9184
lemma Set.singleton_of_union_empty {α : Type} {x : α} {A B : Set α}
9285
(h : ¬A = {x}) (hsingleton : A ∪ B = {x}) : A = ∅ := by

InferenceInLean/Syntax.lean

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ inductive Atom where
6767
@[simp]
6868
def Atom.freeVars {sig : Signature} {X : Variables} : Atom sig X -> Set X
6969
| .pred _ [] => ∅
70-
| .pred P (a :: args) => a.freeVars ∪ (Atom.pred P args).freeVars
70+
| .pred P (a :: args) => a.freeVars ∪ (Atom.pred P args).freeVars
7171

7272
inductive Literal where
7373
| pos (a : Atom sig X)
@@ -118,6 +118,7 @@ def Formula.freeVars {sig : Signature} {X : Variables} : Formula sig X -> Set X
118118
@[simp]
119119
def Formula.closed {sig : Signature} {X : Variables} (F : Formula sig X) : Prop :=
120120
Formula.freeVars F = ∅
121+
121122
/--
122123
Creates formula ∀ x_1 ... x_n, F.
123124
-/
@@ -131,15 +132,102 @@ def Formula.bigForall [DecidableEq X]
131132
@[simp]
132133
def Clause.toFormula : Clause sig X -> Formula sig X
133134
| [] => Formula.falsum
134-
| .pos l :: ls => Formula.or (Formula.atom l) (Clause.toFormula ls)
135-
| .neg l :: ls => Formula.or (Formula.neg (Formula.atom l)) (Clause.toFormula ls)
135+
| .pos l :: ls => (Formula.atom l).or (Clause.toFormula ls)
136+
| .neg l :: ls => Formula.or (Formula.atom l).neg (Clause.toFormula ls)
136137

137138
instance : Coe (Clause sig X) (Formula sig X) :=
138139
⟨Clause.toFormula sig X⟩
139140

140141
instance : Coe (Set <| Clause sig X) (Set <| Formula sig X) :=
141142
fun N => {↑C | C ∈ N}⟩
142143

144+
@[simp]
145+
def Term.freeVarsList [DecidableEq X] : Term sig X -> List X
146+
| Term.var x => [x]
147+
| Term.func _ [] => []
148+
| Term.func f (a :: args) => List.dedup ((Term.freeVarsList a).append (Term.freeVarsList (Term.func f args)))
149+
150+
@[simp]
151+
lemma Term.freeVars_sub_freeVarsList [DecidableEq X] (t : Term sig X) :
152+
t.freeVars ⊆ (t.freeVarsList).toFinset := by
153+
induction' t using Term.induction with x args ih f
154+
· aesop
155+
· induction args with
156+
| nil => aesop
157+
| cons head tail ih' =>
158+
simp
159+
constructor
160+
· specialize ih head (by simp)
161+
generalize freeVarsList sig X head = Fl at *
162+
generalize freeVars sig X head = Fs at *
163+
intro x hxinFs
164+
simp only [Set.mem_setOf_eq]
165+
left
166+
exact List.mem_dedup.mp (ih hxinFs)
167+
· simp_all only [List.coe_toFinset]
168+
intro x hxinfree
169+
aesop
170+
171+
def Atom.freeVarsList [DecidableEq X] : Atom sig X -> List X
172+
| .pred _ [] => []
173+
| .pred P (t :: ts) => List.dedup ((t.freeVarsList).append (Atom.pred P ts).freeVarsList)
174+
175+
def Atom.freeVars_sub_freeVarsList [DecidableEq X] (a : Atom sig X) :
176+
a.freeVars ⊆ (a.freeVarsList).toFinset := by
177+
simp_all only [List.coe_toFinset]
178+
induction a with
179+
| pred p args =>
180+
induction args with
181+
| nil => aesop
182+
| cons head tail ih =>
183+
simp only [freeVars, Set.union_subset_iff]
184+
constructor
185+
· have hfree_subset := Term.freeVars_sub_freeVarsList sig X head
186+
unfold freeVarsList
187+
intro x hxinfree
188+
simp_all only [List.coe_toFinset, List.append_eq, List.mem_dedup, List.mem_append, Set.mem_setOf_eq]
189+
apply Or.inl
190+
apply hfree_subset
191+
simp_all only
192+
· unfold freeVarsList
193+
intro x hxinfree
194+
simp_all only [List.coe_toFinset, List.append_eq, List.mem_dedup, List.mem_append, Set.mem_setOf_eq]
195+
apply Or.inr
196+
apply ih
197+
exact hxinfree
198+
199+
def Clause.freeVarsList [DecidableEq X] : Clause sig X -> List X
200+
| [] => []
201+
| (.pos l) :: ls => List.dedup (l.freeVarsList ++ freeVarsList ls)
202+
| (.neg l) :: ls => List.dedup (l.freeVarsList ++ freeVarsList ls)
203+
204+
@[simp]
205+
lemma nodup_clauseFreeVarsList [DecidableEq X] (C : Clause sig X) :
206+
List.Nodup (C.freeVarsList) := by
207+
unfold Clause.freeVarsList
208+
simp_all only [Clause]
209+
split <;> simp_all only [List.nodup_nil, List.nodup_dedup]
210+
211+
@[simp]
212+
def Clause.toClosedFormula [DecidableEq X] (C : Clause sig X) : Formula sig X :=
213+
Formula.bigForall sig X (C.freeVarsList) C
214+
215+
lemma Clause.closedEmpty_closed [DecidableEq X] :
216+
Formula.closed (Clause.toClosedFormula sig X []) := by aesop
217+
218+
lemma Clause.consClosed [DecidableEq X] (L : Literal sig X) (C : Clause sig X) :
219+
(Clause.toClosedFormula sig X C).closed → (Clause.toClosedFormula sig X (L :: C)).closed := by
220+
intro h
221+
sorry
222+
223+
theorem Clause.closedClause_closed [DecidableEq X] (C : Clause sig X) :
224+
Formula.closed C.toClosedFormula := by
225+
induction C with
226+
| nil => aesop
227+
| cons head tail ih =>
228+
simp_all
229+
exact Clause.consClosed sig X head tail ih
230+
143231
@[simp]
144232
def Substitution := X -> Term sig X
145233

0 commit comments

Comments
 (0)