From 6c73f54680bdfa638ac6aebfb6c3e055704f7059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20B=C3=B6ving?= Date: Tue, 6 Aug 2024 20:22:46 +0200 Subject: [PATCH] refactor: final refactor of CNF.Basic --- LeanSAT/CNF/Basic.lean | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/LeanSAT/CNF/Basic.lean b/LeanSAT/CNF/Basic.lean index b50de2e..ee27ef8 100644 --- a/LeanSAT/CNF/Basic.lean +++ b/LeanSAT/CNF/Basic.lean @@ -16,16 +16,27 @@ The literal `(i, b)` is satisfied is the assignment to `i` agrees with `b`. -/ abbrev CNF.Clause (α : Type u) : Type u := List (Literal α) +/-- +A CNF formula. + +Literals are identified by members of `α`. +-/ abbrev CNF (α : Type u) : Type u := List (CNF.Clause α) namespace CNF +/-- +Evaluating a `Clause` with respect to an assignment `f`. +-/ def Clause.eval (f : α → Bool) (c : Clause α) : Bool := c.any fun (i, n) => f i == n @[simp] theorem Clause.eval_nil (f : α → Bool) : Clause.eval f [] = false := rfl @[simp] theorem Clause.eval_succ (f : α → Bool) : Clause.eval f (i :: c) = (f i.1 == i.2 || Clause.eval f c) := rfl +/-- +Evaluating a `CNF` formula with respect to an assignment `f`. +-/ def eval (f : α → Bool) (g : CNF α) : Bool := g.all fun c => c.eval f @[simp] theorem eval_nil (f : α → Bool) : eval f [] = true := rfl @@ -51,6 +62,9 @@ instance : HSat α (CNF α) where namespace Clause +/-- +Literal `a` occurs in `Clause` `c`. +-/ def mem (a : α) (c : Clause α) : Prop := (a, false) ∈ c ∨ (a, true) ∈ c instance {a : α} {c : Clause α} [DecidableEq α] : Decidable (mem a c) := @@ -86,6 +100,9 @@ theorem eval_congr (f g : α → Bool) (c : Clause α) (w : ∀ i, mem i c → f end Clause +/-- +Literal `a` occurs in `CNF` formula `g`. +-/ def mem (a : α) (g : CNF α) : Prop := ∃ c, c ∈ g ∧ c.mem a instance {a : α} {g : CNF α} [DecidableEq α] : Decidable (mem a g) := @@ -163,3 +180,5 @@ theorem eval_congr (f g : α → Bool) (x : CNF α) (w : ∀ i, mem i x → f i · intro i h apply w simp [h] + +end CNF