From 9d562c0b12c300b1d95bb5f763c08cdd087eb570 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 14 Dec 2007 16:45:34 +0000 Subject: [PATCH] Corrected checkConstantEq to actually remove the constant equations, rather than only checking them for consistency --- transformations/ArrayUsageCheck.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/transformations/ArrayUsageCheck.hs b/transformations/ArrayUsageCheck.hs index d158c9b..5c3a5fe 100644 --- a/transformations/ArrayUsageCheck.hs +++ b/transformations/ArrayUsageCheck.hs @@ -216,11 +216,12 @@ mygcdList (x:xs) = foldl mygcd x xs -- and turns any 2x + y <= 4, 2x + y >= 4 pairs into equalities. The list of such equalities -- (which may well be an empty list) and the remaining inequalities is returned. -- As an additional step not specified in the paper, equations with no variables in them are checked --- for consistency. That is, all equations c >= 0 (where c is constant) are checked to ensure c is indeed >= 0. +-- for consistency. That is, all equations c >= 0 (where c is constant) are checked to +-- ensure c is indeed >= 0, and those equations are removed. pruneAndCheck :: InequalityProblem -> Maybe (EqualityProblem, InequalityProblem) pruneAndCheck ineq = do let (opps,others) = splitEither $ groupOpposites $ map pruneGroup groupedIneq (opps', eq) <- mapM checkOpposite opps >>* splitEither - checked <- mapM checkConstantEq (concat opps' ++ others) + checked <- mapM checkConstantEq (concat opps' ++ others) >>* catMaybes return (eq, checked) where groupedIneq = groupBy (\x y -> EQ == coeffSort x y) $ sortBy coeffSort ineq @@ -283,9 +284,16 @@ pruneAndCheck ineq = do let (opps,others) = splitEither $ groupOpposites $ map p | (x ! 0) + (y ! 0) == 0 = Just $ Right x | otherwise = Just $ Left [x,y] - checkConstantEq :: InequalityConstraintEquation -> Maybe InequalityConstraintEquation - checkConstantEq eq | all (== 0) (tail $ elems eq) = if (eq ! 0) >= 0 then Just eq else Nothing - | otherwise = Just eq + -- The type of this function is quite confusing. We want to use in the Maybe monad, so + -- the outer type indicates error; Nothing is an error. Just x indicates non-failure, + -- but x may either be Just y (keep the equation) or Nothing (remove it). So the three + -- possible returns are: + -- * Nothing: Equation inconsistent + -- * Just Nothing: Equation redundant + -- * Just (Just e) : Keep equation. + checkConstantEq :: InequalityConstraintEquation -> Maybe (Maybe InequalityConstraintEquation) + checkConstantEq eq | all (== 0) (tail $ elems eq) = if (eq ! 0) >= 0 then Just Nothing else Nothing + | otherwise = Just $ Just eq -- | Returns Nothing if there is definitely no solution, or (Just ineq) if -- further investigation is needed