def ones

bend-collections-laws-math@1.0.0.0 · spec/math/number.bend:20

import bend-collections-laws-math@1.0.0.0/spec/math/number.bend as Number
import Base
import bend-collections-laws-math@1.0.0.0/spec/lib/common.bend as C

20# the 1 bits among the k lowest bits of n
21def ones(k: Nat, +n: Nat) -> Nat:
22  match k:
23    case 0n:
24      0n
25    case 1n+p:
26      Nat.add(C.bit(n), ones(p, C.half(n)))

Uses (4)

Used by (10)