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 #
Cslib.Logic.PL.Term.consistent,Cslib.Logic.PL.Term.force,Cslib.Logic.PL.Term.width: consistency, forcing the literals of a term, and its number of distinct variables.Cslib.Logic.PL.DNF.modelCount: the number of satisfying assignments.Cslib.Logic.PL.wordAssignment: the assignment reading the variables of a list from a word.
Main results #
Cslib.Logic.PL.Term.eval_force,Cslib.Logic.PL.Term.force_eq_of_eval,Cslib.Logic.PL.Term.consistent_iff_exists_eval: forcing and consistency.Cslib.Logic.PL.Term.eval_dedup,Cslib.Logic.PL.Term.length_dedup_of_consistent: removing repeated literals keeps the value, and leaves a consistent term witht.widthliterals.Cslib.Logic.PL.Term.isTautClause_negate: the negation of a term is a tautological clause exactly when the term is inconsistent.Cslib.Logic.PL.DNF.eval_congr: a formula only depends on its variables.Cslib.Logic.PL.DNF.modelCount_eq_card_filter: the count over words ofCNF.numVars φbits.Cslib.Logic.PL.DNF.card_filter_eval_eq_sum: the partition by the first satisfied term.Cslib.Logic.PL.card_filter_force: forcing a term is2 ^ t.width-to-one.Cslib.Logic.PL.two_pow_sub_width_le_modelCount: a consistent term ofφcontributes2 ^ (CNF.numVars φ - t.width)satisfying assignments.Cslib.Logic.PL.Term.card_filter_eval_le: a term onkvariables is satisfied by at most2 ^ (|V| - k)assignments of a finite type of variables.
References #
Terms #
A term is consistent when no variable occurs in it with both signs.
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.
Forcing a term does not change variables outside it.
Forcing a consistent term gives each of its variables the sign of its literals.
Forcing a consistent term satisfies it.
A satisfiable term is consistent.
A term is consistent exactly when it is satisfiable.
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.
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 #
The number of satisfying assignments of a formula in disjunctive normal form: the
assignments of the variables occurring in φ that satisfy it.
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 φ.
Forcing a term on a word #
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.
A consistent term on the variables of a nodup list vs is satisfied by
2 ^ (|vs| - t.width) assignments of these variables.
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).
A term of φ reads only variables of φ.
A consistent term of φ contributes a subcube: φ has at least
2 ^ (CNF.numVars φ - t.width) satisfying assignments.