From 88f7d1ec92af62a8a3f46bc26bf053613ef48d67 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 12 Dec 2007 17:40:37 +0000 Subject: [PATCH] Refactored the equation normalisation and added a custom GCD function --- transformations/ArrayUsageCheck.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/transformations/ArrayUsageCheck.hs b/transformations/ArrayUsageCheck.hs index 09e2b3e..df0ea01 100644 --- a/transformations/ArrayUsageCheck.hs +++ b/transformations/ArrayUsageCheck.hs @@ -77,13 +77,14 @@ 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 (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 - ) + normalise' e | g == 0 = Just e + | ((e ! 0) `mod` g) /= 0 = Nothing + | otherwise = Just $ amap (\x -> x `div` g) e + where g = foldl1 mygcd (map abs $ tail $ elems e) -- g is the GCD of a_1 .. a_n (not a_0) + + mygcd :: Integer -> Integer -> Integer + mygcd 0 0 = 0 + mygcd x y = gcd x y -- | Solves all equality problems in the given list. -- Will either succeed (Just () in the Error/Maybe monad) or fail (Nothing)