~/bend-docscommunity

spin_collatz.bend checks

raw source on the hub · import 0x492532af6deb895462a134d016a53dfe/spin_collatz.bend as Spin_collatz

Collatz steps, summed over a fork tree: the leaf is a flat tail loop (spin), the tree a bang. total!(d, i) = sum over lane k < 2^d of steps(i + k + 1) (steps of 1 is 0)

1 import
import Base

Definitions

def steps source · line 7 · raw

@fuel:Nat -> @+n:U32 -> @+acc:U32 -> U32

a flat tail loop (Nat fuel counting down, accumulators carried): the Collatz step count of n, 512 steps of fuel (n < 2^16 needs at most 339)

def pow2 source · line 17 · raw

@d:Nat -> Nat

def total source · line 25 · raw

@d:Nat -> @+i:U32 -> U32

def main source · line 33 · raw

IO(Unit)