Ejemplo n.º 1
0
        public override Answer CheckPredicate(Element /*!*/ e, IExpr /*!*/ pred)
        {
            //Contract.Requires(pred != null);
            //Contract.Requires(e != null);
            PolyhedraLatticeElement /*!*/ ple = (PolyhedraLatticeElement)Constrain(e, pred);

            Contract.Assert(ple != null);
            if (ple.lcs.IsBottom())
            {
                return(Answer.No);
            }

            // Note, "pred" may contain expressions that are not understood by the propFactory (in
            // particular, this may happen because--currently, and perhaps is a design we'll want
            // to change in the future--propFactory deals with BoogiePL expressions whereas "pred"
            // may also refer to Equivalences.UninterpFun expressions).  Thus, we cannot just
            // call propFactory.Not(pred) to get the negation of "pred".
            pred = new PolyhedraLatticeNegation(pred);
            ple  = (PolyhedraLatticeElement)Constrain(e, pred);
            if (ple.lcs.IsBottom())
            {
                return(Answer.Yes);
            }
            else
            {
                return(Answer.Maybe);
            }
        }
Ejemplo n.º 2
0
        public override Element /*!*/ Constrain(Element /*!*/ e, IExpr /*!*/ expr)
        {
            //Contract.Requires(expr != null);
            //Contract.Requires(e != null);
            Contract.Ensures(Contract.Result <Element>() != null);
            log.DbgMsg(string.Format("Constraining with {0} into {1} ...", expr, this.ToString(e)));

            PolyhedraLatticeElement ple = (PolyhedraLatticeElement)e;

            if (ple.lcs.IsBottom())
            {
                return(ple);
            }
            LinearCondition le = LinearExpressionBuilder.AsCondition(expr);

            if (le != null)
            {
                // update the polyhedron according to the linear expression
                Contract.Assume(ple.lcs.Constraints != null);
                ArrayList /*LinearConstraint*/ clist = (ArrayList /*!*/ /*LinearConstraint*/)cce.NonNull(ple.lcs.Constraints.Clone());
                le.AddToConstraintSystem(clist);
                LinearConstraintSystem newLcs = new LinearConstraintSystem(clist);

                return(new PolyhedraLatticeElement(newLcs));
            }
            return(ple);
        }
Ejemplo n.º 3
0
        public override bool IsTop(Element /*!*/ element)
        {
            //Contract.Requires(element != null);
            PolyhedraLatticeElement e = (PolyhedraLatticeElement)element;

            return(e.lcs.IsTop());
        }
Ejemplo n.º 4
0
        public override Answer CheckVariableDisequality(Element /*!*/ e, IVariable /*!*/ var1, IVariable /*!*/ var2)
        {
            //Contract.Requires(var2 != null);
            //Contract.Requires(var1 != null);
            //Contract.Requires(e != null);
            PolyhedraLatticeElement /*!*/ ple = (PolyhedraLatticeElement)cce.NonNull(e);

            Contract.Assume(ple.lcs.Constraints != null);
            ArrayList /*LinearConstraint!*//*!*/ clist = (ArrayList /*LinearConstraint!*/)cce.NonNull(ple.lcs.Constraints.Clone());
            LinearConstraint /*!*/ lc = new LinearConstraint(LinearConstraint.ConstraintRelation.EQ);

            Contract.Assert(lc != null);
            lc.SetCoefficient(var1, Rational.ONE);
            lc.SetCoefficient(var2, Rational.MINUS_ONE);
            clist.Add(lc);
            LinearConstraintSystem newLcs = new LinearConstraintSystem(clist);

            if (newLcs.IsBottom())
            {
                return(Answer.Yes);
            }
            else
            {
                return(Answer.Maybe);
            }
        }
Ejemplo n.º 5
0
        public override IExpr /*!*/ ToPredicate(Element /*!*/ element)
        {
            //Contract.Requires(element != null);
            Contract.Ensures(Contract.Result <IExpr>() != null);
            PolyhedraLatticeElement e = (PolyhedraLatticeElement)element;

            return(e.lcs.ConvertToExpression(factory));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns true iff a is a subset of this.
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        protected override bool AtMost(Element /*!*/ first, Element /*!*/ second) // this <= that
        {
            //Contract.Requires(first != null);
            //Contract.Requires(second != null);
            PolyhedraLatticeElement a = (PolyhedraLatticeElement)first;
            PolyhedraLatticeElement b = (PolyhedraLatticeElement)second;

            return(b.lcs.IsSubset(a.lcs));
        }
Ejemplo n.º 7
0
        public override Lattice.Element /*!*/ NontrivialMeet(Element /*!*/ first, Element /*!*/ second)
        {
            //Contract.Requires(second != null);
            //Contract.Requires(first != null);
            Contract.Ensures(Contract.Result <Lattice.Element>() != null);
            PolyhedraLatticeElement aa = (PolyhedraLatticeElement)first;
            PolyhedraLatticeElement bb = (PolyhedraLatticeElement)second;

            return(new PolyhedraLatticeElement(aa.lcs.Meet(bb.lcs)));
        }
Ejemplo n.º 8
0
        public override Element /*!*/ Eliminate(Element /*!*/ e, IVariable /*!*/ variable)
        {
            //Contract.Requires(variable != null);
            //Contract.Requires(e != null);
            Contract.Ensures(Contract.Result <Element>() != null);
            log.DbgMsg(string.Format("Eliminating {0} ...", variable));

            PolyhedraLatticeElement ple = (PolyhedraLatticeElement)e;

            if (ple.lcs.IsBottom())
            {
                return(ple);
            }
            return(new PolyhedraLatticeElement(ple.lcs.Project(variable)));
        }
Ejemplo n.º 9
0
        public override Lattice.Element /*!*/ NontrivialJoin(Element /*!*/ first, Element /*!*/ second)
        {
            //Contract.Requires(second != null);
            //Contract.Requires(first != null);
            Contract.Ensures(Contract.Result <Lattice.Element>() != null);
            log.DbgMsg("Joining ...");
            log.DbgMsgIndent();
            PolyhedraLatticeElement aa     = (PolyhedraLatticeElement)first;
            PolyhedraLatticeElement bb     = (PolyhedraLatticeElement)second;
            PolyhedraLatticeElement result = new PolyhedraLatticeElement(aa.lcs.Join(bb.lcs));

            log.DbgMsg(string.Format("{0} |_| {1} --> {2}", this.ToString(first), this.ToString(second), this.ToString(result)));
            log.DbgMsgUnindent();
            return(result);
        }
Ejemplo n.º 10
0
        public override Element /*!*/ Rename(Element /*!*/ e, IVariable /*!*/ oldName, IVariable /*!*/ newName)
        {
            //Contract.Requires(newName != null);
            //Contract.Requires(oldName != null);
            //Contract.Requires(e != null);
            Contract.Ensures(Contract.Result <Element>() != null);
            log.DbgMsg(string.Format("Renaming {0} to {1} in {2} ...", oldName, newName, this.ToString(e)));

            PolyhedraLatticeElement ple = (PolyhedraLatticeElement)e;

            if (ple.lcs.IsBottom())
            {
                return(ple);
            }
            return(new PolyhedraLatticeElement(ple.lcs.Rename(oldName, newName)));
        }
Ejemplo n.º 11
0
    public override Lattice.Element/*!*/ Widen(Element/*!*/ first, Element/*!*/ second) {
      //Contract.Requires(second != null);
      //Contract.Requires(first != null);
      Contract.Ensures(Contract.Result<Lattice.Element>() != null);
      log.DbgMsg("Widening ...");
      log.DbgMsgIndent();
      PolyhedraLatticeElement aa = (PolyhedraLatticeElement)first;
      PolyhedraLatticeElement bb = (PolyhedraLatticeElement)second;

      LinearConstraintSystem lcs = aa.lcs.Widen(bb.lcs);
      PolyhedraLatticeElement result = new PolyhedraLatticeElement(lcs);
      log.DbgMsg(string.Format("{0} |_| {1} --> {2}", this.ToString(first), this.ToString(second), this.ToString(result)));
      log.DbgMsgUnindent();
      return result;
    }