Polynomial-time arithmetic on binary naturals #
Polynomial-time certificates for arithmetic on the binary encoding Turing.MultiTapeTM.encNat
(digits least significant first), the binary counterparts of the unary certificates in
Complexity/Computability/Machines/Turing/MultiTape/Complexity/PolyTime/Nat.lean. Addition and
multiplication are Christian Reitwiessner's degree-bounded
machines (Turing.MultiTapeTM.computableTidilyInDegree_add,
Turing.MultiTapeTM.computableTidilyInDegree_mul). A list is summed by a left fold whose
accumulator grows by at most one digit more than the length of the element added. Powers of two are
computed from a unary exponent by repeated doubling. Strict comparison is the linear-time zip
transducer of Turing.MultiTapeTM.computableInTimeAndSpace_natLt. The verifiers and reductions
of the number problems (Cslib.Complexity.SubsetSum and its relatives) are built from these.
Truncated subtraction is schoolbook subtraction: a left fold over the digit pairs of both operands
keeps a borrow and appends one difference digit per position. A final borrow means that the
difference is negative; otherwise the digits are read back as a natural
(Turing.MultiTapeTM.ofBits, certified by Turing.MultiTapeTM.Decoder.nat), dropping trailing
zeros. General powers to a unary exponent are computed by repeated
multiplication.
Main definitions #
Turing.MultiTapeTM.BinarySub.subStep: one round of schoolbook subtraction with a borrow.
Main results #
Turing.MultiTapeTM.ComputableTidilyInPolyTime.bitsToNat: binary decoding of arbitrary words.Nat.size_add_le: a sum has at most one binary digit more than its summands together.Nat.lt_iff_exists_testBit: strict order through the highest differing bit.Nat.size_add_le_max,Nat.size_mul_le,Nat.size_pow_le,Nat.size_sum_le: binary lengths of sums, products, powers and list sums.Turing.MultiTapeTM.BinarySub.sub_eq: truncated subtraction through the final borrow.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_add,.binary_mul: addition and multiplication.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_sum: the sum of a list.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_two_pow:2 ^ kin binary, fromkin unary.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_lt,.binary_le: comparisons.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_sub: truncated subtraction.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_pow: a power to a unary exponent.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_add',.binary_lt',.binary_le': composition rules forfun_prop.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_mul',.binary_sub',.binary_pow': composition rules forfun_prop.Turing.MultiTapeTM.ComputableInPolyTime.binary_bitwise,.binary_and,.binary_or,.binary_xor,.binary_and',.binary_or',.binary_xor': bitwise operations on binary naturals, and their composition rules.Turing.MultiTapeTM.ComputableInPolyTime.binary_size,.binary_min_unary,.binary_min_unary',.binary_shiftRight,.binary_shiftRight': bit-length in unary, capping a binary natural by a unary bound, and binary right shift.Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_testBit: a bit of a binary number at a unary position.
Decode arbitrary little-endian bit words to binary naturals.
The binary digits of a natural number, as a raw bit string.
Add computed binary values, fixing their intermediate encodings for proof search.
The sum of a list of binary naturals, by a left fold of binary additions.
2 ^ k in binary, from k in unary, by doubling.
Strictly compare computed binary values, fixing their intermediate encodings.
Compare computed binary values, fixing their intermediate encodings.
Multiply computed binary values, fixing their intermediate encodings for proof search.
Raise a computed binary value to a computed unary exponent, fixing the intermediate encodings.
Subtract computed binary values, truncating at zero and fixing their intermediate encodings.
Read the bit of a computed binary number at a computed unary position.
Bitwise AND of computed binary naturals.
Bitwise OR of computed binary naturals.
Bitwise XOR of computed binary naturals.
The bit-length Nat.size n of a binary natural, returned in unary.
Cap a computed binary natural by a computed unary bound, returning the result in unary.
Right shift of computed binary naturals.
The strict order of two computed numbers in binary.
Plain polynomial-time automation #
2 ^ k in binary, from k in unary, by doubling.
Subtract computed binary values using the shared plain certificate.
Turing.MultiTapeTM.ComputableTidilyInPolyTime.binary_pow' for plain certificates.