def iroot_k

bend-collections-laws-math@1.0.0.0 · src/math/natural.bend:235

import bend-collections-laws-math@1.0.0.0/src/math/natural.bend as Natural
import Base
import bend-collections-laws-math@1.0.0.0/src/math/pow2.bend as P2

235# the largest r with r^k <= n (k >= 1)
236def iroot_k(+n: Nat, +k: Nat) -> Nat:
237  match k:
238    case 0n:
239      0n
240    case 1n:
241      n
242    case 2n+ +kp:
243      search(n, 2n+kp, 0n, P2.pow2t(1n+Nat.div(bit_length(n), 2n+kp)))

Uses (5)

Used by (11)