module Algebra.PLM
( propPLM
, computePLM_B
) where
import Algebra.Structures.CommutativeRing
import Algebra.Structures.BezoutDomain
import Algebra.Ideal
import Algebra.Matrix
propPLM :: (CommutativeRing a, Eq a) => Ideal a -> Matrix a -> Bool
propPLM (Id xs) (M vs)
| isSquareMatrix (M vs) =
let as = map unVec vs
sumDiag = sumRing [ ai !! i | (ai,i) <- zip as [0..]]
n = length as 1
ijl = and [ as !! l !! j <*> xs !! i ==
as !! l !! i <*> xs !! j
| i <- [0..n]
, j <- [0..n]
, l <- [0..n]
]
in one == sumDiag && ijl
| otherwise = error "isPLM: Not square matrix"
computePLM_B :: (BezoutDomain a, Eq a) => Ideal a -> Matrix a
computePLM_B (Id xs) =
let (Id [g],us,ys) = toPrincipal (Id xs)
n = length xs 1
in M [ Vec [ us !! i <*> ys !! j | j <- [0..n] ] | i <- [0..n] ]