A fast Chebyshev–Legendre transform using an asymptotic formula Alex Townsend MIT (Joint work with Nick Hale) SIAM OPSFA, 5th June 2015 Introduction What is the Chebyshev–Legendre transform? Suppose we have a degree N ´ 1 polynomial. It can be expressed in the Chebyshev or Legendre polynomial basis: pN ´1 px q “ Nÿ ´1 leg ck Pk px q ðñ pN ´1 px q “ k “0 Nÿ ´1 ckcheb Tk px q k “0 The Chebyshev–Legendre transform: forward transform leg leg c0 , . . . , cN ´1 ÝÝÝÝÝÝÝÝÝÝÝÝÝÝá OpN plog N q2 { log log N q âÝÝÝÝÝÝÝÝÝÝÝÝÝ c0cheb , . . . , cNcheb . ´1 inverse transform Applications in: I I I I Convolution [Hale & T., 14] Legendre-tau spectral methods QR of a quasimatrix [Trefethen, 08] best least squares approximation Alex Townsend @ MIT 1/18 Introduction What is the Chebyshev–Legendre transform? Suppose we have a degree N ´ 1 polynomial. It can be expressed in the Chebyshev or Legendre polynomial basis: pN ´1 px q “ Nÿ ´1 leg ck Pk px q ðñ pN ´1 px q “ k “0 Nÿ ´1 ckcheb Tk px q k “0 The Chebyshev–Legendre transform: forward transform leg leg c0 , . . . , cN ´1 ÝÝÝÝÝÝÝÝÝÝÝÝÝÝá OpN plog N q2 { log log N q âÝÝÝÝÝÝÝÝÝÝÝÝÝ c0cheb , . . . , cNcheb . ´1 inverse transform Applications in: I I I I Convolution [Hale & T., 14] Legendre-tau spectral methods QR of a quasimatrix [Trefethen, 08] best least squares approximation Alex Townsend @ MIT 1/18 Introduction What is the Chebyshev–Legendre transform? Suppose we have a degree N ´ 1 polynomial. It can be expressed in the Chebyshev or Legendre polynomial basis: pN ´1 px q “ Nÿ ´1 leg ck Pk px q ðñ pN ´1 px q “ k “0 Nÿ ´1 ckcheb Tk px q k “0 The Chebyshev–Legendre transform: forward transform leg leg c0 , . . . , cN ´1 ÝÝÝÝÝÝÝÝÝÝÝÝÝÝá OpN plog N q2 { log log N q âÝÝÝÝÝÝÝÝÝÝÝÝÝ c0cheb , . . . , cNcheb . ´1 inverse transform Applications in: I I I I Convolution [Hale & T., 14] Legendre-tau spectral methods QR of a quasimatrix [Trefethen, 08] best least squares approximation Alex Townsend @ MIT 1/18 Introduction Related work discrete cosine transform O pN log N q Values at Chebyshev points Potts et al. ` ˘ O N plog N q2 Mori et al. O pN log N q Values in the complex plane Legendre coefficients Iserles O pN log N q Alpert & Rokhlin O pN q `Tygert ˘ O N plog N q2 Chebyshev coefficients Values at Legendre points New features of our algorithms FFT-based approach Analysis-based No precomputation Alex Townsend @ MIT 2/18 Introduction The fast Fourier transform The FFT computes the DFT in OpN log N q operations: ř Xk “ nN“´01 xn ¨ e ´2πink {N , 0 ď k ď N ´ 1. sinp ´2π t q Imag axis e ´2πit Top 10 algorithm ; cos p´2 James Cooley t Alex Townsend @ MIT ; πt q John Tukey xis al a Re 3/18 Introduction Many special functions are trigonometric-like Trigonometric functions cospωx q, sinpωx q Chebyshev polynomials Tn px q Legendre polynomials Pn px q Bessel functions Jν pz q Airy functions Ai px q Also, Jacobi polynomials, Hermite polynomials, cylinder functions, etc. Alex Townsend @ MIT 4/18 Introduction Many special functions are trigonometric-like Trigonometric functions cospωx q, sinpωx q Chebyshev polynomials Tn px q Legendre polynomials Pn px q Bessel functions Jν pz q Airy functions Ai px q Also, Jacobi polynomials, Hermite polynomials, cylinder functions, etc. Alex Townsend @ MIT 4/18 Introduction Many special functions are trigonometric-like Trigonometric functions cospωx q, sinpωx q Chebyshev polynomials Tn px q Legendre polynomials Pn px q Bessel functions Jν pz q Airy functions Ai px q Also, Jacobi polynomials, Hermite polynomials, cylinder functions, etc. Alex Townsend @ MIT 4/18 Introduction Many special functions are trigonometric-like Trigonometric functions cospωx q, sinpωx q Chebyshev polynomials Tn px q Legendre polynomials Pn px q Bessel functions Jν pz q Airy functions Ai px q Also, Jacobi polynomials, Hermite polynomials, cylinder functions, etc. Alex Townsend @ MIT 4/18 Introduction Many special functions are trigonometric-like Trigonometric functions cospωx q, sinpωx q Chebyshev polynomials Tn px q Legendre polynomials Pn px q Bessel functions Jν pz q Airy functions Ai px q Also, Jacobi polynomials, Hermite polynomials, cylinder functions, etc. Alex Townsend @ MIT 4/18 Introduction Many special functions are trigonometric-like Trigonometric functions cospωx q, sinpωx q Chebyshev polynomials Tn px q Legendre polynomials Pn px q Bessel functions Jν pz q Airy functions Ai px q Also, Jacobi polynomials, Hermite polynomials, cylinder functions, etc. Alex Townsend @ MIT 4/18 Introduction An asymptotic expansion of Legendre polynomials Legendre polynomials Pn pcos θq “ Cn Mÿ ´1 hm,n m “0 c Cn “ 4 Γpn ` 1q , π Γpn ` 3{2q ˘ ` cos pm ` n ` 12 qθ ´ pm ` 21 q π2 p2 sin θqm`1{2 # hm,n “ 1, pj ´1{2q2 j “1 j pn`j `1{2q , śm ` Rn,M pθq m “ 0, m ą 0. Thomas Stieltjes Boundary Region: Bessel−like Interior Region: Trig−like Alex Townsend @ MIT 5/18 Introduction Numerical pitfalls of an asymptotic expansionist ` ˘ Mÿ ´1 cos pm ` n ` 12 qθ ´ pm ` 12 q π2 Pn pcos θq “ Cn hm,n ` Rn,M pθq p2 sin θqm`1{2 m “0 |Rn,M pθq| M“1 M“3 n “ 1,000 M “ 5, 7 x Fix M. Where is the asymptotic expansion accurate? Alex Townsend @ MIT 6/18 Computing the Chebyshev–Legendre transform The transform comes in two parts The Chebyshev–Legendre transform naturally splits into two parts: This bit leg leg c0 , . . . , cN ´1 ÝÝÝÝÝÝÝá âÝÝÝÝÝÝÝ IDCT q pN ´1 px0cheb q, . . . , pN ´1 pxNcheb ´1 ÝÝÝÝÝÝá DCT c0cheb , . . . , cNcheb ´1 âÝÝÝÝÝÝ Task: Compute the following matrix-vector product in quasilinear time? ¨ ˛ ¨ leg ˛ c0 P0 pcos θ0 q . . . PN ´1 pcos θ0 q ˚ ˚ ‹˚ . ‹ kπ .. .. ... ‹ ˚ .. ‹ PN c “ ˚ ‹ , θk “ . . ˝ ‚˝ ‚ N´1 leg P0 pcos θN ´1 q . . . PN ´1 pcos θN ´1 q c N ´1 Alex Townsend @ MIT 7/18 Computing the Chebyshev–Legendre transform The transform comes in two parts The Chebyshev–Legendre transform naturally splits into two parts: This bit leg leg c0 , . . . , cN ´1 ÝÝÝÝÝÝÝá âÝÝÝÝÝÝÝ IDCT q pN ´1 px0cheb q, . . . , pN ´1 pxNcheb ´1 ÝÝÝÝÝÝá DCT c0cheb , . . . , cNcheb ´1 âÝÝÝÝÝÝ Task: Compute the following matrix-vector product in quasilinear time? ¨ ˛ ¨ leg ˛ c0 P0 pcos θ0 q . . . PN ´1 pcos θ0 q ˚ ˚ ‹˚ . ‹ kπ .. .. ... ‹ ˚ .. ‹ PN c “ ˚ ‹ , θk “ . . ˝ ‚˝ ‚ N´1 leg P0 pcos θN ´1 q . . . PN ´1 pcos θN ´1 q c N ´1 Alex Townsend @ MIT 7/18 Computing the Chebyshev–Legendre transform Asymptotic expansions as a matrix decomposition The asymptotic expansion Pn pcos θk q “ Cn Mÿ ´1 hm,n m “0 ˘ ` cos pm ` n ` 21 qθk ´ pm ` 12 q π2 p2 sin θk qm`1{2 ` Rn,M pθk q gives a matrix decomposition (sum of diagonally scaled DCTs and DSTs): » fi ˛ ¨ 0 0 0 Mÿ ´1 ˝Du CN DCh ` Dv –0 SN ´2 0fl DCh ‚ ` RN,M . PN “ m m m m m “0 0 0 0 PN Alex Townsend @ MIT “ PASY N ` RN,M 8/18 Computing the Chebyshev–Legendre transform Asymptotic expansions as a matrix decomposition The asymptotic expansion Pn pcos θk q “ Cn Mÿ ´1 hm,n m “0 ˘ ` cos pm ` n ` 21 qθk ´ pm ` 12 q π2 p2 sin θk qm`1{2 ` Rn,M pθk q gives a matrix decomposition (sum of diagonally scaled DCTs and DSTs): » fi ˛ ¨ 0 0 0 Mÿ ´1 ˝Du CN DCh ` Dv –0 SN ´2 0fl DCh ‚ ` RN,M . PN “ m m m m m “0 0 0 0 PN Alex Townsend @ MIT “ PASY N ` RN,M 8/18 Computing the Chebyshev–Legendre transform Asymptotic expansions as a matrix decomposition The asymptotic expansion Pn pcos θk q “ Cn Mÿ ´1 hm,n m “0 ˘ ` cos pm ` n ` 21 qθk ´ pm ` 12 q π2 p2 sin θk qm`1{2 ` Rn,M pθk q gives a matrix decomposition (sum of diagonally scaled DCTs and DSTs): » fi ˛ ¨ 0 0 0 Mÿ ´1 ˝Du CN DCh ` Dv –0 SN ´2 0fl DCh ‚ ` RN,M . PN “ m m m m m “0 0 0 0 PN Alex Townsend @ MIT “ PASY N ` RN,M 8/18 Computing the Chebyshev–Legendre transform Be careful and stay safe Error curve: |Rn,M pθk q| “ Fix M. Where is the asymptotic expansion accurate? RN,M “ M “5 M “7 M “ 15 |Rn,M pθk q| ď Alex Townsend @ MIT M“ 6 2Cn hM,n p2 sin θk qM `1{2 9/18 Computing the Chebyshev–Legendre transform Partitioning and balancing competing costs α3 N α2 N αN N PEVAL N PN “ (3) PN Theorem (2) PN The matrix-vector product f “ PN c can be computed in OpN plog N q2 { loglog N q operations. (1) PN α too small PEVAL c N OpN 2 q (j) PN c OpN log N q Alex Townsend @ MIT 10/18 Computing the Chebyshev–Legendre transform Partitioning and balancing competing costs α3 N α2 N αN N PEVAL N PN “ (3) PN Theorem (2) PN The matrix-vector product f “ PN c can be computed in OpN plog N q2 { loglog N q operations. (1) PN α too small PEVAL c N OpN 2 q (j) PN c OpN log N q Alex Townsend @ MIT 10/18 Computing the Chebyshev–Legendre transform Partitioning and balancing competing costs α3 N α2 N αN N PEVAL N PN “ (3) PN Theorem (2) PN The matrix-vector product f “ PN c can be computed in OpN plog N q2 { loglog N q operations. (1) PN α too small PEVAL c N OpN 2 q (j) PN c OpN log N q Alex Townsend @ MIT 10/18 Computing the Chebyshev–Legendre transform Partitioning and balancing competing costs α3 N α2 N αN N PEVAL N PN “ (3) PN Theorem (2) PN The matrix-vector product f “ PN c can be computed in OpN plog N q2 { loglog N q operations. (1) PN (j) PN c α too large OpN 2 log N q PEVAL c N OpN log N q Alex Townsend @ MIT 11/18 Computing the Chebyshev–Legendre transform Partitioning and balancing competing costs α3 N α2 N αN N PEVAL N PN “ (3) PN Theorem (2) PN The matrix-vector product f “ PN c can be computed in OpN plog N q2 { loglog N q operations. (1) PN α “ Op1{ log Nq (j) PN c OpN plog N q2 { loglog N q Alex Townsend @ MIT PEVAL c N OpN plog N q2 { loglog N q 12/18 Computing the Chebyshev–Legendre transform Numerical results Op N2 q Mollification of rough signals g plo N Op gN o l og 2 {l q N q d ż1 Pn px qe ´iωx dx “ im No precomputation. ´1 Alex Townsend @ MIT 2π Jm`1{2 p´ωq ´ω 13/18 Computing the Chebyshev–Legendre transform The inverse Chebyshev–Legendre transform The integral formula for Legendre coefficients gives the following relation: „ “ ‰ IN `1 cheb leg cheb T cheb c N “ IN `1 | 0N Ds 2N P2N px 2N q Dw 2N T2N px 2N q cN , 0N 2αN PEVAL 2N T (3) T P2N (2) T P2N (1) T P2N 2N Alex Townsend @ MIT qT P2N px cheb 2N Op N2 q 2α3 N 2α2 N i31 Execution time i11 i21 g plo N Op g glo Nq o 2 {l q N N 14/18 Future work Fast spherical harmonic transform Spherical harmonic transform: f pθ, φq “ Nÿ ´1 l ÿ |m| imφ αm l Pl pcos θqe l “0 m“´l [Mohlenkamp, 1999], [Rokhlin & Tygert, 2006], [Tygert, 2008] A new generation of fast transforms with no precomputation. Alex Townsend @ MIT 15/18 Thank you Thank you Alex Townsend @ MIT 16/18 References D. H. Bailey, K. Jeyabalan, and X. S. Li, A comparison of three high-precision quadrature schemes, 2005. P. Baratella and I. Gatteschi, The bounds for the error term of an asymptotic approximation of Jacobi polynomials, Lecture notes in Mathematics, 1988. Z. Battels and L. N. Trefethen, An extension of Matlab to continuous functions and operators, SISC, 2004. Iteration-free computation of Gauss–Legendre quadrature nodes and weights, SISC, 2014. G. H. Golub and J. H. Welsch, Calculation of Gauss quadrature rules, Math. Comput., 1969. N. Hale and A. Townsend, Fast and accurate computation of Gauss–Legendre and Gauss–Jacobi quadrature nodes and weights, SISC, 2013. N. Hale and A. Townsend, A fast, simple, and stable Chebyshev–Legendre transform using an asymptotic formula, SISC, 2014. Y. Nakatsukasa, V. Noferini, and A. Townsend, Computing the common zeros of two bivariate functions via Bezout resultants, Numerische Mathematik, 2014. Alex Townsend @ MIT 17/18 References F. W. J. Olver, Asymptotics and Special Functions, Academic Press, New York, 1974. A. Townsend and L. N. Trefethen, An extension of Chebfun to two dimensions, SISC, 2013. A. Townsend, T. Trogdon, and S. Olver, Fast computation of Gauss quadrature nodes and weights on the whole real line, to appear in IMA Numer. Anal., 2015. A. Townsend, The race to compute high-order Gauss quadrature, SIAM News, 2015. A. Townsend, A fast analysis-based discrete Hankel transform using asymptotics expansions, submitted, 2015. F. G. Tricomi, Sugli zeri dei polinomi sferici ed ultrasferici, Ann. Mat. Pura. Appl., 1950. Alex Townsend @ MIT 18/18