JML

org.jmlspecs.models.resolve
Class NaturalNumber

java.lang.Object
  extended byjava.lang.Number
      extended byorg.jmlspecs.models.resolve.NaturalNumber
All Implemented Interfaces:
AntisymmetricCompareTo, Cloneable, Comparable, CompareTo, JMLType, PreorderedCompareTo, ReflexiveCompareTo, Serializable, TotalCompareTo, TotallyOrderedCompareTo, TotalPreorderedCompareTo, TransitiveCompareTo

public class NaturalNumber
extends Number
implements TotallyOrderedCompareTo, JMLType

The natural numbers. These are essentially unlimited in size.

Version:
$Revision: 1.26 $
Author:
Gary T. Leavens
See Also:
BigInteger, JMLFiniteInteger

Class Specifications
private invariant this.value.compareTo(java.math.BigInteger.ZERO) >= 0;
public invariant this.owner == null;
public invariant org.jmlspecs.models.resolve.NaturalNumber.ZERO != null&&org.jmlspecs.models.resolve.NaturalNumber.ZERO.equals(valueOf(0));
public invariant org.jmlspecs.models.resolve.NaturalNumber.ONE != null&&org.jmlspecs.models.resolve.NaturalNumber.ONE.equals(valueOf(1));
private constraint_redundantly this.value == \old(this.value);
public constraint org.jmlspecs.models.resolve.NaturalNumber.ZERO == \old(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
public constraint org.jmlspecs.models.resolve.NaturalNumber.ONE == \old(org.jmlspecs.models.resolve.NaturalNumber.ONE);

Specifications inherited from class Object
represents objectState <- org.jmlspecs.lang.JMLDataGroup.IT;
public represents _getClass <- \typeof(this);

Specifications inherited from interface AntisymmetricCompareTo
instance public invariant ( \forall org.jmlspecs.models.resolve.AntisymmetricCompareTo x, y; x != null&&y != null&&x.isComparableTo(y)&&y.isComparableTo(x); x.compareTo(y) <= 0&&y.compareTo(x) <= 0 ==> x.compareTo(y) == 0);
instance public invariant_redundantly ( \forall org.jmlspecs.models.resolve.AntisymmetricCompareTo x, y; x != null&&y != null&&x.isComparableTo(y)&&y.isComparableTo(x); x.compareTo(y) >= 0&&y.compareTo(x) >= 0 ==> x.compareTo(y) == 0);

Specifications inherited from interface Comparable
instance public invariant ( \forall java.lang.Comparable x; x != null; x.compareTo(x) == 0);
instance public invariant ( \forall java.lang.Comparable x, y; x != null&&y != null&&this.definedComparison(x,y)&&this.definedComparison(y,x); this.sgn(x.compareTo(y)) == -this.sgn(y.compareTo(x)));
instance public invariant ( \forall int n; n == -1||n == 1; ( \forall java.lang.Comparable x, y, z; x != null&&y != null&&z != null&&this.definedComparison(x,y)&&this.definedComparison(y,z)&&this.definedComparison(x,z); this.sgn(x.compareTo(y)) == n&&this.sgn(y.compareTo(z)) == n ==> this.sgn(x.compareTo(z)) == n));
instance public invariant ( \forall int n; n == -1||n == 1; ( \forall java.lang.Comparable x, y, z; x != null&&y != null&&z != null&&this.definedComparison(x,y)&&this.definedComparison(y,z)&&this.definedComparison(x,z); (this.sgn(x.compareTo(y)) == 0&&this.sgn(y.compareTo(z)) == n||this.sgn(x.compareTo(y)) == n&&this.sgn(y.compareTo(z)) == 0) ==> this.sgn(x.compareTo(z)) == n));
instance public invariant ( \forall java.lang.Comparable x, y, z; x != null&&y != null&&z != null&&this.definedComparison(x,y)&&this.definedComparison(x,z)&&this.definedComparison(y,z); this.sgn(x.compareTo(y)) == 0 ==> this.sgn(x.compareTo(z)) == this.sgn(y.compareTo(z)));

Specifications inherited from interface ReflexiveCompareTo
instance public invariant ( \forall org.jmlspecs.models.resolve.ReflexiveCompareTo x; x != null; x.isComparableTo(x)&&x.compareTo(x) == 0);

Specifications inherited from interface TransitiveCompareTo
instance public invariant ( \forall org.jmlspecs.models.resolve.TransitiveCompareTo x, y, z; x != null&&y != null&&z != null&&x.isComparableTo(y)&&y.isComparableTo(z); x.compareTo(y) < 0&&y.compareTo(z) < 0 ==> x.isComparableTo(z)&&x.compareTo(z) < 0);
instance public invariant ( \forall org.jmlspecs.models.resolve.TransitiveCompareTo x, y, z; x != null&&y != null&&z != null&&x.isComparableTo(y)&&y.isComparableTo(z); x.compareTo(y) <= 0&&y.compareTo(z) <= 0 ==> x.isComparableTo(z)&&x.compareTo(z) <= 0);
instance public invariant ( \forall org.jmlspecs.models.resolve.TransitiveCompareTo x, y, z; x != null&&y != null&&z != null&&x.isComparableTo(y)&&y.isComparableTo(z); x.compareTo(y) == 0&&y.compareTo(z) == 0 ==> x.isComparableTo(z)&&x.compareTo(z) == 0);
instance public invariant_redundantly ( \forall org.jmlspecs.models.resolve.TransitiveCompareTo x, y, z; x != null&&y != null&&z != null&&x.isComparableTo(y)&&y.isComparableTo(z); x.compareTo(y) >= 0&&y.compareTo(z) >= 0 ==> x.isComparableTo(z)&&x.compareTo(z) >= 0);
instance public invariant_redundantly ( \forall org.jmlspecs.models.resolve.TransitiveCompareTo x, y, z; x != null&&y != null&&z != null&&x.isComparableTo(y)&&y.isComparableTo(z); x.compareTo(y) > 0&&y.compareTo(z) > 0 ==> x.isComparableTo(z)&&x.compareTo(z) > 0);

Model Field Summary
 
Model fields inherited from class java.lang.Object
_getClass, objectState, theString
 
Ghost Field Summary
 
Ghost fields inherited from class java.lang.Object
objectTimesFinalized, owner
 
Field Summary
private static NaturalNumber intMaxVal
          The maximum integer as a natural number.
static NaturalNumber ONE
          The natural number one.
private  BigInteger value
          The value of this natural number.
static NaturalNumber ZERO
          The natural number zero.
 
Constructor Summary
NaturalNumber()
          Initialize this natural number to zero.
NaturalNumber(non_null BigInteger val)
          Initialize this natural number to the given BigInteger value.
NaturalNumber(long val)
          Initialize this natural number to the given long value.
 
Model Method Summary
 
Model methods inherited from class java.lang.Object
hashValue
 
Model methods inherited from interface org.jmlspecs.models.resolve.CompareTo
isComparableTo
 
Model methods inherited from interface org.jmlspecs.models.resolve.TotalCompareTo
isComparableTo
 
Model methods inherited from interface java.lang.Comparable
definedComparison, sgn
 
Method Summary
 NaturalNumber add(non_null NaturalNumber val)
          Return the sum of this natural number and the given one.
 BigInteger bigIntegerValue()
          Return the BigInteger value of this natural number.
 Object clone()
          Return a clone of this object.
 int compareTo(non_null Object o)
          Compare this to obj, returning negative if this is strictly less than obj, 0 if they are equal, and positive otherwise.
 int compareTo(non_null BigInteger val)
           
 int compareTo(non_null NaturalNumber val)
          Return negative if this natural numbers strictly less than the given one, 0 if they are equal, and positive if this natural numbers is strictly greater than the given one.
 NaturalNumber divide(non_null NaturalNumber val)
          Return the quotient of this natural number divided by the given one.
 boolean divides(non_null NaturalNumber val)
          Tell if this natural number divides the given one evenly.
 double doubleValue()
           
 boolean equals(nullable Object x)
          Tell if this object is equal to the given argument.
 float floatValue()
           
 NaturalNumber gcd(non_null NaturalNumber val)
          Return the greatest common denominator of this number and the given number.
 int hashCode()
          Return a hash code for this object.
 int intValue()
           
 boolean isZero()
          Tell if this object is equal to zero.
 long longValue()
           
 NaturalNumber max(non_null NaturalNumber val)
          Return the smaller of the given natural number and this one.
 NaturalNumber min(non_null NaturalNumber val)
          Return the smaller of the given natural number and this one.
 NaturalNumber mod(non_null NaturalNumber m)
          Return this natural number modulo the given one.
 NaturalNumber multiply(non_null NaturalNumber val)
          Return the product of this natural number and the given one.
 NaturalNumber pow(int exponent)
          Return this natural number multiplied by itself the given number of times.
 NaturalNumber pow(non_null NaturalNumber exponent)
          Return this natural number multiplied by itself the given number of times.
 NaturalNumber remainder(non_null NaturalNumber val)
          Return the remainder of this natural number divided by the given one.
 NaturalNumber shiftLeft(int n)
          Return this natural number left shifted the given number of bits.
 NaturalNumber shiftRight(int n)
          Return this natural number right shifted the given number of bits.
 NaturalNumber suc()
          Return the successor of this natural number.
static NaturalNumber suc(non_null NaturalNumber v)
          Return the successor of the given natural number.
 String toString()
           
static NaturalNumber valueOf(long val)
          Return a natural number with the given value.
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

value

private final BigInteger value
The value of this natural number.

Specifications: non_null
is in groups: objectState

ZERO

public static final NaturalNumber ZERO
The natural number zero.

See Also:
NaturalNumber(), ONE
Specifications: non_null

ONE

public static final NaturalNumber ONE
The natural number one.

See Also:
NaturalNumber(long), valueOf(long), ZERO
Specifications: non_null

intMaxVal

private static final NaturalNumber intMaxVal
The maximum integer as a natural number.

Specifications: non_null
Constructor Detail

NaturalNumber

public NaturalNumber()
Initialize this natural number to zero.

See Also:
ZERO, NaturalNumber(long), NaturalNumber(BigInteger)
Specifications: (class)pure
public normal_behavior
assignable objectState, owner;
ensures this.isZero();

NaturalNumber

public NaturalNumber(long val)
              throws IllegalArgumentException
Initialize this natural number to the given long value.

Throws:
IllegalArgumentException
See Also:
NaturalNumber(), NaturalNumber(BigInteger), valueOf(long)
Specifications: (class)pure
public normal_behavior
requires val >= 0;
assignable objectState, owner;
ensures this.longValue() == val;
     also
signals (java.lang.IllegalArgumentException) val < 0;

NaturalNumber

public NaturalNumber(non_null BigInteger val)
              throws IllegalArgumentException
Initialize this natural number to the given BigInteger value.

Throws:
IllegalArgumentException
See Also:
NaturalNumber(), NaturalNumber(BigInteger)
Specifications: (class)pure
public normal_behavior
requires val != null&&val.compareTo(java.math.BigInteger.ZERO) >= 0;
assignable objectState, owner;
ensures this.bigIntegerValue().equals(val);
Method Detail

valueOf

public static NaturalNumber valueOf(long val)
Return a natural number with the given value.

See Also:
NaturalNumber(long), NaturalNumber(BigInteger)
Specifications: pure non_null
public normal_behavior
requires val >= 0;
ensures \result != null&&\result .equals(new org.jmlspecs.models.resolve.NaturalNumber(val));
    implies_that
requires val >= 0;

suc

public NaturalNumber suc()
Return the successor of this natural number.

See Also:
suc(NaturalNumber), add(org.jmlspecs.models.resolve.NaturalNumber), ONE
Specifications: non_null (class)pure
public normal_behavior
ensures \result != null&&\result .equals(this.add(org.jmlspecs.models.resolve.NaturalNumber.ONE));

suc

public static NaturalNumber suc(non_null NaturalNumber v)
Return the successor of the given natural number.

See Also:
suc(), add(org.jmlspecs.models.resolve.NaturalNumber)
Specifications: pure non_null
public normal_behavior
requires v != null;
ensures \result != null&&\result .equals(v.suc());
ensures_redundantly \result != null&&\result .equals(v.add(org.jmlspecs.models.resolve.NaturalNumber.ONE));

add

public NaturalNumber add(non_null NaturalNumber val)
Return the sum of this natural number and the given one.

See Also:
suc(), add(org.jmlspecs.models.resolve.NaturalNumber)
Specifications: non_null (class)pure
public normal_behavior
requires val != null;
{|
requires val.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
ensures \result != null&&\result .equals(this);
also
forall org.jmlspecs.models.resolve.NaturalNumber v;
requires !(val.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO));
ensures v != null&&v.suc().equals(val) ==> \result != null&&\result .equals(this.add(v).suc());
|}
    for_example
