module Data.Colour.Matrix where
import Data.List (transpose)
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
eforall a. Num a => a -> a -> a
*a
iforall a. Num a => a -> a -> a
-a
fforall a. Num a => a -> a -> a
*a
h)forall a. Fractional a => a -> a -> a
/a
det, -(a
bforall a. Num a => a -> a -> a
*a
iforall a. Num a => a -> a -> a
-a
cforall a. Num a => a -> a -> a
*a
h)forall a. Fractional a => a -> a -> a
/a
det, (a
bforall a. Num a => a -> a -> a
*a
fforall a. Num a => a -> a -> a
-a
cforall a. Num a => a -> a -> a
*a
e)forall a. Fractional a => a -> a -> a
/a
det]
,[-(a
dforall a. Num a => a -> a -> a
*a
iforall a. Num a => a -> a -> a
-a
fforall a. Num a => a -> a -> a
*a
g)forall a. Fractional a => a -> a -> a
/a
det, (a
aforall a. Num a => a -> a -> a
*a
iforall a. Num a => a -> a -> a
-a
cforall a. Num a => a -> a -> a
*a
g)forall a. Fractional a => a -> a -> a
/a
det, -(a
aforall a. Num a => a -> a -> a
*a
fforall a. Num a => a -> a -> a
-a
cforall a. Num a => a -> a -> a
*a
d)forall a. Fractional a => a -> a -> a
/a
det]
,[(a
dforall a. Num a => a -> a -> a
*a
hforall a. Num a => a -> a -> a
-a
eforall a. Num a => a -> a -> a
*a
g)forall a. Fractional a => a -> a -> a
/a
det, -(a
aforall a. Num a => a -> a -> a
*a
hforall a. Num a => a -> a -> a
-a
bforall a. Num a => a -> a -> a
*a
g)forall a. Fractional a => a -> a -> a
/a
det, (a
aforall a. Num a => a -> a -> a
*a
eforall a. Num a => a -> a -> a
-a
bforall a. Num a => a -> a -> a
*a
d)forall a. Fractional a => a -> a -> a
/a
det]]
where
det :: a
det = 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
aforall a. Num a => a -> a -> a
*(a
eforall a. Num a => a -> a -> a
*a
iforall a. Num a => a -> a -> a
-a
fforall a. Num a => a -> a -> a
*a
h) forall a. Num a => a -> a -> a
- a
bforall a. Num a => a -> a -> a
*(a
dforall a. Num a => a -> a -> a
*a
iforall a. Num a => a -> a -> a
-a
fforall a. Num a => a -> a -> a
*a
g) forall a. Num a => a -> a -> a
+ a
cforall a. Num a => a -> a -> a
*(a
dforall a. Num a => a -> a -> a
*a
hforall a. Num a => a -> a -> a
-a
eforall a. Num a => a -> a -> a
*a
g)
mult :: [[b]] -> [b] -> [b]
mult [[b]]
l [b]
x = forall a b. (a -> b) -> [a] -> [b]
map (forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall a. Num a => a -> a -> a
(*) [b]
x)) [[b]]
l
matrixMult :: [[a]] -> [[a]] -> [[a]]
matrixMult [[a]]
l [[a]]
m = forall a. [[a]] -> [[a]]
transpose (forall a b. (a -> b) -> [a] -> [b]
map (forall {b}. Num b => [[b]] -> [b] -> [b]
mult [[a]]
l) (forall a. [[a]] -> [[a]]
transpose [[a]]
m))