Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
refactor: final refactor of CNF.Basic
Browse files Browse the repository at this point in the history
  • Loading branch information
hargoniX committed Aug 6, 2024
1 parent 5315f34 commit 6c73f54
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LeanSAT/CNF/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) :=
Expand Down Expand Up @@ -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) :=
Expand Down Expand Up @@ -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

0 comments on commit 6c73f54

Please sign in to comment.