I am creating a Matrix module in Haskell, and I want to use QuickCheck to check some properties of my code. In particular, I want to generate random matrices that have a related inverse. Next up is my attempt to create a QuickCheck generator that generates such matrices.
invertibleMatrix :: (Num a, Arbitrary a) => Gen (Matrix a)
invertibleMatrix = do s <- choose (2,10)
a <- vectorOf s (vector s)
if (det (Matrix a) == 0) then
invertibleMatrix
else
return (Matrix a)
First, the code creates a size from 2 to 10, and then a vector of vectors of that size. If the determinant is zero, then the matrix is not invertible and therefore I call the invertible matrix recursively. Otherwise, I return a new matrix.
The problem is that this code does not end when I put it in a property for verification. (I think that he constantly creates the same sx s-matrix of zero elements, which obviously has no inverse and therefore goes into an infinite loop). What am I doing wrong? How to fix it? Thank.
Mark
source
share