Skip to content

Commit f59997a

Browse files
committed
Last sorry at Clause.consClosed remaining
1 parent 1d72b5e commit f59997a

File tree

1 file changed

+70
-13
lines changed

1 file changed

+70
-13
lines changed

InferenceInLean/Syntax.lean

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ inductive Atom where
6666

6767
@[simp]
6868
def Atom.freeVars {sig : Signature} {X : Variables} : Atom sig X -> Set X
69-
| .pred _ args => args.foldl (fun acc t => acc ∪ Term.freeVars sig X t) ∅
69+
| .pred _ [] => ∅
70+
| .pred P (a :: args) => a.freeVars ∪ (Atom.pred P args).freeVars
7071

7172
inductive Literal where
7273
| pos (a : Atom sig X)
@@ -140,36 +141,92 @@ instance : Coe (Clause sig X) (Formula sig X) :=
140141
instance : Coe (Set <| Clause sig X) (Set <| Formula sig X) :=
141142
fun N => {↑C | C ∈ N}⟩
142143

143-
def Term.freeVarsList : Term sig X -> List X
144+
@[simp]
145+
def Term.freeVarsList [DecidableEq X] : Term sig X -> List X
144146
| Term.var x => [x]
145147
| Term.func _ [] => []
146-
| Term.func f (a :: args) => (Term.freeVarsList a).append (Term.freeVarsList (Term.func f args))
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
147170

148171
def Atom.freeVarsList [DecidableEq X] : Atom sig X -> List X
149172
| .pred _ [] => []
150173
| .pred P (t :: ts) => List.dedup ((t.freeVarsList).append (Atom.pred P ts).freeVarsList)
151174

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+
152199
def Clause.freeVarsList [DecidableEq X] : Clause sig X -> List X
153200
| [] => []
154201
| (.pos l) :: ls => List.dedup (l.freeVarsList ++ freeVarsList ls)
155202
| (.neg l) :: ls => List.dedup (l.freeVarsList ++ freeVarsList ls)
156203

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+
157211
@[simp]
158212
def Clause.toClosedFormula [DecidableEq X] (C : Clause sig X) : Formula sig X :=
159213
Formula.bigForall sig X (C.freeVarsList) C
160214

161-
theorem Clause.closedClause_closed [DecidableEq X] (C : Clause sig X) :
162-
Formula.closed C.toClosedFormula := by
163-
unfold toClosedFormula
164-
unfold Formula.closed
165-
unfold Formula.freeVars
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
166221
sorry
167222

168-
theorem nodup_clauseFreeVarsList [DecidableEq X] (C : Clause sig X) :
169-
List.Nodup (C.freeVarsList) := by
170-
unfold Clause.freeVarsList
171-
simp_all only [Clause]
172-
split <;> simp_all only [List.nodup_nil, List.nodup_dedup]
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
173230

174231
@[simp]
175232
def Substitution := X -> Term sig X

0 commit comments

Comments
 (0)