( Expr(..)
, Cond(..)
, Constant(..)
+ , ContainsSymbols(..)
, Literal(..)
, CompareOp(..)
, UnaryFunction(..)
, buildConditional
+ , findUniqueSymbol
, pow
, simplify
, (~==)
Or e1 e2 -> Set.union (findSymbols e1) (findSymbols e2)
Not e -> findSymbols e
+findUniqueSymbol :: (ContainsSymbols e) => String -> e -> String
+findUniqueSymbol prefix expr =
+ head [n | n <- generateNames, Set.notMember n syms ] where
+ syms = findSymbols expr
+ generateNames = [prefix ++ "_" ++ show n | n <- [0::Integer ..]]
simplify :: Expr -> Expr
simplify (Sum pairSeq) = rebuild $ normalise pairSeq
import LTA.Symbolic
+data Matrix
+ = Matrix Expr Expr Expr
+ deriving(Eq, Ord, Show)
+
+multiply :: Matrix -> Matrix -> Matrix
+multiply (Matrix aRows aCols aExpr) (Matrix bRows bCols bExpr) =
+ Matrix aRows bCols $ Summation sumVar 0 aCols (aExpr' * bExpr') where
+ sumVar = findUniqueSymbol "sum" (aExpr * bExpr)
+ aExpr' = rename "col" sumVar aExpr
+ bExpr' = rename "row" sumVar bExpr
+
main :: IO()
-main = putStrLn . show $ dft (IntegerSymbol "N")
+main = putStrLn . show $ (pad size) `multiply` (dft size) where
+ size = IntegerSymbol "N"
row :: Expr
row = IntegerSymbol "row"
pi :: Expr
pi = Constant Pi
-dft :: Expr -> Expr
-dft size = pow e ((- i * 2 * Main.pi * row * col) / size)
+dft :: Expr -> Matrix
+dft size = Matrix size size $ pow e ((- i * 2 * Main.pi * row * col) / size)
isEven :: Expr -> Cond
isEven n = (n `Mod` 2) ~== 0
-pad :: Expr -> Expr
-pad size = Conditional (isEven size) (evenPad size) (oddPad size)
+pad :: Expr -> Matrix
+pad size =
+ Matrix (2*size) size $ Conditional (isEven size) (evenPad size) (oddPad size)
evenPad :: Expr -> Expr
evenPad size = buildConditional 0 conditions where