Word arithmetic over the De Morgan basis #
Words are Lean's BitVecs, stored least significant bit first. 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.word: the word with given bits.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 word with the given bits, least significant first.
Instances For
The word representation and the bit-string numbering use the same unsigned value.
The coordinate functions of a word-valued function.
Instances For
Zero extension and truncation only rewire available bits and the false constant.
One available control bit selects between two available functions in four gates.
One carry chain uses four gates per bit and its initial constant.
All carries of a sum, each computed once from the previous one.
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.