Documentation

Complexity.Computability.Circuit.Arithmetic.Power

Binary-power arithmetic circuits #

Binary powering computes each intermediate power once and shares it between the two inputs of a squaring gate. Every further binary digit adds one squaring and, for a one bit, a multiplication by the retained original input. A positive exponent e uses at most 2 * Nat.log2 e gates, all multiplications. Exponent zero uses a single named constant gate; exponent one uses only the input wire.

The constant symbol denoting one is an explicit parameter. Its interpretation is required to equal one only in the correctness theorem. Arbitrary weighted costs, including constant costs, are accounted for exactly. These are circuit-size results, not uniform TM-time certificates for circuit generation or evaluation.

Main definitions #

Main results #

References #

Add a binary digit to a shared power: square, then multiply by the original input for a one bit.

Instances For
    def Cslib.Circuits.binaryPowerCircuit {C : Type v} (one : C) (e : ℕ) :

    Binary powering with a specified constant symbol for one.

    Instances For

      Exact multiplication count of binary powering: one squaring per nonleading bit and one further multiplication per nonleading one bit.

      Instances For
        theorem Cslib.Circuits.eval_binaryPowerCircuit {C : Type v} {R : Type u} [Add R] [Monoid R] (one : C) (constant : C → R) (hone : constant one = 1) (e : ℕ) (x : Fin 1 → R) :
        (binaryPowerCircuit one e).eval (arithInterpretationWith C constant) x 0 = x 0 ^ e

        The circuit computes the natural power, including exponents zero and one.

        Exact weighted cost, charging the constant gate for exponent zero.

        @[simp]

        Every gate at a positive exponent is a multiplication; exponent zero has one constant.

        The multiplication count includes multiplication by scalars.

        Binary powering uses at most twice the base-two logarithm many multiplications.

        theorem Cslib.Circuits.size_binaryPowerCircuit_le {C : Type v} (one : C) {e : ℕ} (he : 0 < e) :

        A positive exponent needs at most 2 * log₂ e gates, all multiplications.