SlideShare a Scribd company logo
Multiplying Polynomials Fast

 Why do we need Complex
       Numbers?
The Problem


• (an xn + an-1 xn-1+…..+ a0 x0) * (bn xn + bn-1 xn-1+…..+ b0 x0)

• O(n^2) time
  – (Σi=0..k ai * bk-i) is coefficient of xk

• Can one do better?
Applications

• Where all does a pattern string P appear in a text string
  T?

   – P 0’s, 1’s and don’t cares.

   – T 0’s and 1’s


• Easy in O(|P|*|T|) time

   – Can one do better?
Conversion to Polynomial
                    Multiplication
•   Treat P and T as polynomials

     – T=0101       1 x0 + 0 x1 + 1 x2 + 0 x3
                                                                  tk-i       tk-2 tk-1 tk
     – P=01D1       0 x0 + 1 x1 + 0 x2 + 1 x3
                                                      1   0   1   0      1   1    0    0    1

•   Multiply Prev and T
                                                          1   0    0 0       1   0 0
                                                                  p-i            p-1 p-0
     – (Σi=0..k previ * tk-i) is coefficient of xk

     – (Σi=0..k p|P|-i * tk-i) is coefficient of xk


•   >=1 if and only if a 1 in P aligns with a 0 in T when P is placed with end at
    tk
     – 2 polynomial multiplications suffice to find all matches of P in T
Other Applications

• Image Processing                   At this
                                    location



      Slide this mask
        all over the
                                    Multiply each bit
         bigger one                  in the mask with
                                            the
                                    corresponding bit
                                       in the image,
                                       sum these up
Polynomial Multiplication
                     An Equivalent Form

• Evaluate each polynomial at 2n+1 distinct x’s

   – A(x) = (an xn + an-1 xn-1+…..+ a0 x0) -> A(v0)…..A(v2n)

   – B(x) = (bn xn + bn-1 xn-1+…..+ b0 x0) -> B(v0)…..B(v2n)


• A(x) * B(x)       ->   A(v0)*B(v0)………..A(v2n)*B(v2n)

   – Convolution in one domain=Simple multiplication in another

   – O(n) time!!!
Multi-Point Polynomial Evaluation

• Evaluate A(x) at v0 ……vn

  – O(n) time per vi using Horner’s rule




• Problems
  – O(n2) time

  – Large numbers with n log vi bits
Multi-Point Polynomial Evaluation
                Speed Up
• A(x) mod (x-v)

   – A(v)

   – O(n) time using high school polynomial division



• A’(x) = A(x) mod (x-v0) (x-v1)         [how fast?]
   – A’(x) mod (x-v0) = A(v0)   [O(1)]

   – A’(x) mod (x-v1) = A(v1)   [O(1)]

   – 2 expensive polynomial divisions could potentially be replaced by 1
Fast Multi-Point Polynomial Evaluation

                                          T0(x)=A(x) mod (x-v0) (x-v1).. (x-vn)

T1(x)=T0 (x) mod (x-v0)..(x-v(n+1)/2-1)        T2 (x)=T0 (x) mod (x-v(n+1)/2) (x-vn)




    • If T(x) mod (x-vi).. (x-vj) can be done in O(deg(T))
      time, then what is the total time taken?

         – O(n log n)!!
Computing T(x) mod (x-v1).. (x-vk)

•   High school algorithm

    – Time taken: O( deg(T) * k )

    – How do we make this faster?


• Stroke of genius
       • Can we choose vi’s so (x-v1).. (x-vk) = xk-v?

       • Then we get O(deg(T) ) time
Choosing vi’s
• When is (x-v1)(x-v2) = x2+v1v2 ?

   – v2+v1=0


• When is (x-a)(x+a)(x-b)(x+b) = x4+ a2b2?

   – b2-a2=0 => b2=-a2

      • => b= sqrt(-1) a

      • the 4 numbers are 1 –i -1 i

      • alternatively (–i)0 (–i)1 (–i)2 (–i)3
