module Numeric.Module.Representable
(
addRep, sinnum1pRep
, zeroRep, sinnumRep
, negateRep, minusRep, subtractRep, timesRep
, mulRep
, oneRep
, fromNaturalRep
, fromIntegerRep
) where
import Control.Applicative
import Data.Functor
import Data.Functor.Rep
import Numeric.Additive.Class
import Numeric.Additive.Group
import Numeric.Algebra.Class
import Numeric.Algebra.Unital
import Numeric.Natural
import Numeric.Rig.Class
import Numeric.Ring.Class
import Control.Category
import Prelude (($), Integral(..),Integer)
addRep :: (Applicative m, Additive r) => m r -> m r -> m r
addRep = liftA2 (+)
sinnum1pRep :: (Functor m, Additive r) => Natural -> m r -> m r
sinnum1pRep = fmap . sinnum1p
zeroRep :: (Applicative m, Monoidal r) => m r
zeroRep = pure zero
sinnumRep :: (Functor m, Monoidal r) => Natural -> m r -> m r
sinnumRep = fmap . sinnum
negateRep :: (Functor m, Group r) => m r -> m r
negateRep = fmap negate
minusRep :: (Applicative m, Group r) => m r -> m r -> m r
minusRep = liftA2 ()
subtractRep :: (Applicative m, Group r) => m r -> m r -> m r
subtractRep = liftA2 subtract
timesRep :: (Integral n, Functor m, Group r) => n -> m r -> m r
timesRep = fmap . times
mulRep :: (Representable m, Algebra r (Rep m)) => m r -> m r -> m r
mulRep m n = tabulate $ mult (\b1 b2 -> index m b1 * index n b2)
oneRep :: (Representable m, Unital r, UnitalAlgebra r (Rep m)) => m r
oneRep = tabulate $ unit one
fromNaturalRep :: (UnitalAlgebra r (Rep m), Representable m, Rig r) => Natural -> m r
fromNaturalRep n = tabulate $ unit (fromNatural n)
fromIntegerRep :: (UnitalAlgebra r (Rep m), Representable m, Ring r) => Integer -> m r
fromIntegerRep n = tabulate $ unit (fromInteger n)