%%HP: T(3)A(D)F(.);
@ by Robert W Yoder.
DIR
  DFT
    \<< SWAP DUP SIZE 1 GET \pi \->NUM (0,-2) * OVER / 4 PICK * \-> d x s q
      \<< 0 s 1 -
        FOR k 0 0 s 1 -
          FOR n q k * n * EXP x n 1 + GET * +
          NEXT
        NEXT s \->ARRY
        IF d -1 SAME
        THEN s INV *
        END
      \>>
    \>>
  FFT
    \<< ARRY\-> 1 GET
      IF DUP LN 2 LN / DUP IP ==
      THEN \-> t
        \<< 1 t LN 2 LN /
          FOR c -2 \pi * i * 2 c ^ / EXP \->NUM 2 c 1 - ^ \-> f k
            \<< t 2 / 1 + t
              FOR d 0 k 1 - FOR e t ROLL d e + ROLL f e ^ * - LASTARG + e 2 +
                ROLLD NEXT k
              STEP
            \>>
          NEXT t \->ARRY
        \>>
      ELSE \->ARRY "FFT Error: Size \=/ 2^N" 1 DISP 1400 .07 BEEP
      END
    \>>
  FFTI
    \<< CONJ FFT DUP SIZE 1 GET / CONJ
    \>>
  FT
    \<< DUP SIZE 1 GET
      IF LN 2 LN / FP
      THEN 1 DFT
      ELSE FFT
      END -10 RND
    \>>
  INVFT
    \<< DUP SIZE 1 GET
      IF LN 2 LN / FP
      THEN -1 DFT
      ELSE FFTI
      END -10 RND
    \>>
  PCNV
    \<< FT SWAP FT \-> a b
      \<< a SIZE 1 GET \-> s
        \<< 1 s
          FOR n a n GET b n GET *
          NEXT s \->ARRY
        \>>
      \>> INVFT
    \>>
  APCNV
    \<< \-> a b
      \<< a SIZE 1 GET b SIZE 1 GET + 1 - 1 \->LIST \-> s
        \<< a s RDM b s RDM
        \>>
      \>> PCNV
    \>>
  FFT2
    \<< DUP SIZE LIST\-> DROP \-> a nr nc
      \<< "[" 1 nr
        FOR r 1 nc
          FOR c 'a(r,c)' \->NUM
          NEXT nc \->ARRY FT \->STR +
        NEXT STR\-> 'a' STO "[" 1 nc
        FOR c 1 nr
          FOR r 'a(r,c)' \->NUM
          NEXT nr \->ARRY FT \->STR +
        NEXT STR\-> TRN CONJ
      \>>
    \>>
  IFFT2
    \<< DUP SIZE LIST\-> DROP \-> a nr nc
      \<< "[" 1 nc
        FOR c 1 nr
          FOR r 'a(r,c)' \->NUM
          NEXT nr \->ARRY INVFT \->STR +
        NEXT STR\-> TRN CONJ 'a' STO "[" 1 nr
        FOR r 1 nc
          FOR c 'a(r,c)' \->NUM
          NEXT nc \->ARRY INVFT \->STR +
        NEXT STR\->
      \>>
    \>>
  FTSH
    \<< DUP SIZE DUP LIST\-> DROP \-> a s rt ct
      \<< rt 2 / DUP 1 + ct 2 / DUP 1 + \-> r2 r3 c2 c1
        \<< r3 rt
          FOR r c1 ct
            FOR c 'a(r,c)' \->NUM
            NEXT 1 c2
            FOR c 'a(r,c)' \->NUM
            NEXT
          NEXT 1 r2
          FOR r c1 ct
            FOR c 'a(r,c)' \->NUM
            NEXT 1 c2
            FOR c 'a(r,c)' \->NUM
            NEXT
          NEXT s \->ARRY
        \>>
      \>>
    \>>
END