Choosing vi’s


• Choose vi to be roots of xn -1

   = Cos(2Πk/n) + i Sin(2Πk/n)
   = e i 2Πk/n

   – Powering just goes around the unit circle

      • Computing with log n bits suffices
Exercise


• Choose vi to be roots of xn -1

   = Cos(2Πk/n) + i Sin(2Πk/n)
   = e i 2Πk/n

   – Organize these roots so we get polynomials with
     just 2 terms in every node of the tree on slide 9
      • Assume n+1 is a power of 2
Conclusion


• Also called : Fast Fourier Transform

• Complex Numbers are interesting!

     • Reality can be explained elegantly only with
       complex numbers!!

More Related Content

PDF
Brief summary of signals
PPTX
Smart Multitask Bregman Clustering
PPTX
Overlap save method and overlap add method in dsp
PDF
CS571: Language Models
PDF
CS571: Gradient Descent
PDF
PDF
Bayesian Dark Knowledge and Matrix Factorization
PDF
CS571: Distributional semantics
Brief summary of signals
Smart Multitask Bregman Clustering
Overlap save method and overlap add method in dsp
CS571: Language Models
CS571: Gradient Descent
Bayesian Dark Knowledge and Matrix Factorization
CS571: Distributional semantics

What's hot (17)

PDF
optimal control principle slided
PDF
Higher-order Factorization Machines(第5回ステアラボ人工知能セミナー)
PDF
Nodal Domain Theorem for the p-Laplacian on Graphs and the Related Multiway C...
PDF
Conditional neural processes
PPTX
Introduction to Neural Networks and Deep Learning from Scratch
PDF
A new Perron-Frobenius theorem for nonnegative tensors
PDF
Estimating structured vector autoregressive models
PDF
Small updates of matrix functions used for network centrality
PDF
Gentle intro to SVM
PDF
Image Restoration 2 (Digital Image Processing)
PDF
Murphy: Machine learning A probabilistic perspective: Ch.9
PDF
Levitan Centenary Conference Talk, June 27 2014
PPT
Convex Optimization Modelling with CVXOPT
PDF
PDF
CS571:: Part of-Speech Tagging
optimal control principle slided
Higher-order Factorization Machines(第5回ステアラボ人工知能セミナー)
Nodal Domain Theorem for the p-Laplacian on Graphs and the Related Multiway C...
Conditional neural processes
Introduction to Neural Networks and Deep Learning from Scratch
A new Perron-Frobenius theorem for nonnegative tensors
Estimating structured vector autoregressive models
Small updates of matrix functions used for network centrality
Gentle intro to SVM
Image Restoration 2 (Digital Image Processing)
Murphy: Machine learning A probabilistic perspective: Ch.9
Levitan Centenary Conference Talk, June 27 2014
Convex Optimization Modelling with CVXOPT
CS571:: Part of-Speech Tagging
Ad

Viewers also liked (19)

PPT
5.9 complex numbers
PPT
Complex Numbers
PPT
complex numbers
PPSX
Complex number
PPTX
Complex Numbers
PPTX
Complex Number's Applications
PPTX
Complex numbers org.ppt
PPT
Complex Number I - Presentation
PPTX
Ankit maths ppt
PDF
Ch 7 Review March 18
PPT
Complex Numbers And Appsfeb
PPTX
Lattice multiplication
PPT
Lattice Multiplication
PPTX
Complex Numbers
POTX
Ch 7 c volumes
PPTX
Applications of Definite Intergral
DOCX
B.tech ii unit-3 material multiple integration
DOCX
B.tech ii unit-2 material beta gamma function
PPTX
Complex number
5.9 complex numbers
Complex Numbers
complex numbers
Complex number
Complex Numbers
Complex Number's Applications
Complex numbers org.ppt
Complex Number I - Presentation
Ankit maths ppt
Ch 7 Review March 18
Complex Numbers And Appsfeb
Lattice multiplication
Lattice Multiplication
Complex Numbers
Ch 7 c volumes
Applications of Definite Intergral
B.tech ii unit-3 material multiple integration
B.tech ii unit-2 material beta gamma function
Complex number
Ad

