Documentation

Complexity.Foundations.Data.BitString.Multiplication

Binary multiplication columns and carries #

Each multiplication column is a bitwise subword of the first input. Its number of set bits is the column's unnormalized coefficient. The weighted coefficients sum to the ordinary product; bounded carries normalize them to the product bits.

Main definitions #

Main results #

References #

The set bits record exactly the rows contributing to column j.

Instances For

    A column word is a subword of the first input, including in non-power-of-two universes.

    The exact bitwise meaning of a multiplication column.

    The unnormalized coefficient of 2^j in binary multiplication.

    Instances For
      theorem Cslib.BitString.mulColumn_le {x w : ℕ} (hx : x < 2 ^ w) (y j : ℕ) :
      mulColumn x y j ≤ w

      At most one row per input bit contributes to a column.

      The weighted contribution of all columns strictly below k.

      Instances For

        The carry entering column k, constructed from the actual lower columns.

        Instances For
          @[simp]
          theorem Cslib.BitString.mulCarry_zero (x y : ℕ) :
          mulCarry x y 0 = 0

          No carry enters column 0.

          theorem Cslib.BitString.mulCarry_add_column (x y k : ℕ) :
          mulCarry x y k + mulColumn x y k = ((x * y).testBit k).toNat + 2 * mulCarry x y (k + 1)

          The actual carries satisfy the exact, nonmodular column equation.

          theorem Cslib.BitString.mulCarry_le {x w : ℕ} (hx : x < 2 ^ w) (y k : ℕ) :
          mulCarry x y k ≤ w

          Carries never exceed the number of available rows.

          theorem Cslib.BitString.mulCarry_eq_zero {x y w k : ℕ} (hx : x < 2 ^ w) (hy : y < 2 ^ w) (hk : 2 * w ≤ k) :
          mulCarry x y k = 0

          The terminal carry vanishes once the full product width is covered.

          theorem Cslib.BitString.mul_eq_of_columns {x y z w k : ℕ} (hx : x < 2 ^ w) (hy : y < 2 ^ w) (hz : z < 2 ^ k) (hk : 2 * w ≤ k) (c : ℕ → ℕ) (hzero : c 0 = 0) (hend : c k = 0) (hstep : ∀ i < k, c i + mulColumn x y i = (z.testBit i).toNat + 2 * c (i + 1)) :
          x * y = z

          Any exact zero-ended carry sequence determines ordinary multiplication.

          theorem Cslib.BitString.mul_eq_of_blocks {x y z w k s : ℕ} (hx : x < 2 ^ w) (hy : y < 2 ^ w) (hz : z < 2 ^ k) (hk : 2 * w ≤ k) (hs : 0 < s) (hks : s ∣ k) (c : ℕ → ℕ) (hzero : c 0 = 0) (hend : c k = 0) (hblock : ∀ (q : ℕ), q * s < k → ∃ (a : ℕ → ℕ), a 0 = c (q * s) ∧ a s = c (q * s + s) ∧ ∀ t < s, a t + mulColumn x y (q * s + t) = (z.testBit (q * s + t)).toNat + 2 * a (t + 1)) :
          x * y = z

          Blocks sharing their endpoint carries determine multiplication. The boundary sequence is global, while the interior witnesses may be chosen separately for every block.