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
CslibFrontier/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.ComputableInPolyTime.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 #
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.ComputableInPolyTime.intBin_isNeg,.intBin_natAbs: the sign and the binary magnitude.Turing.MultiTapeTM.ComputableInPolyTime.intBin_signMagnitude,.intBin_natCast: integers from a sign and a binary magnitude, and from binary naturals.Turing.MultiTapeTM.ComputableInPolyTime.intBin_isZero,.intBin_isPos,.intBin_sign,.intBin_toNat: sign tests, the sign and truncation at zero.Turing.MultiTapeTM.ComputableInPolyTime.intBin_neg,.intBin_add,.intBin_sub,.intBin_mul,.intBin_pow: ring operations, powers to a unary exponent.Turing.MultiTapeTM.ComputableInPolyTime.intBin_lt,.intBin_le: comparisons.Turing.MultiTapeTM.ComputableInPolyTime.intBin_sum,.intBin_prod,.intBin_finset_prod,.intBin_prod_range: the sum and product of a list, the product of a fixed finite family, and the product of a computed family over a unary range.Turing.MultiTapeTM.ComputableInPolyTime.intBin_add',.intBin_sub',.intBin_mul',.intBin_pow',.intBin_lt',.intBin_le': composition rules forfun_prop.
Whether a binary integer is negative: the sign bit of its code.
The binary magnitude of a binary integer: its code without the sign bit.
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: a nonnegative sign bit in front of its digits.
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.
Compare two computed binary integers with <, fixing their intermediate encodings.
Compare two computed binary integers with ≤, fixing their intermediate encodings.
Multiply a fixed finite family of computed binary integers.
Multiply a uniformly computed family of binary integers over a computed unary range.
Tidy forms #
Tidy proofs in Lyubashevsky.Efficient, Lyubashevsky.NativeExtract and
ExactOne.DrawingPolyTime still compose these rules; each is the plain rule above.
Turing.MultiTapeTM.ComputableInPolyTime.intBin_natCast for tidy certificates.
Turing.MultiTapeTM.ComputableInPolyTime.intBin_sub for tidy certificates.
Turing.MultiTapeTM.ComputableInPolyTime.intBin_mul for tidy certificates.
Turing.MultiTapeTM.ComputableInPolyTime.intBin_pow for tidy certificates.
Turing.MultiTapeTM.ComputableInPolyTime.intBin_add' for tidy certificates.
Turing.MultiTapeTM.ComputableInPolyTime.intBin_sub' for tidy certificates.
Turing.MultiTapeTM.ComputableInPolyTime.intBin_mul' for tidy certificates.