|
1 | | -import InferenceInLean.Basic |
| 1 | +import InferenceInLean.Resolution |
2 | 2 | import Mathlib.Data.Finset.Defs |
3 | 3 |
|
4 | 4 | set_option autoImplicit false |
@@ -163,150 +163,4 @@ theorem ex_4_2b : ∃ I : Interpretation sig42 (Fin 2), ∃ β : Assignment Stri |
163 | 163 | end Task2 |
164 | 164 |
|
165 | 165 |
|
166 | | -/- ### Exercise 4.6 |
167 | | - Let Σ = (Ω, Π) be a signature. For every Σ-formula F without equality, |
168 | | - let neg(F) be the formula that one obtains from F by replacing every atom P(t1,...,tn) |
169 | | - in F by its negation ¬P(t1,...,tn) for every P/n ∈ Π. |
170 | | - Prove: If F is valid, then neg(F) is valid. -/ |
171 | | - |
172 | | -namespace Task6 |
173 | | - |
174 | | -/- ! Rather large chunks of this namespace were generated by Claude 3.7 Sonnet (free version) ! |
175 | | - Let's see if I want to fix this... -/ |
176 | | - |
177 | | --- Define the neg function that negates all atoms in a formula |
178 | | -@[simp] |
179 | | -def negFormula {sig : Signature} {X : Variables} : Formula sig X → Formula sig X |
180 | | - | Formula.falsum => Formula.falsum |
181 | | - | Formula.verum => Formula.verum |
182 | | - | Formula.atom a => Formula.neg (Formula.atom a) -- replace atom with its negation |
183 | | - | Formula.neg (Formula.atom a) => Formula.atom a -- special case: double negation of atom |
184 | | - | Formula.neg f => Formula.neg (negFormula f) |
185 | | - | Formula.and f g => Formula.and (negFormula f) (negFormula g) |
186 | | - | Formula.or f g => Formula.or (negFormula f) (negFormula g) |
187 | | - | Formula.imp f g => Formula.imp (negFormula f) (negFormula g) |
188 | | - | Formula.iff f g => Formula.iff (negFormula f) (negFormula g) |
189 | | - | Formula.all x f => Formula.all x (negFormula f) |
190 | | - | Formula.ex x f => Formula.ex x (negFormula f) |
191 | | - |
192 | | --- Define a "dual" interpretation that flips the truth value of all predicates |
193 | | -@[simp] |
194 | | -def dualInterpretation {sig : Signature} {univ : Universes} |
195 | | - (I : Interpretation sig univ) : Interpretation sig univ := |
196 | | - ⟨I.functions, fun p args => ¬(I.predicates p args)⟩ |
197 | | - |
198 | | -theorem dualInterpretation.funs_eq {sig : Signature} {X : Variables} {univ : Universes} |
199 | | - [DecidableEq X] (I : Interpretation sig univ) : |
200 | | - I.functions = (dualInterpretation I).functions := rfl |
201 | | - |
202 | | --- Lemma: For any term t, eval(t) in the original interpretation is the same as in the dual |
203 | | -@[simp] |
204 | | -theorem term_eval_invariant {sig : Signature} {X : Variables} {univ : Universes} |
205 | | - [DecidableEq X] (I : Interpretation sig univ) (β : Assignment X univ) (t : Term sig X) : |
206 | | - Term.eval I β t = Term.eval (dualInterpretation I) β t := by |
207 | | - induction' t using Term.induction with x args ih f <;> aesop |
208 | | - |
209 | | --- Lemma: For any atom a, eval(¬a) in the original interpretation equals eval(a) in the dual |
210 | | -@[simp] |
211 | | -theorem atom_eval_dual {sig : Signature} {X : Variables} {univ : Universes} |
212 | | - [DecidableEq X] (I : Interpretation sig univ) (β : Assignment X univ) (a : Atom sig X) : |
213 | | - ¬(Atom.eval I β a) ↔ Atom.eval (dualInterpretation I) β a := by |
214 | | - simp [term_eval_invariant] |
215 | | - induction a.2 with |
216 | | - | nil => simp |
217 | | - | cons head tail ih => |
218 | | - induction' head using Term.induction with x args ih f |
219 | | - sorry |
220 | | - sorry |
221 | | - |
222 | | --- Main theorem: The key equivalence - F evaluates to true in I iff neg(F) evaluates to true in dual(I) |
223 | | -theorem negFormula_eval_iff {sig : Signature} {X : Variables} {univ : Universes} |
224 | | - [DecidableEq X] (I : Interpretation sig univ) (β : Assignment X univ) (F : Formula sig X) : |
225 | | - Formula.eval I β F ↔ Formula.eval (dualInterpretation I) β (negFormula F) := by |
226 | | - sorry |
227 | | - |
228 | | - -- Final theorem: If F is valid, then neg(F) is valid |
229 | | -theorem valid_negFormula {sig : Signature} {X : Variables} {univ : Universes} |
230 | | - [DecidableEq X] (F : Formula sig X) : |
231 | | - @Valid sig X univ _ F → @Valid sig X univ _ (negFormula F) := by |
232 | | - intro h_valid I β |
233 | | - simp_all only [Valid] |
234 | | - have := h_valid I β |
235 | | - have := (negFormula_eval_iff I β F).mp this |
236 | | - sorry |
237 | | - |
238 | | -end Task6 |
239 | | - |
240 | | - |
241 | | -/- ### Exercise 4.7 (*) |
242 | | - Let Π be a set of propositional variables. Let N and N' be sets |
243 | | - of clauses over Π. Let S be a set of literals that does not contain any complementary |
244 | | - literals. Prove: If every clause in N contains at least one literal L with L ∈ S and if no |
245 | | - clause in N' contains a literal L with L ∈ S, then N ∪ N' is satisfiable if and only if N' |
246 | | - is satisfiable. -/ |
247 | | - |
248 | | -namespace Task7 |
249 | | - |
250 | | -def Interpretation.add (I : Interpretation ⟨Empty, String⟩ String) |
251 | | - (β : Assignment Empty String) (L : Literal ⟨Empty, String⟩ Empty) : |
252 | | - Interpretation ⟨Empty, String⟩ String := |
253 | | - -- add something to I such that Formula.eval L is true |
254 | | - Interpretation.mk I.functions (match L with |
255 | | - | Literal.pos a => match a with |
256 | | - | Atom.pred p args => |
257 | | - have argsinter := args.map (Term.eval I β) |
258 | | - (fun p' args' => if p' == p && args' == argsinter |
259 | | - then True |
260 | | - else I.predicates p' args') |
261 | | - | Literal.neg a => match a with |
262 | | - | Atom.pred p args => |
263 | | - have argsinter := args.map (Term.eval I β) |
264 | | - (fun p' args' => if p' == p && args' == argsinter |
265 | | - then False |
266 | | - else I.predicates p' args') |
267 | | - ) |
268 | | - |
269 | | -lemma tmp (I : Interpretation ⟨Empty, String⟩ String) (β : Assignment Empty String) |
270 | | - (C : Clause ⟨Empty, String⟩ Empty) |
271 | | - (hCsat : EntailsInterpret I β C) (L : Literal ⟨Empty, String⟩ Empty) (h : L.comp ∉ C) : |
272 | | - EntailsInterpret (Interpretation.add I β L) β C := by |
273 | | - sorry |
274 | | - |
275 | | -theorem ex_4_7 |
276 | | - (N N' : Set <| Clause ⟨Empty, String⟩ Empty) (S : Set <| Literal ⟨Empty, String⟩ Empty) |
277 | | - (hSnoCompl : ∀ L ∈ S, L.comp ∉ S) |
278 | | - (hNsatByS : ∀ C ∈ N, ∃ L ∈ C, L ∈ S) (hN'noComplS : ∀ C ∈ N', ¬∃ L ∈ C, L.comp ∈ S) : |
279 | | - (@ClauseSetSatisfiable _ _ univ _ (N ∪ N') ↔ @ClauseSetSatisfiable _ _ univ _ N') := by |
280 | | - simp only [not_exists, not_and] at hN'noComplS |
281 | | - apply Iff.intro |
282 | | - · simp [ClauseSetSatisfiable] |
283 | | - intro I β h |
284 | | - apply Exists.intro |
285 | | - · apply Exists.intro |
286 | | - · intro C a |
287 | | - apply h |
288 | | - simp_all only [or_true] |
289 | | - · simp [ClauseSetSatisfiable] |
290 | | - intro I_N' β_N' hN'sat |
291 | | - use I_N' |
292 | | - use β_N' -- delay instanciation of assignment |
293 | | - intro C hC |
294 | | - cases hC |
295 | | - next hCinN => |
296 | | - /- This is the actual hard case of this exercise. On paper it might look like this: |
297 | | - - Show that I_N' and β_N' do not contradict (SAT N) (this is due to hN'noComplS) |
298 | | - - Expand β_N' by the assignments implied by S to β_N'andS |
299 | | - - then β_N'andS satisfies N using hNsatByS |
300 | | - -/ |
301 | | - obtain ⟨L, ⟨hLinC, hLinS⟩⟩ := hNsatByS C hCinN |
302 | | - have hLcompninS : L.comp ∉ S := by exact hSnoCompl L hLinS |
303 | | - --let ?β := β_N' |
304 | | - --let β_N'andS := β.modify L |
305 | | - sorry |
306 | | - |
307 | | - next hCinN' => exact hN'sat C hCinN' |
308 | | - |
309 | | -end Task7 |
310 | | - |
311 | | - |
312 | 166 | end Exercise4 |
0 commit comments