From ef9b4f76fa3a8dccfc08c8c87799945cef98ba54 Mon Sep 17 00:00:00 2001 From: Sidharth Kapur Date: Wed, 27 Jan 2016 16:48:10 -0600 Subject: Add Num, Fractional, Floating instances for Sym --- packages/base/src/Numeric/LinearAlgebra/Static.hs | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'packages/base/src') diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs index e18ba0c..84a623b 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Static.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs @@ -786,3 +786,40 @@ instance (KnownNat m, KnownNat n) => Normed (L m n) norm_1 m = norm_1 (extract m) norm_2 m = norm_2 (extract m) norm_Inf m = norm_Inf (extract m) + +mkSym f = Sym . f . unSym +mkSym2 f x y = Sym (f (unSym x) (unSym y)) + +instance KnownNat n => Num (Sym n) + where + (+) = mkSym2 (+) + (*) = mkSym2 (*) + (-) = mkSym2 (-) + abs = mkSym abs + signum = mkSym signum + negate = mkSym negate + fromInteger = Sym . fromInteger + +instance KnownNat n => Fractional (Sym n) + where + fromRational = Sym . L . Dim . Dim . fromRational + (/) = mkSym2 (/) + +instance KnownNat n => Floating (Sym n) where + sin = mkSym sin + cos = mkSym cos + tan = mkSym tan + asin = mkSym asin + acos = mkSym acos + atan = mkSym atan + sinh = mkSym sinh + cosh = mkSym cosh + tanh = mkSym tanh + asinh = mkSym asinh + acosh = mkSym acosh + atanh = mkSym atanh + exp = mkSym exp + log = mkSym log + sqrt = mkSym sqrt + (**) = mkSym2 (**) + pi = Sym pi -- cgit v1.2.3