The naive algorithm and why it fails
- Setup:
nvariables,mclauses; let apfraction of the2ⁿassignments satisfy the formula. The goal is to estimatep33:36,34:20. - Naive: sample uniformly random assignments, check satisfaction, take the empirical fraction
34:20. - Failure mode: if
pis tiny — e.g. the formulax₁ ∧ x₂ ∧ … ∧ xₙhas exactly one satisfying assignment, sop = 1/2ⁿ— you need exponentially many samples before seeing a hit, and you conclude the answer is zero35:02,35:24,35:46. - The trick: rig the sample space so that the success probability is not too small
36:10.
The enlarged universe
Sᵢ= set of assignments satisfying clauseCᵢ36:10.B = ⋃ᵢ Sᵢ— the target; we want|B|up to1 ± ε36:54.B′ = { (i, x) : x satisfies Cᵢ }— the disjoint union of theSᵢ. Each satisfying assignment appears once per clause it satisfies37:33,38:25.
|B′| is computable exactly and fast 39:50, 40:57:
|B′| = Σᵢ |Sᵢ|, where |Sᵢ| = 2^(n − #literals in Cᵢ)
because the clause's own literals are forced and every other variable is free 40:22.
Estimating the ratio instead
- Estimate
p′ = |B| / |B′|, then outputp̃′ · |B′|40:57. - Key bound:
p′ ≥ 1/m. Every assignment inBappears at least once and at mostmtimes inB′, so|B′| ≤ m·|B|41:27,41:57. - This is exactly what the naive approach lacked
42:19.
Making "is it in B?" well-typed — the canonical-representative bijection
- Type mismatch: an element of
Bis ann-bit string; an element ofB′is a bit string plus an index in[m]. Also, every element ofB′trivially satisfies the DNF, so a naive membership test would always say yes44:27,44:52. - Fix: bijectively map
Binto the subset{ (i, x) ∈ B′ : Cᵢ is the *first* clause that x satisfies }45:19,45:45,46:14. - Each satisfying assignment is now counted exactly once, and the test is cheap: run
xthrough every clause and confirmiis the first hit46:14.
Sampling uniformly from B′
Two steps 48:25, 48:47, 49:14:
- Pick clause
inot uniformly but with probability|Sᵢ| / Σⱼ |Sⱼ|48:47. - Pick a uniformly random satisfying assignment for
Cᵢ: force the clause's literals, choose every other variable uniformly at random49:14,50:35.
This yields a uniformly random element of B′, and all the |Sᵢ| values needed are computable in closed form 49:14, 50:13.
- Housekeeping: any clause containing both
xand¬xcan be discarded, since it is never satisfiable50:13.
Final algorithm
- Sample
Telements fromB′51:20. - Let
p̃′= fraction of thoseTsamples that are canonical (i.e. "inB")51:20. - Output
p̃′ · |B′|51:20.
flowchart TD
A["DNF: C₁ ∨ … ∨ C_m"] --> B["Compute |Sᵢ| = 2^(n−lᵢ)<br/>exactly"]
B --> C["|B′| = Σ |Sᵢ|"]
C --> D["Sample clause i<br/>w.p. |Sᵢ|/|B′|"]
D --> E["Sample uniform<br/>satisfying x for Cᵢ"]
E --> F{"Is Cᵢ the FIRST<br/>clause x satisfies?"}
F -->|yes| G["count it"]
F -->|no| H["reject"]
G --> I["p̃′ = hits / T"]
H --> I
I --> J["output p̃′ · |B′|"]
Analysis via Chernoff
- Let
Xⱼ = 1if thej-th sample lies inB, andX = Σⱼ Xⱼ; by linearityE[X] = p′·T52:46,53:24. - Failure means
|X − E[X]| > ε·E[X]; Chernoff bounds this by2·e^(−ε²μ/c)for a small constantc(3 or 4), withμ = p′T53:24,54:00. - This drops below
δonce
T ≳ log(1/δ) / (p′ · ε²)
- Substituting
p′ ≥ 1/mgives the polynomial sample count
T = O( m · log(1/δ) / ε² )