Documentation

Complexitylib.Models.TuringMachine.Subroutines.BinaryShiftMul.Internal.Pure

Width-driven binary shift-and-add multiplication -- pure proofs #

This file proves the generalized arithmetic invariant of the little-endian shift-and-add fold, its multiplication specialization, and width bounds for every partial accumulator and shifted multiplicand.

theorem Complexity.BinaryShiftMul.fold_eq_internal (bits : List Bool) (acc shift : ) :
fold bits acc shift = (acc + shift * Nat.fromBitsLE bits, shift * 2 ^ bits.length)

The generalized shift-and-add fold accumulates shift times the decoded bit string and doubles shift once per consumed bit.

Taking a low-order prefix cannot increase its little-endian decoded value.

theorem Complexity.BinaryShiftMul.fold_take_eq_internal (lhs rhs i : ) (hi : i rhs.size) :
fold (List.take i rhs.bits) 0 lhs = (partialAcc lhs rhs i, partialShift lhs i)

If the iteration index is within the canonical multiplier width, folding its prefix produces the advertised partial accumulator and shift.

theorem Complexity.BinaryShiftMul.step_partial_internal (lhs rhs i : ) (hi : i < rhs.size) :
step (rhs.bits.get i, ) (partialAcc lhs rhs i) (partialShift lhs i) = (partialAcc lhs rhs (i + 1), partialShift lhs (i + 1))

One live multiplier bit advances the partial arithmetic invariant by one iteration.

theorem Complexity.BinaryShiftMul.fold_natBits_internal (lhs rhs : ) :
fold rhs.bits 0 lhs = (lhs * rhs, lhs * 2 ^ rhs.size)

Folding all canonical multiplier bits computes multiplication and leaves the shift advanced by the multiplier width.

theorem Complexity.BinaryShiftMul.partialAcc_full_internal (lhs rhs : ) :
partialAcc lhs rhs rhs.size = lhs * rhs

The complete partial accumulator is the product.

The complete partial shift has advanced by the multiplier width.

theorem Complexity.BinaryShiftMul.fold_natBits_fst_internal (lhs rhs : ) :
(fold rhs.bits 0 lhs).1 = lhs * rhs

The accumulator component of the complete pure fold is the product.

Every partial accumulator is bounded by the complete product.

Binary width is subadditive under multiplication.

Every partial accumulator fits in the combined input width.

Shifting left by i grows binary width by at most i.

theorem Complexity.BinaryShiftMul.partial_widths_le_internal (lhs rhs i : ) (hi : i rhs.size) :
(partialAcc lhs rhs i).size lhs.size + rhs.size (partialShift lhs i).size lhs.size + rhs.size

At any live multiplier iteration, both arithmetic values fit in the combined input width.