Skip to content

Commit 757e5e2

Browse files
ana-pantiliegithub-actions
andauthored
Overhaul Predicate simplifier: Equals, v2 (#2766)
* Overhaul Predicate simplifier: Equals, v2 * Format with fourmolu * Add sort info to simplifyEquals * Address review comment Co-authored-by: github-actions <github-actions@github.com>
1 parent 30641b7 commit 757e5e2

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

kore/src/Kore/Simplify/Predicate.hs

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Kore.Attribute.Pattern.FreeVariables (
1616
freeVariableNames,
1717
occursIn,
1818
)
19-
import qualified Kore.Internal.Conditional as Conditional
2019
import Kore.Internal.From
2120
import Kore.Internal.MultiAnd (
2221
MultiAnd,
@@ -29,11 +28,9 @@ import qualified Kore.Internal.MultiOr as MultiOr
2928
import Kore.Internal.OrPattern (
3029
OrPattern,
3130
)
32-
import qualified Kore.Internal.OrPattern as OrPattern
3331
import Kore.Internal.Pattern (
3432
Condition,
3533
)
36-
import qualified Kore.Internal.Pattern as Pattern
3734
import Kore.Internal.Predicate (
3835
Predicate,
3936
PredicateF (..),
@@ -47,7 +44,10 @@ import Kore.Internal.Substitution (
4744
pattern UnorderedAssignment,
4845
)
4946
import qualified Kore.Internal.Substitution as Substitution
50-
import Kore.Internal.TermLike (TermLike)
47+
import Kore.Internal.TermLike (
48+
TermLike,
49+
termLikeSort,
50+
)
5151
import qualified Kore.Internal.TermLike as TermLike
5252
import Kore.Log.WarnUnsimplifiedPredicate (
5353
warnUnsimplifiedPredicate,
@@ -56,6 +56,7 @@ import Kore.Rewrite.RewritingVariable (
5656
RewritingVariableName,
5757
)
5858
import qualified Kore.Simplify.Ceil as Ceil
59+
import qualified Kore.Simplify.Equals as Equals
5960
import qualified Kore.Simplify.In as In
6061
import qualified Kore.Simplify.Not as Not
6162
import Kore.Simplify.Simplify
@@ -64,6 +65,7 @@ import Kore.Syntax (
6465
And (..),
6566
Bottom (..),
6667
Ceil (..),
68+
Equals (..),
6769
Exists (..),
6870
Floor (..),
6971
Forall (Forall),
@@ -73,47 +75,14 @@ import Kore.Syntax (
7375
Not (..),
7476
Or (..),
7577
SomeVariableName,
78+
Sort,
7679
Top (..),
7780
variableName,
7881
)
7982
import qualified Kore.Syntax.Exists as Exists
8083
import qualified Kore.Syntax.Forall as Forall
81-
import qualified Kore.TopBottom as TopBottom
82-
import Kore.Unparser
8384
import Logic
8485
import Prelude.Kore
85-
import qualified Pretty
86-
87-
{- | Simplify the 'Predicate' once.
88-
89-
@simplifyPredicate@ does not attempt to apply the resulting substitution and
90-
re-simplify the result.
91-
92-
See also: 'simplify'
93-
-}
94-
simplifyPredicateTODO ::
95-
( HasCallStack
96-
, MonadSimplify simplifier
97-
) =>
98-
SideCondition RewritingVariableName ->
99-
Predicate RewritingVariableName ->
100-
LogicT simplifier (MultiAnd (Predicate RewritingVariableName))
101-
simplifyPredicateTODO sideCondition predicate = do
102-
patternOr <-
103-
simplifyTermLike sideCondition (Predicate.fromPredicate_ predicate)
104-
& lift
105-
-- Despite using lift above, we do not need to
106-
-- explicitly check for \bottom because patternOr is an OrPattern.
107-
from @(Condition _) @(MultiAnd (Predicate _)) <$> scatter (OrPattern.map eraseTerm patternOr)
108-
where
109-
eraseTerm conditional
110-
| TopBottom.isTop (Pattern.term conditional) =
111-
Conditional.withoutTerm conditional
112-
| otherwise =
113-
(error . show . Pretty.vsep)
114-
[ "Expecting a \\top term, but found:"
115-
, unparse conditional
116-
]
11786

11887
{- | @NormalForm@ is the normal form result of simplifying 'Predicate'.
11988
The primary purpose of this form is to transmit to the external solver.
@@ -124,7 +93,6 @@ type NormalForm = MultiOr (MultiAnd (Predicate RewritingVariableName))
12493

12594
simplify ::
12695
forall simplifier.
127-
HasCallStack =>
12896
MonadSimplify simplifier =>
12997
SideCondition RewritingVariableName ->
13098
Predicate RewritingVariableName ->
@@ -180,9 +148,11 @@ simplify sideCondition original =
180148
ForallF forallF ->
181149
traverse worker (Forall.refreshForall avoid forallF)
182150
>>= simplifyForall sideCondition
151+
EqualsF equalsF@(Equals _ _ term _) ->
152+
simplifyEquals sideCondition (termLikeSort term)
153+
=<< traverse simplifyTerm equalsF
183154
InF inF ->
184155
simplifyIn sideCondition =<< traverse simplifyTerm inF
185-
_ -> simplifyPredicateTODO sideCondition predicate & MultiOr.observeAllT
186156
where
187157
_ :< predicateF = Recursive.project predicate
188158
~avoid = freeVariableNames sideCondition
@@ -527,6 +497,23 @@ extractFirstAssignment someVariableName predicates =
527497
(guard . not) (someVariableName `occursIn` termLike)
528498
pure termLike
529499

500+
simplifyEquals ::
501+
forall simplifier sort.
502+
MonadSimplify simplifier =>
503+
SideCondition RewritingVariableName ->
504+
Sort ->
505+
Equals sort (OrPattern RewritingVariableName) ->
506+
simplifier NormalForm
507+
simplifyEquals sideCondition sort equals =
508+
Equals.simplify sideCondition equals'
509+
<&> MultiOr.map (from @(Condition _))
510+
where
511+
equals' =
512+
equals
513+
{ equalsOperandSort = sort
514+
, equalsResultSort = sort
515+
}
516+
530517
simplifyIn ::
531518
MonadSimplify simplifier =>
532519
SideCondition RewritingVariableName ->

kore/src/Kore/Simplify/Predicate.hs-boot

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import Kore.Rewrite.RewritingVariable (
2222
RewritingVariableName,
2323
)
2424
import Kore.Simplify.Simplify
25-
import Prelude.Kore
2625

2726
-- TODO (thomas.tuegel): Remove this file when the TermLike simplifier no longer
2827
-- depends on the Condition simplifier.
@@ -31,7 +30,6 @@ type NormalForm = MultiOr (MultiAnd (Predicate RewritingVariableName))
3130

3231
simplify ::
3332
forall simplifier.
34-
HasCallStack =>
3533
MonadSimplify simplifier =>
3634
SideCondition RewritingVariableName ->
3735
Predicate RewritingVariableName ->

0 commit comments

Comments
 (0)