public normal_example
requires val != null&&val.equals(new org.jmlspecs.models.resolve.NaturalNumber(3))&&this.equals(new org.jmlspecs.models.resolve.NaturalNumber(7));
ensures \result != null&&\result .equals(new org.jmlspecs.models.resolve.NaturalNumber(10));

multiply

public NaturalNumber multiply(non_null NaturalNumber val)
Return the product of this natural number and the given one.

See Also:
divide(org.jmlspecs.models.resolve.NaturalNumber)
Specifications: non_null (class)pure
public normal_behavior
requires val != null;
{|
requires val.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
ensures \result != null&&\result .isZero();
also
forall org.jmlspecs.models.resolve.NaturalNumber v;
requires !(val.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO));
ensures v != null&&v.suc().equals(val) ==> \result != null&&\result .equals(this.add(this.multiply(v)));
|}
    implies_that
public normal_behavior
requires val != null&&val.equals(org.jmlspecs.models.resolve.NaturalNumber.ONE);
ensures \result != null&&\result .equals(this);
    for_example
public normal_example
requires val != null&&val.equals(new org.jmlspecs.models.resolve.NaturalNumber(3))&&this.equals(new org.jmlspecs.models.resolve.NaturalNumber(7));
ensures \result != null&&\result .equals(new org.jmlspecs.models.resolve.NaturalNumber(21));

