@@ -7,13 +7,11 @@ open Syntax
77open Semantics
88open Models
99open Unification
10- open Inference
10+ open Inferences
1111
1212namespace Examples
1313
14- /-
15- ### Example Peano Arithmetic
16- -/
14+ /- ### Example Peano Arithmetic -/
1715
1816inductive PeanoFuns where
1917 | zero
@@ -23,6 +21,7 @@ inductive PeanoFuns where
2321
2422inductive PeanoPreds where
2523 | less_than
24+ | eq
2625
2726@[simp]
2827def ex_sig_peano : Signature := ⟨PeanoFuns, PeanoPreds⟩
@@ -35,19 +34,19 @@ def ex_formula_peano : @Formula ex_sig_peano String :=
3534 .all "x" <| .all "y" <| .iff
3635 (.or
3736 (.atom (.pred .less_than [.var "x" , .var "y" ]))
38- (.atom (.eq (.var "x" ) (.var "y" ))))
39- (.ex "z" (.atom (.eq (.func .add [.var "x" , .var "z" ]) (.var "y" ))))
37+ (.atom (.pred . eq [ (.var "x" ), (.var "y" )] )))
38+ (.ex "z" (.atom (.pred . eq [ (.func .add [.var "x" , .var "z" ]), (.var "y" )] )))
4039
4140@[simp]
42- def ex_interpret_peano : Interpretation ex_sig_peano where
43- univ := ℕ
41+ def ex_interpret_peano : Interpretation ex_sig_peano ℕ where
4442 functions := λ
4543 | .zero => λ _ => 0
4644 | .succ => λ xs => xs[0 ]! + 1
4745 | .add => λ xs => xs[0 ]! + xs[1 ]!
4846 | .mul => λ xs => xs[0 ]! * xs[1 ]!
4947 predicates := λ f => match f with
5048 | .less_than => λ xs => xs[0 ]! < xs[1 ]!
49+ | .eq => λ xs => xs[0 ]! = xs[1 ]!
5150
5251def ex_assig_peano : Assignment String Nat
5352 | "x" => 0
@@ -61,19 +60,19 @@ def example_substitution : Substitution ex_sig_peano String := λ x => match x w
6160def ex_formula_peano_lt : @Formula ex_sig_peano String :=
6261 .all "z" (.atom $ .pred .less_than [.var "x" , .func .succ [.func .succ [.var "z" ]]])
6362
64- lemma ex_proof_lt : @Formula.eval ex_sig_peano String instDecidableEqString
63+ lemma ex_proof_lt : @Formula.eval ex_sig_peano String ℕ instDecidableEqString
6564 ex_interpret_peano ex_assig_peano ex_formula_peano_lt := by
6665 simp [ex_formula_peano_lt, ex_sig_peano, Interpretation, Assignment, ex_assig_peano]
6766
6867
69- #eval @Term.eval ex_sig_peano String ex_interpret_peano ex_assig_peano (Term.var "y" )
68+ #eval @Term.eval ex_sig_peano String ℕ ex_interpret_peano ex_assig_peano (Term.var "y" )
7069
7170def ex_term_peano : Term ex_sig_peano String :=
7271 Term.func .add [Term.var "x" , Term.var "y" ]
7372
74- #eval @Term.eval ex_sig_peano String ex_interpret_peano ex_assig_peano ex_term_peano
73+ #eval @Term.eval ex_sig_peano String ℕ ex_interpret_peano ex_assig_peano ex_term_peano
7574
76- lemma ex_peano_proof : @Formula.eval ex_sig_peano String instDecidableEqString
75+ lemma ex_peano_proof : @Formula.eval ex_sig_peano String ℕ instDecidableEqString
7776 ex_interpret_peano ex_assig_peano ex_formula_peano := by
7877 simp
7978 intro a b
@@ -92,33 +91,29 @@ lemma ex_peano_proof: @Formula.eval ex_sig_peano String instDecidableEqString
9291 exact Or.symm (Nat.eq_zero_or_pos z)
9392
9493def exa : Formula ex_sig_peano String := .and .falsum .verum
95- example : ¬@Formula.eval ex_sig_peano _ _ ex_interpret_peano ex_assig_peano exa :=
94+ example : ¬@Formula.eval ex_sig_peano _ _ _ ex_interpret_peano ex_assig_peano exa :=
9695 of_eq_true (Eq.trans (congrArg Not (and_true False)) not_false_eq_true)
9796
98-
99- example : @EntailsInterpret ex_sig_peano String _ ex_interpret_peano
97+ example : @EntailsInterpret ex_sig_peano String _ _ ex_interpret_peano
10098 ex_assig_peano ex_formula_peano := ex_peano_proof
10199
102100
101+ variable {sig : Signature} {X : Variables} {univ : Universes}
103102/-
104103Proposition 3.3.3 Let F and G be formulas, let N be a set of formulas. Then
105104(i) F is valid if and only if ¬F is unsatisfiable.
106105(ii) F |= G if and only if F ∧ ¬G is unsatisfiable.
106+ (iii) N |= G if and only if N ∪ {¬G} is unsatisfiable.
107107-/
108- theorem valid_iff_not_unsat {sig : Signature} {X : Variables} [inst : DecidableEq X]
109- (F : Formula sig X) : Valid F ↔ @Unsatisfiable sig X inst (Formula.neg F) := by simp
108+ theorem valid_iff_not_unsat' [inst : DecidableEq X] (F : Formula sig X) :
109+ @Valid _ _ univ _ F ↔ @Unsatisfiable _ _ univ _ (Formula.neg F) := by simp
110110
111- theorem entails_iff_and_not_unsat {sig : Signature} {X : Variables} [inst : DecidableEq X]
112- (F G : Formula sig X) :
113- Entails F G ↔ @Unsatisfiable sig X inst (Formula.and F (Formula.neg G)) := by simp
111+ theorem entails_iff_and_not_unsat' [inst : DecidableEq X] (F G : Formula sig X) :
112+ @Entails _ _ univ _ F G ↔ @Unsatisfiable _ _ univ _ (Formula.and F (Formula.neg G)) := by simp
114113
115- /-
116- -- TODO: finish this proof
117- (iii) N |= G if and only if N ∪ {¬G} is unsatisfiable.
118- -/
119- theorem setEntails_iff_union_not_unsat {sig : Signature} {X : Variables} [inst : DecidableEq X]
114+ theorem setEntails_iff_union_not_unsat' [inst : DecidableEq X]
120115 (N : Set $ Formula sig X) (G : Formula sig X) :
121- SetEntails N G ↔ @SetUnsatisfiable sig X inst (N ∪ {Formula.neg G}) := by
116+ @ SetEntails _ _ univ _ N G ↔ @SetUnsatisfiable _ _ univ _ (N ∪ {Formula.neg G}) := by
122117 apply Iff.intro
123118 · intro hentails I β
124119 simp_all only [SetEntails, Assignment, EntailsInterpret, Set.union_singleton,
@@ -132,6 +127,31 @@ theorem setEntails_iff_union_not_unsat {sig : Signature} {X : Variables} [inst :
132127 aesop
133128
134129
130+ /- ## Exercise 4 -/
131+
132+ namespace Exercise4
133+
134+ /- ### Exercise 4-1 -/
135+
136+ inductive fs where | b | c | d | f deriving BEq
137+ inductive ps where | P
138+ def F : Formula ⟨fs, ps⟩ String := .and (.and (.and (.atom (.pred .P [.func .b []]))
139+ (.atom (.pred .P [.func .c []])))
140+ (.neg (.atom (.pred .P [.func .d []]))))
141+ (.neg (.ex "x" (.atom (.pred .P [.func .f [.func .f [.var "x" ]]]))))
142+
143+ theorem ex_4_1 : ∃ I : Interpretation ⟨fs, ps⟩ (Fin 2 ), ∃ β : Assignment String (Fin 2 ),
144+ Formula.eval I β F := by
145+ let I : Interpretation ⟨fs, ps⟩ (Fin 2 ) := ⟨
146+ fun g a => if g == .f || g == .d then 1 else 0 ,
147+ fun _ u => if u[0 ]! == 0 then True else False⟩
148+ use I
149+ use (fun _ => 0 )
150+ simp [I, F]
151+ have : fs.f == fs.f := rfl
152+ aesop
153+
154+
135155/-
136156Exercise 4.7 (*)
137157Let Π be a set of propositional variables. Let N and N' be sets
@@ -140,86 +160,63 @@ literals. Prove: If every clause in N contains at least one literal L with L ∈
140160clause in N' contains a literal L with L ∈ S, then N ∪ N' is satisfiable if and only if N'
141161is satisfiable.
142162-/
143- theorem ex_4_7 {sig : Signature} {X : Variables} [DecidableEq X]
144- (N N' : Set $ Clause sig X) (S : Set $ Literal sig X)
163+ def Interpretation.add (I : Interpretation ⟨Empty, String⟩ String)
164+ (β : Assignment Empty String) (L : Literal ⟨Empty, String⟩ Empty) :
165+ Interpretation ⟨Empty, String⟩ String :=
166+ -- add something to I such that Formula.eval L is true
167+ Interpretation.mk I.functions (match L with
168+ | Literal.pos a => match a with
169+ | Atom.pred p args =>
170+ have argsinter := args.map (Term.eval I β)
171+ (fun p' args' => if p' == p && args' == argsinter
172+ then True
173+ else I.predicates p' args')
174+ | Literal.neg a => match a with
175+ | Atom.pred p args =>
176+ have argsinter := args.map (Term.eval I β)
177+ (fun p' args' => if p' == p && args' == argsinter
178+ then False
179+ else I.predicates p' args')
180+ )
181+
182+ lemma tmp (I : Interpretation ⟨Empty, String⟩ String) (β : Assignment Empty String)
183+ (C : Clause ⟨Empty, String⟩ Empty)
184+ (hCsat : EntailsInterpret I β C) (L : Literal ⟨Empty, String⟩ Empty) (h : L.comp ∉ C) :
185+ EntailsInterpret (Interpretation.add I β L) β C := by
186+ sorry
187+
188+ theorem ex_4_7
189+ (N N' : Set <| Clause ⟨Empty, String⟩ Empty) (S : Set <| Literal ⟨Empty, String⟩ Empty)
145190 (hSnoCompl : ∀ L ∈ S, L.comp ∉ S)
146- (hNsatByS : ∀ C ∈ N, ∃ L ∈ C, L ∈ S) (hN'noComplS : ∀ C ∈ N', ∀ L ∈ C, L ∉ S) :
147- (ClauseSetSatisfiable (N ∪ N') ↔ ClauseSetSatisfiable N') := by
191+ (hNsatByS : ∀ C ∈ N, ∃ L ∈ C, L ∈ S) (hN'noComplS : ∀ C ∈ N', ¬∃ L ∈ C, L.comp ∈ S) :
192+ (@ClauseSetSatisfiable _ _ univ _ (N ∪ N') ↔ @ClauseSetSatisfiable _ _ univ _ N') := by
193+ simp only [not_exists, not_and] at hN'noComplS
148194 apply Iff.intro
149195 · simp [ClauseSetSatisfiable]
150- intro I β
151- intro h
196+ intro I β h
152197 apply Exists.intro
153198 · apply Exists.intro
154199 · intro C a
155200 apply h
156201 simp_all only [or_true]
157202 · simp [ClauseSetSatisfiable]
158- intro I_N' β_N'
159- intro hN'sat
203+ intro I_N' β_N' hN'sat
160204 use I_N'
161- use β_N'
205+ use β_N' -- delay instanciation of assignment
162206 intro C hC
163207 cases hC
164- /- This is the actual hard case of this exercise. On paper it might look like this:
165- - Show that I_N' and β_N' do not contradict (SAT N) (this is due to hN'noComplS)
166- - Expand β_N' by the assignments implied by S to β_N'andS
167- - then β_N'andS satisfies N using hNsatByS
168- -/
169- next h => sorry
170- next h => exact hN'sat C h
171-
172- /--
173- Example for the proof type with resolution.
174- TODO: Finish this
175- -/
176- inductive ExFuns
177- | b
178- | c
179- | f
180- | h
181-
182- inductive ExPreds
183- | P
184- | Q
185-
186- def ex_sig_ground : Signature := ⟨ExFuns, ExPreds⟩
187-
188- def ex_clause : Clause ex_sig_ground Empty :=
189- [.pos (Atom.pred .P [.func ExFuns.b []]),
190- .pos (Atom.pred .P [.func ExFuns.b []])]
191-
192- def ex_clause' : Clause ex_sig_ground Empty :=
193- [.neg (Atom.pred .P [.func ExFuns.b []])]
194-
195- def ex_conc : Clause ex_sig_ground Empty :=
196- [.pos (Atom.pred .P [.func ExFuns.b []])]
197-
198- -- forget about that, the rules are schematic but we don't have that notion here
199- def example_proof {A : @Atom ex_sig_ground Empty} {C D : @Clause ex_sig_ground Empty} :
200- @Proof ex_sig_ground Empty (@Resolution.GroundResolution ex_sig_ground A D C) := {
201- assumptions := {ex_clause}
202- clauses := [ex_clause, ex_conc]
203- conclusion := ex_conc
204- clauses_not_empty := by simp
205- last_clause_conclusion := by simp
206- is_valid := by
207- simp only [List.length_cons, List.length_singleton, Nat.reduceAdd, Set.mem_insert_iff,
208- Set.mem_singleton_iff]
209- simp_all
210- intro i hle
211- have : i = 0 ∨ i = 1 := by sorry
212- cases this
213- next h => simp [h]
214- next h =>
215- subst h
216- apply Or.inr
217- have fact : Inference ex_sig_ground Empty := {
218- premises := {ex_clause}
219- conclusion := ex_conc
220- }
221- use fact
222- apply And.intro
223- · sorry
224- · sorry
225- }
208+ next hCinN =>
209+ /- This is the actual hard case of this exercise. On paper it might look like this:
210+ - Show that I_N' and β_N' do not contradict (SAT N) (this is due to hN'noComplS)
211+ - Expand β_N' by the assignments implied by S to β_N'andS
212+ - then β_N'andS satisfies N using hNsatByS
213+ -/
214+ obtain ⟨L, ⟨hLinC, hLinS⟩⟩ := hNsatByS C hCinN
215+ have hLcompninS : L.comp ∉ S := by exact hSnoCompl L hLinS
216+ --let ?β := β_N'
217+ --let β_N'andS := β.modify L
218+ sorry
219+
220+ next hCinN' => exact hN'sat C hCinN'
221+
222+ end Exercise4
0 commit comments