// Division public static IntervalElement /*!*/ operator %(IntervalElement /*!*/ a, IntervalElement /*!*/ b) { Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <IntervalElement>() != null); if (b.inf.IsZero && b.sup.IsZero) // Check division by zero { return(IntervalElement.Top); } ExtendedInt /*!*/ infinf = a.inf % b.inf; Contract.Assert(infinf != null); ExtendedInt /*!*/ infsup = a.inf % b.sup; Contract.Assert(infsup != null); ExtendedInt /*!*/ supinf = a.sup % b.inf; Contract.Assert(supinf != null); ExtendedInt /*!*/ supsup = a.sup % b.sup; Contract.Assert(supsup != null); ExtendedInt inf = ExtendedInt.Inf(infinf, infsup, supinf, supsup); ExtendedInt sup = ExtendedInt.Sup(infinf, infsup, supinf, supsup); return(Factory(inf, sup)); }
// Multiplication public static IntervalElement /*!*/ operator *(IntervalElement /*!*/ a, IntervalElement /*!*/ b) { Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <IntervalElement>() != null); ExtendedInt /*!*/ infinf = a.inf * b.inf; Contract.Assert(infinf != null); ExtendedInt /*!*/ infsup = a.inf * b.sup; Contract.Assert(infsup != null); ExtendedInt /*!*/ supinf = a.sup * b.inf; Contract.Assert(supinf != null); ExtendedInt /*!*/ supsup = a.sup * b.sup; Contract.Assert(supsup != null); ExtendedInt /*!*/ inf = ExtendedInt.Inf(infinf, infsup, supinf, supsup); Contract.Assert(inf != null); ExtendedInt /*!*/ sup = ExtendedInt.Sup(infinf, infsup, supinf, supsup); Contract.Assert(sup != null); return(Factory(inf, sup)); }
protected IntervalElement(ExtendedInt /*!*/ inf, ExtendedInt /*!*/ sup) { Contract.Requires(sup != null); Contract.Requires(inf != null); this.inf = inf; this.sup = sup; // base(); }
public static IntervalElement /*!*/ Factory(BigNum inf, BigNum sup) { Contract.Ensures(Contract.Result <IntervalElement>() != null); ExtendedInt /*!*/ i = ExtendedInt.Factory(inf); ExtendedInt /*!*/ s = ExtendedInt.Factory(sup); return(Factory(i, s)); }
public override int CompareTo(ExtendedInt /*!*/ that) { //Contract.Requires(that != null); if (that is MinusInfinity) { return(0); } else { return(-1); } }
/// <summary> /// The classic, pointwise, meet of intervals /// </summary> public override Element /*!*/ NontrivialMeet(Element /*!*/ left, Element /*!*/ right) { //Contract.Requires(right != null); //Contract.Requires(left != null); Contract.Ensures(Contract.Result <Element>() != null); IntervalElement /*!*/ leftInterval = (IntervalElement /*!*/)cce.NonNull(left); IntervalElement /*!*/ rightInterval = (IntervalElement /*!*/)cce.NonNull(right); ExtendedInt inf = ExtendedInt.Sup(leftInterval.Inf, rightInterval.Inf); ExtendedInt sup = ExtendedInt.Inf(leftInterval.Sup, rightInterval.Sup); return(IntervalElement.Factory(inf, sup)); }
// Addition public static IntervalElement /*!*/ operator +(IntervalElement /*!*/ a, IntervalElement /*!*/ b) { Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <IntervalElement>() != null); ExtendedInt /*!*/ inf = a.inf + b.inf; Contract.Assert(inf != null); ExtendedInt /*!*/ sup = a.sup + b.sup; Contract.Assert(sup != null); return(Factory(inf, sup)); }
public static ExtendedInt /*!*/ Sup(ExtendedInt /*!*/ inf, ExtendedInt /*!*/ sup) { Contract.Requires(sup != null); Contract.Requires(inf != null); Contract.Ensures(Contract.Result <ExtendedInt>() != null); if (inf > sup) { return(inf); } else { return(sup); } }
/// <summary> /// The very simple widening of intervals, to be improved with thresholds /// left is the PREVIOUS value in the iterations and right is the NEW one /// </summary> public override Element /*!*/ Widen(Element /*!*/ left, Element /*!*/ right) { //Contract.Requires(right != null); //Contract.Requires(left != null); Contract.Ensures(Contract.Result <Element>() != null); IntervalElement /*!*/ prevInterval = (IntervalElement /*!*/)cce.NonNull(left); IntervalElement /*!*/ nextInterval = (IntervalElement /*!*/)cce.NonNull(right); ExtendedInt inf = nextInterval.Inf < prevInterval.Inf ? ExtendedInt.MinusInfinity : prevInterval.Inf; ExtendedInt sup = nextInterval.Sup > prevInterval.Sup ? ExtendedInt.PlusInfinity : prevInterval.Sup; IntervalElement widening = IntervalElement.Factory(inf, sup); return(widening); }
// Construct an Interval public static IntervalElement /*!*/ Factory(ExtendedInt /*!*/ inf, ExtendedInt /*!*/ sup) { Contract.Requires((sup != null)); Contract.Requires((inf != null)); Contract.Ensures(Contract.Result <IntervalElement>() != null); if (inf is MinusInfinity && sup is PlusInfinity) { return(Top); } if (inf > sup) { return(Bottom); } // otherwise... return(new IntervalElement(inf, sup)); }
public static ExtendedInt /*!*/ Sup(ExtendedInt /*!*/ a, ExtendedInt /*!*/ b, ExtendedInt /*!*/ c, ExtendedInt /*!*/ d) { Contract.Requires(d != null); Contract.Requires(c != null); Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <ExtendedInt>() != null); ExtendedInt /*!*/ supab = Sup(a, b); Contract.Assert(supab != null); ExtendedInt /*!*/ supcd = Sup(c, d); Contract.Assert(supcd != null); return(Sup(supab, supcd)); }
public override int CompareTo(ExtendedInt /*!*/ that) { //Contract.Requires(that != null); if (that is PlusInfinity) { return(-1); } else if (that is PureInteger) { return(this.Value.CompareTo(that.Value)); } else // then that is a MinusInfinity { return(1); } }
public static ExtendedInt /*!*/ Inf(ExtendedInt /*!*/ a, ExtendedInt /*!*/ b, ExtendedInt /*!*/ c, ExtendedInt /*!*/ d) { Contract.Requires(d != null); Contract.Requires(c != null); Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <ExtendedInt>() != null); ExtendedInt /*!*/ infab = Inf(a, b); Contract.Assert(infab != null); ExtendedInt /*!*/ infcd = Inf(c, d); Contract.Assert(infcd != null); return(Inf(infab, infcd)); }
// Unary minus public static ExtendedInt /*!*/ UnaryMinus(ExtendedInt /*!*/ a) { Contract.Requires(a != null); Contract.Ensures(Contract.Result <ExtendedInt>() != null); if (a is PlusInfinity) { return(cachedMinusInf); } if (a is MinusInfinity) { return(cachedPlusInf); } else // a is a PureInteger { return(new PureInteger(-a.Value)); } }
// Subtraction public static ExtendedInt /*!*/ operator -(ExtendedInt /*!*/ a, ExtendedInt /*!*/ b) { Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <ExtendedInt>() != null); if (a is InfinitaryInt) { return(a); } else if (b is InfinitaryInt) { return(UnaryMinus(b)); } else { return(ExtendedInt.Factory(a.Value - b.Value)); } }
// Modulo public static ExtendedInt /*!*/ operator %(ExtendedInt /*!*/ a, ExtendedInt /*!*/ b) { Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result <ExtendedInt>() != null); if (b.IsZero) { return(a.IsPositive ? (ExtendedInt)cachedPlusInf : cachedMinusInf); } if (a is InfinitaryInt) { return(a); } else if (b is InfinitaryInt) { return(b); } else { return(ExtendedInt.Factory(a.Value % b.Value)); } }
public abstract int CompareTo(ExtendedInt/*!*/ that);
// Unary minus public static ExtendedInt/*!*/ UnaryMinus(ExtendedInt/*!*/ a) { Contract.Requires(a != null); Contract.Ensures(Contract.Result<ExtendedInt>() != null); if (a is PlusInfinity) return cachedMinusInf; if (a is MinusInfinity) return cachedPlusInf; else // a is a PureInteger return new PureInteger(-a.Value); }
// Construct an Interval public static IntervalElement/*!*/ Factory(ExtendedInt/*!*/ inf, ExtendedInt/*!*/ sup) { Contract.Requires((sup != null)); Contract.Requires((inf != null)); Contract.Ensures(Contract.Result<IntervalElement>() != null); if (inf is MinusInfinity && sup is PlusInfinity) return Top; if (inf > sup) return Bottom; // otherwise... return new IntervalElement(inf, sup); }
protected IntervalElement(ExtendedInt/*!*/ inf, ExtendedInt/*!*/ sup) { Contract.Requires(sup != null); Contract.Requires(inf != null); this.inf = inf; this.sup = sup; // base(); }
public override int CompareTo(ExtendedInt/*!*/ that) { //Contract.Requires(that != null); if (that is PlusInfinity) return -1; else if (that is PureInteger) return this.Value.CompareTo(that.Value); else // then that is a MinusInfinity return 1; }
public static ExtendedInt/*!*/ Sup(ExtendedInt/*!*/ a, ExtendedInt/*!*/ b, ExtendedInt/*!*/ c, ExtendedInt/*!*/ d) { Contract.Requires(d != null); Contract.Requires(c != null); Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result<ExtendedInt>() != null); ExtendedInt/*!*/ supab = Sup(a, b); Contract.Assert(supab != null); ExtendedInt/*!*/ supcd = Sup(c, d); Contract.Assert(supcd != null); return Sup(supab, supcd); }
public override int CompareTo(ExtendedInt that) { Contract.Requires(that != null); throw new NotImplementedException(); }
// Construct the interval [inf, sup] protected IntervalElement(BigNum infInt, BigNum supInt) { this.inf = ExtendedInt.Factory(infInt); this.sup = ExtendedInt.Factory(supInt); // base(); // to please the compiler... }
public abstract int CompareTo(ExtendedInt /*!*/ that);
public static ExtendedInt/*!*/ Inf(ExtendedInt/*!*/ a, ExtendedInt/*!*/ b, ExtendedInt/*!*/ c, ExtendedInt/*!*/ d) { Contract.Requires(d != null); Contract.Requires(c != null); Contract.Requires(b != null); Contract.Requires(a != null); Contract.Ensures(Contract.Result<ExtendedInt>() != null); ExtendedInt/*!*/ infab = Inf(a, b); Contract.Assert(infab != null); ExtendedInt/*!*/ infcd = Inf(c, d); Contract.Assert(infcd != null); return Inf(infab, infcd); }
public static ExtendedInt/*!*/ Sup(ExtendedInt/*!*/ inf, ExtendedInt/*!*/ sup) { Contract.Requires(sup != null); Contract.Requires(inf != null); Contract.Ensures(Contract.Result<ExtendedInt>() != null); if (inf > sup) return inf; else return sup; }
// Construct the inteval [val, val] protected IntervalElement(BigNum val) { this.inf = this.sup = ExtendedInt.Factory(val); // base(); }
public override int CompareTo(ExtendedInt that) { Contract.Requires(that != null); throw new NotImplementedException(); }
// Construct the inteval [val, val] protected IntervalElement(BigNum val) { this.inf = this.sup = ExtendedInt.Factory(val); // base(); }
public override int CompareTo(ExtendedInt/*!*/ that) { //Contract.Requires(that != null); if (that is MinusInfinity) return 0; else return -1; }
// Construct the interval [inf, sup] protected IntervalElement(BigNum infInt, BigNum supInt) { this.inf = ExtendedInt.Factory(infInt); this.sup = ExtendedInt.Factory(supInt); // base(); // to please the compiler... }