Polynomial-time division and remainder on binary naturals #
Schoolbook shift-and-subtract long division over the binary encoding Turing.MultiTapeTM.encNat.
The dividend's binary digits are reversed to most-significant-bit-first order and folded with
Turing.MultiTapeTM.BinaryDiv.divModStep, which shifts the running remainder by one bit, adds the
next dividend bit, and subtracts the divisor whenever it fits. A zero divisor never subtracts, so
the quotient stays 0 and the remainder reconstructs the dividend, matching a / 0 = 0 and
a % 0 = a.
After consuming any prefix word of the reversed digits, the state (q, r) is the quotient and
remainder of Cslib.BitString.binaryValue word by the divisor (BinaryDiv.foldl_divModStep). Both
components are therefore at most binaryValue word < 2 ^ word.length, so their binary encodings
have length at most word.length, keeping the encoded pair linearly bounded throughout the fold.
Main definitions #
Turing.MultiTapeTM.BinaryDiv.divModStep: one shift-and-subtract step of binary long division.
Main results #
Turing.MultiTapeTM.BinaryDiv.foldl_divModStep: foldingdivModStepover a most-significant-first bit word computes the quotient and remainder of itsbinaryValue.Turing.MultiTapeTM.BinaryDiv.divMod_eq: folding overa.bits.reversecomputes(a / b, a % b).Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_divMod: joint quotient and remainder onencNat.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_div,.binary_mod: binary division and remainder onencNat.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_div',.binary_mod': composition rules forfun_propandpolytime.Turing.MultiTapeTM.ComputableInPolyTime.binary_div': named composition rule for plain certificates.
References #
Divide computed binary values, fixing their intermediate encodings for proof search.
Remainder of computed binary values, fixing their intermediate encodings for proof search.
Divide computed binary values using the shared plain certificate.