public void ShouldHaveSubOperation() { Rational seven20 = Rational.For(7, 20); Rational eleven15 = Rational.For(11, 15); Assert.That(seven20 - eleven15, Is.EqualTo(Rational.For(-23, 60))); }
public void ShouldHaveAddOperation() { Rational seven20 = Rational.For(7, 20); Rational eleven15 = Rational.For(11, 15); Assert.That(seven20 + eleven15, Is.EqualTo(Rational.For(325, 300))); }
public void ShouldHaveMulOperation() { Rational seven22 = Rational.For(7, 22); Rational eleven21 = Rational.For(11, 21); Assert.That(seven22 * eleven21, Is.EqualTo(Rational.For(1, 6))); }
public static void Add(List <int> values) { foreach (var val in values) { thresholds_Rational.Add(Rational.For(val)); } }
public void ConsecutiveIntegers() { Assert.That(Interval.AreConsecutiveIntegers(this._1__2, this._3__4), Is.True); Assert.That(Interval.AreConsecutiveIntegers(this._1__2, this._1__2), Is.False); Assert.That(Interval.AreConsecutiveIntegers(this._3__4, this._1__2), Is.False); Assert.That(Interval.AreConsecutiveIntegers(Interval.For(Rational.For(1, 3)), this._1__2), Is.False); }
/// <summary> /// Creates the octagonal constraint x = y /// </summary> public OctagonConstraintXEqualY(int x, int y) { this.x = x; this.y = y; this.c = Rational.For(0); cachedXLeqY = new OctagonConstraintXMinusY(this.x, this.y, 0); // x <= y cachedYLeqX = new OctagonConstraintXMinusY(this.y, this.x, 0); // y <= x }
protected override void AssumeKLessThanRight(DisInterval k, Variable right) { DisInterval refined; if (IntervalInference.TryRefine_KLessThanRight(true, k, right, Rational.For(1), this, out refined)) { this[right] = refined; } }
public SimpleDisequalities <Variable, Expression> TestTrueGeqZero(Expression exp) { // exp >= 0 => exp != -1 (and also -2, ... but we ignore it) Variable expVar = decoder.UnderlyingVariable(exp); this[expVar] = this[expVar].Meet(new SetOfConstraints <Rational>(Rational.For(-1))); return(this); }
public static bool TryMatch_XMinusYPlusK <Variable, Expression>( this Polynomial <Variable, Expression> pol, out Variable x, out Variable y, out Rational k) { Contract.Ensures(!Contract.Result <bool>() || !object.Equals(Contract.ValueAtReturn(out k), null)); if (!pol.Relation.HasValue && pol.IsLinear) { if (pol.Left.Length == 3) { var left0 = pol.Left[0]; if (left0.K == 1 && pol.Left[1].K == -1 && pol.Left[2].IsConstant) { left0.IsVariable(out x); var b = pol.Left[1].IsVariable(out y); k = pol.Left[2].K; return(b); } else if (left0.K == -1 && pol.Left[1].K == 1 && pol.Left[2].IsConstant) { left0.IsVariable(out y); var b = pol.Left[1].IsVariable(out x); k = pol.Left[2].K; return(b); } } else if (pol.Left.Length == 2 && pol.Left[0].Degree == 1 && pol.Left[1].Degree == 1) { if (pol.Left[0].K == 1 && pol.Left[1].K == -1) { x = pol.Left[0].VariableAt(0); y = pol.Left[1].VariableAt(0); k = Rational.For(0); return(true); } else if (pol.Left[0].K == -1 && pol.Left[1].K == 1) { y = pol.Left[0].VariableAt(0); x = pol.Left[1].VariableAt(0); k = Rational.For(0); return(true); } } } x = y = default(Variable); k = default(Rational); return(false); }
/// <returns>True iff 0 \in this[e]</returns> public FlatAbstractDomain <bool> CheckIfNonZero(Expression e) { Variable eVar = decoder.UnderlyingVariable(e); if (ContainsKey(eVar) && this[eVar].IsNormal()) { return(this[eVar].Contains(Rational.For(0)) ? CheckOutcome.True : CheckOutcome.Top); } return(CheckOutcome.Top); }
public override bool VisitUInt32(Expression exp, Unit input) { UInt32 value; if (Decoder.TryValueOf(exp, ExpressionType.UInt32, out value)) { result = Rational.For(value); hasValue = true; } return(hasValue); }
public void ShouldHaveDivOperation() { Rational seven22 = Rational.For(7, 22); Rational eleven21 = Rational.For(21, 11); Assert.That(seven22 / eleven21, Is.EqualTo(Rational.For(1, 6))); Rational result; Assert.That(Rational.TryDivide(one, zero, out result), Is.False, "shouldn't div by zero"); Assert.That(Rational.TryDivide(seven22, zero, out result), Is.False, "shouldn't div by zero"); }
public override bool VisitInt64(Expression exp, Unit input) { Int64 value; if (Decoder.TryValueOf(exp, ExpressionType.Int64, out value) && Rational.CanRepresentExactly(value)) { result = Rational.For(value); hasValue = true; } return(hasValue); }
public override Interval For(long value) { if (Rational.CanRepresentExactly(value)) { return(Interval.For(Rational.For(value))); } else if (value >= 0) // of course it will never be zero, it is just to shut up the compiler { return(Interval.For(1, Rational.PlusInfinity)); } else { return(Interval.For(Rational.MinusInfinity, -1)); } }
/// <summary> /// Adds the constraints x != value.LowerBound-1 and x != value.UpperBound+1 /// </summary> public void AssumeInInterval(Variable x, Interval value) { if (value.IsNormal) { var strictBounds = new Set <Rational>(2); if (!value.LowerBound.IsInfinity) { try { strictBounds.Add(value.LowerBound - 1); } catch (ArithmeticExceptionRational) { // It may be the case that value.UpperBound is too large, so we catch it // and do nothing (i.e. we abstract) } } if (!value.UpperBound.IsInfinity) { try { strictBounds.Add(value.UpperBound + 1); } catch (ArithmeticExceptionRational) { // It may be the case that value.UpperBound is too large, so we catch it // and do nothing (i.e. we abstract) } } // Check if zero is not included. In the case, we want to add the constraint x != 0 if (value.DoesNotInclude(0)) { strictBounds.Add(Rational.For(0)); } // It may be the case that the interval is e.g. [+oo, +oo], so we cannot blindly add the matrixes if (strictBounds.Count > 0) { this[x] = new SetOfConstraints <Rational>(strictBounds); } } }
public void ShouldDivIntervalsByMaxMin() { Assert.That(this.Bottom / this._1__2, Is.EqualTo(this.Bottom), "bottom / normal = bottom"); Assert.That(this.Bottom / this.Top, Is.EqualTo(this.Bottom), "bottom / top = bottom"); Assert.That(this.Bottom / this.Bottom, Is.EqualTo(this.Bottom), "bottom / bottom = bottom"); Assert.That(this.Top / this.Top, Is.EqualTo(this.Top), "top / top = top"); Assert.That(this.Top / this._1__2, Is.EqualTo(this.Top), "top / normal = top"); Assert.That(this.Top / this.Bottom, Is.EqualTo(this.Bottom), "top / bottom = bottom"); Assert.That(this._1__2 / this.Bottom, Is.EqualTo(this.Bottom), "normal / bottom = bottom"); Assert.That(this._1__2 / this.Top, Is.EqualTo(this.Top), "normal / top = top"); Assert.That(this._1__2 / this.zero_to_one, Is.EqualTo(this.Top), "normal / zeroToOne = top"); Assert.That(this._1__2 / this.minus_one_to_zero, Is.EqualTo(this.Top), "normal / minusOneToZero = top"); Assert.That( this._1__2 / this._3__4, Is.EqualTo(Interval.For(Rational.For(1, 4), Rational.For(2, 3))), "normal / normal = normal"); }
public override SetOfConstraints <Rational> this[Variable index] { get { if (ContainsKey(index)) { return(base[index]); } else { return(new SetOfConstraints <Rational>(Rational.For(-30)).Top); // Top } } set { if (decoder.IsSlackOrFrameworkVariable(index)) { base[index] = value; } } }
public static Interval ConvertFromDouble(this Double d) { Contract.Ensures(Contract.Result <Interval>() != null); if (d.Equals(Double.NaN) || Double.IsInfinity(d) || d < Int64.MinValue || d > Int64.MaxValue) { return(Interval.UnknownInterval); } var trunc = Math.Truncate(d); var l = (long)trunc; if (d == trunc) { return(Interval.For(Rational.For(l, 1))); } else { Interval candidate; if (d > 0) { candidate = Interval.For(Rational.For(l, 1), Rational.For(l + 1, 1)); } else { candidate = Interval.For(Rational.For(l - 1, 1), Rational.For(l, 1)); } // Check for conversion errors if (candidate.LowerBound.Ceiling > d || candidate.UpperBound.Floor < d) { return(Interval.UnknownInterval); } return(candidate); } }
public override SimpleDisequalities <Variable, Expression> Visit(Expression exp, SimpleDisequalities <Variable, Expression> data) { SimpleDisequalities <Variable, Expression> result = base.Visit(exp, data); // We also know that exp != 0 var expNotZero = new SetOfConstraints <Rational>(Rational.For(0)); SetOfConstraints <Rational> prev; Variable expVar = Decoder.UnderlyingVariable(exp); if (result.TryGetValue(expVar, out prev)) { result[expVar] = prev.Meet(expNotZero); } else { result[expVar] = expNotZero; } return(result); }
private FlatAbstractDomain <bool> IsNotZero(Expression x) { // First try: Is it a constant? evalConstant.Visit(x); if (evalConstant.HasValue) { if (evalConstant.Result.IsZero) { return(CheckOutcome.False); } else { return(CheckOutcome.True); } } // Second try: Do we have some propagated information Variable xVar = Decoder.UnderlyingVariable(x); SetOfConstraints <Rational> constraints; if (Domain.TryGetValue(xVar, out constraints)) { // We know it is != 0 for sure? if (constraints.IsNormal() && constraints.Contains(Rational.For(0))) { return(CheckOutcome.True); } if (constraints.IsBottom) { return(CheckOutcome.Bottom); } } // we do not know... return(CheckOutcome.Top); }
static public void InferConstraints_NotEq <Variable, Expression, IType>( Expression left, Expression right, IExpressionDecoder <Variable, Expression> decoder, ISetOfNumbersAbstraction <Variable, Expression, Rational, IType> iquery, out List <Pair <Variable, IType> > resultLeft, out List <Pair <Variable, IType> > resultRight, out bool isBottomLeft, out bool isBottomRight) where IType : IntervalBase <IType, Rational> { isBottomLeft = false; // False untils someone proves the contrary isBottomRight = false; resultLeft = new List <Pair <Variable, IType> >(); resultRight = new List <Pair <Variable, IType> >(); var kLeft = iquery.Eval(left); var kRight = iquery.Eval(right); var rightVar = decoder.UnderlyingVariable(right); var leftVar = decoder.UnderlyingVariable(left); var succ = IsFloat(left, decoder) || IsFloat(right, decoder) ? Rational.For(0) : Rational.For(1); NewMethod <Variable, Expression, IType>(succ, iquery, kLeft, kRight, rightVar, leftVar, resultLeft); NewMethod <Variable, Expression, IType>(succ, iquery, kRight, kLeft, leftVar, rightVar, resultRight); // Try to infer some more fact Polynomial <Variable, Expression> tmpLeftPoly, tmpRightPoly; if (Polynomial <Variable, Expression> .TryToPolynomialForm(left, decoder, out tmpLeftPoly) && Polynomial <Variable, Expression> .TryToPolynomialForm(right, decoder, out tmpRightPoly)) { NewMethod2 <Variable, Expression, IType>(tmpLeftPoly, tmpRightPoly, iquery, ref isBottomLeft, resultLeft); NewMethod2 <Variable, Expression, IType>(tmpRightPoly, tmpLeftPoly, iquery, ref isBottomRight, resultRight); } }
static public List <Pair <Variable, IType> > InferConstraints_LT <Variable, Expression, IType>( bool isSignedComparison, Expression left, Expression right, IExpressionDecoder <Variable, Expression> decoder, ISetOfNumbersAbstraction <Variable, Expression, Rational, IType> iquery, out bool isBottom) where IType : IntervalBase <IType, Rational> { Contract.Ensures(Contract.Result <List <Pair <Variable, IType> > >() != null); isBottom = false; // False untils someone proves the contrary var result = new List <Pair <Variable, IType> >(); var kLeft = iquery.Eval(left); var kRight = iquery.Eval(right); if (!isSignedComparison && !IsFloat(left, decoder) && !IsFloat(right, decoder)) { kLeft = kLeft.ToUnsigned(); kRight = kRight.ToUnsigned(); } IType refinedIntv; var rightVar = decoder.UnderlyingVariable(right); var succ = IsFloat(left, decoder) || IsFloat(right, decoder) ? Rational.For(0) : Rational.For(1); if (TryRefine_KLessThanRight(isSignedComparison, kLeft, rightVar, succ, iquery, out refinedIntv)) { // If it is an unsigned comparison, and it is a constant, then we should avoid generating the constraint // Example: left <{un} right, with right == -1 then we do not want to generate the constraint right == 2^{32}-1 which is wrong! // unsigned ==> right is not a constant if (isSignedComparison || !kRight.IsSingleton) { result.Add(rightVar, refinedIntv); } } if (IsFloat(left, decoder) || IsFloat(right, decoder)) { return(result); } var leftVar = decoder.UnderlyingVariable(left); if (TryRefine_LeftLessThanK(isSignedComparison, leftVar, kRight, iquery, out refinedIntv)) { // As above // unsigned ==> right is not a constant if (isSignedComparison || !kLeft.IsSingleton) { result.Add(leftVar, refinedIntv); } } if (isSignedComparison) { // Try to infer some more fact Polynomial <Variable, Expression> guardInCanonicalForm; if (Polynomial <Variable, Expression> .TryToPolynomialForm(ExpressionOperator.LessThan, left, right, decoder, out guardInCanonicalForm) && guardInCanonicalForm.IsLinear) { // First, we consider only the case when there is at MOST one variable on the left, i.e. a * x < b { if (guardInCanonicalForm.Left.Length == 1) { result = HelperFortestTrueLessThan_AxLtK(guardInCanonicalForm, iquery, result, out isBottom); } // Then, we consider the case when it is in the form a*x + b*y < k else if (guardInCanonicalForm.Left.Length == 2) { return(HelperFortestTrueLessThan_AxByLtK(guardInCanonicalForm, iquery, result, out isBottom)); } } } else { #region Try to infer something else... switch (decoder.OperatorFor(left)) { case ExpressionOperator.And: // case "(leftLeft && leftRight) < right var leftRight = decoder.RightExpressionFor(left); Int32 valueLeft; if (decoder.IsConstantInt(leftRight, out valueLeft)) { if (IsPowerOfTwoMinusOne(valueLeft)) { // add the constraint " 0 <= right < valueLeft " var oldVal = iquery.Eval(right); var evalVal = iquery.Eval(left); var newVal = iquery.For(Rational.For(0), Rational.For(valueLeft - 1)); // [0, valueLeft-1], "-1" as we know it is an integer result.Add(rightVar, oldVal.Meet(newVal).Meet(evalVal)); } } break; default: // do nothing... break; } #endregion } } return(result); }
public OctagonConstraintMinusXMinusY(int x, int y, Int32 c) : this(x, y, Rational.For(c)) { }
public OctagonConstraintMinusX(int x, Int32 c) : this(x, Rational.For(c)) { }
public override SimpleDisequalities <Variable, Expression> VisitNotEqual(Expression left, Expression right, Expression original, SimpleDisequalities <Variable, Expression> data) { SimpleDisequalities <Variable, Expression> result = data; evalConstant.Visit(Decoder.Stripped(right)); if (evalConstant.HasValue) { // left != k data = Update(left, evalConstant.Result, data); data = Update(Decoder.Stripped(left), evalConstant.Result, data); } evalConstant.Visit(Decoder.Stripped(left)); if (evalConstant.HasValue) { // right != k var newConstraintsForRight = new SetOfConstraints <Rational>(evalConstant.Result); // check if k != 0. If so we add the constraint right != 0 if (!evalConstant.Result.IsZero) { newConstraintsForRight = newConstraintsForRight.Meet(new SetOfConstraints <Rational>(Rational.For(0))); } Variable rightVar = Decoder.UnderlyingVariable(right); SetOfConstraints <Rational> prev; if (result.TryGetValue(rightVar, out prev)) { newConstraintsForRight = newConstraintsForRight.Meet(prev); } result[rightVar] = newConstraintsForRight; } return(result); }
[ContractVerification(false)] // The analysis of this method takes forever. Should consider refactoring internal Set <Polynomial <Variable, Expression> > ConvexHullHelper( IntervalEnvironment <Variable, Expression> other, Variable slack, SubPolyhedra.JoinConstraintInference inference) { Contract.Requires(other != null); var result = new Set <Polynomial <Variable, Expression> >(); var commonVariables = this.VariablesNonSlack.SetIntersection(other.VariablesNonSlack); var oct = false; if (commonVariables.Count <= SubPolyhedra.MaxVariablesInOctagonsConstraintInference) { oct = true; } else if (inference == SubPolyhedra.JoinConstraintInference.Standard) { return(result); } bool CH = inference == SubPolyhedra.JoinConstraintInference.CHOct || inference == SubPolyhedra.JoinConstraintInference.ConvexHull2D; oct = oct || inference == SubPolyhedra.JoinConstraintInference.CHOct || inference == SubPolyhedra.JoinConstraintInference.Octagons; int i = 0, j = 0; var this_Bounds = new Dictionary <Variable, Interval>(); var other_Bounds = new Dictionary <Variable, Interval>(); foreach (var e1 in commonVariables) { i++; Interval e1Left, e1Right; if ( !TryEvalWithCache(this, e1, this_Bounds, out e1Left) || !TryEvalWithCache(other, e1, other_Bounds, out e1Right)) { continue; } j = 0; foreach (var e2 in commonVariables) { j++; // either e1 == e2 or we already have relations between e1 and e2 if (e1.Equals(e2) || j <= i) { continue; } Interval e2Left, e2Right; if ( !TryEvalWithCache(this, e2, this_Bounds, out e2Left) || !TryEvalWithCache(other, e2, other_Bounds, out e2Right)) { continue; } if (oct) { #region Adding octogonal constraints to get at least as much precision as octagons var monomials = new Monomial <Variable>[] { new Monomial <Variable>(e1), new Monomial <Variable>(-1, e2), new Monomial <Variable>(slack) }; Polynomial <Variable, Expression> pol; if (!Polynomial <Variable, Expression> .TryToPolynomialForm(true, monomials, out pol)) { throw new AbstractInterpretationException("Impossible case"); } result.Add(pol); #endregion } if (CH) { #region Convex Hull // adaptation of the Monotone Chain algorithm var vertices = new PairNonNull <Rational, Rational>[8] { new PairNonNull <Rational, Rational>(e1Left.LowerBound, e2Left.LowerBound), new PairNonNull <Rational, Rational>(e1Left.LowerBound, e2Left.UpperBound), new PairNonNull <Rational, Rational>(e1Left.UpperBound, e2Left.LowerBound), new PairNonNull <Rational, Rational>(e1Left.UpperBound, e2Left.UpperBound), new PairNonNull <Rational, Rational>(e1Right.LowerBound, e2Right.LowerBound), new PairNonNull <Rational, Rational>(e1Right.LowerBound, e2Right.UpperBound), new PairNonNull <Rational, Rational>(e1Right.UpperBound, e2Right.LowerBound), new PairNonNull <Rational, Rational>(e1Right.UpperBound, e2Right.UpperBound) }; try { Array.Sort(vertices, delegate(PairNonNull <Rational, Rational> x, PairNonNull <Rational, Rational> y) { if ((x.One - y.One).Sign == 0) { return((x.Two - y.Two).Sign); } else { return((x.One - y.One).Sign); } }); } catch (InvalidOperationException) { return(result); } var IsInHull = new bool[8]; try { Polynomial <Variable, Expression> pol; #region Computation of the Lower Hull IsInHull[0] = IsFinite(vertices[0]); IsInHull[2] = IsFinite(vertices[2]); IsInHull[4] = IsFinite(vertices[4]); if (IsInHull[0] && IsInHull[2] && IsInHull[4] && (vertices[2].One - vertices[0].One) * (vertices[4].Two - vertices[0].Two) <= (vertices[4].One - vertices[0].One) * (vertices[2].Two - vertices[0].Two)) { IsInHull[2] = false; } IsInHull[6] = IsFinite(vertices[6]); if (IsInHull[2] && IsInHull[4] && IsInHull[6] && (vertices[4].One - vertices[2].One) * (vertices[6].Two - vertices[2].Two) <= (vertices[6].One - vertices[2].One) * (vertices[4].Two - vertices[2].Two)) { IsInHull[4] = false; } if (IsInHull[0] && IsInHull[4] && IsInHull[6] && (vertices[4].One - vertices[0].One) * (vertices[6].Two - vertices[0].Two) <= (vertices[6].One - vertices[0].One) * (vertices[4].Two - vertices[0].Two)) { IsInHull[4] = false; } if (IsInHull[0] && IsInHull[2] && IsInHull[6] && (vertices[2].One - vertices[0].One) * (vertices[6].Two - vertices[0].Two) <= (vertices[6].One - vertices[0].One) * (vertices[2].Two - vertices[0].Two)) { IsInHull[2] = false; } #endregion #region Computation of the Upper Hull IsInHull[1] = IsFinite(vertices[1]); IsInHull[3] = IsFinite(vertices[3]); IsInHull[5] = IsFinite(vertices[5]); if (IsInHull[1] && IsInHull[3] && IsInHull[5] && (vertices[3].One - vertices[1].One) * (vertices[5].Two - vertices[1].Two) >= (vertices[5].One - vertices[1].One) * (vertices[3].Two - vertices[1].Two)) { IsInHull[3] = false; } IsInHull[7] = IsFinite(vertices[7]); if (IsInHull[3] && IsInHull[5] && IsInHull[7] && (vertices[5].One - vertices[3].One) * (vertices[7].Two - vertices[3].Two) >= (vertices[7].One - vertices[3].One) * (vertices[5].Two - vertices[3].Two)) { IsInHull[5] = false; } if (IsInHull[1] && IsInHull[5] && IsInHull[7] && (vertices[5].One - vertices[1].One) * (vertices[7].Two - vertices[1].Two) >= (vertices[7].One - vertices[1].One) * (vertices[5].Two - vertices[1].Two)) { IsInHull[5] = false; } if (IsInHull[1] && IsInHull[3] && IsInHull[7] && (vertices[3].One - vertices[1].One) * (vertices[7].Two - vertices[1].Two) >= (vertices[7].One - vertices[1].One) * (vertices[3].Two - vertices[1].Two)) { IsInHull[3] = false; } #endregion #region Removing points that are in the hull of the subset of finite points but not in the hull due to infinite extreme points int index = 0; var value = Rational.For(0); if (vertices[0].One.IsInfinity) { index = 2; value = vertices[2].Two; for (int n = 4; n < 8; n += 2) { if (vertices[n].Two <= value) { for (int m = index; m < n; m += 2) { IsInHull[m] = false; } index = n; value = vertices[n].Two; } } } if (vertices[6].One.IsInfinity) { index = 4; value = vertices[4].Two; for (int n = 2; n >= 0; n -= 2) { if (vertices[n].Two <= value) { for (int m = index; m > n; m -= 2) { IsInHull[m] = false; } index = n; value = vertices[n].Two; } } } if (vertices[1].One.IsInfinity) { index = 3; value = vertices[3].Two; for (int n = 5; n < 8; n += 2) { if (vertices[n].Two >= value) { for (int m = index; m < n; m += 2) { IsInHull[m] = false; } index = n; value = vertices[n].Two; } } } if (vertices[7].One.IsInfinity) { index = 5; value = vertices[5].Two; for (int n = 3; n >= 0; n -= 2) { if (vertices[n].Two >= value) { for (int m = index; m > n; m -= 2) { IsInHull[m] = false; } index = n; value = vertices[n].Two; } } } #endregion #region Adding to the result the Polynomials for the edges that are in the hull and neither horizontal nor vertical var point = new PairNonNull <Rational, Rational>(); Rational c; int numberOfPointsInHull = 0; for (int k = 0; k < 8; k += 2) { if (IsInHull[k]) { if (numberOfPointsInHull > 0 && point.One != vertices[k].One && point.Two != vertices[k].Two) { try { c = (vertices[k].One - point.One) / (point.Two - vertices[k].Two); } catch (ArithmeticExceptionRational) { continue; } var list = new Monomial <Variable>[] { new Monomial <Variable>(e1), new Monomial <Variable>(c, e2), new Monomial <Variable>(slack) }; if (!Polynomial <Variable, Expression> .TryToPolynomialForm(true, list, out pol)) { throw new AbstractInterpretationException("Impossible case"); } result.Add(pol); } point = vertices[k]; numberOfPointsInHull++; } } for (int k = 1; k < 8; k += 2) { if (IsInHull[k]) { if (numberOfPointsInHull > 0 && point.One != vertices[k].One && point.Two != vertices[k].Two) { try { c = (vertices[k].One - point.One) / (point.Two - vertices[k].Two); } catch (ArithmeticExceptionRational) { continue; } var list = new Monomial <Variable>[] { new Monomial <Variable>(e1), new Monomial <Variable>(c, e2), new Monomial <Variable>(slack) }; if (!Polynomial <Variable, Expression> .TryToPolynomialForm(true, list, out pol)) { throw new AbstractInterpretationException("Impossible case"); } result.Add(pol); } point = vertices[k]; numberOfPointsInHull++; } } #endregion } catch (ArithmeticExceptionRational) { // Ignore the constraint } #endregion } } } return(result); }
public void ShouldInterpretMinusMinValueAsMaxValue() { Rational maxValue = Rational.For(long.MinValue, -1L); Assert.IsTrue((long)maxValue == long.MaxValue); }