Word arithmetic over the De Morgan basis #
Words are Lean's BitVecs, stored least significant bit first (Cslib.BitString.equivBitVec). A
word-valued function of the inputs is available when each of its coordinate functions is
(Boolean.wordWires). This module bounds the gates needed to make words available from available
words: addition, subtraction, unsigned comparison, comparison with a constant, complementation,
constants, multiplexing, and selection of one of several words by a binary index. Equality of
available bit strings is Formula.equalBits inserted by Synthesis.circuit. Their semantics are
the BitVec operations, through the bit-blasting identities of the core library; no decision
procedure or native evaluation is used.
Addition is a ripple-carry adder: every carry is computed once and shared by the sum bits, for
12 * w + 1 gates on w-bit words including the initial carry constant. All bounds charge every
gate, including constants and negations.
Main definitions #
Cslib.Circuits.Boolean.wordWires: the coordinate functions of a word-valued function.Cslib.Circuits.Boolean.selectBits: select one of several bit strings by a binary index.
Main results #
Cslib.Circuits.Synthesis.mux: a multiplexer in four gates.Cslib.Circuits.Synthesis.word_add,word_addCarry,word_sub: ripple-carry arithmetic.Cslib.Circuits.Synthesis.word_ult,word_eq_const: comparisons.Cslib.Circuits.Synthesis.word_not,word_const,word_mux: bitwise operations.Cslib.Circuits.Synthesis.selectBits: selection charging one comparison per record and bit.
References #
- Adapted from lean/Proofs/{Synthesis,Arithmetic,Words}.lean in S. Schlesinger, Square-root circuit bounds for iterated functions, where each sum bit recomputes its carry chain.
The coordinate functions of a word-valued function.
Zero extension and truncation only rewire available bits and the false constant.
One available control bit selects between two available functions in four gates.
Ripple-carry addition with an initial carry: four gates per carry, eight per sum bit and the initial constant.
Ripple-carry addition modulo the word width.
A hardwired word uses one constant gate per bit.
Bitwise complementation uses one gate per bit.
Unsigned comparison, by the carry of a + ~~~b + 1.
Subtraction modulo the word width, as a + ~~~b + 1.
A word multiplexer shares one available control bit, four gates per bit.
Selecting among available bit strings by an available index charges one comparison with each position for every output bit.
De Morgan Boolean circuit synthesis for unsigned w-bit word maximum in 9 * w + 2 gates.
De Morgan Boolean circuit synthesis for unsigned w-bit word minimum in 9 * w + 2 gates.