Sequential exact-one De Morgan circuits and width-3 Tseitin compilation #
For a list of input wires ws, seqExactlyOneClause n base ws builds a De Morgan gate list of
only 3 * ws.length + 3 gates (O(ws.length) gates rather than quadratic pairwise clauses) whose
output wire evaluates to true exactly when precisely one wire in ws is true. Repeating across
a family wss of wire lists (seqExactlyOneAll n wss) yields a gate list of
1 + 4 * wss.length + 3 * (wss.map List.length).sum gates, and tseitinSatCNF [] n gates out
compiles it to a width-3 CNF formula preserving the exact number of satisfying input bitstrings
in O(n + ∑ |ws|) variables.
Main definitions #
Cslib.Circuits.Boolean.tseitinSatAssignmentEquiv: explicit bijection between satisfying input bitstrings andtseitinSatCNFmodels onFinset.range (n + gates.length).Cslib.Circuits.Boolean.SeqExactlyOneStepResult,Cslib.Circuits.Boolean.ExactOneCircuitResult: named result records for the sequential exact-one transition and circuit gadgets.Cslib.Circuits.Boolean.seqExactlyOneClause:O(d)-gate sequential exact-one De Morgan gadget.Cslib.Circuits.Boolean.seqExactlyOneAll:O(|wss| + ∑ |ws|)-gate conjunction of exact-one constraints.
Main results #
Cslib.Circuits.Boolean.vars_tseitinSatCNF_subset: occurring-variable bound fortseitinSatCNF.Cslib.Circuits.Boolean.isCodeFrom_seqExactlyOneClause,Cslib.Circuits.Boolean.isCodeFrom_seqExactlyOneAll: well-formedness (IsCodeFrom).Cslib.Circuits.Boolean.evalOutput_seqExactlyOneAll: exact evaluation correctness.Cslib.Circuits.Boolean.card_evalOutput_eq_modelCountOn_tseitinSatCNF: exact model-count preservation of any well-formed De Morgan gate list compiled viatseitinSatCNF [] n gates o.
Prefix model-count preservation for tseitinSatCNF #
Explicit assignment bijection between bit strings accepted by a single-output well-formed
gate list and satisfying assignments of tseitinSatCNF [] n gates o on
Finset.range (n + gates.length).
tseitinSatCNF preserves the exact number of accepting input bitstrings.
Every occurring variable of tseitinSatCNF [] n gates o is strictly below n + gates.length
when gates is well-formed (IsCodeFrom signature n 0 gates) and o < n + gates.length.
IsCodeFrom and single-gate evalCode helpers #
Sequential exact-one De Morgan gate list #
Intermediate state of seqExactlyOneStep, pairing the emitted De Morgan gates with the wires
recording whether at least one and at least two true inputs have been seen so far.
Emitted De Morgan gates
(op, args).- seen1Wire : ℕ
Wire index holding
trueiff at least onetruewire has been seen. - seen2Wire : ℕ
Wire index holding
trueiff at least twotruewires have been seen.
Instances For
Recursive linear-size state transition tracking seen1 and seen2 across wire list ws.
Returns the emitted gates together with the updated seen1Wire and seen2Wire.
Sequential exact-one circuit on input wires ws, starting at gate offset base on n total
input wires. Returns the gate list and its output wire. Uses 3 * ws.length + 3 gates.
seqExactlyOneClause n base ws is well-formed starting at gate base whenever all wires in
ws are < n + base.
Evaluation correctness of seqExactlyOneClause: after appending seqExactlyOneClause, its
output wire holds true iff precisely one wire in ws holds true.
Fold a list of wire lists into a conjunction of sequential exact-one De Morgan gadgets.
Returns the gate list and its output wire. Uses 4 * wss.length + 3 * (wss.map List.length).sum
extra gates.
Linear-size sequential exact-one De Morgan circuit checking that every list ws ∈ wss
has precisely one true input wire among 0, …, n - 1. Uses at most
1 + 4 * wss.length + 3 * (wss.map List.length).sum gates.
seqExactlyOneAll n wss is a well-formed De Morgan gate list on n inputs whenever every
wire in every list of wss is < n.
The output wire of seqExactlyOneAll n wss lies strictly below n + gates.length.
Evaluation correctness of seqExactlyOneAll: evalOutput x gates out holds iff every
list ws ∈ wss contains precisely one wire where x evaluates to true.