Presentation is loading. Please wait.

Presentation is loading. Please wait.

Straight Line Code x i = a x i = x j + x k x i = x j  x k Arithmetic circuit DAG No loop No index as variables No if statement w ij : weight of edges.

Similar presentations


Presentation on theme: "Straight Line Code x i = a x i = x j + x k x i = x j  x k Arithmetic circuit DAG No loop No index as variables No if statement w ij : weight of edges."— Presentation transcript:

1 Straight Line Code x i = a x i = x j + x k x i = x j  x k Arithmetic circuit DAG No loop No index as variables No if statement w ij : weight of edges from v i to v j

2 x 1 = 4 x 2 = 3 x 3 = x 1 + x 2 x 4 = x 2 + x 3 x 5 = x 2 * x 4 x 6 = x 3 * x 4 x 7 = x 4 * x 6 Example Straight line code 43 x1x1 x2x2 ++ ** * x3x3 x4x4 x6x6 x5x5 x7x7 Arithmetic Circuit

3 Multi Variate Polynomial v 1 : x 1 1 v 2 : x 2 1 v 3 : x 1 + x 2 1 v 4 : x 1 + 2x 2 1 v 5 : x 1 x 2 + 2x 2 2 2 v 6 : x 1 2 + 3x 2 + 2x 2 2 v 7 : x 1 + …...... degree Parallel Algorithm O(logN log dN) d: degree of circuit (degree of polynomial) N: Size or number of nodes in the circuit d may be large (exponential of N) useful only if d is polynomial of N

4 Application Gaussian Elimination  straight line program with O( N 3 ) nodes O ( log 2 N) time Degree of poly O(N) Construction of heap O ( log 2 N) time [bubble sort, insertion sort] Sorting - Straight line program with O(N 2 ) nodes

5 vivi vjvj + vkvk vkvk Eval - Add Action of Eval -Add v k = v i w ik + v j w jk Eval - Mult vivi vjvj leaf node: its value is evaluated completely Eval - Add: all inputs are leves Eval - Mult: all inputs are leaves one input is leaf Skip - Add: not all inputs are leaves w ik w jk => vivi vjvj vivi vjvj * vkvk vkvk Case (a) Both v i and v j are are leaves => 11 Case (b) v i is a leaf, and v j are not leaf (exactly one input is a leaf node) vivi vivi * vkvk => 11 + vkvk w jk = value(v i ) vjvj vjvj

6 + + + + w2w2 w3w3 w4w4 w1w1 w5w5 w2w2 w3w3 w4w4 w1w1 w 2 *w 5 w 3 *w 5 w 4 *w 5 Skip Add w 1 *w 5 Inputs of the first addition node x are promoted to become inputs to the second addition node y. Inputs to x are are maintained if x is an input to another node z. v x z z

7 Skip-Add Multiple edges from v i to v j may be inserted. New weight from v i to v j if v i, v j are addition node v j : addition node v i : not v j is not an addition nde if v k, v j are addition node otherwise i k j original w ij must be removed(v i, v j both + nodes) Skip Add: W <- W - W + + WW + O(n3) PEs, O(logn) time

8 6 + + 2 + Arithmetic Circuit x 1 = 6 x 2 = 2 x 3 = x 1 + x 2 x 4 = x 2 + x 3 x 5 = x 3 x 4 x 6 = x 3 + x 5 x 7 = x 4 x 5 Straight-line Code nodepolynomialdegree v1v2v3v4v5v6v7v1v2v3v4v5v6v7 x 1 x 2 x 1 + x 2 x 1 + 2x 2 x 1 2 +3x 1 x 2 +2x 2 2 x 1 2 +3x 1 x 2 +2x 2 2 +x 1 +x 2 x 1 3 +5x 1 2 x 2 +8x 1 x 2 2 +4x 2 3 11112231111223 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7

