sourcelibs/Datapath/demos/reduce-sum.xtl
1⍝!/usr/bin/env xetal
2⍝ '+ r_/ v as a tree of adders: eight 16-bit numbers, three levels,
3⍝ seven adders. Wrapping at every adder gives the bits the wrapped
4⍝ exact sum has. Run with "just demo-lib Datapath reduce-sum".
5ᵈᵖ⁼u̲se< "Datapath"
6v ← 1 2 3 4 5 6 7 8
7'+ r̲/ v ⍝ the evaluator
816 ᵈᵖs̲um v ⍝ the tree
9big ← 8 r̲eshape 10000 ⍝ 80000 does not fit in 16 bits
10'+ r̲/ big
1116 ᵈᵖs̲um big ⍝ the tree's answer: 80000 wrapped
12ᵈᵖl̲argest v ⍝ a tree of comparators