Correctness of raw threshold-circuit fragments #
This module exposes an appendable unary dynamic-programming circuit for testing
whether at least threshold referenced wires are true. For k references it
uses exactly 3 + 2 * k * threshold gates: two Boolean constants, two gates per
table cell, and one final output copy.
The core semantic statement uses Mathlib's dependency-light Fin.countP rather
than importing the complexity-class counting layer into the circuit library.
A majority adapter can rewrite this count to the library's popCount at the
higher layer where both APIs are already available.
Main definitions and results #
Threshold.compileRaw: compile an at-least-threshold test over absolute wires.Threshold.length_compileRaw: exact gate count.Threshold.topologicallyWellFormed_compileRaw: every emitted reference points to the existing prefix or an earlier emitted gate.Threshold.evalAux?_compileRaw: exact size, prefix preservation, and semantic correctness of iterative evaluation.
Threshold compilation emits two gates per table cell, two constants, and one final copy gate.
When the requested threshold is at most the input count, the threshold fragment has the advertised quadratic gate bound.
The designated output lies inside the newly emitted fragment.
A threshold fragment's designated output is never before its existing-wire prefix.
The designated threshold output is the final emitted wire.
If every requested input names an existing wire, the threshold fragment only references the existing prefix or earlier gates in the same fragment.
Successful threshold evaluation appends its exact gate count, preserves
the existing memo array, and returns true exactly when at least threshold of
the referenced input values are true.