Similar to Complex numbers polynomial multiplication (20)

PDF
Introduction to polynomials
PPT
16 fft
PDF
Daa chapter7
PDF
A primer on computer algebra
PPT
L6_Large_number_multi.ppt large number multiplication
PDF
Csr2011 june14 17_00_pospelov
PPTX
FFT and DFT algorithm
PDF
Compiled Report
PDF
A Numeric Algorithm for Generating Permutations in Lexicographic Order with a...
PDF
Number theory lecture (part 2)
PDF
Elementary Number Theory with Applications Koshy.pdf
PDF
math1مرحلة اولى -compressed.pdf
PPT
Divide and-conquer multiply two polynomials
PPT
Chapter 9 computation of the dft
PDF
Algebra 6
PPT
2010 3-24 cryptography stamatiou
PPTX
Precalculus 1 chapter 2
DOC
mathematics formulas
PDF
A Solutions To Exercises On Complex Numbers
PDF
Ahlfors sol1
Introduction to polynomials
16 fft
Daa chapter7
A primer on computer algebra
L6_Large_number_multi.ppt large number multiplication
Csr2011 june14 17_00_pospelov
FFT and DFT algorithm
Compiled Report
A Numeric Algorithm for Generating Permutations in Lexicographic Order with a...
Number theory lecture (part 2)
Elementary Number Theory with Applications Koshy.pdf
math1مرحلة اولى -compressed.pdf
Divide and-conquer multiply two polynomials
Chapter 9 computation of the dft
Algebra 6
2010 3-24 cryptography stamatiou
Precalculus 1 chapter 2
mathematics formulas
A Solutions To Exercises On Complex Numbers
Ahlfors sol1

More from Strand Life Sciences Pvt Ltd (12)

PDF
Strand genomics features in CIO review
PPTX
Rules of a Quantum World
PPTX
Least common ancestors in constant time
PPTX
Introduction to statistics iii
PPTX
Introduction to statistics ii
PPTX
Introduction to statistics
PPTX
Dynamic programming for simd
PPTX
Converting High Dimensional Problems to Low Dimensional Ones
PPTX
Searching using Quantum Rules
PPTX
Randomized algorithms
PPTX
PPTX
Alignment of raw reads in Avadis NGS
Strand genomics features in CIO review
Rules of a Quantum World
Least common ancestors in constant time
Introduction to statistics iii
Introduction to statistics ii
Introduction to statistics
Dynamic programming for simd
Converting High Dimensional Problems to Low Dimensional Ones
Searching using Quantum Rules
Randomized algorithms
Alignment of raw reads in Avadis NGS

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
cuic standard and advanced reporting.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
Digital-Transformation-Roadmap-for-Companies.pptx
Electronic commerce courselecture one. Pdf
Chapter 3 Spatial Domain Image Processing.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Weekly Chronicles - August'25 Week I
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The AUB Centre for AI in Media Proposal.docx
cuic standard and advanced reporting.pdf
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
Advanced methodologies resolving dimensionality complications for autism neur...
20250228 LYD VKU AI Blended-Learning.pptx

