Documentation

CslibFrontier.Logics.Propositional.DNF.ModelCount

Counting satisfying assignments of formulas in disjunctive normal form #

DNF.modelCount φ is the number of satisfying assignments of a formula φ in disjunctive normal form: the assignments of the variables occurring in φ that satisfy it. Formulas in disjunctive and conjunctive normal form share their representation as lists of lists of literals, so the variables CNF.vars φ, their distinct listing CNF.distinctVars φ and their number CNF.numVars φ apply to both. As a function of the formula this is the counting problem #DNF, which is #P-complete although satisfiability of formulas in disjunctive normal form is easy Valiant.

The satisfying assignments of a single term t form a subcube. A term is consistent (Term.consistent) when no variable occurs in it with both signs; consistent terms are exactly the satisfiable ones (Term.consistent_iff_exists_eval). Overriding an assignment σ by the literals of t (Term.force t σ) gives an assignment satisfying t whenever t is consistent (Term.eval_force). Reading the variables of a nodup list vs from a word of |vs| bits (wordAssignment), forcing the literals of t is 2 ^ t.width-to-one onto the satisfying assignments of t, where t.width is the number of distinct variables of t (card_filter_force). In particular a consistent term has 2 ^ (|vs| - t.width) satisfying assignments of the variables vs (card_filter_eval_eq_two_pow, two_pow_sub_width_le_modelCount), and any term has at most 2 ^ (|V| - t.width) satisfying assignments of a finite type of variables V (Term.card_filter_eval_le). Removing repeated literals keeps the value of a term (Term.eval_dedup) and leaves a consistent term with exactly t.width literals (Term.length_dedup_of_consistent). The negation of a term is a tautological clause (CNF.isTautClause) exactly when the term is inconsistent (Term.isTautClause_negate).

Counting the satisfying assignments of φ by the first term that they satisfy partitions them (DNF.card_filter_eval_eq_sum). These are the combinatorial facts behind the Karp–Luby–Madras estimator Karp, Luby and Madras, Mitzenmacher and Upfal, Section 11.2.

Main definitions #

Main results #

References #

Terms #

A term is consistent when no variable occurs in it with both signs.

def Cslib.Logic.PL.Term.force {V : Type u_1} [DecidableEq V] (t : Term V) (σ : V → Bool) (v : V) :

Override the assignment σ by the literals of t: a variable occurring in t is true exactly when it occurs positively.

The number of distinct variables of a term.

theorem Cslib.Logic.PL.Term.force_of_forall_ne {V : Type u_1} [DecidableEq V] {t : Term V} {σ : V → Bool} {v : V} (hv : ∀ l ∈ t, l.1 ≠ v) :
t.force σ v = σ v

Forcing a term does not change variables outside it.

theorem Cslib.Logic.PL.Term.force_of_mem {V : Type u_1} [DecidableEq V] {t : Term V} {σ : V → Bool} {l : Literal V} (hl : l ∈ t) (hc : t.consistent = true) :
t.force σ l.1 = l.2

Forcing a consistent term gives each of its variables the sign of its literals.

theorem Cslib.Logic.PL.Term.eval_force {V : Type u_1} [DecidableEq V] {t : Term V} (hc : t.consistent = true) (σ : V → Bool) :
eval (t.force σ) t = true

Forcing a consistent term satisfies it.

theorem Cslib.Logic.PL.Term.force_eq_of_eval {V : Type u_1} [DecidableEq V] {t : Term V} {σ : V → Bool} (h : eval σ t = true) :
t.force σ = σ

Forcing a term on an assignment that already satisfies it changes nothing.

theorem Cslib.Logic.PL.Term.consistent_of_eval {V : Type u_1} [DecidableEq V] {t : Term V} {σ : V → Bool} (h : eval σ t = true) :

A satisfiable term is consistent.

theorem Cslib.Logic.PL.Term.consistent_iff_exists_eval {V : Type u_1} [DecidableEq V] {t : Term V} :
t.consistent = true ↔ ∃ (σ : V → Bool), eval σ t = true

A term is consistent exactly when it is satisfiable.

@[simp]
theorem Cslib.Logic.PL.Term.eval_dedup {V : Type u_1} [DecidableEq V] (σ : V → Bool) (t : Term V) :
eval σ (List.dedup t) = eval σ t

Removing repeated literals does not change the value of a term.

