Documentation

LeanPool.BeyondBethe.BeyondBethe.MachineBinaryMul

A composed polynomial-time binary multiplier #

The multiplier scans the little-endian multiplier. Its state contains the unread multiplier, the current doubled multiplicand, and the accumulated partial product. Each iteration uses the already verified binary adder. A quadratic Cobham width bound is proved for every input string, while exact arithmetic correctness is proved on canonical Nat.bits operands.

def BeyondBethe.machineBinaryMulPack (remaining shift acc : List Bool) :

Encodes multiplication state as remaining multiplier bits, shifted multiplicand, and accumulator.

Equations
Instances For

    Extracts the unprocessed multiplier bits from the multiplication state.

    Equations
    Instances For

      Extracts the shifted multiplicand from the multiplication state.

      Equations
      Instances For

        Extracts the accumulated product from the multiplication state.

        Equations
        Instances For

          Adds the shifted multiplicand to the accumulator when the current multiplier bit is set.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Consumes one multiplier bit, doubles the shift, and conditionally updates the accumulator.

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For

              Initializes multiplication with the second operand as multiplier and a zero accumulator.

              Equations
              Instances For

                Uses the second operand's bits as the multiplication iteration ruler.

                Equations
                Instances For

                  A deliberately generous quadratic state envelope.

                  Equations
                  Instances For

                    Extracts the accumulated product from the final multiplication state.

                    Equations
                    Instances For
                      theorem BeyondBethe.machineBinaryMulPack_mem_FP {remaining shift acc : List Bool → List Bool} (hremaining : remaining ∈ Complexity.FP) (hshift : shift ∈ Complexity.FP) (hacc : acc ∈ Complexity.FP) :
                      (fun (word : List Bool) => machineBinaryMulPack (remaining word) (shift word) (acc word)) ∈ Complexity.FP
                      @[simp]
                      theorem BeyondBethe.machineBinaryMulRemaining_pack (remaining shift acc : List Bool) :
                      machineBinaryMulRemaining (machineBinaryMulPack remaining shift acc) = remaining
                      @[simp]
                      theorem BeyondBethe.machineBinaryMulShift_pack (remaining shift acc : List Bool) :
                      machineBinaryMulShift (machineBinaryMulPack remaining shift acc) = shift
                      @[simp]
                      theorem BeyondBethe.machineBinaryMulAcc_pack (remaining shift acc : List Bool) :
                      machineBinaryMulAcc (machineBinaryMulPack remaining shift acc) = acc
                      @[simp]
                      theorem BeyondBethe.machineBinaryMulStep_pack (bit : Bool) (remaining shift acc : List Bool) :

                      Pure list-level fold mirrored by the bounded machine loop.

                      Equations
                      Instances For
                        def BeyondBethe.MachineBinaryMulReachable (lhs rhs : List Bool) (iterations : ℕ) (state : List Bool) :

                        Bounds the remaining multiplier length and the growth of the shifted operand and accumulator.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          theorem BeyondBethe.machineBinaryMulStep_reachable {lhs rhs : List Bool} {iterations : ℕ} {state : List Bool} (hstate : MachineBinaryMulReachable lhs rhs iterations state) :
                          MachineBinaryMulReachable lhs rhs (iterations + 1) (machineBinaryMulStep state)
                          theorem BeyondBethe.binaryMulFold_natBits (bits : List Bool) (shift acc : ℕ) :
                          (binaryMulFold bits shift.bits acc.bits).2 = (acc + shift * Nat.fromBitsLE bits).bits

                          The concrete multiplier returns the canonical binary expansion of the product of two canonically encoded natural numbers.