Fast Multiplication Polynomial multiplication Toom–Cook method

Slides:



Advertisements
Similar presentations
Chapter 3 Determinants and Eigenvectors 大葉大學 資訊工程系 黃鈴玲 Linear Algebra.
Advertisements

Polynomial and FFT. Topics 1. Problem 2. Representation of polynomials 3. The DFT and FFT 4. Efficient FFT implementations 5. Conclusion.
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
: Arrange the Numbers ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11481: Arrange the Numbers 解題者:李重儀 解題日期: 2008 年 9 月 13 日 題意: 將數列 {1,2,3, …,N}
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
建立使用案例敘述 --Use Case Narrative
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
密碼學與網路安全 第4章 有限體.
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
1.1 線性方程式系統簡介 1.2 高斯消去法與高斯-喬登消去法 1.3 線性方程式系統的應用(-Skip-)
FFT1 The Fast Fourier Transform. FFT2 Outline and Reading Polynomial Multiplication Problem Primitive Roots of Unity (§10.4.1) The Discrete Fourier Transform.
: Factstone Benchmark ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: : Factstone Benchmark 解題者:鐘緯駿 解題日期: 2006 年 06 月 06 日 題意: 假設 1960.
Lecture 8 Median and Order Statistics. Median and Order Statistics2 Order Statistics 問題敘述 在 n 個元素中,找出其中第 i 小的元素。 i = 1 ,即為找最小值。 i = n ,即為找最大值。 i = 或 ,即為找中位數。
Review of Chapter 3 - 已學過的 rules( 回顧 )- 朝陽科技大學 資訊管理系 李麗華 教授.
代數概論 劉兆樑.
Administrative Oct. 2 Oct. 4 – QUIZ #2 (pages of DPV)
Chapter 3 Growth of Functions Asymptotic notation Θ-notation: f(n) = Θ(g(n)) , g(n) is an asymptotically tight bound for f(n) 。 Θ(g(n)) = {f(n)|
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
Young/Freeman University Physics 11e. Ch 18 Thermal Properties of Matter © 2005 Pearson Education.
Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
Digital Signal Processing with Examples in M ATLAB ® Chap 1 Introduction Ming-Hong Shih, Aug 25, 2003.
3.1 矩陣的行列式 3.2 使用基本運算求行列式 3.3 行列式的性質 3.4 特徵值介紹 3.5 行列式的應用
Fourier Series. Jean Baptiste Joseph Fourier (French)(1763~1830)
FFT1 The Fast Fourier Transform by Jorge M. Trabal.
Fugacity Coefficient and Fugacity
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Fast Fourier Transform Jean Baptiste Joseph Fourier ( ) These lecture.
公用品.  該物品的數量不會因一人的消費而受到 影響,它可以同時地被多人享用。 角色分配  兩位同學當我的助手,負責:  其餘各人是投資者,每人擁有 $100 , 可以投資在兩種資產上。  記錄  計算  協助同學討論.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
1 100: The 3n+1 Problem ★★★☆☆ 題組: VOLUME CII 題號: 10721: Problem C-Chopsticks 陳冠男 解題者:陳冠男、侯沛彣 解題日期: 2006 年 4 月 23 日 給定一個正整數 n (n>1) ,當 n 為奇數時令 n  3n+1.
: 05-2 Rendezvous ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11015: 05-2 Rendezvous 解題者:池明洋 解題日期: 2006 年 4 月 16 日 題意: 給 node N 個 , edge.
Section 4.2 Probability Models 機率模式. 由實驗看機率 實驗前先列出所有可能的實驗結果。 – 擲銅板:正面或反面。 – 擲骰子: 1~6 點。 – 擲骰子兩顆: (1,1),(1,2),(1,3),… 等 36 種。 決定每一個可能的實驗結果發生機率。 – 實驗後所有的實驗結果整理得到。
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
資料結構實習-二.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
-Antidifferentiation- Chapter 6 朝陽科技大學 資訊管理系 李麗華 教授.
Chapter 2. Recurrence Relations (遞迴關係)
Chapter 10 m-way 搜尋樹與B-Tree
第4章 有限體.
Extreme Discrete Summation ★★★★☆ 題組: Contest Archive with Online Judge 題號: Extreme Discrete Summation 解題者:蔡宗翰 解題日期: 2008 年 10 月 13 日.
Probability Distribution 機率分配 汪群超 12/12. 目的:產生具均等分配的數值 (Data) ,並以 『直方圖』的功能計算出數值在不同範圍內出現 的頻率,及繪製數值的分配圖,以反應出該 機率分配的特性。
: Help My Brother ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11033: Help My Brother 解題者: 呂明璁 解題日期: 2007 年 5 月 14 日.
計算機概論 第6章 數位邏輯設計.
2005/7 Linear system-1 The Linear Equation System and Eliminations.
冷凍空調自動控制 - 系統性能分析 李達生. Focusing here … 概論 自動控制理論發展 自控系統設計實例 Laplace Transform 冷凍空調自動控制 控制系統範例 控制元件作動原理 控制系統除錯 自動控制理論 系統穩定度分析 系統性能分析 PID Controller 自動控制實務.
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
連續隨機變數 連續變數:時間、分數、重量、……
Introduction to Algorithms
1 高等演算法 -Introduction 1. Analysis 2. Basic arithmetic 3. Modular arithmetic 4. GCD 5. Primality testing 6. Cryptography.
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
: Bee Maja ★★☆☆☆ 題組: Contests Hosting Service with Online Judge 題號: 10182: Bee Maja 解題者:林祺光、李哲宇 解題日期: 2006 年 3 月 26 日 題意:現有兩種六邊形座標系,將甲座標系的某一點轉 為相對應的乙座標系。
第五章IIR數位濾波器設計 濾波器的功能乃對於數位信號進行處理﹐ 以滿足系統的需求規格。其作法為設計一 個系統的轉移函數﹐或者差分方程式﹐使 其頻率響應落在規格的範圍內。本章探討 的是其中一種方法﹐稱為Infinite impulse register(IIR)。 IIR架構說明。 各種不同頻帶(Band)濾波器的設計方法。
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Problem E.Stone Game ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10165: Problem E.Stone Game 解題者:李濟宇 解題日期: 2006 年 3 月 26 日 題意: Jack 與 Jim.
幼兒行為觀察與記錄 第八章 事件取樣法.
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
Fast Fourier Transform Irina Bobkova. Overview I. Polynomials II. The DFT and FFT III. Efficient implementations IV. Some problems.
FFT1 The Fast Fourier Transform. FFT2 Outline and Reading Polynomial Multiplication Problem Primitive Roots of Unity (§10.4.1) The Discrete Fourier Transform.
Discrete Mathematics Chapter 7 Advanced Counting Techniques 大葉大學 資訊工程系 黃鈴玲.
The Fast Fourier Transform
Karatsuba’s Algorithm for Integer Multiplication
Applied Symbolic Computation1 Applied Symbolic Computation (CS 300) Karatsuba’s Algorithm for Integer Multiplication Jeremy R. Johnson.
Chapter 2 Divide-and-Conquer algorithms
Chapter 2 Divide-and-Conquer algorithms
Polynomial + Fast Fourier Transform
The Fast Fourier Transform
The Fast Fourier Transform
Presentation transcript:

Fast Multiplication Polynomial multiplication Toom–Cook method 3. Primitive Roots of Unity 4. The Discrete Fourier Transform 5. The FFT Algorithm 6. Schönhage-Strassen’s method 7. Conclusion

1. Polynomial multiplication (-5, 1, 2) evaluation interpolation 或者 {(-1,-4),(0,-5),(1,-2)} (p(-1), p(0), p(1)) by Lagrange Interpolating Polynomial

1. Polynomial multiplication Lagrange Interpolating Polynomial

1. Polynomial multiplication Given coefficients (a0,a1,a2,…,an-1) and (b0,b1,b2,…,bn-1) defining two polynomials, p() and q(), and number x, compute p(x)q(x).

1. Polynomial multiplication P(x)=a0+a1x+…+an-1xn-1 q(x)=b0+b1x+…+bn-1xn-1 (a0,a1,a2,…,an-1) (b0,b1,b2,…,bn-1) 選2n+1個點 (p(w0), p(w1),…, p(w2n) ) (q(w0), q(w1),…, q(w2n) ) evaluation multiplication Polynomial Multiplication (p(w0)*q(w0), p(w1)*q(w1),… , p(w2n)*q(w2n) ) (c0,c1,c2,…,cn,…,c2n-1) interpolation

1. Polynomial multiplication P(x)=5+x q(x)=1+2x (5,1) (1,2) 選3個點 (p(0)=5, p(1)=6, p(2)=7 ) (q(0)=1, q(1)=3, q(2)=5 ) evaluation multiplication Polynomial Multiplication C(0)=5, C(1)=18, C(2)=3 (5,11,2) interpolation

1. Polynomial multiplication 慎選特殊的點可以降低運算 Evaluation O(n) Total O(n2)

1. Polynomial multiplication Polynomial Evaluation Horner’s Rule: Given coefficients (a0,a1,a2,…,an-1), defining polynomial Given x, we can evaluate p(x) in O(n) time using the equation Eval(A,x): [Where A=(a0,a1,a2,…,an-1)] If n=1, then return a0 Else, Let A’=(a1,a2,…,an-1) [assume this can be done in constant time] return a0+x*Eval(A’,x)

2.Toom–Cook method Toom-k : a simplification of a description of Toom–Cook polynomial multiplication described by Marco Bodrato in 2007. 給定兩整數M, N,擬計算M*N five main steps: Splitting (將整數轉成多項式) Evaluation (找出多項式對應的點) Pointwise multiplication (點値相乘) Interpolation (由點找出多項式) Recomposition (將多項式轉成整數) Marco Bodrato. Towards Optimal Toom–Cook Multiplication for Univariate and Multivariate Polynomials in Characteristic 2 and 0. In WAIFI'07 proceedings, volume 4547 of LNCS, pages 116-133. June 21-22, 2007. author website

2.Toom–Cook method:Toom-3 N= 9 8765 4321 9876 5432 1098 (1) Splitting (將整數轉成多項式) 切成3等份,取base B=108 *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication m0 = 56789012 m1 = 78901234 m2 = 123456 n0 = 54321098 n1 = 43219876 n2 = 98765 p(x) = m0 + m1x + m2x2 q(x) = n0 + n1x + n2x2

2.Toom–Cook method:Toom-3 (2) Evaluation (找出多項式對應的點) p(x) = m0 + m1x + m2x2 q(x) = n0 + n1x + n2x2 p(0) = m0 = 56789012 = 56789012 p(1) = m0 + m1 + m2 = 56789012 + 78901234 + 123456 = 135813702 p(−1) = m0 − m1 + m2 = 56789012 − 78901234 + 123456 = −21988766 p(−2) = m0 − 2m1 + 4m2 = 56789012 − 2×78901234 + 4×123456 = −100519632 p(∞) = m2 = 123456 = 123456 q(0) = n0 = 54321098 = 54321098 q(1) = n0 + n1 + n2 = 54321098 + 43219876 + 98765 = 97639739 q(−1) = n0 − n1 + n2 = 54321098 − 43219876 + 98765 = 11199987 q(−2) = n0 − 2n1 + 4n2 = 54321098 − 2×43219876 + 4×98765 = −31723594 q(∞) = n2 = 98765 = 98765 *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication

2.Toom–Cook method:Toom-3 (3) Pointwise multiplication (點値相乘) r(x)=p(x)q(x) r(0) = p(0)q(0) = 56789012 × 54321098 = 3084841486175176 r(1) = p(1)q(1) = 135813702 × 97639739 = 13260814415903778 r(−1) = p(−1)q(−1) = −21988766 × 11199987 = −246273893346042 r(−2) = p(−2)q(−2) = −100519632 × −31723594 = 3188843994597408 r(∞) = p(∞)q(∞) = 123456 × 98765 = 12193131840 *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication

2.Toom–Cook method:Toom-3 (4) Interpolation (由點找出多項式) *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication

2.Toom–Cook method:Toom-3 (4) Interpolation (由點找出多項式) *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication

2.Toom–Cook method:Toom-3 (4) Interpolation (由點找出多項式) one sequence given by Bodrato *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication

2.Toom–Cook method:Toom-3 (4) Interpolation (由點找出多項式) *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication

2.Toom–Cook method:Toom-3 (5) Recomposition (將多項式轉成整數) *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication

2.Toom–Cook method: Complexity Toom-3 reduces 9 multiplications to 5, and runs in Θ(nlog(5)/log(3)), about Θ(n1.465). In general, Toom-k runs in Θ(c(k)ne), where e = log(2k-1) / log(k), ne is the time spent on sub-multiplications, and c is the time spent on additions and multiplication by small constants *http://en.wikipedia.org/wiki/Toom%E2%80%93Cook_multiplication (in Knuth’s book)

Polynomial multiplication 慎選特殊的點可以降低運算-Primitive Roots of Unity 執行DFT 得到 只需O(nlogn) Evaluation O(n) Total O(n2)

3. Primitive Roots of Unity A number w is a primitive n-th root of unity, for n>1, if wn = 1 The numbers 1, w, w2, …, wn-1 are all distinct Example 1: Z*11: 22=4, 62=3, 72=5, 82=9 are 5-th roots of unity in Z*11 2-1=6, 3-1=4, 4-1=3, 5-1=9, 6-1=2, 7-1=8, 8-1=7, 9-1=5 Example 2: The complex number e2pi/n is a primitive n-th root of unity, where

3. Primitive Roots of Unity Inverse Property: If w is a primitive root of unity, then w -1=wn-1 Proof: wwn-1=wn=1 Cancellation Property: For non-zero -n<k<n, Proof: Reduction Property: If w is a primitve (2n)-th root of unity, then w2 is a primitive n-th root of unity. Proof: If 1,w,w2,…,w2n-1 are all distinct, so are 1,w2,(w2)2,…,(w2)n-1 Reflective Property: If n is even, then wn/2 = -1. Proof: By the cancellation property, for k=n/2: Corollary: wk+n/2= -wk.

4.The Discrete Fourier Transform Given coefficients (a0,a1,a2,…,an-1) for an (n-1)-degree polynomial p(x) The Discrete Fourier Transform is to evaluate p at the values 1,w,w2,…,wn-1 We produce (y0,y1,y2,…,yn-1), where yj=p(wj)

4.The Discrete Fourier Transform Matrix form: y=Fa, where F[i,j]=wij. The Inverse Discrete Fourier Transform recovers the coefficients of an (n-1)-degree polynomial given its values at 1,w,w2,…,wn-1 Matrix form: a=F -1y, where F -1[i,j]=w-ij/n. 註: the matrix F 中column彼此互相orthogonal滿足 FF*=nI,其中F*為F之conjugate

4.The Discrete Fourier Transform The DFT and inverse DFT really are inverse operations Proof: Let A=F -1F. We want to show that A=I, where If i=j, then If i and j are different, then

4.The Discrete Fourier Transform Convolution The DFT and the inverse DFT can be used to multiply two polynomials So we can get the coefficients of the product polynomial quickly if we can compute the DFT (and its inverse) quickly…

4.The Discrete Fourier Transform Convolutions Convolutions 127356 (3,11,37,47,42) 1 2 7 × 3 5 6 6 12 42 5 10 35 3 6 21 3 11 37 47 42

4.The Discrete Fourier Transform Convolutions 127356 1 2 7 1 2 7 × × 3 5 6 3 5 6 6 12 42 6 12 42 5 10 35 5 10 35 3 6 21 3 6 21 3 11 37 47 42 3 11 37 47 42 + 3 11 - 3 11 37 50 53 37 44 31 acyclic convolutions (37,50,53) negacyclic convolutions (37,44,31)

4.The Discrete Fourier Transform Convolution theorem CyclicConvolution(X, Y) = IDFT(DFT(X) · DFT(Y))

5.The Fast Fourier Transform The FFT is an efficient algorithm for computing the DFT The FFT is based on the divide-and-conquer paradigm: If n is even, we can divide a polynomial into two polynomials and we can write

5.The Fast Fourier Transform Given coefficients (a0,a1,a2,…,a7) and w primitive 8-th root of unity

5.The Fast Fourier Transform

5.The Fast Fourier Transform

5.The Fast Fourier Transform 令

5.The Fast Fourier Transform a0 a1 a2 a3 a4 a5 a6 a7

5.The Fast Fourier Transform T(n)=2T(n/2)+O(n) The running time is O(n log n). [inverse FFT is similar]

Polynomial multiplication p(x)=a0+a1x+…+an-1xn-1 q(x)=b0+b1x+…+bn-1xn-1 選w primitive m-th root of unity (m2n) (a0,a1,a2,…,an-1) (b0,b1,b2,…,bn-1) (p(w0), p(w1),…, p(wm-1) ) (q(w0), q(w1),…, q(wm-1) ) Evaluation FFT multiplication Polynomial Multiplication (p(w0)*q(w0), p(w1)*q(w1),… , p(wm-1)*q(wm-1) ) (c0,c1,c2,…,cn,…,cm-1) The running time is O(n log n). Interpolation IFFT

6.Schönhage-Strassen’s method 給定兩大數M,N。計算M*N (1) Splitting (將整數轉成多項式) 令B=2k,則可產生degree 最多n-1之兩個多項式 p(x)=a0+a1B+…+an-1Bn-1 q(x)=b0+b1B+…+bn-1Bn-1 P=(a0,a1,a2,…,an-1) Q=(b0,b1,b2,…,bn-1) (2) Evaluation (找出多項式對應的點) 選w primitive m-th root of unity (m2n)

6. Schönhage-Strassen’s method (3) Pointwise multiplication (點値相乘) (4) Interpolation (由點找出多項式) 對上述點執行the inverse Fourier transform

6. Schönhage-Strassen’s method (5)Recomposition (將多項式轉成整數) 令x=B

6. Schönhage-Strassen’s method Complexity 分析 The running time is O(n log n) 單位? The bound on the numerical errors α on the ci after the FFT process can be proved to be where ε ≅ 1.e-16 α ≤ 6n2B2log(n)ε the number of digits of these basic numbers should be of the order of log(B)+log(n)

6. Schönhage-Strassen’s method Complexity 分析 The running time is O(n log n(log(B) + log(n))2) 然而如果針對所有乘法都採用recursive觀念,即 得到

7. Conclusion Method* complexity integer classical Karatsuba 1962 10,000位數 Toom–3 1963 Toom–Cook (knuth) 1966 40,000位數 Schönhage-Strassen 1971 Fürer 2007 M. Bodrato. Toward Optimal Toom-Cook Multiplication.... In WAIFI'07, Springer, 2007 Schönhage and V. Strassen, "Schnelle Multiplikation großer Zahlen", Computing 7 (1971), pp. 281–292. Martin Fürer, "Faster integer multiplication", STOC 2007 Proceedings, pp. 57-66