Native generation of linear-size threshold circuits #
The population tree is generated one height at a time. Its state includes the current number of leaves in unary as well as the complete circuit code. Only logarithmically many heights are visited, and each intermediate tree has at most twice the requested number of leaves. Thus all wire numbers, framing bits, and intermediate circuit descriptions have polynomial total length.
The resulting polynomial-time certificate concerns the actual gate-and-output encoding used by the native circuit counter.
theorem Cslib.Circuits.Boolean.PopulationCount.computableInPolyTime_tree :
Turing.MultiTapeTM.ComputableInPolyTime (fun (n : ℕ) => (tree (Nat.clog 2 (n + 1))).code) Turing.MultiTapeTM.encUnary
encCode
Generate the power-of-two tree selected by an arbitrary unary input count.
theorem Cslib.Circuits.Boolean.PopulationCount.computableInPolyTime_pad :
Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × ℕ) => (pad p.1 p.2).code)
(Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) encCode
Generate padding from unary input and output counts.
The complete linear-size population-count circuit is generated in polynomial time from its unary number of inputs.