module Data.Colour.Matrix where
import Data.List
default (Rational)
inverse :: [[a]] -> [[a]]
inverse m :: [[a]]
m@[[a
a,a
b,a
c],[a
d,a
e,a
f],[a
g,a
h,a
i]] =
[[(a
ea -> a -> a
forall a. Num a => a -> a -> a
*a
ia -> a -> a
forall a. Num a => a -> a -> a
-a
fa -> a -> a
forall a. Num a => a -> a -> a
*a
h)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det, -(a
ba -> a -> a
forall a. Num a => a -> a -> a
*a
ia -> a -> a
forall a. Num a => a -> a -> a
-a
ca -> a -> a
forall a. Num a => a -> a -> a
*a
h)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det, (a
ba -> a -> a
forall a. Num a => a -> a -> a
*a
fa -> a -> a
forall a. Num a => a -> a -> a
-a
ca -> a -> a
forall a. Num a => a -> a -> a
*a
e)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det]
,[-(a
da -> a -> a
forall a. Num a => a -> a -> a
*a
ia -> a -> a
forall a. Num a => a -> a -> a
-a
fa -> a -> a
forall a. Num a => a -> a -> a
*a
g)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det, (a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
ia -> a -> a
forall a. Num a => a -> a -> a
-a
ca -> a -> a
forall a. Num a => a -> a -> a
*a
g)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det, -(a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
fa -> a -> a
forall a. Num a => a -> a -> a
-a
ca -> a -> a
forall a. Num a => a -> a -> a
*a
d)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det]
,[(a
da -> a -> a
forall a. Num a => a -> a -> a
*a
ha -> a -> a
forall a. Num a => a -> a -> a
-a
ea -> a -> a
forall a. Num a => a -> a -> a
*a
g)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det, -(a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
ha -> a -> a
forall a. Num a => a -> a -> a
-a
ba -> a -> a
forall a. Num a => a -> a -> a
*a
g)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det, (a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
ea -> a -> a
forall a. Num a => a -> a -> a
-a
ba -> a -> a
forall a. Num a => a -> a -> a
*a
d)a -> a -> a
forall a. Fractional a => a -> a -> a
/a
det]]
where
det :: a
det = [[a]] -> a
forall a. Num a => [[a]] -> a
determinant [[a]]
m
determinant :: [[a]] -> a
determinant [[a
a,a
b,a
c],[a
d,a
e,a
f],[a
g,a
h,a
i]] =
a
aa -> a -> a
forall a. Num a => a -> a -> a
*(a
ea -> a -> a
forall a. Num a => a -> a -> a
*a
ia -> a -> a
forall a. Num a => a -> a -> a
-a
fa -> a -> a
forall a. Num a => a -> a -> a
*a
h) a -> a -> a
forall a. Num a => a -> a -> a
- a
ba -> a -> a
forall a. Num a => a -> a -> a
*(a
da -> a -> a
forall a. Num a => a -> a -> a
*a
ia -> a -> a
forall a. Num a => a -> a -> a
-a
fa -> a -> a
forall a. Num a => a -> a -> a
*a
g) a -> a -> a
forall a. Num a => a -> a -> a
+ a
ca -> a -> a
forall a. Num a => a -> a -> a
*(a
da -> a -> a
forall a. Num a => a -> a -> a
*a
ha -> a -> a
forall a. Num a => a -> a -> a
-a
ea -> a -> a
forall a. Num a => a -> a -> a
*a
g)
mult :: [[b]] -> [b] -> [b]
mult [[b]]
l [b]
x = ([b] -> b) -> [[b]] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map ([b] -> b
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum ([b] -> b) -> ([b] -> [b]) -> [b] -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((b -> b -> b) -> [b] -> [b] -> [b]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith b -> b -> b
forall a. Num a => a -> a -> a
(*) [b]
x)) [[b]]
l
matrixMult :: [[a]] -> [[a]] -> [[a]]
matrixMult [[a]]
l [[a]]
m = [[a]] -> [[a]]
forall a. [[a]] -> [[a]]
transpose (([a] -> [a]) -> [[a]] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map ([[a]] -> [a] -> [a]
forall b. Num b => [[b]] -> [b] -> [b]
mult [[a]]
l) ([[a]] -> [[a]]
forall a. [[a]] -> [[a]]
transpose [[a]]
m))