A consistent term without repeated literals has one literal per variable: its length is the width. The clause dual is CNF.nodup_map_fst_dedup_of_not_isTautClause.

@[simp]

The negation of a term is a tautological clause, one containing a literal and its negation, exactly when the term is inconsistent, containing a variable with both signs.

Formulas #

theorem Cslib.Logic.PL.DNF.eval_congr {V : Type u_1} {σ τ : V → Bool} {φ : DNF V} (h : ∀ v ∈ CNF.vars φ, σ v = τ v) :
eval σ φ = eval τ φ

A formula in disjunctive normal form only depends on the variables occurring in it.

The number of satisfying assignments of a formula in disjunctive normal form: the assignments of the variables occurring in φ that satisfy it.

def Cslib.Logic.PL.wordAssignment {V : Type u_1} [DecidableEq V] (vs : List V) (w : List Bool) (v : V) :

The assignment reading the variable at position i of vs from bit i of the word w, and false past the end of w.

Counting over words: the satisfying assignments of φ correspond to the words of CNF.numVars φ bits whose assignment of the distinct variables of φ satisfies φ.

theorem Cslib.Logic.PL.DNF.card_filter_eval_eq_sum {V : Type u_1} {α : Type u_2} (σ : α → V → Bool) (φ : DNF V) (S : Finset α) :
{a ∈ S | eval (σ a) φ = true}.card = ∑ i ∈ Finset.range (List.length φ), {a ∈ S | Term.eval (σ a) (List.getD φ i []) = true ∧ eval (σ a) (List.take i φ) = false}.card

Partition by the first satisfied term. Every satisfying assignment satisfies exactly one term φ[i] that no earlier term φ[j], j < i, satisfies.

Forcing a term on a word #

theorem Cslib.Logic.PL.card_filter_force {V : Type u_1} [DecidableEq V] {vs : List V} (hnd : vs.Nodup) {t : Term V} (ht : ∀ l ∈ t, l.1 ∈ vs) (Q : (V → Bool) → Prop) [DecidablePred Q] :

Forcing a term is 2 ^ t.width-to-one. Reading the variables of a nodup list vs from words of |vs| bits, the words on which forcing t gives an assignment satisfying t and Q are 2 ^ t.width times as many as the words whose assignment satisfies t and Q.

theorem Cslib.Logic.PL.Term.width_le_length {V : Type u_1} [DecidableEq V] {vs : List V} (hnd : vs.Nodup) {t : Term V} (ht : ∀ l ∈ t, l.1 ∈ vs) :

A term on the variables of a nodup list vs has at most |vs| variables.

theorem Cslib.Logic.PL.card_filter_eval_eq_two_pow {V : Type u_1} [DecidableEq V] {vs : List V} (hnd : vs.Nodup) {t : Term V} (ht : ∀ l ∈ t, l.1 ∈ vs) (hc : t.consistent = true) :
{y : Fin vs.length → Bool | Term.eval (wordAssignment vs (List.ofFn y)) t = true}.card = 2 ^ (vs.length - t.width)

A consistent term on the variables of a nodup list vs is satisfied by 2 ^ (|vs| - t.width) assignments of these variables.

theorem Cslib.Logic.PL.Term.card_filter_eval_le {V : Type u_1} [DecidableEq V] [Fintype V] (t : Term V) :
{σ : V → Bool | eval σ t = true}.card ≤ 2 ^ (Fintype.card V - t.width)

A term is satisfied on a small subcube: over a finite type of variables V, a term on k = t.width distinct variables is satisfied by at most 2 ^ (|V| - k) of the 2 ^ |V| assignments, that is, with probability at most 2 ^ (-k).

theorem Cslib.Logic.PL.DNF.mem_distinctVars_of_mem {V : Type u_1} [DecidableEq V] {φ : DNF V} {t : Term V} (ht : t ∈ φ) (l : Literal V) :
l ∈ t → l.1 ∈ CNF.distinctVars φ

A term of φ reads only variables of φ.

theorem Cslib.Logic.PL.two_pow_sub_width_le_modelCount {V : Type u_1} [DecidableEq V] {φ : DNF V} {t : Term V} (ht : t ∈ φ) (hc : t.consistent = true) :

A consistent term of φ contributes a subcube: φ has at least 2 ^ (CNF.numVars φ - t.width) satisfying assignments.