Linear-size population counting and thresholds #
The word width at a node of a balanced addition tree is the height of that node plus one. Consequently, the existing quadratic-size adder suffices for a linear-size population counter: there are exponentially fewer nodes at increasing heights. All gates, including constants, are charged. The input is padded with zeros to a power of two, so the construction also handles an empty input.
Main definitions #
Cslib.Circuits.Boolean.PopulationCount.tree: the counter on a power-of-two input block.Cslib.Circuits.Boolean.populationCountCircuit: the counter on an arbitrary input block.Cslib.Circuits.Boolean.linearThresholdCircuit: a threshold circuit of linear size.
Main results #
Cslib.Circuits.Boolean.val_eval_populationCountCircuit: exact binary population count.Cslib.Circuits.Boolean.size_populationCountCircuit_le: a linear gate bound.Cslib.Circuits.Boolean.eval_linearThresholdCircuit: exact threshold semantics.Cslib.Circuits.Boolean.size_linearThresholdCircuit_le: a linear gate bound.
References #
Binary addition and threshold circuits are standard; see Vollmer, Chapter 1.
The concrete adders and their source attribution are in Boolean.CarryLookahead.
The output word is the exact number of true inputs, including the full carry.
One shared false gate extends a word with zeros.
Padding agrees with the standard zero extension of a bit string.
The circuit computes the exact binary numeral of the input's Hamming weight.
A uniform linear gate bound, with constants and padding included.
Compare the population count with a cutoff. An impossible cutoff returns false.
The linear-size threshold circuit accepts precisely when at least q inputs are true.
Linear population counting followed by comparison remains linear in the input count.