poly-- source --
-- polynomial evaluation, Mou 1991 Algo.4.7
xval=1
poly_b(a,x) = (v=a*x,pwr=x) -- 0th node: (v=a0*1,pwr=1), 1th node (v=a1*x^1,pwr=x^1)
loc((hiv,hipwr), -- high side node data
(lov,lopwr)) -- other, low-side node data, received from # corr
= (lov+hiv*lopwr,lopwr*hipwr) -- in postadjust the whole RHS *= pwr, then add to the LHS
-- postadjust (a1,x^1),(a2,x^1) should yield (a1,x^1),(a1+a2*x^1,x^2)
poly_dc = PDC(d_lr,c_lr,id, (id,!loc) @ #(nil, last(0)), atomq, lift1(poly_b))
poly = unzip.0 @ poly_dc @ zip
randAs = shuffled(3)
Xs = [1] + xvec(xval, 7) -- vector join: +
trace(poly, randAs, Xs)
-- end source --
-- lib: polyb_lib.py --
"""Helpers for polyb.dc: polynomial evaluation per Mou 1991 Algo 4.7.
shuffled(N): a random permutation of [0..2**N - 1] - test input."""
import random
def shuffled(N, seed=None):
if seed is not None:
random.seed(seed)
arr = list(range(2 ** N))
random.shuffle(arr)
return arr
-- end lib --
-- trace: poly([4,1,6,7,2,0,3,5], [1,1,1,1,1,1,1,1]) --
_zip -> [(4, 1),(1, 1),(6, 1),(7, 1),(2, 1),(0, 1),(3, 1),(5, 1)]
poly_dc([(4, 1),(1, 1),(6, 1),(7, 1),(2, 1),(0, 1),(3, 1),(5, 1)])
divide d_lr -> ([(4, 1),(1, 1),(6, 1),(7, 1)], [(2, 1),(0, 1),(3, 1),(5, 1)])
poly_dc([(4, 1),(1, 1),(6, 1),(7, 1)])
divide d_lr -> ([(4, 1),(1, 1)], [(6, 1),(7, 1)])
poly_dc([(4, 1),(1, 1)])
divide d_lr -> ([(4, 1)], [(1, 1)])
poly_dc([(4, 1)])
⇣ atom; basef -> [(4, 1)]
poly_dc([(1, 1)])
⇣ atom; basef -> [(1, 1)]
post #(nil,last0) -> ([(4, 1)], [((1, 1), (4, 1))])
loc(((1, 1), (4, 1))) [hiv=1, hipwr=1, lov=4, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (4+1*1,1*1)
post (id_, !loc) -> ([(4, 1)], [(5, 1)])
combine c_lr -> [(4, 1),(5, 1)]
poly_dc([(6, 1),(7, 1)])
divide d_lr -> ([(6, 1)], [(7, 1)])
poly_dc([(6, 1)])
⇣ atom; basef -> [(6, 1)]
poly_dc([(7, 1)])
⇣ atom; basef -> [(7, 1)]
post #(nil,last0) -> ([(6, 1)], [((7, 1), (6, 1))])
loc(((7, 1), (6, 1))) [hiv=7, hipwr=1, lov=6, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (6+7*1,1*1)
post (id_, !loc) -> ([(6, 1)], [(13, 1)])
combine c_lr -> [(6, 1),(13, 1)]
post #(nil,last0) -> ([(4, 1),(5, 1)], [((6, 1), (5, 1)),((13, 1), (5, 1))])
loc(((6, 1), (5, 1))) [hiv=6, hipwr=1, lov=5, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (5+6*1,1*1)
loc(((13, 1), (5, 1))) [hiv=13, hipwr=1, lov=5, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (5+13*1,1*1)
post (id_, !loc) -> ([(4, 1),(5, 1)], [(11, 1),(18, 1)])
combine c_lr -> [(4, 1),(5, 1),(11, 1),(18, 1)]
poly_dc([(2, 1),(0, 1),(3, 1),(5, 1)])
divide d_lr -> ([(2, 1),(0, 1)], [(3, 1),(5, 1)])
poly_dc([(2, 1),(0, 1)])
divide d_lr -> ([(2, 1)], [(0, 1)])
poly_dc([(2, 1)])
⇣ atom; basef -> [(2, 1)]
poly_dc([(0, 1)])
⇣ atom; basef -> [(0, 1)]
post #(nil,last0) -> ([(2, 1)], [((0, 1), (2, 1))])
loc(((0, 1), (2, 1))) [hiv=0, hipwr=1, lov=2, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (2+0*1,1*1)
post (id_, !loc) -> ([(2, 1)], [(2, 1)])
combine c_lr -> [(2, 1),(2, 1)]
poly_dc([(3, 1),(5, 1)])
divide d_lr -> ([(3, 1)], [(5, 1)])
poly_dc([(3, 1)])
⇣ atom; basef -> [(3, 1)]
poly_dc([(5, 1)])
⇣ atom; basef -> [(5, 1)]
post #(nil,last0) -> ([(3, 1)], [((5, 1), (3, 1))])
loc(((5, 1), (3, 1))) [hiv=5, hipwr=1, lov=3, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (3+5*1,1*1)
post (id_, !loc) -> ([(3, 1)], [(8, 1)])
combine c_lr -> [(3, 1),(8, 1)]
post #(nil,last0) -> ([(2, 1),(2, 1)], [((3, 1), (2, 1)),((8, 1), (2, 1))])
loc(((3, 1), (2, 1))) [hiv=3, hipwr=1, lov=2, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (2+3*1,1*1)
loc(((8, 1), (2, 1))) [hiv=8, hipwr=1, lov=2, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (2+8*1,1*1)
post (id_, !loc) -> ([(2, 1),(2, 1)], [(5, 1),(10, 1)])
combine c_lr -> [(2, 1),(2, 1),(5, 1),(10, 1)]
post #(nil,last0) -> ([(4, 1),(5, 1),(11, 1),(18, 1)], [((2, 1), (18, 1)),((2, 1), (18, 1)),((5, 1), (18, 1)),((10, 1), (18, 1))])
loc(((2, 1), (18, 1))) [hiv=2, hipwr=1, lov=18, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (18+2*1,1*1)
loc(((2, 1), (18, 1))) [hiv=2, hipwr=1, lov=18, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (18+2*1,1*1)
loc(((5, 1), (18, 1))) [hiv=5, hipwr=1, lov=18, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (18+5*1,1*1)
loc(((10, 1), (18, 1))) [hiv=10, hipwr=1, lov=18, lopwr=1] -> (lov+hiv*lopwr,lopwr*hipwr) = (18+10*1,1*1)
post (id_, !loc) -> ([(4, 1),(5, 1),(11, 1),(18, 1)], [(20, 1),(20, 1),(23, 1),(28, 1)])
combine c_lr -> [(4, 1),(5, 1),(11, 1),(18, 1),(20, 1),(20, 1),(23, 1),(28, 1)]
_unzip.0 -> [4,5,11,18,20,20,23,28]
-- result: [4,5,11,18,20,20,23,28]
--
|