divide

public NaturalNumber divide(non_null NaturalNumber val)
Return the quotient of this natural number divided by the given one.

See Also:
multiply(org.jmlspecs.models.resolve.NaturalNumber)
Specifications: non_null (class)pure
public normal_behavior
forall org.jmlspecs.models.resolve.NaturalNumber quot;
forall org.jmlspecs.models.resolve.NaturalNumber rem;
requires val != null&&!val.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
ensures quot != null&&rem != null&&rem.compareTo(this) < 0&&this.equals(rem.add(quot.multiply(val))) ==> \result .equals(quot);
     also
public exceptional_behavior
requires val != null&&val.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
signals_only java.lang.ArithmeticException;
    implies_that
public normal_behavior
requires val != null&&val.equals(org.jmlspecs.models.resolve.NaturalNumber.ONE);
ensures \result != null&&\result .equals(this);
    for_example
public normal_example
requires val != null&&val.equals(new org.jmlspecs.models.resolve.NaturalNumber(3))&&this.equals(new org.jmlspecs.models.resolve.NaturalNumber(22));
ensures \result != null&&\result .equals(new org.jmlspecs.models.resolve.NaturalNumber(7));

remainder

public NaturalNumber remainder(non_null NaturalNumber val)
Return the remainder of this natural number divided by the given one.

