Пример #1
0
            // 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));
            }
Пример #2
0
            // 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));
            }
Пример #3
0
 protected IntervalElement(ExtendedInt /*!*/ inf, ExtendedInt /*!*/ sup)
 {
     Contract.Requires(sup != null);
     Contract.Requires(inf != null);
     this.inf = inf;
     this.sup = sup;
     // base();
 }
Пример #4
0
            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));
            }
Пример #5
0
 public override int CompareTo(ExtendedInt /*!*/ that)
 {
     //Contract.Requires(that != null);
     if (that is MinusInfinity)
     {
         return(0);
     }
     else
     {
         return(-1);
     }
 }
Пример #6
0
        /// <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));
        }
Пример #7
0
            // 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));
            }
Пример #8
0
 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);
     }
 }
Пример #9
0
        /// <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);
        }
Пример #10
0
 // 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));
 }
Пример #11
0
        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));
        }
Пример #12
0
 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);
     }
 }
Пример #13
0
        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));
        }
Пример #14
0
 // 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));
     }
 }
Пример #15
0
 // 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));
     }
 }
Пример #16
0
 // 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));
     }
 }
Пример #17
0
 public abstract int CompareTo(ExtendedInt/*!*/ that);
Пример #18
0
 // 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);
 }
Пример #19
0
 // 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);
 }
Пример #20
0
 protected IntervalElement(ExtendedInt/*!*/ inf, ExtendedInt/*!*/ sup) {
   Contract.Requires(sup != null);
   Contract.Requires(inf != null);
   this.inf = inf;
   this.sup = sup;
   // base();
 }
Пример #21
0
 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;
 }
Пример #22
0
    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);
    }
Пример #23
0
 public override int CompareTo(ExtendedInt that)
 {
     Contract.Requires(that != null);
     throw new NotImplementedException();
 }
Пример #24
0
 // 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...
 }
Пример #25
0
 public abstract int CompareTo(ExtendedInt /*!*/ that);
Пример #26
0
    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);
    }
Пример #27
0
 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;
 }
Пример #28
0
 // Construct the inteval [val, val]
 protected IntervalElement(BigNum val)
 {
     this.inf = this.sup = ExtendedInt.Factory(val);
     // base();
 }
Пример #29
0
 public override int CompareTo(ExtendedInt that) {
   Contract.Requires(that != null);
   throw new NotImplementedException();
 }
Пример #30
0
 // Construct the inteval [val, val]
 protected IntervalElement(BigNum val) {
   this.inf = this.sup = ExtendedInt.Factory(val);
   // base();
 }
Пример #31
0
 public override int CompareTo(ExtendedInt/*!*/ that) {
   //Contract.Requires(that != null);
   if (that is MinusInfinity)
     return 0;
   else
     return -1;
 }
Пример #32
0
 // 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...
 }