     ] map ; inline
 
 ! Cooley–Tukey Algorithm
-:: (fft) ( seq inverse? -- seq' )
+:: (fast-fft) ( seq inverse? -- seq' )
     seq length :> N
     N 1 = [ seq ] [
         seq even-indices inverse? (fft)

IN: math.transforms.fft

<PRIVATE

! Discrete Fourier Transform
:: (slow-fft) ( seq inverse? -- seq' )

        2bi append
    ] if ; inline recursive

: (fft) ( seq inverse? -- seq' )
    over length power-of-2?
    [ (fast-fft) ] [ (slow-fft) ] if ; inline recursive

PRIVATE>

ERROR: not-enough-data ;

: fft ( seq -- seq' )
    [ not-enough-data ] [ f (fft) ] if-empty ;

: ifft ( seq -- seq' )
    [ not-enough-data ] [ t (fft) ] if-empty ;

: correlate ( x y -- z )
    [ fft ] [ reverse fft ] bi* v* ifft ;
