Skip to content

Commit c816481

Browse files
committed
Rename basic to Resolution
Also add abbrev GroundTerm and remove unfinished exercises
1 parent 5239adf commit c816481

File tree

7 files changed

+23
-171
lines changed

7 files changed

+23
-171
lines changed

InferenceInLean.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-- This module serves as the root of the `InferenceInLean` library.
22
-- Import modules here that should be built as part of the library.
3-
import «InferenceInLean».Basic
3+
import «InferenceInLean».Resolution

InferenceInLean/Exercises/Exercise4.lean

Lines changed: 1 addition & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import InferenceInLean.Basic
1+
import InferenceInLean.Resolution
22
import Mathlib.Data.Finset.Defs
33

44
set_option autoImplicit false
@@ -163,150 +163,4 @@ theorem ex_4_2b : ∃ I : Interpretation sig42 (Fin 2), ∃ β : Assignment Stri
163163
end Task2
164164

165165

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-
312166
end Exercise4

InferenceInLean/Exercises/Exercise5.lean

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import InferenceInLean.Basic
1+
import InferenceInLean.Resolution
22
import Mathlib.Data.Finset.Defs
33
import Mathlib.Data.Set.Card
44
import Mathlib.SetTheory.Cardinal.Finite
@@ -33,11 +33,11 @@ def f : List (Term sig5_1 String) -> Term sig5_1 String := .func .f
3333
def P : List (Term sig5_1 String) -> Formula sig5_1 String := fun args =>.atom <| .pred .P args
3434

3535
/- Force the interpretation of P to be false for every list of arguments with the wrong arity. -/
36-
def ArityP : (preds -> List (Term sig5_1 Empty) -> Prop) -> Prop
37-
| ps => ∀ (args : List (Term sig5_1 Empty)), (args.length ≠ 1) → ¬(ps .P args)
36+
def ArityP (ps : preds -> List (GroundTerm sig5_1) -> Prop) : Prop :=
37+
∀ (args : List (GroundTerm sig5_1)), (args.length ≠ 1) → ¬(ps .P args)
3838

3939
-- (1) There is a Σ-model A of P (b) ∧ ¬P (f (b)) such that UA = {7, 8, 9}.
40-
def F₁ : Formula sig5_1 String := .and (P [b]) (.neg (P [f [b]]))
40+
def F₁ : Formula sig5_1 String := (P [b]).and (.neg (P [f [b]]))
4141
theorem task5_1_1 : ∃ (I : Interpretation sig5_1 (Fin 3)), ∀ β : Assignment String (Fin 3),
4242
EntailsInterpret I β F₁ := by
4343
-- Define the interpretation I for universe {0, 1, 2} (representing {7, 8, 9})
@@ -58,7 +58,7 @@ theorem task5_1_1 : ∃ (I : Interpretation sig5_1 (Fin 3)), ∀ β : Assignment
5858
simp [F₁, EntailsInterpret, I, P, b, f]
5959

