Documentation

CslibFrontier.Computability.Machines.Turing.MultiTape.Complexity.PolyTime.Nat.NthRoot

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 #

Integer k-th root Nat.nthRoot k m is polynomial-time, with k in unary and m in binary.

theorem Turing.MultiTapeTM.ComputableInPolyTime.binary_nthRoot' {α : Type} {input : α ↪ List Bool} {k m : α → ℕ} (hk : ComputableInPolyTime k input encUnary) (hm : ComputableInPolyTime m input encNat) :
ComputableInPolyTime (fun (a : α) => (k a).nthRoot (m a)) input encNat

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.