See Also:
divide(org.jmlspecs.models.resolve.NaturalNumber)
Specifications: non_null (class)pure
public normal_behavior
forall org.jmlspecs.models.resolve.NaturalNumber quot;
forall org.jmlspecs.models.resolve.NaturalNumber rem;
requires val != null&&!val.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
ensures quot != null&&rem != null&&rem.compareTo(this) < 0&&this.equals(rem.add(quot.multiply(val))) ==> \result .equals(rem);
     also
public exceptional_behavior
requires val != null&&val.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
signals_only java.lang.ArithmeticException;
    implies_that
public normal_behavior
requires val != null&&val.equals(org.jmlspecs.models.resolve.NaturalNumber.ONE);
ensures \result != null&&\result .equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
    for_example
public normal_example
requires val != null&&val.equals(new org.jmlspecs.models.resolve.NaturalNumber(3))&&this.equals(new org.jmlspecs.models.resolve.NaturalNumber(22));
ensures \result != null&&\result .equals(new org.jmlspecs.models.resolve.NaturalNumber(1));

pow

public NaturalNumber pow(non_null NaturalNumber exponent)
                  throws OutOfMemoryError
Return this natural number multiplied by itself the given number of times.

Throws:
OutOfMemoryError
See Also:
multiply(org.jmlspecs.models.resolve.NaturalNumber), pow(int)
Specifications: non_null (class)pure
public normal_behavior
requires exponent != null;
{|
requires !this.isZero()&&exponent.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
ensures \result != null&&\result .equals(org.jmlspecs.models.resolve.NaturalNumber.ONE);
also
forall org.jmlspecs.models.resolve.NaturalNumber v;
requires !(exponent.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO))&&exponent.compareTo(java.math.BigInteger.valueOf(2147483647)) <= 0;
ensures v != null&&v.suc().equals(exponent) ==> \result != null&&\result .equals(this.multiply(this.pow(v)));
|}
    implies_that
public normal_behavior
requires exponent != null&&exponent.equals(org.jmlspecs.models.resolve.NaturalNumber.ONE);
ensures \result != null&&\result .equals(this);
     also
public normal_behavior
requires exponent != null&&this.isZero()&&!exponent.isZero()&&exponent.compareTo(java.math.BigInteger.valueOf(2147483647)) <= 0;
ensures \result != null&&\result .equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
ensures_redundantly \result != null&&\result .equals(this);
    for_example
public normal_example
requires exponent != null&&exponent.equals(new org.jmlspecs.models.resolve.NaturalNumber(3))&&this.equals(new org.jmlspecs.models.resolve.NaturalNumber(3));
ensures \result != null&&\result .equals(new org.jmlspecs.models.resolve.NaturalNumber(27));

