{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Math.ExpPairs.ProcessMatrix
( Process (..)
, ProcessMatrix ()
, aMatrix
, baMatrix
, evalMatrix
) where
import GHC.Generics (Generic (..))
import Data.Text.Prettyprint.Doc
import Math.ExpPairs.Matrix3
data Process
= A
| BA
deriving (Eq, Show, Read, Ord, Enum, Generic)
instance Pretty Process where
pretty = pretty . show
newtype ProcessMatrix = ProcessMatrix (Matrix3 Integer)
deriving (Eq, Num, Show, Pretty)
instance Semigroup ProcessMatrix where
ProcessMatrix a <> ProcessMatrix b = ProcessMatrix $ normalize $ a * b
instance Monoid ProcessMatrix where
mempty = 1
mappend = (<>)
process2matrix :: Process -> ProcessMatrix
process2matrix A = ProcessMatrix $ Matrix3 1 0 0 1 1 1 2 0 2
process2matrix BA = ProcessMatrix $ Matrix3 0 1 0 2 0 1 2 0 2
aMatrix :: ProcessMatrix
aMatrix = process2matrix A
baMatrix :: ProcessMatrix
baMatrix = process2matrix BA
evalMatrix :: Num t => ProcessMatrix -> (t, t, t) -> (t, t, t)
evalMatrix (ProcessMatrix m) = multCol (fmap fromInteger m)
{-# INLINABLE evalMatrix #-}
{-# SPECIALIZE evalMatrix :: ProcessMatrix -> (Integer, Integer, Integer) -> (Integer, Integer, Integer) #-}