Exemplo n.º 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));
            }
Exemplo n.º 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));
            }
Exemplo n.º 3
0
 protected IntervalElement(ExtendedInt /*!*/ inf, ExtendedInt /*!*/ sup)
 {
     Contract.Requires(sup != null);
     Contract.Requires(inf != null);
     this.inf = inf;
     this.sup = sup;
     // base();
 }
Exemplo n.º 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));
            }
Exemplo n.º 5
0
 public override int CompareTo(ExtendedInt /*!*/ that)
 {
     //Contract.Requires(that != null);
     if (that is MinusInfinity)
     {
         return(0);
     }
     else
     {
         return(-1);
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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));
            }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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));
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 17
0
 public abstract int CompareTo(ExtendedInt/*!*/ that);
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }
Exemplo n.º 20
0
 protected IntervalElement(ExtendedInt/*!*/ inf, ExtendedInt/*!*/ sup) {
   Contract.Requires(sup != null);
   Contract.Requires(inf != null);
   this.inf = inf;
   this.sup = sup;
   // base();
 }
Exemplo n.º 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;
 }
Exemplo n.º 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);
    }
Exemplo n.º 23
0
 public override int CompareTo(ExtendedInt that)
 {
     Contract.Requires(that != null);
     throw new NotImplementedException();
 }
Exemplo n.º 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...
 }
Exemplo n.º 25
0
 public abstract int CompareTo(ExtendedInt /*!*/ that);
Exemplo n.º 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);
    }
Exemplo n.º 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;
 }
Exemplo n.º 28
0
 // Construct the inteval [val, val]
 protected IntervalElement(BigNum val)
 {
     this.inf = this.sup = ExtendedInt.Factory(val);
     // base();
 }
Exemplo n.º 29
0
 public override int CompareTo(ExtendedInt that) {
   Contract.Requires(that != null);
   throw new NotImplementedException();
 }
Exemplo n.º 30
0
 // Construct the inteval [val, val]
 protected IntervalElement(BigNum val) {
   this.inf = this.sup = ExtendedInt.Factory(val);
   // base();
 }
Exemplo n.º 31
0
 public override int CompareTo(ExtendedInt/*!*/ that) {
   //Contract.Requires(that != null);
   if (that is MinusInfinity)
     return 0;
   else
     return -1;
 }
Exemplo n.º 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...
 }