Skip to content

Commit 7b87490

Browse files
Simplification.And.retractLocalFunction: cases for sort inj and builtins (#2166)
* Simplification.And.retractLocalFunction: cases for sort inj and builtins + tests * Update golden * Add integration test * test_andSimplification: remove "Constructor equality" test The "Constructor equality" test case doesn't make sense because both predicates under the conjunction should independently be \bottom. * retractLocalFunction: cleanup * Revert "Add integration test" This reverts commit f376a6f. It's not evident that this integration test checks something useful. Co-authored-by: Thomas Tuegel <ttuegel@mailbox.org> Co-authored-by: Thomas Tuegel <thomas.tuegel@runtimeverification.com>
1 parent a6d3bda commit 7b87490

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

kore/src/Kore/Step/Simplification/And.hs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ import Kore.Internal.TermLike
7272
( And (..)
7373
, pattern And_
7474
, pattern App_
75+
, pattern Builtin_
7576
, pattern Equals_
7677
, pattern Exists_
7778
, pattern Forall_
79+
, pattern Inj_
7880
, pattern Mu_
7981
, pattern Not_
8082
, pattern Nu_
@@ -351,18 +353,29 @@ global definitions (axioms) apply. We are looking for a 'TermLike' of the form
351353
\equals(f(...), C(...))
352354
@
353355
354-
where @f@ is a function and @C@ is a constructor. @retractLocalFunction@ will
355-
match an @\equals@ predicate with its arguments in either order, but the
356-
function pattern is always returned first in the 'Pair'.
356+
where @f@ is a function and @C@ is a constructor, sort injection or builtin.
357+
@retractLocalFunction@ will match an @\equals@ predicate with its arguments
358+
in either order, but the function pattern is always returned first in the
359+
'Pair'.
357360
358361
-}
359362
retractLocalFunction
360363
:: TermLike variable
361364
-> Maybe (Pair (TermLike variable))
362-
retractLocalFunction (Equals_ _ _ term1@(App_ symbol1 _) term2@(App_ symbol2 _))
363-
| isConstructor symbol1, isFunction symbol2 = Just (Pair term2 term1)
364-
| isConstructor symbol2, isFunction symbol1 = Just (Pair term1 term2)
365-
retractLocalFunction _ = Nothing
365+
retractLocalFunction =
366+
\case
367+
Equals_ _ _ term1 term2 -> go term1 term2 <|> go term2 term1
368+
_ -> Nothing
369+
where
370+
go term1@(App_ symbol1 _) term2
371+
| isFunction symbol1 =
372+
case term2 of
373+
App_ symbol2 _
374+
| isConstructor symbol2 -> Just (Pair term1 term2)
375+
Inj_ _ -> Just (Pair term1 term2)
376+
Builtin_ _ -> Just (Pair term1 term2)
377+
_ -> Nothing
378+
go _ _ = Nothing
366379

367380
applyAndIdempotenceAndFindContradictions
368381
:: InternalVariable variable

kore/test/Test/Kore/Step/Simplification/And.hs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -554,41 +554,41 @@ test_andSimplification =
554554
assertEqual "" (MultiOr.make [expect]) actual
555555
, testGroup "Local function evaluation" $
556556
let f = Mock.f (mkElemVar Mock.x)
557+
fInt = Mock.fInt (mkElemVar Mock.xInt)
557558
defined = makeCeilPredicate_ f & Condition.fromPredicate
558559
a = Mock.a
559560
b = Mock.b
560-
mkLocalDefn (Left t) = makeEqualsPredicate_ t f
561-
mkLocalDefn (Right t) = makeEqualsPredicate_ f t
562-
test name eitherC1 eitherC2 =
561+
injA = Mock.sortInjection10 Mock.a
562+
injB = Mock.sortInjection10 Mock.b
563+
int2 = Mock.builtinInt 2
564+
int3 = Mock.builtinInt 3
565+
mkLocalDefn func (Left t) = makeEqualsPredicate_ t func
566+
mkLocalDefn func (Right t) = makeEqualsPredicate_ func t
567+
test name func eitherC1 eitherC2 =
563568
testCase name $ do
564-
let equals1 = mkLocalDefn eitherC1 & Condition.fromPredicate
565-
equals2 = mkLocalDefn eitherC2 & Condition.fromPredicate
569+
let equals1 = mkLocalDefn func eitherC1 & Condition.fromPredicate
570+
equals2 = mkLocalDefn func eitherC2 & Condition.fromPredicate
566571
pattern1 = Pattern.fromCondition_ (defined <> equals1)
567572
pattern2 = Pattern.fromCondition_ (defined <> equals2)
568573
actual <- evaluatePatterns pattern1 pattern2
569574
assertBool "Expected \\bottom" $ isBottom actual
570575
in
571-
[ test "contradiction: f(x) = a ∧ f(x) = b" (Right a) (Right b)
572-
, test "contradiction: a = f(x) ∧ f(x) = b" (Left a) (Right b)
573-
, test "contradiction: a = f(x) ∧ b = f(x)" (Left a) (Left b)
574-
, test "contradiction: f(x) = a ∧ b = f(x)" (Right a) (Left b)
576+
[ -- Constructor at top
577+
test "contradiction: f(x) = a ∧ f(x) = b" f (Right a) (Right b)
578+
, test "contradiction: a = f(x) ∧ f(x) = b" f (Left a) (Right b)
579+
, test "contradiction: a = f(x) ∧ b = f(x)" f (Left a) (Left b)
580+
, test "contradiction: f(x) = a ∧ b = f(x)" f (Right a) (Left b)
581+
-- Sort injection at top
582+
, test "contradiction: f(x) = injA ∧ f(x) = injB" f (Right injA) (Right injB)
583+
, test "contradiction: injA = f(x) ∧ f(x) = injB" f (Left injA) (Right injB)
584+
, test "contradiction: injA = f(x) ∧ injB = f(x)" f (Left injA) (Left injB)
585+
, test "contradiction: f(x) = injA ∧ injB = f(x)" f (Right injA) (Left injB)
586+
-- Builtin at top
587+
, test "contradiction: f(x) = 2 ∧ f(x) = 3" fInt (Right int2) (Right int3)
588+
, test "contradiction: 2 = f(x) ∧ f(x) = 3" fInt (Left int2) (Right int3)
589+
, test "contradiction: 2 = f(x) ∧ 3 = f(x)" fInt (Left int2) (Left int3)
590+
, test "contradiction: f(x) = 2 ∧ 3 = f(x)" fInt (Right int2) (Left int3)
575591
]
576-
, testCase "Constructor equality" $ do
577-
actual <-
578-
evaluatePatterns
579-
(makeEqualsPredicate_
580-
Mock.c
581-
Mock.a
582-
& Condition.fromPredicate
583-
& Pattern.fromCondition_
584-
)
585-
( makeEqualsPredicate_
586-
Mock.b
587-
Mock.c
588-
& Condition.fromPredicate
589-
& Pattern.fromCondition_
590-
)
591-
assertEqual "" (MultiOr.make []) actual
592592
]
593593
where
594594
yExpanded = Conditional

test/symbolic-ensures/1.strict.out.golden

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77
#Equals
88
true
99
}
10-
#And
11-
{
12-
true
13-
#Equals
14-
?X <=Int 3
15-
}
1610
#And
1711
{
1812
true

0 commit comments

Comments
 (0)