public virtual IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> AssumeEqual (TExpr left, TExpr right, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env) { var leftVar = env.Decoder.UnderlyingVariable(left); var rightVar = env.Decoder.UnderlyingVariable(right); if (env.Contains(leftVar)) { var res = env; var interval = env.Eval(left).Meet(env.Eval(right)); res = res.With(leftVar, interval); res = res.With(rightVar, interval); return(res); } if (env.Decoder.IsConstant(left) && env.Decoder.IsConstant(right) && env.Eval(left).Meet(env.Eval(right)).IsBottom) { return(env.Bottom); } return(env); }
public override IntervalEnvironmentBase <Var, Expr, DisInterval, Rational> AssumeNotEqual (Expr left, Expr right, IntervalEnvironmentBase <Var, Expr, DisInterval, Rational> env) { var result = env; var rightIntv = env.Eval(right); if (rightIntv.IsSinglePoint) { var everythingExcept = DisInterval.EverythingExcept(rightIntv); result = result.RefineVariable(env.Decoder.UnderlyingVariable(left), everythingExcept); } IntervalInference.InferenceResult <Var, DisInterval> resultLeft; IntervalInference.InferenceResult <Var, DisInterval> resultRight; IntervalInference.ConstraintsFor.NotEqual(left, right, env.Decoder, result, out resultLeft, out resultRight); var join = resultLeft.Join(resultRight); if (join.IsBottom) { return(env.Bottom as IntervalEnvironmentBase <Var, Expr, DisInterval, Rational>); } return(AssumeConstraints(join.Constraints, env)); }
public override IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> AssumeNotEqualToZero (TExpr e, IntervalEnvironmentBase < TVar , TExpr , TInterval , Rational > env) { var variable = env.Decoder.UnderlyingVariable(e); var intv = env.Eval(e); TInterval refinement; if (intv.LowerBound.IsZero) { refinement = env.Context.For(1L, intv.UpperBound); } else if (intv.UpperBound.IsZero) { refinement = env.Context.For(intv.LowerBound, -1L); } else { refinement = env.Context.TopValue; } return(env.With(variable, intv.Meet(refinement))); }
public override IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> Visit(TExpr expr, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> data) { var res = base.Visit(expr, data); if (!Decoder.IsBinaryExpression(expr)) { return(res); } var left = Decoder.LeftExpressionFor(expr); var right = Decoder.RightExpressionFor(expr); var intv = data.Eval(right); if (intv.IsBottom) { return(data.Bottom); } if (!intv.IsSinglePoint) { return(res); } switch (Decoder.OperatorFor(expr)) { case ExpressionOperator.LessThan: { var leftVar = Decoder.UnderlyingVariable(left); return(res.Assumer.AssumeLessEqualThan(intv, leftVar, res)); } case ExpressionOperator.LessEqualThan: { var leftVar = Decoder.UnderlyingVariable(left); return(res.Assumer.AssumeLessThan(intv, leftVar, res)); } } return(data); }