@@ -481,6 +481,33 @@ mkSubstitution initialSubst =
481
481
)
482
482
breakCycles
483
483
484
+ -- | Given a equality @'Term'@, decide if it can be interpreted as substitution.
485
+ mbSubstitution ::
486
+ Internal. Term -> InternalisedPredicate
487
+ mbSubstitution = \ case
488
+ eq@ (Internal. EqualsInt (Internal. Var x) e)
489
+ | x `Set.member` freeVariables e -> boolPred eq
490
+ | otherwise -> SubstitutionPred x e
491
+ eq@ (Internal. EqualsInt e (Internal. Var x))
492
+ | x `Set.member` freeVariables e -> boolPred eq
493
+ | otherwise -> SubstitutionPred x e
494
+ eq@ (Internal. EqualsK (Internal. KSeq _sortL (Internal. Var x)) (Internal. KSeq _sortR e)) ->
495
+ do
496
+ -- NB sorts do not have to agree! (could be subsorts)
497
+ if (x `Set.member` freeVariables e)
498
+ then boolPred eq
499
+ else SubstitutionPred x e
500
+ eq@ (Internal. EqualsK (Internal. KSeq _sortL e) (Internal. KSeq _sortR (Internal. Var x))) ->
501
+ do
502
+ -- NB sorts do not have to agree! (could be subsorts)
503
+ if (x `Set.member` freeVariables e)
504
+ then boolPred eq
505
+ else SubstitutionPred x e
506
+ other ->
507
+ boolPred other
508
+ where
509
+ boolPred = BoolPred . Internal. Predicate
510
+
484
511
internalisePred ::
485
512
Flag " alias" ->
486
513
Flag " subsorts" ->
@@ -542,9 +569,9 @@ internalisePred allowAlias checkSubsorts sortVars definition@KoreDefinition{sort
542
569
case (argS, a, b) of
543
570
-- for "true" #Equals P, check whether P is in fact a substitution
544
571
(Internal. SortBool , Internal. TrueBool , x) ->
545
- mapM mbSubstitution [ x]
572
+ pure [ mbSubstitution x]
546
573
(Internal. SortBool , x, Internal. TrueBool ) ->
547
- mapM mbSubstitution [ x]
574
+ pure [ mbSubstitution x]
548
575
-- we could also detect NotBool (NEquals _) in "false" #Equals P
549
576
(Internal. SortBool , Internal. FalseBool , x) ->
550
577
pure [BoolPred $ Internal. Predicate $ Internal. NotBool x]
@@ -602,33 +629,6 @@ internalisePred allowAlias checkSubsorts sortVars definition@KoreDefinition{sort
602
629
throwE (IncompatibleSorts (map externaliseSort [s1, s2]))
603
630
zipWithM_ go args1 args2
604
631
605
- mbSubstitution :: Internal. Term -> Except PatternError InternalisedPredicate
606
- mbSubstitution = \ case
607
- eq@ (Internal. EqualsInt (Internal. Var x) e)
608
- | x `Set.member` freeVariables e -> pure $ boolPred eq
609
- | otherwise -> pure $ SubstitutionPred x e
610
- eq@ (Internal. EqualsInt e (Internal. Var x))
611
- | x `Set.member` freeVariables e -> pure $ boolPred eq
612
- | otherwise -> pure $ SubstitutionPred x e
613
- eq@ (Internal. EqualsK (Internal. KSeq _sortL (Internal. Var x)) (Internal. KSeq _sortR e)) ->
614
- do
615
- -- NB sorts do not have to agree! (could be subsorts)
616
- pure $
617
- if (x `Set.member` freeVariables e)
618
- then boolPred eq
619
- else SubstitutionPred x e
620
- eq@ (Internal. EqualsK (Internal. KSeq _sortL e) (Internal. KSeq _sortR (Internal. Var x))) ->
621
- do
622
- -- NB sorts do not have to agree! (could be subsorts)
623
- pure $
624
- if (x `Set.member` freeVariables e)
625
- then boolPred eq
626
- else SubstitutionPred x e
627
- other ->
628
- pure $ boolPred other
629
-
630
- boolPred = BoolPred . Internal. Predicate
631
-
632
632
----------------------------------------
633
633
634
634
-- for use with withAssoc
0 commit comments