Fast Fourier transform: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: changed whitespace and indentations, optimized a computation.)
(→‎{{header|Perl 6}}: give terser functional version, along with its drawback and fix)
Line 2,010: Line 2,010:
<lang perl6>sub fft {
<lang perl6>sub fft {
@_ == 1 ?? @_ !!
@_ == 1 ?? @_ !!
fft( @_[0, 2 ... *] ) «+»
fft(@_[0,2...*]) «+«
(<1 -1> X* (fft( @_[1,3...*] ) Z* map &cis, (0,-τ/@_...*)))
fft(@_[1,3...*]) «*« map &cis, (0,-τ/@_...^-τ)
}</lang>

This particular version is numerically inaccurate though, because of the pi approximation. It is possible to fix it with the 'cisPi' function available in the TrigPi module:

<lang perl6>sub fft {
use TrigPi;
@_ == 1 ?? @_ !!
fft(@_[0,2...*]) «+«
fft(@_[1,3...*]) «*« map &cisPi, (0,-2/@_...^-2)
}</lang>
}</lang>