/
fft.hs
49 lines (37 loc) · 1.23 KB
/
fft.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- Module : FFT (Generalized Fast Fourier Transforms)
-- Copyright : (c) 2012 Grant Rotskoff
-- License : GPL-3
--
-- Maintainer : gmr1887@gmail.com
-- Stability : experimental
-- Based on Clausen's Fourier Transform on Symmetric Groups
module FFT where
import Sn
import Partitions
import Tableau
import Matrix
import Functions
import qualified Data.Map as Map
import Data.Complex
-- A partially applicable Fourier transform!
-- We use a factorization of into a product of contiguous cycles to execute the recursion
-- Need to pass along the original function
-- Major testing/debugging remains a TODO.
fft :: SnMap -> Partition -> [[Double]]
fft (F f) l
| (length $ Map.toList f) == 1 = mScale (snd $ head $ Map.toList f) (identityMatrix (dim l))
| otherwise = foldr1 mSum [ mTimes (yor (o i) l) (fft (mapAdapt (F f) (o i)) l) | i <- [1..n]] where
o i = fromCycles [[i..n]] n
n = factInv $ fDim (F f)
randomFFT :: Partition -> (IO [[Double]])
randomFFT (Part l) = (randomF n) >>= (\s -> return (fft s (Part l))) where
n = sum l
-- Temp. / Inelegant
factInv :: Int -> Int
factInv x = case x of
1 -> 1
2 -> 2
6 -> 3
24 -> 4
120 -> 5
720 -> 6