Polynomial-time integer k-th roots on binary naturals #
Nat.nthRoot k m (⌊m ^ (1 / k)⌋) is computable in polynomial time, with k in unary and m
in binary, by a most-significant-bit-first fold over the m.size bit positions: at position
i, the candidate bit 2 ^ i is added to the running root acc whenever (acc + 2 ^ i) ^ k ≤ m
and acc + 2 ^ i ≤ m. The second test is implied by the first when k ≠ 0, and keeps every
intermediate root at most m also for k = 0.
The square root Turing.MultiTapeTM.ComputableInPolyTime.binary_sqrt is the case k = 2.
On unary naturals, the ceiling ⌈n ^ (p / q)⌉ of a rational power is a bounded search: it is
the greatest m ≤ n ^ p with (m - 1) ^ q < n ^ p.
Main results #
Turing.MultiTapeTM.ComputableInPolyTime.binary_nthRoot,.binary_nthRoot': plain polynomial-time integerk-th rootNat.nthRootwith unarykand binary radicand.Turing.MultiTapeTM.ComputableInPolyTime.unary_ceil_rpow: the ceiling⌈n ^ (p / q)⌉of a rational power, unary in and out.
Integer k-th root Nat.nthRoot k m is polynomial-time, with k in unary and m in
binary.
Integer k-th root of a computed binary natural, with a computed unary k.
Unary rational-power ceilings. For naturals p and q ≠ 0, n ↦ ⌈n ^ (p / q)⌉ is
polynomial time with unary input and output, by a bounded search below n ^ p.