@@ -273,8 +273,8 @@ enum Predicate {
273
273
case Not (p : Atomic & Predicate ) extends Predicate with Atomic
274
274
case Conj (s : Set [Predicate ])
275
275
case Disj (s : Set [Predicate ])
276
- case BVCmp (op : BVCmpOp , x : BVTerm , y : BVTerm ) extends Predicate with Atomic
277
- case GammaCmp (op : BoolCmpOp , x : GammaTerm , y : GammaTerm ) extends Predicate with Atomic
276
+ case BVCmp (op : BVCmpOp | PolyCmp , x : BVTerm , y : BVTerm ) extends Predicate with Atomic
277
+ case GammaCmp (op : BoolCmpOp | PolyCmp , x : GammaTerm , y : GammaTerm ) extends Predicate with Atomic
278
278
279
279
private var simplified : Boolean = false
280
280
@@ -578,19 +578,19 @@ enum Predicate {
578
578
case Conj (s2) => cur - p ++ s2
579
579
case Not (p) if cur.contains(p) => Set (False )
580
580
case BVCmp (BVSLE , a, b) if cur.contains(BVCmp (BVSLE , b, a)) =>
581
- cur - p - BVCmp (BVSLE , b, a) + BVCmp (BVEQ , a, b).simplify
581
+ cur - p - BVCmp (BVSLE , b, a) + BVCmp (EQ , a, b).simplify
582
582
case BVCmp (BVSLE , a, b) if cur.contains(BVCmp (BVSGE , a, b)) =>
583
- cur - p - BVCmp (BVSGE , a, b) + BVCmp (BVEQ , a, b).simplify
583
+ cur - p - BVCmp (BVSGE , a, b) + BVCmp (EQ , a, b).simplify
584
584
case BVCmp (BVSGE , a, b) if cur.contains(BVCmp (BVSGE , b, a)) =>
585
- cur - p - BVCmp (BVSGE , b, a) + BVCmp (BVEQ , a, b).simplify
585
+ cur - p - BVCmp (BVSGE , b, a) + BVCmp (EQ , a, b).simplify
586
586
case BVCmp (BVULE , a, b) if cur.contains(BVCmp (BVULE , b, a)) =>
587
- cur - p - BVCmp (BVULE , b, a) + BVCmp (BVEQ , a, b).simplify
587
+ cur - p - BVCmp (BVULE , b, a) + BVCmp (EQ , a, b).simplify
588
588
case BVCmp (BVULE , a, b) if cur.contains(BVCmp (BVUGE , a, b)) =>
589
- cur - p - BVCmp (BVUGE , a, b) + BVCmp (BVEQ , a, b).simplify
589
+ cur - p - BVCmp (BVUGE , a, b) + BVCmp (EQ , a, b).simplify
590
590
case BVCmp (BVUGE , a, b) if cur.contains(BVCmp (BVUGE , b, a)) =>
591
- cur - p - BVCmp (BVUGE , b, a) + BVCmp (BVEQ , a, b).simplify
591
+ cur - p - BVCmp (BVUGE , b, a) + BVCmp (EQ , a, b).simplify
592
592
case GammaCmp (BoolIMPLIES , a, b) if cur.contains(GammaCmp (BoolIMPLIES , b, a)) =>
593
- cur - p - GammaCmp (BoolIMPLIES , b, a) + GammaCmp (BoolEQ , a, b).simplify
593
+ cur - p - GammaCmp (BoolIMPLIES , b, a) + GammaCmp (EQ , a, b).simplify
594
594
case Disj (s2) if s.intersect(s2).nonEmpty => cur - p
595
595
case _ => cur
596
596
}
@@ -662,22 +662,22 @@ enum Predicate {
662
662
case BVCmp (BVUGT , a, b) if cur.contains(BVCmp (BVUGE , b, a)) => cur - p - BVCmp (BVUGE , b, a) + True
663
663
case BVCmp (BVUGT , a, b) if cur.contains(BVCmp (BVULE , a, b)) => cur - p - BVCmp (BVULE , a, b) + True
664
664
665
- case BVCmp (BVSLT , a, b) if cur.contains(BVCmp (BVEQ , a, b)) =>
666
- cur - p - BVCmp (BVEQ , a, b) + BVCmp (BVSLE , a, b).simplify
667
- case BVCmp (BVSLT , a, b) if cur.contains(BVCmp (BVEQ , b, a)) =>
668
- cur - p - BVCmp (BVEQ , b, a) + BVCmp (BVSLE , a, b).simplify
669
- case BVCmp (BVSGT , a, b) if cur.contains(BVCmp (BVEQ , a, b)) =>
670
- cur - p - BVCmp (BVEQ , a, b) + BVCmp (BVSGE , a, b).simplify
671
- case BVCmp (BVSGT , a, b) if cur.contains(BVCmp (BVEQ , b, a)) =>
672
- cur - p - BVCmp (BVEQ , b, a) + BVCmp (BVSGE , a, b).simplify
673
- case BVCmp (BVULT , a, b) if cur.contains(BVCmp (BVEQ , a, b)) =>
674
- cur - p - BVCmp (BVEQ , a, b) + BVCmp (BVULE , a, b).simplify
675
- case BVCmp (BVULT , a, b) if cur.contains(BVCmp (BVEQ , b, a)) =>
676
- cur - p - BVCmp (BVEQ , b, a) + BVCmp (BVULE , a, b).simplify
677
- case BVCmp (BVUGT , a, b) if cur.contains(BVCmp (BVEQ , a, b)) =>
678
- cur - p - BVCmp (BVEQ , a, b) + BVCmp (BVUGE , a, b).simplify
679
- case BVCmp (BVUGT , a, b) if cur.contains(BVCmp (BVEQ , b, a)) =>
680
- cur - p - BVCmp (BVEQ , b, a) + BVCmp (BVUGE , a, b).simplify
665
+ case BVCmp (BVSLT , a, b) if cur.contains(BVCmp (EQ , a, b)) =>
666
+ cur - p - BVCmp (EQ , a, b) + BVCmp (BVSLE , a, b).simplify
667
+ case BVCmp (BVSLT , a, b) if cur.contains(BVCmp (EQ , b, a)) =>
668
+ cur - p - BVCmp (EQ , b, a) + BVCmp (BVSLE , a, b).simplify
669
+ case BVCmp (BVSGT , a, b) if cur.contains(BVCmp (EQ , a, b)) =>
670
+ cur - p - BVCmp (EQ , a, b) + BVCmp (BVSGE , a, b).simplify
671
+ case BVCmp (BVSGT , a, b) if cur.contains(BVCmp (EQ , b, a)) =>
672
+ cur - p - BVCmp (EQ , b, a) + BVCmp (BVSGE , a, b).simplify
673
+ case BVCmp (BVULT , a, b) if cur.contains(BVCmp (EQ , a, b)) =>
674
+ cur - p - BVCmp (EQ , a, b) + BVCmp (BVULE , a, b).simplify
675
+ case BVCmp (BVULT , a, b) if cur.contains(BVCmp (EQ , b, a)) =>
676
+ cur - p - BVCmp (EQ , b, a) + BVCmp (BVULE , a, b).simplify
677
+ case BVCmp (BVUGT , a, b) if cur.contains(BVCmp (EQ , a, b)) =>
678
+ cur - p - BVCmp (EQ , a, b) + BVCmp (BVUGE , a, b).simplify
679
+ case BVCmp (BVUGT , a, b) if cur.contains(BVCmp (EQ , b, a)) =>
680
+ cur - p - BVCmp (EQ , b, a) + BVCmp (BVUGE , a, b).simplify
681
681
682
682
case Conj (s2) if s.intersect(s2).nonEmpty => cur - p
683
683
case _ => cur
@@ -695,15 +695,15 @@ enum Predicate {
695
695
import BVTerm .*
696
696
(op, a.simplify, b.simplify) match {
697
697
case (op, BVTerm .Lit (a), BVTerm .Lit (b)) => if evalBVLogBinExpr(op, a, b) then True else False
698
- case (BVEQ , a, b) if a == b => True
699
- case (BVEQ , a, Uop (BVNEG , b)) => BVCmp (BVEQ , Bop (BVADD , a, b), BVTerm .Lit (BitVecLiteral (0 , a.size))).simplify
700
- case (BVEQ , l : BVTerm .Lit , v : Var ) => BVCmp (BVEQ , v, l) // Canonical form-ish (to remove duplicate terms
698
+ case (EQ , a, b) if a == b => True
699
+ case (EQ , a, Uop (BVNEG , b)) => BVCmp (EQ , Bop (BVADD , a, b), BVTerm .Lit (BitVecLiteral (0 , a.size))).simplify
700
+ case (EQ , l : BVTerm .Lit , v : Var ) => BVCmp (EQ , v, l) // Canonical form-ish (to remove duplicate terms
701
701
case (op, a, b) => BVCmp (op, a, b)
702
702
}
703
703
case GammaCmp (op, a, b) =>
704
704
(op, a.simplify, b.simplify) match {
705
705
case (BoolIMPLIES , a, b) if a == b => True
706
- case (BoolEQ , a, b) if a == b => True
706
+ case (EQ , a, b) if a == b => True
707
707
case (op, a, b) => GammaCmp (op, a, b)
708
708
}
709
709
case _ => this
@@ -748,22 +748,21 @@ object Predicate {
748
748
749
749
def or (ps : Predicate * ): Predicate = Disj (ps.toSet).flatten
750
750
751
- def bop (op : BoolBinOp , a : Predicate , b : Predicate ): Predicate = {
751
+ def bop (op : ( BoolBinOp | PolyCmp ) , a : Predicate , b : Predicate ): Predicate = {
752
752
op match {
753
- case BoolEQ => or(and(not(a), not(b)), and(a, b))
754
- case BoolNEQ => or(and(not(a), b), and(a, not(b)))
753
+ case EQ => or(and(not(a), not(b)), and(a, b))
754
+ case NEQ => or(and(not(a), b), and(a, not(b)))
755
755
case BoolAND => and(a, b)
756
756
case BoolOR => or(a, b)
757
757
case BoolIMPLIES => or(not(a), b)
758
- case BoolEQUIV => bop(BoolEQ , a, b)
759
758
}
760
759
}
761
760
762
761
def implies (a : Predicate , b : Predicate ): Predicate = bop(BoolIMPLIES , a, b)
763
762
764
763
def gammaLeq (a : GammaTerm , b : GammaTerm ) = GammaCmp (BoolIMPLIES , b, a)
765
764
def gammaGeq (a : GammaTerm , b : GammaTerm ) = GammaCmp (BoolIMPLIES , a, b)
766
- def gammaEq (a : GammaTerm , b : GammaTerm ) = GammaCmp (BoolEQ , a, b)
765
+ def gammaEq (a : GammaTerm , b : GammaTerm ) = GammaCmp (EQ , a, b)
767
766
}
768
767
769
768
/**
@@ -804,10 +803,22 @@ def exprToGammaTerm(e: Expr): Option[GammaTerm] = e match {
804
803
def exprToPredicate (e : Expr ): Option [Predicate ] = e match {
805
804
case b : BoolLit => Some (Predicate .Lit (b))
806
805
case UnaryExpr (BoolNOT , arg) => exprToPredicate(arg).map(p => Predicate .not(p))
807
- case BinaryExpr (op : BoolBinOp , arg1, arg2) =>
808
- exprToPredicate(arg1).flatMap(p => exprToPredicate(arg2).map(q => Predicate .bop(op, p, q)))
809
- case BinaryExpr (op : BVCmpOp , arg1, arg2) =>
810
- exprToBVTerm(arg1).flatMap(p => exprToBVTerm(arg2).map(q => Predicate .BVCmp (op, p, q)))
806
+ case BinaryExpr (op : (PolyCmp | BVCmpOp | BoolCmpOp ), arg1, arg2) =>
807
+ (
808
+ List (arg1, arg2).map(e =>
809
+ e.getType match {
810
+ case BoolType => exprToPredicate(e)
811
+ case _ : BitVecType => exprToBVTerm(e)
812
+ case _ => None
813
+ }
814
+ ),
815
+ op
816
+ ) match {
817
+ case (Some (l : Predicate ) :: Some (r : Predicate ) :: Nil , op : (BoolCmpOp | PolyCmp )) => Some (Predicate .bop(op, l, r))
818
+ case (Some (l : BVTerm ) :: Some (r : BVTerm ) :: Nil , op : (BVCmpOp | PolyCmp )) => Some (Predicate .BVCmp (op, l, r))
819
+ case _ => None
820
+ }
821
+
811
822
case _ => None
812
823
}
813
824
0 commit comments