File: Exp.hs

package info (click to toggle)
haskell-algebra 2.1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 420 kB
  • sloc: haskell: 4,758; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 863 bytes parent folder | download
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
module Numeric.Exp
  ( Exp(..)
  ) where

import Data.Function (on)
import Numeric.Algebra

import Prelude hiding ((+),(-),negate,replicate,subtract)

newtype Exp r = Exp { runExp :: r } 

instance Additive r => Multiplicative (Exp r) where
  Exp a * Exp b = Exp (a + b)
  productWith1 f = Exp . sumWith1 (runExp . f)
  pow1p (Exp m) n = Exp (sinnum1p n m)

instance Monoidal r => Unital (Exp r) where
  one = Exp zero
  pow (Exp m) n = Exp (sinnum n m)
  productWith f = Exp . sumWith (runExp . f)

instance Group r => Division (Exp r) where
  Exp a / Exp b = Exp (a - b)
  recip (Exp a) = Exp (negate a)
  Exp a \\ Exp b = Exp (subtract a b)
  Exp m ^ n = Exp (times n m)

instance Abelian r => Commutative (Exp r)

instance Idempotent r => Band (Exp r)

instance Partitionable r => Factorable (Exp r) where
  factorWith f = partitionWith (f `on` Exp) . runExp