pow

public NaturalNumber pow(int exponent)
Return this natural number multiplied by itself the given number of times.

See Also:
multiply(org.jmlspecs.models.resolve.NaturalNumber), pow(NaturalNumber)
Specifications: non_null (class)pure
public normal_behavior
requires exponent >= 0;
{|
requires !this.isZero()&&exponent == 0;
ensures \result != null&&\result .equals(org.jmlspecs.models.resolve.NaturalNumber.ONE);
also
forall int v;
requires exponent != 0;
ensures v+1 == exponent ==> \result != null&&\result .equals(this.multiply(this.pow(v)));
|}
    implies_that
public normal_behavior
requires exponent == 1;
ensures \result != null&&\result .equals(this);

gcd

public NaturalNumber gcd(non_null NaturalNumber val)
Return the greatest common denominator of this number and the given number.

Specifications: non_null (class)pure
public normal_behavior
forall org.jmlspecs.models.resolve.NaturalNumber n;
requires !this.isZero()&&val != null&&!val.isZero();
ensures n != null&&n.divides(this)&&n.divides(val)&&( \forall org.jmlspecs.models.resolve.NaturalNumber m; m != null&&m.divides(this)&&m.divides(val); n.compareTo(m) >= 0) ==> \result .equals(n);
     also
public normal_behavior
requires this.isZero()&&val != null&&val.isZero();
ensures \result .isZero();
    for_example
public normal_example
requires val != null&&val.equals(new org.jmlspecs.models.resolve.NaturalNumber(12))&&this.equals(new org.jmlspecs.models.resolve.NaturalNumber(30));
ensures \result != null&&\result .equals(new org.jmlspecs.models.resolve.NaturalNumber(6));

mod

public NaturalNumber mod(non_null NaturalNumber m)
Return this natural number modulo the given one.

See Also:
remainder(org.jmlspecs.models.resolve.NaturalNumber)
Specifications: non_null (class)pure
public normal_behavior
requires m != null&&!m.isZero();
ensures \result .equals(this.remainder(m));
     also
public exceptional_behavior
requires m != null&&m.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
signals_only java.lang.ArithmeticException;

shiftLeft

public NaturalNumber shiftLeft(int n)
Return this natural number left shifted the given number of bits.

See Also:
shiftRight(int), pow(int)
Specifications: non_null (class)pure
public normal_behavior
requires n >= 0;
ensures \result != null&&\result .equals(this.multiply(new org.jmlspecs.models.resolve.NaturalNumber(2).pow(new org.jmlspecs.models.resolve.NaturalNumber(n))));
     also
public normal_behavior
requires n <= 0;
ensures \result != null&&\result .equals(this.shiftRight(java.lang.Math.abs(n)));
    implies_that
public normal_behavior
requires n == 0;
ensures \result != null&&\result .equals(this);

shiftRight

public NaturalNumber shiftRight(int n)
Return this natural number right shifted the given number of bits.

See Also:
shiftLeft(int), pow(int)
Specifications: non_null (class)pure
public normal_behavior
requires n >= 0;
ensures \result != null&&\result .equals(this.divide(new org.jmlspecs.models.resolve.NaturalNumber(2).pow(new org.jmlspecs.models.resolve.NaturalNumber(n))));
     also
public normal_behavior
requires n <= 0;
ensures \result != null&&\result .equals(this.shiftLeft(java.lang.Math.abs(n)));

compareTo

public int compareTo(non_null NaturalNumber val)
Return negative if this natural numbers strictly less than the given one, 0 if they are equal, and positive if this natural numbers is strictly greater than the given one.

See Also:
compareTo(Object), equals(java.lang.Object)
Specifications: (class)pure
public normal_behavior
requires val != null;
ensures \result == this.bigIntegerValue().compareTo(val.bigIntegerValue());
Specifications inherited from overridden method compareTo(Object o) in interface Comparable:
       pure
public behavior
requires o != null;
ensures (* \result is negative if this is "less than" o *);
ensures (* \result is 0 if this is "equal to" o *);
ensures (* \result is positive if this is "greater than" o *);
signals_only java.lang.ClassCastException;
signals (java.lang.ClassCastException) (* the class of o prohibits it from being compared to this *);
     also
public behavior
requires o != null&&o instanceof java.lang.Comparable;
ensures this.definedComparison((java.lang.Comparable)o,this);
ensures o == this ==> \result == 0;
ensures this.sgn(\result ) == -this.sgn(((java.lang.Comparable)o).compareTo(this));
signals (java.lang.ClassCastException) !this.definedComparison((java.lang.Comparable)o,this);
Specifications inherited from overridden method compareTo(Object obj) in interface TotalCompareTo:
       pure
     also
