-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classA simple type for recording the result of attempting to take the union of two intervals i1 and i2. -
Method Summary
Modifier and TypeMethodDescriptionReturns absolute value of number, preserving type.add(IntegerNumber arg0, IntegerNumber arg1) Adds two integer numbers and returns the result.To calculate the sum of two non-nulland not emptyIntervalwith same type (real/integer)Adds two numbers and returns result.add(RationalNumber arg0, RationalNumber arg1) Adds two rational numbers and returns the result.affineTransform(Interval interval, Number a, Number b) Computes the affineTransform of the input intervalitvwith two numbers:aandbas parameters.ceil(RationalNumber arg0) Returns the least integer greater than or equal to the given rational number.intcompare(IntegerNumber arg0, IntegerNumber arg1) Returns a positive value if arg0 is greater than arg1, 0 if arg0 equals arg1, -1 if arg0 is less than arg1.intComputes the relationships of twoIntervals.intReturns a positive value if arg0 is greater than arg1, 0 if arg0 equals arg1, a negative value if arg0 is less than arg1.intcompare(RationalNumber arg0, RationalNumber arg1) Returns a positive value if arg0>arg1, 0 if arg0 equals arg1, -1 if arg0invalid input: '<'arg1.decrement(IntegerNumber arg) arg - 1subtracts 1 of proper typedecrement(RationalNumber arg) arg-1.0denominator(RationalNumber arg0) Returns the denominator in a representation of the rational number as the quotient of two integers.divide(IntegerNumber arg0, IntegerNumber arg1) Divides two integer numbers and returns the result.Divides two givenIntervals and returns result.Divides two numbers and returns result.divide(RationalNumber arg0, RationalNumber arg1) Divides two rational numbers and returns the result.Returns the empty integer interval: (0,0).Returns the empty real interval: (0.0, 0.0).floor(RationalNumber arg0) Returns the greatest integer less than or equal to the given rational number.fraction(IntegerNumber numerator, IntegerNumber denominator) Returns the rational number which is the quotient of the two integers.booleangaussianElimination(RationalNumber[][] matrix) Performs Gauss-Jordan Elimination on a matrix of rational numbers, transforming the matrix to reduced row echelon form.gcd(IntegerNumber arg0, IntegerNumber arg1) Returns the greatest common divisor of two integers.increment(IntegerNumber arg) add(arg, 1)adds 1 of proper typeincrement(RationalNumber arg) add(arg, 1.0)infiniteInteger(boolean isPositiveInfinity) Returns an infiniteIntegerNumber, its signum is determined by the given boolean value.infiniteNumber(boolean isIntegral, boolean isPositiveInfinity) Returns an infiniteNumber, its type is determined by the first boolean argumentisIntegeraland its signum is determined by the second boolean argumentisPositiveInfinity.infiniteRational(boolean isPositiveInfinity) Returns an infiniteRationalNumber, its signum is determined by the given boolean value.integer(int value) Returns an integer number corresponding to the given Java int.integer(long value) Returns the IntegerNumber with value specified by the long.Returns the integer number specified by the given string.integer(BigInteger big) Returns the IntegerNumber with value specified by the BigInteger.integerToRational(IntegerNumber integer) Casts an integer to a rational number.integerValue(RationalNumber arg0) Returns the value of the rational number as an integer number.intersection(Interval i1, Interval i2) Returns the interval which is the intersection of the two given intervals.booleanisIntegral(RationalNumber arg0) Returns true iff the rational number is an integer, e.g., "3.0", or "4/2".Returns the smallest interval containing both of the given intervals.lcm(IntegerNumber arg0, IntegerNumber arg1) Returns the least common multiple of the two positive integers.mod(IntegerNumber arg0, IntegerNumber arg1) Modulo operations.multiply(IntegerNumber arg0, IntegerNumber arg1) Multiplies two integer numbers and returns the result.To calculate the product of two non-nulland not emptyIntervalwith same type (real/integer)
This is the smallest interval containing all x1*x2, where x1 is in i1 and x2 is in i2.Multiplies two numbers and returns result.multiply(RationalNumber arg0, RationalNumber arg1) Multiplies two rational numbers and returns the result.negate(IntegerNumber arg0) Returns the negation of the given integer number, i.e., -x.To negate the given non-nullinterval.Negates the number, preserving the type (IntegerNumberIF or RationalNumberIF).negate(RationalNumber arg0) Returns the negation of the given rational number, i.e., -x.Return aIntegerNumberrepresenting the negative infinity.Return aRationalNumberrepresenting the negative infinity.newInterval(boolean isIntegral, Number lower, boolean strictLower, Number upper, boolean strictUpper) Returns a newIntervalas specified.nthRootInt(IntegerNumber number, IntegerNumber n) Calculate the nth root of the given number and n.Makes best guest on type of number based on string.numerator(RationalNumber arg0) Returns the numerator in a representation of the rational number as the quotient of two integers.The integer number zero.The rational number one.Return aIntegerNumberrepresenting the positive infinity.Return aRationalNumberrepresenting the positive infinity.power(IntegerNumber number, int exp) Calculate the given integer number powering a given exponent and returns result.power(IntegerNumber number, IntegerNumber exp) Calculate the givenIntegerNumberbase powering a givenIntegerNumberexponent and returns result.To calculate the power-result of a given non-nulland not emptyIntervalwith a given natural number.power(Interval interval, IntegerNumber expr) To calculate the power-result of a given non-nulland not emptyIntervalwith a given non-nullnon-negativeIntegerNumber.Calculate the given number powering a given exponent and returns result.power(Number number, IntegerNumber exp) Calculate the givenNumberbase powering a givenIntegerNumberexponent and returns result.power(RationalNumber number, int exp) Calculate the given rational number powering a given exponent and returns result.power(RationalNumber number, IntegerNumber exp) Calculate the givenRationalNumberbase powering a givenIntegerNumberexponent and returns result.Returns a rational representation of the number.Returns the rational number specified by the given string, where the string is a decimal representation of the number.rational(BigInteger numerator, BigInteger denominator) Returns the rational number which is the quotient of the two given integers.booleanrelativeGaussianElimination(RationalNumber[][] mat1, RationalNumber[][] mat2) Performs a form of "relative Gauss-Jordan elimination".restrictLower(Interval interval, Number bound, boolean strict) Restricts the lower bound of an interval as specified.restrictUpper(Interval interval, Number bound, boolean strict) Restricts the upper bound of an interval as specified.scientificString(RationalNumber num, int numSig) Constructs a string representation of the given rational number in scientific notation: x.xxxx * 10^{-yyy}.Returns the interval consisting of the single finite number x: [x,x].subtract(IntegerNumber arg0, IntegerNumber arg1) Subtracts two integer numbers and returns the result.Subtracts two numbers and returns result.subtract(RationalNumber arg0, RationalNumber arg1) Subtracts two rational numbers and returns the result.voidunion(Interval i1, Interval i2, NumberFactory.IntervalUnion result) Computes the union of two intervals or reports that the union is not an interval and why.Returns the universal integer interval: (-∞, +∞).Returns the universal real interval: (-∞, +∞).The integer number zero.The rational number zero.
-
Method Details
-
integer
Returns the integer number specified by the given string. The string could be something like "7583902" or "-1" or "0". There is no bound on the length of the string. -
integer
Returns an integer number corresponding to the given Java int. -
infiniteInteger
Returns an infiniteIntegerNumber, its signum is determined by the given boolean value.- Parameters:
isPositiveInfinity- A boolean value determines whether this number is positive or negative.
-
rational
Returns the rational number specified by the given string, where the string is a decimal representation of the number. The string may be an integer string, such as "394" or "-1" or "0". Or it may contain a decimal point, as in "-3.1415" or "2." or ".234" or "-.234". There is no limit on the number of digits. -
infiniteRational
Returns an infiniteRationalNumber, its signum is determined by the given boolean value.- Parameters:
isPositiveInfinity- A boolean value determines whether this number is positive or negative.
-
number
Makes best guest on type of number based on string. -
infiniteNumber
Returns an infiniteNumber, its type is determined by the first boolean argumentisIntegeraland its signum is determined by the second boolean argumentisPositiveInfinity.- Parameters:
isPositiveInfinity- A boolean value determines whether this number is positive or negative.isIntegeral- A boolean value determines whether this number is an integer number or a rational one.- Returns:
-
abs
Returns absolute value of number, preserving type. -
isIntegral
Returns true iff the rational number is an integer, e.g., "3.0", or "4/2". If this method returns true, it is then safe to invoke method integerValue() on the number. -
fraction
Returns the rational number which is the quotient of the two integers. -
integerToRational
Casts an integer to a rational number. -
zeroRational
RationalNumber zeroRational()The rational number zero. -
oneRational
RationalNumber oneRational()The rational number one. -
zeroInteger
IntegerNumber zeroInteger()The integer number zero. -
oneInteger
IntegerNumber oneInteger()The integer number zero. -
positiveInfinityRational
RationalNumber positiveInfinityRational()Return aRationalNumberrepresenting the positive infinity.- Returns:
-
positiveInfinityInteger
IntegerNumber positiveInfinityInteger()Return aIntegerNumberrepresenting the positive infinity.- Returns:
-
negativeInfinityRational
RationalNumber negativeInfinityRational()Return aRationalNumberrepresenting the negative infinity.- Returns:
-
negativeInfinityInteger
IntegerNumber negativeInfinityInteger()Return aIntegerNumberrepresenting the negative infinity.- Returns:
-
add
Adds two numbers and returns result. The numbers must be of same type (integer or real), which is also the type of the result. -
subtract
Subtracts two numbers and returns result. The numbers must be of same type (integer or real), which is also the type of the result. -
multiply
Multiplies two numbers and returns result. The numbers must be of same type (integer or real), which is also the type of the result. -
divide
Divides two numbers and returns result. The numbers must be of same type (integer or real), which is also the type of the result. -
negate
Negates the number, preserving the type (IntegerNumberIF or RationalNumberIF). -
add
Adds two rational numbers and returns the result. -
subtract
Subtracts two rational numbers and returns the result. -
multiply
Multiplies two rational numbers and returns the result. -
divide
Divides two rational numbers and returns the result. An ArithmeticException is thrown if arg1 is zero. -
negate
Returns the negation of the given rational number, i.e., -x. -
add
Adds two integer numbers and returns the result. -
subtract
Subtracts two integer numbers and returns the result. -
multiply
Multiplies two integer numbers and returns the result. -
divide
Divides two integer numbers and returns the result. Note that this is integer division. The result is obtained by taking the real quotient and rounding towards zero. An ArithmeticException is thrown if the denominator is zero. -
mod
Modulo operations. Returns the result of arg0 % arg1. -
negate
Returns the negation of the given integer number, i.e., -x. -
increment
add(arg, 1.0) -
increment
add(arg, 1) -
increment
adds 1 of proper type -
decrement
arg-1.0 -
decrement
arg - 1 -
decrement
subtracts 1 of proper type -
gcd
Returns the greatest common divisor of two integers. The two integers must be positive. -
lcm
Returns the least common multiple of the two positive integers. -
numerator
Returns the numerator in a representation of the rational number as the quotient of two integers. This method is coordinated with method denominator so that the quotient of the numerator and denominator give the original rational number. -
denominator
Returns the denominator in a representation of the rational number as the quotient of two integers. This method is coordinated with method numerator so that the quotient of the numerator and denominator give the original rational number. -
integerValue
Returns the value of the rational number as an integer number. Applies only to a rational number which is integral. I.e., the method isIntegral() must return true.- Throws:
ArithmeticException- if arg0 is not integral
-
floor
Returns the greatest integer less than or equal to the given rational number. -
ceil
Returns the least integer greater than or equal to the given rational number. -
compare
Returns a positive value if arg0>arg1, 0 if arg0 equals arg1, -1 if arg0invalid input: '<'arg1. -
compare
Returns a positive value if arg0 is greater than arg1, 0 if arg0 equals arg1, -1 if arg0 is less than arg1. -
rational
Returns a rational representation of the number. If the number already is rational, returns the number. Else casts from integer to rational. -
compare
Returns a positive value if arg0 is greater than arg1, 0 if arg0 equals arg1, a negative value if arg0 is less than arg1. -
gaussianElimination
Performs Gauss-Jordan Elimination on a matrix of rational numbers, transforming the matrix to reduced row echelon form.- Parameters:
matrix-- Returns:
trueiff a non-trivial modification was made tomatrix. A non-trivial modification is any modification other than a permutation of the rows.
-
relativeGaussianElimination
Performs a form of "relative Gauss-Jordan elimination". Given two matrices with the same number of columns. The first matrix is transformed to reduced row echelon form by the usual Gauss-Jordan elimination (method
gaussianElimination(RationalNumber[][])). Then suitable multiples of the rows in the first matrix are added to rows in the second matrix so as to make all entries in columns in the second matrix corresponding to pivot columns in the first matrix 0. Then the usual Gauss-Jordan elimination is performed on the second matrix.Motivation: the idea is that a context specifies some set of constraints in mat1, and a sub-context specifies additional constraints in mat2. To simplify the sub-context, you can use any of the information in the original context.
Let A1=mat1 in reduced row echelon form. Let A2=mat2 and A2' result of performing one elementary row operation. Want:
A2x=b2 iff A2'x=b2' for all x s.t. A1x=b1.
This holds since A2' is obtained by adding the same number to both sides of an equation.- Parameters:
mat1- the first matrix, which is the "background" contextmat2- the second matrix, which is the one being reduced under the context above- Returns:
trueiff a non-trivial modification was made tomatrix. A non-trivial modification is any modification other than a permutation of the rows.
-
rational
Returns the rational number which is the quotient of the two given integers. It can of course be simplified.- Parameters:
numerator- any BigIntegerdenominator- any BigInteger- Returns:
- numerator/denominator
- Throws:
ArithmeticException- if denominator is zero
-
integer
Returns the IntegerNumber with value specified by the BigInteger. No precision is lost- Parameters:
big- any BigInteger- Returns:
- the corresponding IntegerNumber
-
integer
Returns the IntegerNumber with value specified by the long. No precision is lost.- Parameters:
value- any long- Returns:
- the corresponding IntegerNumber
-
emptyIntegerInterval
Interval emptyIntegerInterval()Returns the empty integer interval: (0,0).- Returns:
- empty integer interval
-
emptyRealInterval
Interval emptyRealInterval()Returns the empty real interval: (0.0, 0.0).- Returns:
- empty real interval
-
universalIntegerInterval
Interval universalIntegerInterval()Returns the universal integer interval: (-∞, +∞).- Returns:
- universal integer interval
-
universalRealInterval
Interval universalRealInterval()Returns the universal real interval: (-∞, +∞).- Returns:
- universal real interval
-
singletonInterval
Returns the interval consisting of the single finite number x: [x,x].- Parameters:
x- a non-nullNumber- Returns:
- closed interval of same type as
xwith both bounds equal toxand non-strict
-
restrictUpper
Restricts the upper bound of an interval as specified. Returns the interval which is the intersection of the givenintervaland the interval (-∞,bound) (ifstrict) or (-∞,bound] (if notstrict). This method could be implemented usingintersection(Interval, Interval)or it could be implemented more efficiently in an equivalent way. -
restrictLower
Restricts the lower bound of an interval as specified. Returns the interval which is the intersection of the givenintervaland the interval (bound,∞) (ifstrict) or (bound,∞] (if notstrict). This method could be implemented usingintersection(Interval, Interval)or it could be implemented more efficiently in an equivalent way. -
newInterval
Interval newInterval(boolean isIntegral, Number lower, boolean strictLower, Number upper, boolean strictUpper) Returns a newIntervalas specified. If the bound ofthisIntervalis an implementation ofRealInfinity, the bound represents an infinity.
Precondition:- if the type is integral, then the upper and lower bounds must be
instances of
IntegerNumber, else they must be instances ofRationalNumber
- if the type is integral, then the upper and lower bounds must be
instances of
IntegerNumber, else they must be instances ofRationalNumber - if the bound is exclusive, the corresponding
strictLower(orstrictUpper) must betrue. - the lower bound must be less than or equal to the upper bound (Otherwise, this method will return an empty interval.)
- if the bounds are finite and equal: either (1) both
strictLowerandstrictUpperwill befalse, or (2)strictLowerandstrictUpperwill betrueand the upper and lower bounds will be 0. The first case represents an interval consisting of a single point; the second case represents the empty interval. - if the lower bound
loweris infinite, it must be a negative infinity. And if the upper boundupperis infinite, it must be a positive infinity. - if
isIntegralistrue: if the lower bound is finite thenstrictLowermust befalse; if the upper bound is finite thenstrictUppermust befalse.
- Parameters:
isIntegral- does the interval have integer type (as opposed to real type)?lower- the lower bound of the interval with the type defined by isIntegralstrictLower- is the lower bound strict? (i.e., "(" if exclusive, as opposed to "[" if inclusive)upper- the upper bound of the interval with the type defined by isIntegralstrictUpper- is the upper bound strict? (i.e., ")" if exclusive, as opposed to "]" if inclusive)- Returns:
- a new interval instance as specified
- if the type is integral, then the upper and lower bounds must be
instances of
-
intersection
Returns the interval which is the intersection of the two given intervals. The two given intervals must have the same type. -
union
Computes the union of two intervals or reports that the union is not an interval and why. The result is stored in theresultobject. If the union of the two intervals is an interval,result.statuswill be set to 0 andresult.unionwill hold the union interval. Otherwise, the status will be set to either a negative or positive integer andresult.unionwill be set tonull. A positive status indicates that every element of i1 is greater than every element of i2; a negative status indicates every element of i1 is less than every element of i2.- Parameters:
i1- an non-nullIntervali2- an non-nullIntervalof same type (integral or rational) as "i1"result- an non-nullNumberFactory.IntervalUnionused for receiving the result union
-
join
Returns the smallest interval containing both of the given intervals. -
affineTransform
Computes the affineTransform of the input intervalitvwith two numbers:aandbas parameters. -
compare
Computes the relationships of twoIntervals.
- Return -3, if the first
Intervalis on the left side and disjointed with the secondInterval- Return -2, if the first
Intervalis on the left side and intersected with the secondInterval- Return -1, if the first
Intervalcontains the secondInterval- Return 0, if the first
Intervalis exactly same with the secondInterval- Return 1, if the first
Intervalis contained in the secondInterval- Return 2, if the first
Intervalis on the right side and intersected with the secondInterval- Return 3, if the first
Intervalis on the right side and disjointed with the secondInterval - Return -3, if the first
-
negate
To negate the given non-nullinterval. -
add
To calculate the sum of two non-nulland not emptyIntervalwith same type (real/integer) -
multiply
To calculate the product of two non-nulland not emptyIntervalwith same type (real/integer)
This is the smallest interval containing all x1*x2, where x1 is in i1 and x2 is in i2. -
power
To calculate the power-result of a given non-nulland not emptyIntervalwith a given natural number. -
power
To calculate the power-result of a given non-nulland not emptyIntervalwith a given non-nullnon-negativeIntegerNumber.- Parameters:
interval- a non-nullIntervalexpr- anIntegerNumberof a natural number- Returns:
- the power result described above.
-
power
Calculate the given number powering a given exponent and returns result. The exponent must be a natural number.- Parameters:
number- a non-nullIntegerNumberexp- a non-nullIntegerNumberrepresenting an natural number which is greater or equal to zero.- Returns:
- the power result of the
Numberwith the given integer
-
power
Calculate the given integer number powering a given exponent and returns result. The exponent must be a natural number.- Parameters:
number- a non-nullIntegerNumberexp- a non-nullIntegerNumberrepresenting an natural number which is greater or equal to zero.- Returns:
- the power result of the
IntegerNumberwith the given integer
-
power
Calculate the given rational number powering a given exponent and returns result. The exponent must be a natural number.- Returns:
- the power result of the
RationalNumberwith the given integer
-
power
Calculate the givenNumberbase powering a givenIntegerNumberexponent and returns result. The exponent must be a natural number.- Parameters:
number- a non-nullNumberexp- a non-nullIntegerNumberrepresenting an natural number which is greater or equal to zero.- Returns:
-
power
Calculate the givenRationalNumberbase powering a givenIntegerNumberexponent and returns result. The exponent must be a natural number.- Parameters:
number- a non-nullRationalNumberexp- a non-nullIntegerNumberrepresenting an natural number which is greater or equal to zero.- Returns:
-
power
Calculate the givenIntegerNumberbase powering a givenIntegerNumberexponent and returns result. The exponent must be a natural number.- Parameters:
number- a non-nullIntegerNumberexp- a non-nullIntegerNumberrepresenting an natural number which is greater or equal to zero.- Returns:
-
nthRootInt
Calculate the nth root of the given number and n. The inputs and output areinvalid reference
IntegerNumbers- Parameters:
number- a non-nullfinite;invalid reference
IntegerNumbersn- a non-nullpositive finiterepresenting the n;invalid reference
IntegerNumbers- Returns:
-
divide
Return theIntervalconsisting of allNumbers that eachNumberxin theIntervalmultiplies with the givennumis in the giveninterval.
(i.e., for allxin the returned result,x*numis ininterval.)
E.g., for integer intervals: [1,3]/2 = [1,1]; [1,4]/3 = [1,1]; [1,5]/6 = empty, for rational intervals: [1,3]/2 = [0.5,1.5]. -
divide
Divides two givenIntervals and returns result. They must be of same type (integer or real), which is also the type of the result.
This is the smallest interval containing all x1/x2, where x1 is in i1 and x2 is in i2. -
multiply
-
scientificString
Constructs a string representation of the given rational number in scientific notation: x.xxxx * 10^{-yyy}.- Parameters:
num- the rational numbernumSig- the number of significant digits- Returns:
- string representation in scientific notation
-