9 6 + 2 + after Eval-Add 6 + 2 + + 6 + 2 + + 62 + 62 + 62 + v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 v1v1 v2v2 v3v3 v4v4 v5v5 v6v6 v7v7 1 1 1 1 1 1 1 1 1 1 8 1 1 1 1 1 1 8 1 1 1 after Eval-Mult after Skip-Add after Eval-Add after Eval-Mult after Skip-Add 8 8 8 1 1 1 10 800 80 888 888 8 8

10 Complexity Define height leaf node = 2 * node : h(x) = h(a) + h(b) + node: max (a+1, m) a = max (h 1,..., h i ) v 1,..., v i : + nodes inputs to x m = max (h i+1,..., h k ) v i+1,....,v k : * nodes inputs to x degree and height: almost same except + node degree: max(d1,d2), height: max (h1,h2)+1 Theorem: O(logdN) phases are sufficient. Proof is based on the following two claims. Claim 1: The of an N-node circuit of degree d  (N+1)d Claim 2: After log 3/2 h phases, every node has been reduced to a leaf node. b a x + x * + +** v1v1 vkvk vivi v i+1

11 Proof on the complexity of straight line program Lemma: The height of an arithmetic circuit of degree d is at most (Z+2)d, where Z is the number of addition nodes in the circuit that have addition nodes as inputs. Proof: By induction on the number of nodes N in the circuit. Basis (N=1) trivially true. Inductive hypothesis: Assume that the claim is true for N. Inductive step: Let us prove for N+1. Let v be a node with degree d and max height h with inputs v 1,...,v k, having degree d 1,...d k, and heights h 1,...,h k. Three cases. case 1: v is “*” node. Then d=d 1 +... + d k, and h=h 1 +... + h k, h i  (Z+2)d i by inductive hypothesis. Thus, h  (Z+2)d. case 2: v is “+” node, and max of h 1,..., h k is not attained by “+” node. h i = max {h i }  max{(Z+2)d i }  (Z+2)d. case 3: v is “+” node, and max of h 1,..., h k is attained by “+” node. h i = 1 + max {h i }  1 + max{(Z+1)d i }  1 + (Z+1)d  (Z+2)d. ( h i  (Z+1)d i follows from the fact that v itself is a type of Z, and must not be part of d i subcircuit, and inductive hypothesis.) Thus, the lemma holds. Corollary: The height of N node circuit of degree d is at most (N+1)d. Proof: Since Z  N-1, it follows.

12 Proof on the complexity (cont’) Lemma: Given any circuit and node v, let h :the height of v at the beginning of a phase, h’ :the height of v at the end of the phase. If h  3, then h’  (2/3)h. Moreover, if v is *” node that gets converted into an addition node during the phase, then h’  (2/3)h - 1/3. Proof: Induction on the size of circuit. Suppose that v is *node at the beginning of phase. Case 1. v becomes a leaf during the phase. h’=2, * node h  4. Thus, h’  h/2. v v1 v2 * Case 2. v remains *. Nor v1, v2 are leaf before Eval-Mult. Thus, h1,h2 > 3 h 1 ’  (2/3)h 1, h 2 ’  (2/3)h 2, by inductive hypo. Thus, h’  h 1 ’ + h 2 ’  (2/3) (h 1 +h 2 )  (2/3)h Case 3. v becomes “+” node during the phase. One node was leaf, the other is not. Let v1 be the input to v before the phase. After the phase, either v1 stays as the only input, or v1 participate skip-add during the phase. If v 1 remains input of v: h = h 1 +2, h 1 ’  (2/3)h 1, thus, h’ = h 1 ’+1  (2/3)h - 1. If v 1 participate skip-add during the phase, then any new input u to v after the phase should be the input to v1 before the phase. Note that the height of u is less than the height of v1, so the same argument as the above holds.


Download ppt "Straight Line Code x i = a x i = x j + x k x i = x j  x k Arithmetic circuit DAG No loop No index as variables No if statement w ij : weight of edges."

Similar presentations


Ads by Google