Polynomial-time arithmetic on binary integers #
Polynomial-time certificates for arithmetic on the binary sign-magnitude integers
Turing.MultiTapeTM.encIntBin. The sign bit and the magnitude are read off the code directly. Every
other operation is an ordinary functional program over the sign and the magnitude, by cases on
the signs, built from the binary natural arithmetic of
Complexity/Computability/Machines/Turing/MultiTape/Complexity/PolyTime/Nat/Binary.lean; no new
machine
is involved. A result is assembled from a sign and a magnitude by
Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_signMagnitude, which clears the sign of a
zero magnitude. Integers of equal sign add their magnitudes; otherwise the smaller magnitude is
subtracted from the larger one, which keeps its sign. A product multiplies the magnitudes, and is
negative when exactly one factor is. Lists are summed and powers taken by left folds, with
the binary length bounds of Int.size_natAbs_add_le and Int.size_natAbs_mul_le.
Main results #
Turing.MultiTapeTM.ComputableInPolyTime.intBin_mul': multiply two plain-certified binary integers from the same complete input encoding.Turing.MultiTapeTM.ComputableInPolyTime.intBin_prod_range: the product of a plain-certified family of binary integers over a computed unary range.Int.size_natAbs_add_le,Int.size_natAbs_sub_le,Int.size_natAbs_mul_le,Int.size_natAbs_pow_le,Int.size_natAbs_sum_le,Int.size_natAbs_prod_le: binary lengths of magnitudes of sums, differences, products, powers, list sums and list products.Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_isNeg,.intBin_natAbs: the sign and the binary magnitude.Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_signMagnitude,.intBin_natCast: integers from a sign and a binary magnitude, and from binary naturals.Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_isZero,.intBin_isPos,.intBin_sign,.intBin_toNat: sign tests, the sign and truncation at zero.Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_neg,.intBin_add,.intBin_sub,.intBin_mul,.intBin_pow: ring operations, powers to a unary exponent.Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_lt,.intBin_le: comparisons.Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_sum,.intBin_prod: the sum and product of a list.Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_add',.intBin_sub',.intBin_mul',.intBin_pow',.intBin_lt',.intBin_le': composition rules forfun_prop.
The sign of a binary integer: whether it is negative.
The magnitude of a binary integer, as a binary natural.
Assemble a binary integer from a sign and a binary magnitude. A negative sign on a zero magnitude is dropped, so the code stays unique.
A binary natural as a binary integer.
Negation of binary integers flips the sign of a nonzero magnitude.
Test whether a binary integer is zero: its magnitude has no digits.
Test whether a binary integer is positive.
The sign of a binary integer, as a binary integer.
Truncate a binary integer at zero, as a binary natural.
The sum of a list of binary integers, by a left fold of binary additions.
The product of a list of binary integers, by a left fold of binary multiplications.
Add computed binary integers, fixing their intermediate encodings for proof search.
Subtract computed binary integers, fixing their intermediate encodings.
Multiply computed binary integers, fixing their intermediate encodings.
Raise a computed binary integer to a computed unary exponent, fixing the intermediate encodings.
Strictly compare computed binary integers, fixing their intermediate encodings.
Compare computed binary integers, fixing their intermediate encodings.
Multiply a uniformly computed family of binary integers over a computed unary range.
Multiply computed binary integers, preserving the complete input encoding.
The cast of a binary natural number to a binary integer.
Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_sub for plain certificates.
Turing.MultiTapeTM.ComputableTidilyInPolyTime.intBin_prod_range for plain certificates.