BendMlLlama.tree_sum: def of bend-ml-llama@0.2.1.0 Import: import bend-ml-llama@0.2.1.0/main.bend as BendMlLlama Lines 373-384 of bend-ml-llama@0.2.1.0/main.bend: https://jend.leeeet.dev/read.txt?path=bend-ml-llama@0.2.1.0/main.bend&start_line=373&end_line=384 import Base # the sum as a balanced tree of additions (pairwise summation): its rounding error grows with log2(n), not n, as # in PyTorch's cascade sum. A running sum loses the small squares next to a large one (NOTES, 2026-10-10). def tree_sum(fuel: Nat, xs: List<&2, F32>) -> F32: match fuel xs: case _ Nil{}: 0.0 case _ Con{+a, Nil{}}: a case 0n Con{+a, t}: list.sum.go(t, a) case 1n+p Con{+a, t}: tree_sum(p, pair_sums(Con{a, t})) Uses (5): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=List https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=bend-ml-llama@0.2.1.0/main.bend&name=list.sum.go https://jend.leeeet.dev/definition.txt?path=bend-ml-llama@0.2.1.0/main.bend&name=pair_sums