@@ -59,7 +59,9 @@ simplifyPred' c@(Impl ids p1 p2) = do
5959 p2' <- simpl subst p2
6060 let subst' = collectSubst p2'
6161 p2'' <- simpl subst' p2'
62- return $ removeTrivialImpls . removeTrivialIds $ (Impl ids p1' p2'')
62+ p1'' <- simplifyPred' p1
63+ p2'' <- simplifyPred' p2''
64+ return $ removeTrivialImpls . removeTrivialIds $ Impl ids p1'' p2''
6365
6466simplifyPred' c@ (Exists id k p) = do
6567 p' <- simplifyPred' p
@@ -71,7 +73,36 @@ simplifyPred' c@(Exists id k p) = do
7173simplifyPred' c@ (NegPred p) =
7274 simplifyPred' p >>= return . NegPred
7375
74- simplifyPred' (Con c) = return (Con c)
76+ simplifyPred' (Con c) =
77+ case simplifyConstraint c of
78+ Nothing -> return (Conj [] )
79+ Just c' -> return (Con c')
80+
81+ -- simplify a constraint, returning Nothing if it is trivial
82+ -- (e.g. x == x) or Just the simplified constraint (which could)
83+ -- be the same as the original constraint if simplifications cannot be applied
84+ simplifyConstraint :: Constraint -> Maybe Constraint
85+ simplifyConstraint (Eq t c1 c2 k) =
86+ if c1 == c2
87+ then Nothing
88+ else Just (Eq t c1 c2 k)
89+ simplifyConstraint cc@ (ApproximatedBy t c1 c2 k) =
90+ if c1 == c2
91+ then Nothing
92+ else Just (ApproximatedBy t c1 c2 k)
93+ simplifyConstraint (Neq t c1 c2 k) =
94+ if c1 == c2
95+ then Nothing
96+ else Just (Neq t c1 c2 k)
97+ simplifyConstraint (LtEq t c1 c2) =
98+ if c1 == c2
99+ then Nothing
100+ else Just (LtEq t c1 c2)
101+ simplifyConstraint (GtEq t c1 c2) =
102+ if c1 == c2
103+ then Nothing
104+ else Just (GtEq t c1 c2)
105+ simplifyConstraint c = Just c
75106
76107flatten :: Pred -> Pred
77108flatten (Conj [] ) = Conj []
0 commit comments