public behavior
requires obj != null;
ensures obj instanceof org.jmlspecs.models.resolve.TotalCompareTo;
signals_only java.lang.ClassCastException;
signals (java.lang.ClassCastException) !(obj instanceof org.jmlspecs.models.resolve.TotalCompareTo);
Specifications inherited from overridden method compareTo(Object obj) in interface CompareTo:
       pure
public behavior
requires obj != null;
ensures this.isComparableTo(obj);
ensures (* returns if this is comparable to obj *);
signals_only org.jmlspecs.models.resolve.UndefinedException, java.lang.ClassCastException;
signals (org.jmlspecs.models.resolve.UndefinedException e) (* no comparison between this and obj is defined *)&&e != null;
signals (java.lang.ClassCastException e) (* obj's type prevents it from being compared to this *)&&e != null;

compareTo

public int compareTo(non_null BigInteger val)
Specifications: (class)pure
public normal_behavior
ensures \result == this.bigIntegerValue().compareTo(val);
Specifications inherited from overridden method compareTo(Object o) in interface Comparable:
       pure
public behavior
requires o != null;
ensures (* \result is negative if this is "less than" o *);
ensures (* \result is 0 if this is "equal to" o *);
ensures (* \result is positive if this is "greater than" o *);
signals_only java.lang.ClassCastException;
signals (java.lang.ClassCastException) (* the class of o prohibits it from being compared to this *);
     also
public behavior
requires o != null&&o instanceof java.lang.Comparable;
ensures this.definedComparison((java.lang.Comparable)o,this);
ensures o == this ==> \result == 0;
ensures this.sgn(\result ) == -this.sgn(((java.lang.Comparable)o).compareTo(this));
signals (java.lang.ClassCastException) !this.definedComparison((java.lang.Comparable)o,this);
Specifications inherited from overridden method compareTo(Object obj) in interface TotalCompareTo:
       pure
     also
public behavior
requires obj != null;
ensures obj instanceof org.jmlspecs.models.resolve.TotalCompareTo;
signals_only java.lang.ClassCastException;
signals (java.lang.ClassCastException) !(obj instanceof org.jmlspecs.models.resolve.TotalCompareTo);
Specifications inherited from overridden method compareTo(Object obj) in interface CompareTo:
       pure
public behavior
requires obj != null;
ensures this.isComparableTo(obj);
ensures (* returns if this is comparable to obj *);
signals_only org.jmlspecs.models.resolve.UndefinedException, java.lang.ClassCastException;
signals (org.jmlspecs.models.resolve.UndefinedException e) (* no comparison between this and obj is defined *)&&e != null;
signals (java.lang.ClassCastException e) (* obj's type prevents it from being compared to this *)&&e != null;

compareTo

public int compareTo(non_null Object o)
              throws ClassCastException
Description copied from interface: CompareTo
Compare this to obj, returning negative if this is strictly less than obj, 0 if they are equal, and positive otherwise.

Specified by:
compareTo in interface CompareTo
Throws:
ClassCastException
Specifications: (class)pure
     also
public normal_behavior
requires o != null&&o instanceof org.jmlspecs.models.resolve.NaturalNumber;
requires this.equals(o);
ensures \result == 0;
Specifications inherited from overridden method compareTo(Object o) in interface Comparable:
       pure
public behavior
requires o != null;
ensures (* \result is negative if this is "less than" o *);
ensures (* \result is 0 if this is "equal to" o *);
ensures (* \result is positive if this is "greater than" o *);
signals_only java.lang.ClassCastException;
signals (java.lang.ClassCastException) (* the class of o prohibits it from being compared to this *);
     also
public behavior
requires o != null&&o instanceof java.lang.Comparable;
ensures this.definedComparison((java.lang.Comparable)o,this);
ensures o == this ==> \result == 0;
ensures this.sgn(\result ) == -this.sgn(((java.lang.Comparable)o).compareTo(this));
signals (java.lang.ClassCastException) !this.definedComparison((java.lang.Comparable)o,this);
Specifications inherited from overridden method compareTo(Object obj) in interface TotalCompareTo:
       pure
     also
public behavior
requires obj != null;
ensures obj instanceof org.jmlspecs.models.resolve.TotalCompareTo;
signals_only java.lang.ClassCastException;
signals (java.lang.ClassCastException) !(obj instanceof org.jmlspecs.models.resolve.TotalCompareTo);
Specifications inherited from overridden method compareTo(Object obj) in interface CompareTo:
       pure
public behavior
requires obj != null;
ensures this.isComparableTo(obj);
ensures (* returns if this is comparable to obj *);
signals_only org.jmlspecs.models.resolve.UndefinedException, java.lang.ClassCastException;
signals (org.jmlspecs.models.resolve.UndefinedException e) (* no comparison between this and obj is defined *)&&e != null;
signals (java.lang.ClassCastException e) (* obj's type prevents it from being compared to this *)&&e != null;

equals

public boolean equals(nullable Object x)
Tell if this object is equal to the given argument.

Specified by:
equals in interface JMLType
Overrides:
equals in class Object
See Also:
compareTo(Object), compareTo(NaturalNumber), equals(java.lang.Object)
Specifications: (class)pure
Specifications inherited from overridden method equals(Object obj) in class Object:
       pure
public normal_behavior
requires obj != null;
ensures (* \result is true when obj is "equal to" this object *);
     also
public normal_behavior
requires this == obj;
ensures \result ;
     also
public code normal_behavior
requires obj != null;
ensures \result <==> this == obj;
     also
diverges false;
ensures obj == null ==> !\result ;
Specifications inherited from overridden method equals(Object ob2) in interface JMLType:
       pure
     also
public normal_behavior
ensures \result ==> ob2 != null&&(* ob2 is not distinguishable from this, except by using mutation or == *);
    implies_that
public normal_behavior
{|
requires ob2 != null&&ob2 instanceof org.jmlspecs.models.JMLType;
ensures ((org.jmlspecs.models.JMLType)ob2).equals(this) == \result ;
also
requires ob2 == this;
ensures \result <==> true;
|}

clone

public Object clone()
Description copied from interface: JMLType
Return a clone of this object.

Specified by:
clone in interface JMLType
Overrides:
clone in class Object
Specifications: (class)pure
Specifications inherited from overridden method in class Object:
       non_null
protected normal_behavior
requires this instanceof java.lang.Cloneable;
assignable \nothing;
ensures \result != null;
ensures \typeof(\result ) == \typeof(this);
ensures (* \result is a clone of this *);
     also
protected normal_behavior
requires this.getClass().isArray();
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((java.lang.Object[])\result ).length == ((java.lang.Object[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((java.lang.Object[])this).length; ((java.lang.Object[])\result )[i] == ((java.lang.Object[])this)[i]);
     also
requires this.getClass().isArray();
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures java.lang.reflect.Array.getLength(\result ) == java.lang.reflect.Array.getLength(this);
ensures ( \forall int i; 0 <= i&&i < java.lang.reflect.Array.getLength(this); ( \exists java.lang.Object result_i; result_i == java.lang.reflect.Array.get(\result ,i); (result_i == null&&java.lang.reflect.Array.get(this,i) == null)||(result_i != null&&result_i.equals(java.lang.reflect.Array.get(this,i)))));
     also
protected exceptional_behavior
requires !(this instanceof java.lang.Cloneable);
assignable \nothing;
signals_only java.lang.CloneNotSupportedException;
     also
protected normal_behavior
requires \elemtype(\typeof(this)) <: \type(java.lang.Object);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((java.lang.Object[])\result ).length == ((java.lang.Object[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((java.lang.Object[])this).length; ((java.lang.Object[])\result )[i] == ((java.lang.Object[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(int);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((int[])\result ).length == ((int[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((int[])this).length; ((int[])\result )[i] == ((int[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(byte);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((byte[])\result ).length == ((byte[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((byte[])this).length; ((byte[])\result )[i] == ((byte[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(char);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((char[])\result ).length == ((char[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((char[])this).length; ((char[])\result )[i] == ((char[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(long);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((long[])\result ).length == ((long[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((long[])this).length; ((long[])\result )[i] == ((long[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(short);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((short[])\result ).length == ((short[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((short[])this).length; ((short[])\result )[i] == ((short[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(boolean);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((boolean[])\result ).length == ((boolean[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((boolean[])this).length; ((boolean[])\result )[i] == ((boolean[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(float);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((float[])\result ).length == ((float[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((float[])this).length; (java.lang.Float.isNaN(((float[])\result )[i])&&java.lang.Float.isNaN(((float[])this)[i]))||((float[])\result )[i] == ((float[])this)[i]);
     also
protected normal_behavior
requires \elemtype(\typeof(this)) == \type(double);
assignable \nothing;
ensures \elemtype(\typeof(\result )) == \elemtype(\typeof(this));
ensures ((double[])\result ).length == ((double[])this).length;
ensures ( \forall int i; 0 <= i&&i < ((double[])this).length; (java.lang.Double.isNaN(((double[])\result )[i])&&java.lang.Double.isNaN(((double[])this)[i]))||((double[])\result )[i] == ((double[])this)[i]);
Specifications inherited from overridden method in interface JMLType:
       pure
     also
public normal_behavior
ensures \result != null;
ensures \result instanceof org.jmlspecs.models.JMLType;
ensures ((org.jmlspecs.models.JMLType)\result ).equals(this);
    implies_that
ensures \result != null&&\typeof(\result ) <: \type(org.jmlspecs.models.JMLType);

isZero

public boolean isZero()
Tell if this object is equal to zero.

See Also:
ZERO, compareTo(NaturalNumber), equals(java.lang.Object)
Specifications: (class)pure
public normal_behavior
ensures \result <==> this.equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);
ensures_redundantly \result <==> this.compareTo(org.jmlspecs.models.resolve.NaturalNumber.ZERO) == 0;
ensures_redundantly \result <==> this.equals(new org.jmlspecs.models.resolve.NaturalNumber());

divides

public boolean divides(non_null NaturalNumber val)
Tell if this natural number divides the given one evenly.

See Also:
remainder(org.jmlspecs.models.resolve.NaturalNumber), mod(org.jmlspecs.models.resolve.NaturalNumber)
Specifications: (class)pure
public normal_behavior
requires val != null;
ensures \result <==> !this.isZero()&&val.remainder(this).equals(org.jmlspecs.models.resolve.NaturalNumber.ZERO);

min

public NaturalNumber min(non_null NaturalNumber val)
Return the smaller of the given natural number and this one.

See Also:
max(org.jmlspecs.models.resolve.NaturalNumber), compareTo(NaturalNumber)
Specifications: (class)pure
public normal_behavior
requires val != null;
{|
requires this.compareTo(val) <= 0;
ensures \result != null&&\result .equals(this);
also
requires val.compareTo(this) <= 0;
ensures \result != null&&\result .equals(val);
|}

max

public NaturalNumber max(non_null NaturalNumber val)
Return the smaller of the given natural number and this one.

See Also:
max(org.jmlspecs.models.resolve.NaturalNumber), compareTo(NaturalNumber)
Specifications: (class)pure
public normal_behavior
requires val != null;
{|
requires this.compareTo(val) >= 0;
ensures \result != null&&\result .equals(this);
also
requires val.compareTo(this) >= 0;
ensures \result != null&&\result .equals(val);
|}

hashCode

public int hashCode()
Description copied from interface: JMLType
Return a hash code for this object.

Specified by:
hashCode in interface JMLType
Overrides:
hashCode in class Object
Specifications: (class)pure
Specifications inherited from overridden method in class Object:
public behavior
assignable objectState;
ensures (* \result is a hash code for this object *);
     also
public code normal_behavior
assignable \nothing;
Specifications inherited from overridden method in interface JMLType:
       pure

toString

public String toString()
Overrides:
toString in class Object
Specifications: (class)pure
Specifications inherited from overridden method in class Object:
       non_null
public normal_behavior
assignable objectState;
ensures \result != null&&\result .equals(this.theString);
ensures (* \result is a string representation of this object *);
     also
public code normal_behavior
assignable \nothing;
ensures \result != null&&(* \result is the instance's class name, followed by an @, followed by the instance's hashcode in hex *);
     also
public code model_program { ... }
    implies_that
assignable objectState;
ensures \result != null;

bigIntegerValue

public BigInteger bigIntegerValue()
Return the BigInteger value of this natural number.

See Also:
intValue(), longValue()
Specifications: non_null (class)pure
public normal_behavior
ensures \result != null&&new org.jmlspecs.models.resolve.NaturalNumber(\result ).equals(this);

intValue

public int intValue()
Specifications: (class)pure
Specifications inherited from overridden method in class Number:
       pure
public normal_behavior
ensures (* \result is an int approximation to the value of this object *);

longValue

public long longValue()
Specifications: (class)pure
Specifications inherited from overridden method in class Number:
       pure
public normal_behavior
ensures (* \result is an long approximation to the value of this object *);

floatValue

public float floatValue()
Specifications: (class)pure
Specifications inherited from overridden method in class Number:
       pure
public normal_behavior
ensures (* \result is an float approximation to the value of this object *);

doubleValue

public double doubleValue()
Specifications: (class)pure
Specifications inherited from overridden method in class Number:
       pure
public normal_behavior
ensures (* \result is an double approximation to the value of this object *);

JML

JML is Copyright (C) 1998-2002 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This release depends on code from the MultiJava project and is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.