Complex numbers polynomial multiplication

  • 1. Multiplying Polynomials Fast Why do we need Complex Numbers?
  • 2. The Problem • (an xn + an-1 xn-1+…..+ a0 x0) * (bn xn + bn-1 xn-1+…..+ b0 x0) • O(n^2) time – (Σi=0..k ai * bk-i) is coefficient of xk • Can one do better?
  • 3. Applications • Where all does a pattern string P appear in a text string T? – P 0’s, 1’s and don’t cares. – T 0’s and 1’s • Easy in O(|P|*|T|) time – Can one do better?
  • 4. Conversion to Polynomial Multiplication • Treat P and T as polynomials – T=0101 1 x0 + 0 x1 + 1 x2 + 0 x3 tk-i tk-2 tk-1 tk – P=01D1 0 x0 + 1 x1 + 0 x2 + 1 x3 1 0 1 0 1 1 0 0 1 • Multiply Prev and T 1 0 0 0 1 0 0 p-i p-1 p-0 – (Σi=0..k previ * tk-i) is coefficient of xk – (Σi=0..k p|P|-i * tk-i) is coefficient of xk • >=1 if and only if a 1 in P aligns with a 0 in T when P is placed with end at tk – 2 polynomial multiplications suffice to find all matches of P in T
  • 5. Other Applications • Image Processing At this location Slide this mask all over the Multiply each bit bigger one in the mask with the corresponding bit in the image, sum these up
  • 6. Polynomial Multiplication An Equivalent Form • Evaluate each polynomial at 2n+1 distinct x’s – A(x) = (an xn + an-1 xn-1+…..+ a0 x0) -> A(v0)…..A(v2n) – B(x) = (bn xn + bn-1 xn-1+…..+ b0 x0) -> B(v0)…..B(v2n) • A(x) * B(x) -> A(v0)*B(v0)………..A(v2n)*B(v2n) – Convolution in one domain=Simple multiplication in another – O(n) time!!!
  • 7. Multi-Point Polynomial Evaluation • Evaluate A(x) at v0 ……vn – O(n) time per vi using Horner’s rule • Problems – O(n2) time – Large numbers with n log vi bits
  • 8. Multi-Point Polynomial Evaluation Speed Up • A(x) mod (x-v) – A(v) – O(n) time using high school polynomial division • A’(x) = A(x) mod (x-v0) (x-v1) [how fast?] – A’(x) mod (x-v0) = A(v0) [O(1)] – A’(x) mod (x-v1) = A(v1) [O(1)] – 2 expensive polynomial divisions could potentially be replaced by 1
  • 9. Fast Multi-Point Polynomial Evaluation T0(x)=A(x) mod (x-v0) (x-v1).. (x-vn) T1(x)=T0 (x) mod (x-v0)..(x-v(n+1)/2-1) T2 (x)=T0 (x) mod (x-v(n+1)/2) (x-vn) • If T(x) mod (x-vi).. (x-vj) can be done in O(deg(T)) time, then what is the total time taken? – O(n log n)!!
  • 10. Computing T(x) mod (x-v1).. (x-vk) • High school algorithm – Time taken: O( deg(T) * k ) – How do we make this faster? • Stroke of genius • Can we choose vi’s so (x-v1).. (x-vk) = xk-v? • Then we get O(deg(T) ) time
  • 11. Choosing vi’s • When is (x-v1)(x-v2) = x2+v1v2 ? – v2+v1=0 • When is (x-a)(x+a)(x-b)(x+b) = x4+ a2b2? – b2-a2=0 => b2=-a2 • => b= sqrt(-1) a • the 4 numbers are 1 –i -1 i • alternatively (–i)0 (–i)1 (–i)2 (–i)3
  • 12. Choosing vi’s • Choose vi to be roots of xn -1 = Cos(2Πk/n) + i Sin(2Πk/n) = e i 2Πk/n – Powering just goes around the unit circle • Computing with log n bits suffices
  • 13. Exercise • Choose vi to be roots of xn -1 = Cos(2Πk/n) + i Sin(2Πk/n) = e i 2Πk/n – Organize these roots so we get polynomials with just 2 terms in every node of the tree on slide 9 • Assume n+1 is a power of 2
  • 14. Conclusion • Also called : Fast Fourier Transform • Complex Numbers are interesting! • Reality can be explained elegantly only with complex numbers!!