@@ -16,7 +16,6 @@ import Kore.Attribute.Pattern.FreeVariables (
1616 freeVariableNames ,
1717 occursIn ,
1818 )
19- import qualified Kore.Internal.Conditional as Conditional
2019import Kore.Internal.From
2120import Kore.Internal.MultiAnd (
2221 MultiAnd ,
@@ -29,11 +28,9 @@ import qualified Kore.Internal.MultiOr as MultiOr
2928import Kore.Internal.OrPattern (
3029 OrPattern ,
3130 )
32- import qualified Kore.Internal.OrPattern as OrPattern
3331import Kore.Internal.Pattern (
3432 Condition ,
3533 )
36- import qualified Kore.Internal.Pattern as Pattern
3734import Kore.Internal.Predicate (
3835 Predicate ,
3936 PredicateF (.. ),
@@ -47,7 +44,10 @@ import Kore.Internal.Substitution (
4744 pattern UnorderedAssignment ,
4845 )
4946import qualified Kore.Internal.Substitution as Substitution
50- import Kore.Internal.TermLike (TermLike )
47+ import Kore.Internal.TermLike (
48+ TermLike ,
49+ termLikeSort ,
50+ )
5151import qualified Kore.Internal.TermLike as TermLike
5252import Kore.Log.WarnUnsimplifiedPredicate (
5353 warnUnsimplifiedPredicate ,
@@ -56,6 +56,7 @@ import Kore.Rewrite.RewritingVariable (
5656 RewritingVariableName ,
5757 )
5858import qualified Kore.Simplify.Ceil as Ceil
59+ import qualified Kore.Simplify.Equals as Equals
5960import qualified Kore.Simplify.In as In
6061import qualified Kore.Simplify.Not as Not
6162import 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 )
7982import qualified Kore.Syntax.Exists as Exists
8083import qualified Kore.Syntax.Forall as Forall
81- import qualified Kore.TopBottom as TopBottom
82- import Kore.Unparser
8384import Logic
8485import 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
12594simplify ::
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+
530517simplifyIn ::
531518 MonadSimplify simplifier =>
532519 SideCondition RewritingVariableName ->
0 commit comments