public override IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> AssumeLessThan
            (TExpr left, TExpr right, IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> env)
        {
            bool isBottom;
            var  constraints =
                IntervalInference.ConstraintsFor.LessThan <IIntervalEnvironment <TVar, TExpr, TInterval, Rational>, TVar, TExpr, TInterval>
                    (left, right, env.Decoder, env, out isBottom);

            if (isBottom)
            {
                return(env.Bottom);
            }

            var res = env;

            foreach (var v in constraints.Keys)
            {
                var intervals = constraints[v].AsEnumerable();
                foreach (var intv in intervals)
                {
                    res = res.RefineVariable(v, intv);
                }
            }

            return(res);
        }
        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)));
        }
Example #3
0
        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));
        }
Example #4
0
 public override IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> VisitMultiply
     (TExpr left, TExpr right, TExpr original,
     IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env)
 {
     env = base.VisitMultiply(left, right, original, env);
     return(env.Assumer.AssumeNotEqualToZero(original, env));
 }
Example #5
0
        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);
        }
Example #6
0
 protected override IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> DispatchCompare(
     CompareVisitor cmp, TExpr left, TExpr right, TExpr original,
     IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> data)
 {
     data = cmp(left, right, original, data);
     return(base.DispatchCompare(cmp, left, right, original, data));
 }
Example #7
0
 public abstract IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> AssumeLessThan
     (TExpr left,
     TExpr right,
     IntervalEnvironmentBase
     <TVar,
      TExpr,
      TInterval
      ,
      TNumeric
     > env);
        public override IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> AssumeGreaterEqualThanZero
            (TExpr expr,
            IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> env)
        {
            var constraints =
                IntervalInference.ConstraintsFor.GreaterEqualThanZero
                <IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational>, TVar, TExpr, TInterval>
                    (expr, env.Decoder, env);

            return(AssumeConstraints(constraints, env));
        }
        public override IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> AssumeLessEqualThan
        (
            TInterval intv, TVar right, IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> env)
        {
            TInterval refined;

            if (
                !IntervalInference.ConstraintsFor.TryRefineLessEqualThan
                <IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational>, TVar, TExpr, TInterval>
                    (intv, right, env, out refined))
            {
                return(env);
            }

            return(env.With(right, refined));
        }
Example #10
0
        public override IntervalEnvironmentBase <TVar, TExpr, Interval, Rational> AssumeNotEqual
            (TExpr left, TExpr right, IntervalEnvironmentBase <TVar, TExpr, Interval, Rational> env)
        {
            IntervalInference.InferenceResult <TVar, Interval> resultLeft;
            IntervalInference.InferenceResult <TVar, Interval> resultRight;
            IntervalInference.ConstraintsFor.NotEqual(left, right, env.Decoder, env, out resultLeft,
                                                      out resultRight);

            IntervalInference.InferenceResult <TVar, Interval> join = resultLeft.Join(resultRight);
            if (join.IsBottom)
            {
                return(env.Bottom);
            }

            return(this.AssumeConstraints(join.Constraints, env));
        }
Example #11
0
 public virtual IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> AssumeEqualToZero
     (TVar var,
     IntervalEnvironmentBase
     <
         TVar
         ,
         TExpr
         ,
         TInterval
         ,
         TNumeric
     >
     env)
 {
     return(env.RefineVariable(var, env.Context.Zero));
 }
Example #12
0
        protected IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> AssumeConstraints
            (IImmutableMap <TVar, Sequence <TInterval> > constraints,
            IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env)
        {
            var res = env;

            foreach (var v in constraints.Keys)
            {
                var seq = constraints[v];
                foreach (var intv in seq.AsEnumerable())
                {
                    res = res.RefineVariable(v, intv);
                }
            }

            return(res);
        }
        public override IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> AssumeLessEqualThan
            (TExpr left, TExpr right, IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational> env)
        {
            bool isBottom;
            var  constraints =
                IntervalInference.ConstraintsFor.LessEqualThan
                <IntervalEnvironmentBase <TVar, TExpr, TInterval, Rational>, TVar, TExpr, TInterval>
                    (left, right, env.Decoder, env,
                    out isBottom);

            if (isBottom)
            {
                return(env.Bottom);
            }

            return(AssumeConstraints(constraints, env));
        }
Example #14
0
        public virtual IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> AssumeNotEqual
            (TExpr left,
            TExpr right,
            IntervalEnvironmentBase
            <TVar,
             TExpr,
             TInterval
             ,
             TNumeric
            > env)
        {
            int value;

            if (env.Decoder.OperatorFor(left).IsRelational() && env.Decoder.IsConstantInt(right, out value))
            {
                return(value == 0 ? env.AssumeTrue(left) : env.AssumeFalse(left));
            }

            var assumer = env.Assumer;

            return(assumer.AssumeLessThan(left, right, env).Join(assumer.AssumeLessThan(right, left, env)));
        }
Example #15
0
 public override IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> VisitLessEqualThan
     (TExpr left, TExpr right, TExpr original,
     IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env)
 {
     return(env.Assumer.AssumeLessEqualThan(left, right, env));
 }
Example #16
0
 public abstract IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> AssumeGreaterEqualThanZero
     (TExpr expr, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env);
Example #17
0
 public abstract IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> AssumeLessEqualThan
     (TInterval intv, TVar right, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env);
Example #18
0
 public abstract IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> AssumeNotEqualToZero
     (TExpr e, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env);
 public bool LessEqual(IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> that)
 {
     return(vars_to_intervals.LessEqual(that.vars_to_intervals));
 }
Example #20
0
        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);
        }
Example #21
0
 static IntervalEnvironmentBase <Var, Expr, DisInterval, Rational> AssumeEqualToDisInterval
     (Var var, DisInterval intv, IntervalEnvironmentBase <Var, Expr, DisInterval, Rational> env)
 {
     return(env.RefineVariable(var, intv));
 }
Example #22
0
 public override IntervalEnvironmentBase <Var, Expr, DisInterval, Rational> AssumeNotEqualToZero
     (Var var, IntervalEnvironmentBase <Var, Expr, DisInterval, Rational> env)
 {
     return(AssumeEqualToDisInterval(var, DisInterval.NotZero, env));
 }
Example #23
0
 public override IntervalEnvironmentBase <TVar, TExpr, Interval, Rational> AssumeNotEqualToZero
     (TVar v, IntervalEnvironmentBase <TVar, TExpr, Interval, Rational> env)
 {
     //do nothing, we can't exclude one point
     return(env);
 }
Example #24
0
 public override IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> VisitVariable
     (TVar var, TExpr expr, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env)
 {
     return(env.Assumer.AssumeNotEqualToZero(expr, env));
 }
 public IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> Meet(IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> that)
 {
     return(NewInstance(vars_to_intervals.Meet(that.vars_to_intervals)));
 }
 public IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> Join(IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> that, bool widen, out bool weaker)
 {
     return(NewInstance(vars_to_intervals.Join(that.vars_to_intervals, widen, out weaker)));
 }
Example #27
0
 public override IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> VisitUnknown
     (TExpr expr, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env)
 {
     env = base.VisitUnknown(expr, env);
     return(env.Assumer.AssumeNotEqualToZero(expr, env));
 }
Example #28
0
 public override IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> VisitNot
     (TExpr expr, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> env)
 {
     return(FalseVisitor.Visit(expr, env));
 }
 public IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> VisitFalse(TExpr guard, IntervalEnvironmentBase <TVar, TExpr, TInterval, TNumeric> data)
 {
     return(false_visitor.Visit(guard, data));
 }