From cba5ff45f1135a20454e8445c0470ece1ee3eba9 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 12 Dec 2007 14:16:29 +0000 Subject: [PATCH] Fixed a small bug in the equation normalisation --- transformations/ArrayUsageCheck.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/transformations/ArrayUsageCheck.hs b/transformations/ArrayUsageCheck.hs index 5e47b3d..6a71d1a 100644 --- a/transformations/ArrayUsageCheck.hs +++ b/transformations/ArrayUsageCheck.hs @@ -77,8 +77,13 @@ solveConstraints p ineq normalise = mapM normalise' --Note the mapM; if any calls to normalise' fail, so will normalise where normalise' :: EqualityConstraintEquation -> Maybe EqualityConstraintEquation - normalise' e = let g = foldl1 gcd (elems e) in - if (((e ! 0) `mod` g) /= 0) then Nothing else Just $ amap (\x -> x `div` g) e + normalise' e = let g = foldl1 gcd (tail $ elems e) in -- g is the GCD of a_1 .. a_n (not a_0) + if (g == 0) + then Just e + else (if (((e ! 0) `mod` g) /= 0) -- If g doesn't divide a_0 + then Nothing + else Just $ amap (\x -> x `div` g) e -- Divide all coefficients by g + ) solve :: EqualityProblem -> StateT InequalityProblem Maybe EqualityProblem solve [] = return []