Multiplication of polynomials M. Gastineau IMCCE - Observatoire de Paris - CNRS UMR8028 77, avenue Denfert Rochereau 75014 PARIS FRANCE [email protected] Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Different products Full • All terms are computed Truncated in the partial or total degree of the variables Special truncation to select terms satisfying a rule Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Available methods Naive method • efficient for low degree or for sparse polynomials Karatsuba’s algorithm • efficient for intermediate degree and dense polynomials • reduce the number of multiplications FFT method • efficient only for large degree Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Naive multiplication A(x) = da max ! ai xi and B(x) = i=damin db max ! bi xi i=dbmin Perform the multiplication of all terms C(x) = damax +dbmax ! ck x with ck = k k=damin +dbmin ! ai bj i+j=k if A, B and C, have r, s and t terms • rs multiplications and rs-t additions • complexity : O(rs) Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Multiplication for univariate polynomials stored as vector Algorithm 1: Compute the full product of univariate polynomials A and B represented with a dense vector Input: A: polynomial {damin , damax , array of coefficients a } Input: B: polynomial {dbmin , dbmax , array of coefficients b } Output: C: polynomial {dcmin , dcmax , array of coefficients c } dcmin ← damin + dbmin dcmax ← damax + dbmax C ← create a polynomial with minimal degree dcmin and maximal degree dcmax for k ← dcmin to dcmax do c[k] ← a[damin ] × b[k − damin ] for j ← damin + 1 to damax do c[k] ← c[k] + a[j] × b[k − j] end end return C Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Multiplication for recursive dense vector 1/2 Function mulfull(A,B ) Compute the full product of multivariate polynomials A and B represented with a recursive dense vector Input: A: multivariate polynomial {damin , damax , array of coefficients a} Input: B: multivariate polynomial {dbmin , dbmax , array of coefficients b} Output: C: multivariate polynomial {dcmin , dcmax , array of coefficients c} dcmin ← damin + dbmin dcmax ← damax + dbmax C ← create a polynomial with minimal dcmin and maximal dcmax degree for k ← dcmin to dcmax do c[k] ← mulfull (a[damin ], b[k − damin ]) for j ← damin + 1 to damax do fmafull (a[j], b[k − j], c[k]) end end return C Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Multiplication for recursive dense vector 2/2 Procedure fmafull(A,B,C ) Compute the full fused multiplicationaddition C = C + A × B with A, B and C multivariate polynomials represented as recursive dense vector Input: A: multivariate polynomial {damin , damax , array of coefficients a} Input: B: multivariate polynomial {dbmin , dbmax , array of coefficients b} Input: C: multivariate polynomial {dcmin , dcmax , array of coefficients c } Output: C: multivariate polynomial newdcmin ← damin + dbmin newdcmax ← damax + dbmax if newdcmin < dcmin or dcmax < newdcmax then dcmin ←min(newdcmin , dcmin ) dcmax ←max(newdcmax , dcmax ) resize C end for k ← dcmin to dcmax do c[k] ← mulfull (a[damin ], b[k − damin ]) for j ← damin + 1 to damax do fmafull (a[j], b[k − j], c[k]) end end if c contains 0 at its beginning or at its end then adjust dcmin adjust dcmax resize C end Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Multiplication for univariate polynomials stored as list Function mulfull(A,B ) Compute the full product of univariate polynomials A and B represented with a list Input: A: polynomial { list of ( coefficients a , degree δa ) } Input: B: polynomial { list of ( coefficients b , degree δb ) } Output: C: polynomial { list of ( coefficients c , degree δc )} C ← create a empty polynomial foreach element in A do D ← create a empty polynomial foreach element in B do add to the tail of D an element (a × b, δa + δb ) end C ←C +D end return C Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Multiplication for recursive list Procedure fmafull(A,B,C ) Compute the full fused multiplicationaddition C = C + A × B with A, B and C multivariate polynomials represented as recursive list Input: A: polynomial { list of ( coefficients a , degree δa ) } Input: B: polynomial { list of ( coefficients b , degree δb ) } Input: C: polynomial { list of ( coefficients c , degree δc ) } Output: C: polynomial { list of ( coefficients c , degree δc ) } iter ← head of C foreach element in A do // avoid to scan to C when the loop on B is finished iterb ← iter foreach element in B do // find after iterb in C if the degree δa + δb is present while current degree δc referenced by iterb < δa + δb do iterb ← next element after iterb end if δc = δa + δb then fmafull (a, b, c) if c = 0 then remove the element referenced by iterb else insert an element (mulfull (a, b), δa + δb ) just before iterb end if current element is the first element of B then iter ← iterb end end end Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Multiplication for flat vector 1/2 variables X1 Xn exponents 1 2 coefficients m 1st term 2nd term 65th term 66th term 64*(m-1)+1 term 64*(m-1)+2 term 64th term 128th term 64*m term 1 2 m How to sort terms ? • search and shift operations too slow • need an intermediate and adjustable storage : BURST TRIE Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Multiplication for flat vector 2/2 Burst tries • trie node = dense container • leaf node = sparse container 3 + 5z + 7z 3 + 11y + 9zy + 13zyx + 8z 2 x2 + 9x4 Burst trie Coe!cients 0 4 8 1 0 0 1 2 3 3 1 4 1 5 1 0 1 6 2 7 3 5 7 11 9 13 8 9 Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Homogeneous block A= da max ! BHδ (a) , B= × d!1 d!2 d!n bj X1 X2 ...Xn = C =A×B = with BHδ (b) δ=dbmin δ=damin ai X1d1 X2d2 ...Xndn db max ! d1 +d!1 d2 +d!2 dn +d!n ai bj X1 X2 ...Xn dc max ! BHδ (c) δ=dcmin dcmin = damin + dbmin dcmax = damax + dbmax ! BHδ (c) = BHi (a) × BHj (b) i+j=δ Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Homogeneous block Function fmafull(BHδ (a), BHδ! (b), BHδ+δ! (c)) Compute the full fused multiplication-addition BHδ+δ! (c) = BHδ+δ! (c) + BHδ (a) × BHδ! (b) Input: BHδ (a) : homogeneous blocks { degree δ, a : array of r coeff. } Input: BHδ! (b) : homogeneous blocks { degree δ ! , b : array of s coeff. } Input: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff. } Output: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff.} for i ← 1 to r do for j ← 1 to s do l ← get location of the term in BHδ+δ! (c) BHδ+δ! (c)[l] ← BHδ+δ! (c)[l] + BHδ (a)[i] × BHδ! (b)[j] end end Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Homogeneous block using functions Function fmafull(BHδ (a), BHδ! (b), BHδ+δ! (c)) Compute the full fused multiplication-addition BHδ+δ! (c) = BHδ+δ! (c) + BHδ (a) × BHδ! (b) using functions to compute location Input: BHδ (a) : homogeneous blocks { degree δ, a : array of r coeff. } Input: BHδ! (b) : homogeneous blocks { degree δ ! , b : array of s coeff.s } Input: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff. } Output: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff.} for i ← 1 to r do expoa ← get array of exponents from the location i in BHδ for j ← 1 to s do expob ← get array of exponents from the location j in BHδ! expoc ← expoa + expob l ← get location of the term with exponents expoc in BHδ+δ! BHδ+δ! (c)[l] ← BHδ+δ! (c)[l] + BHδ (a)[i] × BHδ! (b)[j] end end Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Homogeneous block using addressing tables Construction of the addressing table for the product of blocks in 3 variables with exponent tables of degree 1 and 2. + T exp1 0 0 1 0 1 0 0 0 0 1 1 2 1 0 0 1 2 5 = T exp2 0 1 2 0 1 0 2 1 0 1 0 0 T addr1,2 2 3 5 6 3 4 6 7 6 7 8 9 T exp3 0 0 3 0 1 2 0 2 1 0 3 0 1 0 2 1 1 1 1 2 0 2 0 1 2 1 0 3 0 0 8 9 10 T addr2,1 =t T addr1,2 Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Execution time to build the tables of exponents build the tables of exponents for homogeneous blocks in 10 variables up to the degree 20 0.4 20 0.35 0.3 19 time (s) 0.25 0.2 18 0.15 17 0.1 16 0.05 13 12 14 15 0 0 2 4 6 8 10 12 number of terms (in Millions) Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Execution time to build the addressing tables product of two homogeneous blocks in 5 variables up to the total degree 40 initialization after initialization 10 20+20 8 time (s) 20+19 6 20+18 20+17 4 20+16 20+15 2 20+14 20+13 20+12 20+11 20+10 0 0 20 40 60 80 100 120 muliplication operations (in Millions) Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Overhead to load the addressing tables from disk 30 execution time overhead (%) 25 20 15 10 5 0 20 22 24 26 28 30 32 34 36 38 40 total degree of the addressing table Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Homogeneous blocks BH(X,Y,Z) BH0 BH1 BH2 BH3 BH4 3 5 11 0 0 9 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 0 9 P (x, y, z) = 3 + 5z + 7z 3 + 11y + 9yz + 13xyz + 8x2 z 2 + 9x4 Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Compacted homogeneous blocks BHC(X,Y,Z) BHC0 BHC1 BHC2 BHC3 BHC4 3 5 1 11 2 9 2 13 6 8 10 9 15 Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Homogeneous block using addressing tables Function fmafull(BHδ (a), BHδ! (b), T addrδ,δ! , BHδ+δ! (c)) Compute the full fused multiplication-addition BHδ+δ! (c) = BHδ+δ! (c) + BHδ (a) × BHδ! (b) using the addressing table Input: BHδ (a) : homogeneous blocks { degree δ, a : array of r coeff. } Input: BHδ! (b) : homogeneous blocks { degree δ ! , b : array of s coeff. } Input: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff. } Input: T addrδ,δ! : addressing table of degree δ, δ ! Output: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coefficients } for i ← 1 to r do for j ← 1 to s do l ← T addrδ,δ! [i, j] BHδ+δ! (c)[l] ← BHδ+δ! (c)[l] + BHδ (a)[i] × BHδ! (b)[j] end end Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Homogeneous block using addressing tables Function fmafull(BHδ (a), BHδ! (b), T addrδ,δ! , BHδ+δ! (c)) Compute the full fused multiplication-addition BHδ+δ! (c) = BHδ+δ! (c) + BHδ (a) × BHδ! (b) using the addressing table Input: BHδ (a) : homogeneous blocks { degree δ, a : array of r coeff. } Input: BHδ! (b) : homogeneous blocks { degree δ ! , b : array of s coeff. } Input: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff. } Input: T addrδ,δ! : addressing table of degree δ, δ ! Output: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coefficients } for i ← 1 to r do for j ← 1 to s do ! [i, j] δ (a).index[i], BHCδ ! (b).index[j]] ! [BHC ←TTaddr addrδ,δ ll← δ,δ BHδ+δ! (c)[l] ← BHδ+δ! (c)[l] + BHδ (a)[i] × BHδ! (b)[j] end end Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Homogeneous block using addressing tables Function fmafull(BHδ (a), BHδ! (b), T addrδ,δ! , BHδ+δ! (c)) Compute the full fused multiplication-addition BHδ+δ! (c) = BHδ+δ! (c) + BHδ (a) × BHδ! (b) using the addressing table Input: BHδ (a) : homogeneous blocks { degree δ, a : array of r coeff. } Input: BHδ! (b) : homogeneous blocks { degree δ ! , b : array of s coeff. } Input: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff. } Input: T addrδ,δ! : addressing table of degree δ, δ ! Output: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coefficients } for i ← 1 to r do for j ← 1 to s do l ← T addrδ,δ! [i, j] BHδ+δ! (c)[l] ← BHδ+δ! (c)[l] + BHδ (a)[i] × BHδ! (b)[j] end end Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Cache blocking technique BH!(a) BH!(b) BH!(b) BH!(a) normal flow flow with cache blocking Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Cache blocking technique Input: BHδ (a) : homogeneous blocks { degree δ, a : array of r coeff. } Input: BHδ! (b) : homogeneous blocks { degree δ ! , b : array of s coeff. } Input: T addrδ,δ! : addressing table of degree δ, δ ! Input: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff. } Input: chunksize : chunk size { arrays of two integers} Output: BHδ+δ! (c) : homog. blocks { degree δ + δ ! , c : array of t coeff.} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 iteri ← r/chunksize[1] /* number of chunks for the loop i iterj ← s/chunksize[2] /* number of chunks for the loop j for ci ← 0 to iteri − 1 do for cj ← 0 to iterj − 1 do for bi ← 1 to chunksize[1] do for bj ← 1 to chunksize[2] do i ← ci × iteri + bi j ← cj × iterj + bj l ← T addrδ,δ! [i, j] BHδ+δ! (c)[l] ← BHδ+δ! (c)[l] + BHδ (a)[i] × BHδ! (b)[j] end end end /* if s not divisible by chunksize[2] for bi ← 1 to chunksize[1] do for j ← iterj × chunksize[2] to s do i ← ci × iteri + bi l ← T addrδ,δ! [i, j] BHδ+δ! (c)[l] ← BHδ+δ! (c)[l] + BHδ (a)[i] × BHδ! (b)[j] end end end */ */ 22 23 24 25 26 27 /* if r not divisible by chunksize[1] */ for i ← iteri × chunksize[1] to r do for j ← 1 to s do l ← T addrδ,δ! [i, j]; BHδ+δ! (c)[l] ← BHδ+δ! (c)[l] + BHδ (a)[i] × BHδ! (b)[j] end end */ Function fmafull(BHδ (a), BHδ! (b), T addrδ,δ! , chunksize, BHδ+δ! (c)) Compute the full fused multiplication-addition using the addressing table and cache blocking technique Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Benchmark of the cache blocking technique Factor of the reduction of the execution time for the product of two homogeneous blocks in 8 variables of degree 7 Core2 duo processor G5 processor 1000 1.1 900 1.05 1000 1.1 900 1.05 800 800 1 1 700 700 0.95 600 500 0.9 400 0.85 300 0.95 600 500 0.9 400 0.85 300 0.8 200 0.8 200 0.75 100 0 0.7 0 100 200 300 400 500 600 700 800 900 1000 0.75 100 0 0.7 0 100 200 300 400 500 600 700 800 900 1000 Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Benchmark of the cache blocking technique Factor of the reduction of the execution time of the product of two homogeneous blocks in 8 variables of degree 9 double precision 1000 quadruple precision 1.1 900 1.05 800 1000 1.1 900 1.05 800 1 1 700 700 0.95 600 500 0.9 400 0.85 0.95 600 500 0.9 400 0.85 300 300 0.8 0.8 200 200 0.75 100 0 0.7 0 100 200 300 400 500 600 700 800 900 1000 0.75 100 0 0.7 0 100 200 300 400 500 600 700 800 900 1000 Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Benchmarks s × (s + 1) with s = (1 + x + y + z + t + u)14 CAS Ginac 1.3.2 Maple 10 Singular 3.0.2 Maxima 5.9.2 Mathematica 5.2 TRIP 0.99 TRIP 0.99 TRIP 0.99 TRIP 0.99 representation tree DAG list recursive list tree recursive vector recursive list flat vector homogeneous blocks (with initialization) (after initialization) time (s) 4137 2899.70 144.27 443.95 766.65 13.50 12.85 28.10 5.44 0.57 Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Effect of the sparsity of the polynomials s × s with s containing some terms of (1 + x1 + x2 + x3 + x4 + x5 )10 0.8 recursive list recursive vector flat vector homogeneous block compacted homogeneous block 0.7 0.6 time (s) 0.5 0.4 0.3 0.2 0.1 0 0 500 1000 1500 2000 2500 3000 number of terms Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS full product VxV with different representations The serie V has 3052 terms and the result has 227453 terms V (λ, λ , X, X, Y, Y , X , X ! , Y , Y ! ) = ! ! ! ! d2 X d1 X Y d3 Y d4 d6 d8 ! X !d5 X ! Y !d7 Y ! eı(k1 λ+k2 λ ) d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 = 7 CAS Maple 10 Mathematica 5.2 TRIP 0.99 TRIP 0.99 TRIP 0.99 TRIP 0.99 representation DAG tree recursive vector recursive list flat vector homogeneous blocks TRIP 0.99 compacted homogeneous blocks TRIP 0.99 d’alembert blocks TRIP 0.99 compacted d’alembert blocks (with initialization) (after initialization) (with initialization) (after initialization) (with initialization) (after initialization) (with initialization) (after initialization) time (s) 345.08 149.63 2.91 2.32 1.97 2468.10 2403.45 17.07 15.11 22.55 8.55 11.01 1.25 Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS full product VxV for different degrees 300 recursive vector recursive list flat vector BH BHC BHDAL BHDALC 250 time (s) 200 150 100 50 0 4 5 6 7 8 9 10 11 12 degree Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Karatsuba's algorithm Idea : one multiplication could be avoided for polynomial of degree 1 Let A and B polynomials A(X) = a0 + a1 X and B(X) = b0 + b1 X The naive multiplication C = AB is C(X) = a0 b0 + (a0 b1 + a1 b0 )X 1 + a1 b1 X 2 But the coefficient of X 1 could be written as a0 b1 + a1 b0 = (a0 + a1 )(b0 + b1 ) − a0 b0 − a1 b1 we need to perform 3 multiplications and 4 additions instead of 4 multiplications and 1 addition. could be applied recursively to polynomials of degree 2k-1 complexity O(n1.59) Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS k is equal to 0. The Karatsuba’s multiplication algorithm 11 performs the product k . Depending of the relative speed of the addition and of two polynomials of degree 2 Karatsuba's algorithm the multiplication of the coefficients, the recursive call could be stopped before. A generalization of the karatsuba algorithm to any degree is available in [33]. Karatsuba’s multiplication could be computed at most in 9nlog2 3 or O(n1.59 ) operations [12]. Algorithm 11: Compute the full product of two polynomials A and B using the Karatsuba’s multiplication algorithm Input: A : polynomial of degree at most n − 1 with n = 2k for k ∈ N Input: B : polynomial of degree at most n − 1 Output: C : polynomial if n = 1 then return C ← AB C1 ← A(0) B (0) by a recursive call C2 ← A(1) B (1) by a recursive call C3 ← A(0) + A(1) C4 ← B (0) + B (1) C5 ← C3 C4 by a recursive call C6 ← C5 − C1 − C2 C ← C1 + C6 X n/2 + C2 X n return C 4.4 multiplication using Advanced DFT and FFT School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Truncated product Univariate polynomials ! n n (a0 + a1 X + ... + an X + O(X )) (b0 + b1 X + ... + bn X n + O(X n )) = (c0 + c1 X + ... + cn X n + O(X n )) Multivariate polynomials • keep the term ai X1d1 X2d2 ...Xndn ! d!1 d!2 d!n bj X1 X2 ...Xn if d1 + d!1 + d2 + d!2 + ... + dn + d!n ≤ T • if truncation is performed only on some variables, truncated variables must be ordered Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Truncated product on polynomials stored as recursive list Function fmatruncated(A,B,C, T ) Compute the truncated fused multiplication-addition C = C + A × B with A, B and C multivariate polynomials represented as recursive list Input: A: polynomial { list of ( coefficients a , degree δa ) } Input: B: polynomial { list of ( coefficients b , degree δb ) } Input: C: polynomial { list of ( coefficients c , degree δc )} Input: T : degree of the truncation Output: C: polynomial { list of ( coefficients c , degree δc )} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 if variable of A is truncated then iter ← head of C foreach element in A such that δa ≤ T do /* avoid to scan to C when the loop on B is finished */ iterb ← iter foreach element in B such that δa + δb ≤ T do /* find after iterb in C if the degree δa + δb is present */ while current degree δc referenced by iterb < δa + δb do iterb ← next element after iterb end if δc = δa + δb then fmatruncated (a, b, c, T − δa + δb ) if c = 0 then remove the element referenced by iterb else insert an element (multruncated (a, b, T − δa + δb ), δa + δb ) just before iterb end if current element is the first element of B then iter ← iterb end end end else fmafull (A,B,C) end Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Truncated product on homogeneous blocks Let A= ! BHδ (a) , B= ! BHδ (b) Truncated product on the total degree C=A ! B= T " δ=0 BHδ (c) with BHδ (c) = δ " n=0 BHn (a) × BHδ−n (b) • use the full product of 2 homogeneous blocks • use less addressing tables than for the full product Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Truncated product - benchmarks 600 recursive vector recursive list flat vector BH BHC BHDAL BHDALC 500 400 300 200 100 0 6 8 10 12 14 16 18 20 degree Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Special truncated product in degree Perform the product of two Poisson series but we only want to keep terms which have specific values for k1 and k2 e.g., S1 × S2 = S , we want only terms such that k1 = 0 and k2 = 0 S= ! ! ai X1d1 X2d2 ...Xndn expı(k1 λ+k2 λ ) very easy for the recursive representation if the series are correctly ordered. Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Special truncated product on magnitude ai X1d1 X2d2 ...Xndn ⊗ d!1 d!2 d!n bj X1 X2 ...Xn is kept if |ai bj | ≥ !0 brut-force method Algorithm 1: Compute the truncated product of the series A and B in the amplitude of their coefficients ! Input: A: serie ! ai xi ordered by decreasing amplitude Input: B: serie bi xi ordered by decreasing amplitude Input: !0 : thresold > 0 Output: C: series C = AB with all coefficients greater than !0 C ← create an empty polynomial foreach coefficient ai such that |ai b0 | ≥ !0 do foreach coefficient bj such that |bj | ≥ !0 /|ai | do C ← C + ai bj xi+j end end return C order the series on the magnitude of the coefficient ? Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS Special truncated product on magnitude p Let a variable !, and a small parameter !!0 such that !!0 = !0 with p ∈ N. Each coefficient ai of the serie A(x) could be written as ai = a!i xi !k with k = " log |ai | ai ! # and a = i log !!0 !!0 k ! ! A (!, x) = ( a!j xj )!k ! k j A(x) = A! (!!0 , x) The truncated product A(x) ⊗ B(x) on the amplitude of the coefficient is transformed to a ! truncated product A! (!, x) B ! (!, x) on the variable !. The degree of truncation is p. Advanced School on Specific Algebraic Manipulators, 2007, © M. Gastineau, ASD/IMCCE/CNRS 58 Special truncated product in amplitude CHAPTER 4. MULTIPLICATION source code s 1 =(1+0.05∗ x ) ˆ 3 ; s 2 =(1+0.04∗ x ) ˆ 4 ; /∗ i n t r o d u c e t h e v a r i a b l e e p s i n s 1 and s 2 ∗/ s 1 e=s e r e p s ( s1 , eps , 0 . 1 ) ; s 2 e=s e r e p s ( s2 , eps , 0 . 1 ) ; /∗ d e f i n e t h e t r u n c a t u r e on a m pl i t u d e t o ( 0 . 1 ) ˆ 2 ∗/ t r =({ eps , 2 } ) ; usetronc ( tr ) ; /∗ perform t h e p r o d u c t ∗/ s 3 e=s 1 e ∗ s 2 e ; /∗ remove t h e v a r i a b l e e p s from s 3 e ∗/ s 3=i n v s e r e p s ( s3e , eps , 0 . 1 ) ; Execution of the previous source code by trip s1(x) = 1 + 0.15*x + 0.0075*x**2 + 0.000125*x**3 s2(x) = 1 + 0.16*x + 0.0096*x**2 + 0.000256*x**3 + 2.56E-06*x**4 s1e(x,eps) = 1 + 0.15*x + 0.75*x**2*eps**2 + 0.125*x**3*eps**3 s2e(x,eps) = 1 + 0.16*x + 0.96*x**2*eps**2 + 0.256*x**3*eps**3 + 0.256*x**4*eps**5 tr = ( { eps, 2 } ) s3e(x,eps) = 1 + 0.31*x + 0.024*x**2 + 1.71*x**2*eps**2 + 0.264*x**3*eps**2 s3(x) = 1 + 0.31*x + 0.0411*x**2 + 0.00264*x**3 Advanced Schoolof on Specific Manipulators, 2007, © M.of Gastineau, Table 4.6: Source code and execution by TRIP the Algebraic truncated product two ASD/IMCCE/CNRS series
© Copyright 2026 Paperzz