Horn satisfiability
DefinitionHorn formula#✓fully proved
A CNF formula is a Horn formula when every clause contains at most one distinct positive literal.
def IsHorn (φ : CNF) : Prop :=
∀ C ∈ φ, ∀ l ∈ C, ∀ m ∈ C, l.2 = true → m.2 = true → l = m
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
Uses 2 · Used by 3
DefinitionBody of a clause contained in a set#✓fully proved
For a finite set \(T\) of variables and a CNF clause \(C\), this Boolean test is true exactly when every negative literal of \(C\) has its variable in \(T\).
def bodyIn (T : Finset Nat) (C : CNFClause) : Bool :=
C.all fun l ↦ l.2 || decide (l.1 ∈ T)
abbrev CNFClause := List (Nat × Bool)
CSLibExt/Logics/Propositional/CNF/Basic.lean:30
Uses 1 · Used by 4
DefinitionForward-chaining step#✓fully proved
For a CNF formula \(\varphi\) and a finite set \(T\) of variables, the derived set consists of the variables \(x\) such that some clause of \(\varphi\) contains the positive literal \(x\) and has every one of its negative literals on a variable in \(T\).
def derive (φ : CNF) (T : Finset Nat) : Finset Nat :=
((φ.filter (bodyIn T)).flatMap fun C ↦ (C.filter (·.2)).map Prod.fst).toFinset
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def bodyIn (T : Finset Nat) (C : CNFClause) : Bool :=
C.all fun l ↦ l.2 || decide (l.1 ∈ T)
CSLibExt/Algorithms/SAT/Horn/Basic.lean:70
Uses 3 · Used by 3
DefinitionForward-chaining closure#✓fully proved
For a CNF formula \(\varphi\) and a finite set \(T\) of variables, the closure of \(T\) is computed by iterating the forward-chaining step of \(\varphi\): if every variable derived from \(T\) already lies in \(T\), the closure is \(T\); otherwise it is the closure of the union of \(T\) with the derived variables.
The iteration terminates because each step that does not stop adds a variable of \(\varphi\).
def close (φ : CNF) (T : Finset Nat) : Finset Nat :=
if derive φ T ⊆ T then T else close φ (T ∪ derive φ T)
termination_by (φ.vars \ T).card
decreasing_by
obtain ⟨x, hxD, hxT⟩ := Finset.not_subset.mp ‹¬derive φ T ⊆ T›
apply Finset.card_lt_card
refine Finset.ssubset_iff_subset_ne.mpr ⟨?_, fun heq ↦ ?_⟩
· exact Finset.sdiff_subset_sdiff le_rfl Finset.subset_union_left
· have hx : x ∈ φ.vars \ T := Finset.mem_sdiff.mpr ⟨derive_subset_vars φ T hxD, hxT⟩
rw [← heq, Finset.mem_sdiff] at hx
exact hx.2 (Finset.mem_union_right _ hxD)
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def derive (φ : CNF) (T : Finset Nat) : Finset Nat :=
((φ.filter (bodyIn T)).flatMap fun C ↦ (C.filter (·.2)).map Prod.fst).toFinset
CSLibExt/Algorithms/SAT/Horn/Basic.lean:81
Uses 6 · Used by 3
DefinitionLeast model candidate#✓fully proved
For a CNF formula \(\varphi\), the least model candidate is the assignment that makes a variable true exactly when it lies in the forward-chaining closure of the empty set under \(\varphi\).
def leastModel (φ : CNF) : Nat → Bool := fun x ↦ decide (x ∈ close φ ∅)
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def close (φ : CNF) (T : Finset Nat) : Finset Nat :=
if derive φ T ⊆ T then T else close φ (T ∪ derive φ T)
termination_by (φ.vars \ T).card
decreasing_by
obtain ⟨x, hxD, hxT⟩ := Finset.not_subset.mp ‹¬derive φ T ⊆ T›
apply Finset.card_lt_card
refine Finset.ssubset_iff_subset_ne.mpr ⟨?_, fun heq ↦ ?_⟩
· exact Finset.sdiff_subset_sdiff le_rfl Finset.subset_union_left
· have hx : x ∈ φ.vars \ T := Finset.mem_sdiff.mpr ⟨derive_subset_vars φ T hxD, hxT⟩
rw [← heq, Finset.mem_sdiff] at hx
exact hx.2 (Finset.mem_union_right _ hxD)
CSLibExt/Algorithms/SAT/Horn/Basic.lean:107
Uses 2 · Used by 4
TheoremOn Horn formulas, the least model candidate lies below every model#✓fully proved
Let \(\varphi\) be a Horn CNF formula and \(\sigma\) an assignment satisfying \(\varphi\). Every variable that the least model candidate of \(\varphi\) makes true is also true under \(\sigma\).
theorem leastModel_le {φ : CNF} (hφ : IsHorn φ) {σ : Nat → Bool} (hσ : φ.Satisfies σ)
{x : Nat} (hx : leastModel φ x = true) : σ x = true
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def IsHorn (φ : CNF) : Prop :=
∀ C ∈ φ, ∀ l ∈ C, ∀ m ∈ C, l.2 = true → m.2 = true → l = m
CSLibExt/Algorithms/SAT/Horn/Basic.lean:62
def leastModel (φ : CNF) : Nat → Bool := fun x ↦ decide (x ∈ close φ ∅)
CSLibExt/Algorithms/SAT/Horn/Basic.lean:140
Uses 12 · Used by 1
TheoremHorn satisfiability via the least model#✓fully proved
A Horn CNF formula \(\varphi\) is satisfiable if and only if its least model candidate satisfies \(\varphi\).
theorem satisfies_leastModel_iff {φ : CNF} (hφ : IsHorn φ) :
φ.Satisfies (leastModel φ) ↔ CNFSat φ
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def IsHorn (φ : CNF) : Prop :=
∀ C ∈ φ, ∀ l ∈ C, ∀ m ∈ C, l.2 = true → m.2 = true → l = m
CSLibExt/Algorithms/SAT/Horn/Basic.lean:62
def leastModel (φ : CNF) : Nat → Bool := fun x ↦ decide (x ∈ close φ ∅)
CSLibExt/Algorithms/SAT/Horn/Basic.lean:140
def CNFSat (φ : CNF) : Prop :=
∃ v : Nat → Bool, ∀ C ∈ φ, ∃ (x : Nat) (b : Bool), (x, b) ∈ C ∧ v x = b
CSLibExt/Logics/Propositional/CNF/Basic.lean:36
Uses 15 · Used by 1
DefinitionHorn satisfiability test#✓fully proved
For a CNF formula \(\varphi\), the Horn satisfiability test returns the Boolean truth value of \(\varphi\) under its least model candidate.
def hornSat (φ : CNF) : Bool := formulaSatisfied (leastModel φ) φ
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def formulaSatisfied (assignment : Nat → Bool) (formula : CNF) : Bool :=
formula.all (clauseSatisfied assignment)
CSLibExt/Algorithms/SAT/DPLL/Solver.lean:48
def leastModel (φ : CNF) : Nat → Bool := fun x ↦ decide (x ∈ close φ ∅)
CSLibExt/Algorithms/SAT/Horn/Basic.lean:140
Uses 3 · Used by 1
TheoremCorrectness of the Horn satisfiability test#✓fully proved
If \(\varphi\) is a Horn CNF formula, then the Horn satisfiability test returns true on \(\varphi\) if and only if \(\varphi\) is satisfiable.
theorem hornSat_eq_true_iff {φ : CNF} (hφ : IsHorn φ) : hornSat φ = true ↔ CNFSat φ
abbrev CNF := List CNFClause
CSLibExt/Logics/Propositional/CNF/Basic.lean:33
def IsHorn (φ : CNF) : Prop :=
∀ C ∈ φ, ∀ l ∈ C, ∀ m ∈ C, l.2 = true → m.2 = true → l = m
CSLibExt/Algorithms/SAT/Horn/Basic.lean:62
def hornSat (φ : CNF) : Bool := formulaSatisfied (leastModel φ) φ
CSLibExt/Algorithms/SAT/Horn/Basic.lean:190
def CNFSat (φ : CNF) : Prop :=
∃ v : Nat → Bool, ∀ C ∈ φ, ∃ (x : Nat) (b : Bool), (x, b) ∈ C ∧ v x = b
CSLibExt/Logics/Propositional/CNF/Basic.lean:36
Uses 11
Loading dependency explorer…
The dependency explorer needs JavaScript and its graph data.