6060
-- (2) There is no Σ-model A of P (b) ∧ ¬P (f (f (b))) such that fA (a) = a for every a ∈ UA.
61-
def F₂ : Formula sig5_1 String := .and (P [b]) (.neg (P [f [f [b]]]))
61+
def F₂ : Formula sig5_1 String := (P [b]).and (.neg (P [f [f [b]]]))
6262
theorem task5_1_2 : ¬∃ (univ : Universes) (I : Interpretation sig5_1 univ),
6363
∀ β : Assignment String univ, EntailsInterpret I β F₂ ∧
6464
(∀ a, (I.functions .f) [a] = a):= by
@@ -85,7 +85,7 @@ theorem task5_1_2 : ¬∃ (univ : Universes) (I : Interpretation sig5_1 univ),
8585
theorem task5_1_3 : ∃ preds, ∀ β, EntailsInterpret (HerbrandInterpretation sig5_1 preds) β F₁ := by
8686
-- First, let's define our Herbrand interpretation
8787
-- We need to define how predicates behave on ground terms
88-
let preds : sig5_1.preds → List (Term sig5_1 Empty) → Prop := fun p args =>
88+
let preds : sig5_1.preds → List (GroundTerm sig5_1) → Prop := fun p args =>
8989
match p, args with
9090
| .P, [.func .b []] => True
9191
| .P, [.func .f [.func .b []]] => False
@@ -100,16 +100,16 @@ theorem task5_1_3 : ∃ preds, ∀ β, EntailsInterpret (HerbrandInterpretation
100100
-- (4) P(b) ∧ ∀x ¬P(x) has no Herbrand model.
101101
def F₄ : Formula sig5_1 String := .and (P [b]) (.all "x" (.neg (P [.var "x"])))
102102
theorem task5_1_4 : ¬∃ preds, ∀ β, EntailsInterpret (HerbrandInterpretation sig5_1 preds) β F₄ := by
103-
let b' : Term sig5_1 Empty := Term.func .b []
103+
let b' : GroundTerm sig5_1 := Term.func .b []
104104
intro h
105105
rcases h with ⟨preds, h⟩
106-
let β₀ : Assignment String (Term sig5_1 Empty) := fun _ => b'
106+
let β₀ : Assignment String (GroundTerm sig5_1) := fun _ => b'
107107
have h₀ := h β₀
108108
have hPb : preds .P [b'] := by
109109
simp [F₄, P, b] at h₀
110110
exact h₀.1
111111
obtain ⟨_, h_forall⟩ := h₀
112-
let β₁ : Assignment String (Term sig5_1 Empty) := β₀.modify "x" b'
112+
let β₁ : Assignment String (GroundTerm sig5_1) := β₀.modify "x" b'
113113
have hNotPb : ¬preds .P [b'] := by
114114
simp [Formula.eval, HerbrandInterpretation, Atom.eval, Term.eval,
115115
Assignment.modify, Formula.all, β₁] at h_forall
@@ -120,13 +120,13 @@ theorem task5_1_4 : ¬∃ preds, ∀ β, EntailsInterpret (HerbrandInterpretatio
120120

121121
-- (5) ∀x P (f (x)) does not have a Herbrand model with a two-element universe.
122122
def F₅ : Formula sig5_1 String := .all "x" (P [f [.var "x"]])
123-
theorem task5_1_5 (S : Set <| Term sig5_1 Empty) (hall : ∀ t : Term sig5_1 Empty, t ∈ S) :
123+
theorem task5_1_5 (S : Set <| GroundTerm sig5_1) (hall : ∀ t : GroundTerm sig5_1, t ∈ S) :
124124
Set.encard S ≠ 2 := by
125-
let t₀ : Term sig5_1 Empty := .func .b []
126-
let t₁ : Term sig5_1 Empty := .func .f [t₀]
127-
let t₂ : Term sig5_1 Empty := .func .f [t₁]
128-
let t₃ : Term sig5_1 Empty := .func .f [t₂]
129-
let S' : Set (Term sig5_1 Empty) := {t₀, t₁, t₂}
125+
let t₀ : GroundTerm sig5_1 := .func .b []
126+
let t₁ : GroundTerm sig5_1 := .func .f [t₀]
127+
let t₂ : GroundTerm sig5_1 := .func .f [t₁]
128+
let t₃ : GroundTerm sig5_1 := .func .f [t₂]
129+
let S' : Set (GroundTerm sig5_1) := {t₀, t₁, t₂}
130130
have ht₀ := hall t₀
131131
have ht₁ := hall t₁
132132
have ht₂ := hall t₂
@@ -158,10 +158,10 @@ theorem task5_1_6 : ∃! ps,
158158
ext p args
159159
cases p
160160
-- Let's prove that P must be true for all args for preds'
161-
have h : ∀ (t : Term sig5_1 Empty), preds' .P [t] := by
161+
have h : ∀ (t : GroundTerm sig5_1), preds' .P [t] := by
162162
intro t
163163
-- Create an assignment that maps x to t
164-
let β : Assignment String (Term sig5_1 Empty) := fun v => Term.func .b []
164+
let β : Assignment String (GroundTerm sig5_1) := fun v => Term.func .b []
165165
-- Use the entailment hypothesis
166166
have h_entails_β := h_entails β
167167
-- Extract the universal quantifier's meaning
File renamed without changes.

InferenceInLean/Semantics.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ structure Interpretation where
2020
predicates : sig.preds -> (List univ -> Prop)
2121

2222
@[simp]
23-
def HerbrandInterpretation (sig : Signature) (preds : sig.preds -> List (Term sig Empty) -> Prop) :
24-
Interpretation sig (Term sig Empty) := ⟨fun f args => Term.func f args, preds⟩
23+
def HerbrandInterpretation (sig : Signature) (preds : sig.preds -> List (GroundTerm sig) -> Prop) :
24+
Interpretation sig (GroundTerm sig) := ⟨fun f args => Term.func f args, preds⟩
2525

2626
/- ### Assigments
2727
> β : X → univ

InferenceInLean/Syntax.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ inductive Term where
2222
| var (x : X)
2323
| func (f : sig.funs) (args: List Term)
2424

25+
abbrev GroundTerm (sig : Signature) := Term sig Empty
26+
2527
lemma Term.induction {P : (Term sig X) → Prop}
2628
(base : ∀ x : X, P (var x)) (step : ∀ (args : List (Term sig X)),
2729
(ih : ∀ term ∈ args, P term) → ∀ (f : sig.funs), P (func f args)) :

InferenceInLean/Unification.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ def MostGeneralUnifier {sig : Signature} {X : Variables} [DecidableEq X]
4949
(E : EqualityProblem sig X) (σ : Substitution sig X) : Prop :=
5050
Unifier E σ ∧ (∀ τ : Substitution sig X, Unifier E τ → σ ≤ τ)
5151

52-
/-
53-
TODO: Add example proof for a mgu.
54-
-/
55-
5652
lemma mgu_imp_unifier {sig : Signature} {X : Variables} [DecidableEq X] (E : EqualityProblem sig X)
5753
(σ : Substitution sig X) : MostGeneralUnifier E σ → Unifier E σ := fun ⟨h, _⟩ => h
5854

0 commit comments

Comments
 (0)