INNER CODE UNIT · Python
prefix_or6
lschoe/mpyc · demos/PrefixOrExplained.py:312
def prefix_or6(x):
def pf(a, x):
n = len(x)
if n == 1:
return [a | x[0]], x[0]
y0, b0 = pf(a, x[:n//2])
y1, b1 = pf(a | b0, x[n//2:])
return y0 + y1, b0 | b1
return pf(0, x)[0]
# The auxiliary input for the second half becomes `a | b0`, to include the or `b0` over the first half.
# In[21]: