private bool TryHelperFor_MatchkY(Expression x, INumericalAbstractDomainQuery <Variable, Expression> adom, Expression y, Rational k, out Expression leqExp) { Contract.Requires(adom != null); Contract.Requires(y != null); Contract.Requires(!object.ReferenceEquals(k, null)); Contract.Ensures(!Contract.Result <bool>() || Contract.ValueAtReturn(out leqExp) != null); var yPositive = adom.CheckIfGreaterEqualThanZero(y); if (k >= 1 && yPositive.IsNormal()) { if (yPositive.BoxedElement) { leqExp = expManager.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.LessEqualThan, y, x); return(true); } else { leqExp = expManager.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.LessEqualThan, x, y); return(true); } } leqExp = default(Expression); return(false); }
public override Set <Expression> VisitOr(Expression left, Expression right, Expression original, INumericalAbstractDomainQuery <Variable, Expression> data) { var result = new Set <Expression>(); if (data == null || left == null || right == null) { return(result); } if (data.CheckIfGreaterEqualThanZero(left).IsTrue() && data.CheckIfGreaterEqualThanZero(right).IsTrue()) { result.Add(expManager.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.LessEqualThan, left, x)); result.Add(expManager.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.LessEqualThan, right, x)); } return(result); }
public List <Expression> InferConstraints(Expression x, Expression exp, INumericalAbstractDomainQuery <Variable, Expression> adom) { Contract.Ensures(Contract.Result <List <Expression> >() != null); var result = new List <Expression>(); if (adom == null) { return(result); } // This may appear straightforward and repeatitive, but sometimes the CheckIfxxx are more precise than what the abstract domain can track // (because of the refinement of the expressions, and the fact that they are "goal directed") // As a consequence, we add explicitely this information to the abstract domain var isGeqZero = adom.CheckIfGreaterEqualThanZero(exp); if (isGeqZero.IsNormal()) { var zero = ExpressionManager.Encoder.ConstantFor(0); if (isGeqZero.IsTrue()) { // Discovered the disequality : 0 <= x var newConstraint = ExpressionManager.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.GreaterEqualThan, x, zero); result.Add(newConstraint); } else { // Discovered the disequality : x < 0" var newConstraint = ExpressionManager.Encoder.CompoundExpressionFor(ExpressionType.Bool, ExpressionOperator.LessThan, x, zero); result.Add(newConstraint); } } return(result); }