BigRational
edu.jas.arith

## Class BigRational

• ### Field Summary

Fields
Modifier and TypeField and Description
`BigInteger``den`
Denominator part of the data structure.
`BigInteger``num`
Numerator part of the data structure.
`static BigRational``ONE`
The Constant 1.
`static BigRational``ZERO`
The Constant 0.
• ### Constructor Summary

Constructors
Constructor and Description
`BigRational()`
Constructor for a BigRational with no arguments.
`BigRational(BigInteger n)`
Constructor for a BigRational from math.BigIntegers.
`BigRational(BigInteger n)`
Constructor for a BigRational from jas.arith.BigIntegers.
`BigRational(BigInteger n, BigInteger d)`
Constructor for a BigRational from jas.arith.BigIntegers.
`BigRational(long n)`
Constructor for a BigRational from longs.
`BigRational(long n, long d)`
Constructor for a BigRational from longs.
`BigRational(String s)`
Constructor for a BigRational from String.
• ### Method Summary

Methods
Modifier and TypeMethod and Description
`BigRational``abs()`
Rational number absolute value.
`BigInteger``characteristic()`
Characteristic of this ring.
`int``compareTo(BigRational S)`
Rational number comparison.
`BigRational``copy()`
Clone this.
`BigRational``copy(BigRational c)`
Copy BigRational element c.
`BigInteger``denominator()`
Get the denominator.
`BigRational``divide(BigRational S)`
Rational number quotient.
`BigRational[]``egcd(BigRational S)`
BigRational extended greatest common divisor.
`boolean``equals(Object b)`
Comparison with any other object.
`BigRational``factory()`
Get the corresponding element factory.
`BigRational``fromInteger(BigInteger a)`
Get a BigRational element from a math.BigInteger.
`BigRational``fromInteger(BigInteger a)`
Get a BigRational element from a arith.BigInteger.
`BigRational``fromInteger(long a)`
Get a BigRational element from a long.
`BigRational``gcd(BigRational S)`
Rational number greatest common divisor.
`List<BigRational>``generators()`
Get a list of the generating elements.
`BigRational``getONE()`
Get the one element.
`BigRational``getRational()`
Return a BigRational approximation of this Element.
`BigRational``getZERO()`
Get the zero element.
`int``hashCode()`
Hash code for this BigRational.
`BigRational``inverse()`
Rational number inverse.
`boolean``isAssociative()`
Query if this ring is associative.
`boolean``isCommutative()`
Query if this ring is commutative.
`boolean``isField()`
Query if this ring is a field.
`boolean``isFinite()`
Is this structure finite or infinite.
`boolean``isONE()`
Is BigRational one.
`boolean``isUnit()`
Is BigRational unit.
`boolean``isZERO()`
Is BigRational zero.
`Iterator<BigRational>``iterator()`
Get a BigRational iterator.
`BigRational``multiply(BigRational S)`
Rational number product.
`BigRational``negate()`
Rational number negative.
`BigInteger``numerator()`
Get the numerator.
`BigRational``parse(Reader r)`
`BigRational``parse(String s)`
Parse rational number from String.
`BigRational[]``quotientRemainder(BigRational S)`
Quotient and remainder by division of this by S.
`BigRational``random(int n)`
Rational number, random.
`BigRational``random(int n, Random rnd)`
Rational number, random.
`static BigRational``reduction(BigInteger n, BigInteger d)`
Rational number reduction to lowest terms.
`BigRational``remainder(BigRational S)`
Rational number remainder.
`static BigRational``RNABS(BigRational R)`
Rational number absolute value.
`static int``RNCOMP(BigRational R, BigRational S)`
Rational number comparison.
`static BigInteger``RNDEN(BigRational R)`
Rational number denominator.
`static BigRational``RNDIF(BigRational R, BigRational S)`
Rational number difference.
`static void``RNDWR(BigRational R, int NL)`
Rational number decimal write.
`static BigRational``RNINT(BigInteger A)`
Rational number from integer.
`static BigRational``RNINV(BigRational R)`
Rational number inverse.
`static BigRational``RNNEG(BigRational R)`
Rational number negative.
`static BigInteger``RNNUM(BigRational R)`
Rational number numerator.
`static BigRational``RNPROD(BigRational R, BigRational S)`
Rational number product.
`static BigRational``RNQ(BigRational R, BigRational S)`
Rational number quotient.
`static BigRational``RNRAND(int NL)`
Rational number, random.
`static BigRational``RNRED(BigInteger n, BigInteger d)`
Rational number reduction to lowest terms.
`static int``RNSIGN(BigRational R)`
Rational number sign.
`static BigRational``RNSUM(BigRational R, BigRational S)`
Rational number sum.
`void``setAllIterator()`
Set the iteration algorithm to all elements.
`void``setDuplicatesIterator()`
Set the iteration algorithm to allow duplicate elements.
`void``setNoDuplicatesIterator()`
Set the iteration algorithm to no duplicate elements.
`void``setNonNegativeIterator()`
Set the iteration algorithm to non-negative elements.
`int``signum()`
Rational number sign.
`BigRational``subtract(BigRational S)`
Rational number difference.
`BigRational``sum(BigRational S)`
Rational number sum.
`String``toScript()`
Get a scripting compatible string representation.
`String``toScriptFactory()`
Get a scripting compatible string representation of the factory.
`String``toString()`
Get the string representation.
`String``toString(int n)`
Get the decimal string representation with given precision.
`Iterator<BigRational>``uniqueIterator()`
Get a BigRational iterator with no duplicates.
`static BigRational``valueOf(BigInteger a)`
Get a BigRational element from a math.BigInteger.
`static BigRational``valueOf(long a)`
Get a BigRational element from a long.
• ### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### num

`public final BigInteger num`
Numerator part of the data structure.
• #### den

`public final BigInteger den`
Denominator part of the data structure.
• #### ZERO

`public static final BigRational ZERO`
The Constant 0.
• #### ONE

`public static final BigRational ONE`
The Constant 1.
• ### Constructor Detail

• #### BigRational

`public BigRational(BigInteger n)`
Constructor for a BigRational from math.BigIntegers.
Parameters:
`n` - math.BigInteger.
• #### BigRational

`public BigRational(BigInteger n)`
Constructor for a BigRational from jas.arith.BigIntegers.
Parameters:
`n` - edu.jas.arith.BigInteger.
• #### BigRational

`public BigRational(BigInteger n,           BigInteger d)`
Constructor for a BigRational from jas.arith.BigIntegers.
Parameters:
`n` - edu.jas.arith.BigInteger.
`d` - edu.jas.arith.BigInteger.
• #### BigRational

`public BigRational(long n,           long d)`
Constructor for a BigRational from longs.
Parameters:
`n` - long.
`d` - long.
• #### BigRational

`public BigRational(long n)`
Constructor for a BigRational from longs.
Parameters:
`n` - long.
• #### BigRational

`public BigRational()`
Constructor for a BigRational with no arguments.
• #### BigRational

`public BigRational(String s)            throws NumberFormatException`
Constructor for a BigRational from String.
Parameters:
`s` - String.
Throws:
`NumberFormatException`
• ### Method Detail

• #### factory

`public BigRational factory()`
Get the corresponding element factory.
Specified by:
`factory` in interface `Element<BigRational>`
Returns:
factory for this Element.
`Element.factory()`
• #### generators

`public List<BigRational> generators()`
Get a list of the generating elements.
Specified by:
`generators` in interface `ElemFactory<BigRational>`
Returns:
list of generators for the algebraic structure.
`ElemFactory.generators()`
• #### isFinite

`public boolean isFinite()`
Is this structure finite or infinite.
Specified by:
`isFinite` in interface `ElemFactory<BigRational>`
Returns:
true if this structure is finite, else false.
`ElemFactory.isFinite()`
• #### copy

`public BigRational copy()`
Clone this.
Specified by:
`copy` in interface `Element<BigRational>`
Returns:
Creates and returns a copy of this Element.
`Object.clone()`
• #### copy

`public BigRational copy(BigRational c)`
Copy BigRational element c.
Specified by:
`copy` in interface `ElemFactory<BigRational>`
Parameters:
`c` - BigRational.
Returns:
a copy of c.
• #### getRational

`public BigRational getRational()`
Return a BigRational approximation of this Element.
Specified by:
`getRational` in interface `Rational`
Returns:
a BigRational approximation of this.
`Rational.getRational()`
• #### numerator

`public BigInteger numerator()`
Get the numerator.
Returns:
num.
• #### denominator

`public BigInteger denominator()`
Get the denominator.
Returns:
den.
• #### toString

`public String toString()`
Get the string representation.
Overrides:
`toString` in class `Object`
`Object.toString()`
• #### toString

`public String toString(int n)`
Get the decimal string representation with given precision.
Parameters:
`n` - precission.
Returns:
decimal approximation.
• #### toScript

`public String toScript()`
Get a scripting compatible string representation.
Specified by:
`toScript` in interface `Element<BigRational>`
Specified by:
`toScript` in interface `ElemFactory<BigRational>`
Returns:
script compatible representation for this Element.
`Element.toScript()`
• #### toScriptFactory

`public String toScriptFactory()`
Get a scripting compatible string representation of the factory.
Specified by:
`toScriptFactory` in interface `Element<BigRational>`
Returns:
script compatible representation for this ElemFactory.
`Element.toScriptFactory()`
• #### getZERO

`public BigRational getZERO()`
Get the zero element.
Specified by:
`getZERO` in interface `AbelianGroupFactory<BigRational>`
Returns:
0 as BigRational.
• #### getONE

`public BigRational getONE()`
Get the one element.
Specified by:
`getONE` in interface `MonoidFactory<BigRational>`
Returns:
1 as BigRational.
• #### isCommutative

`public boolean isCommutative()`
Query if this ring is commutative.
Specified by:
`isCommutative` in interface `MonoidFactory<BigRational>`
Returns:
true.
• #### isAssociative

`public boolean isAssociative()`
Query if this ring is associative.
Specified by:
`isAssociative` in interface `MonoidFactory<BigRational>`
Returns:
true.
• #### isField

`public boolean isField()`
Query if this ring is a field.
Specified by:
`isField` in interface `RingFactory<BigRational>`
Returns:
true.
• #### characteristic

`public BigInteger characteristic()`
Characteristic of this ring.
Specified by:
`characteristic` in interface `RingFactory<BigRational>`
Returns:
characteristic of this ring.
• #### fromInteger

`public BigRational fromInteger(BigInteger a)`
Get a BigRational element from a math.BigInteger.
Specified by:
`fromInteger` in interface `ElemFactory<BigRational>`
Parameters:
`a` - math.BigInteger.
Returns:
BigRational from a.
• #### fromInteger

`public BigRational fromInteger(BigInteger a)`
Get a BigRational element from a arith.BigInteger.
Parameters:
`a` - arith.BigInteger.
Returns:
BigRational from a.
• #### valueOf

`public static BigRational valueOf(BigInteger a)`
Get a BigRational element from a math.BigInteger.
Parameters:
`a` - math.BigInteger.
Returns:
BigRational from a.
• #### fromInteger

`public BigRational fromInteger(long a)`
Get a BigRational element from a long.
Specified by:
`fromInteger` in interface `ElemFactory<BigRational>`
Parameters:
`a` - long.
Returns:
BigRational from a.
• #### valueOf

`public static BigRational valueOf(long a)`
Get a BigRational element from a long.
Parameters:
`a` - long.
Returns:
BigRational from a.
• #### isZERO

`public boolean isZERO()`
Is BigRational zero.
Specified by:
`isZERO` in interface `AbelianGroupElem<BigRational>`
Returns:
If this is 0 then true is returned, else false.
`AbelianGroupElem.isZERO()`
• #### isONE

`public boolean isONE()`
Is BigRational one.
Specified by:
`isONE` in interface `MonoidElem<BigRational>`
Returns:
If this is 1 then true is returned, else false.
`MonoidElem.isONE()`
• #### isUnit

`public boolean isUnit()`
Is BigRational unit.
Specified by:
`isUnit` in interface `MonoidElem<BigRational>`
Returns:
If this is a unit then true is returned, else false.
`MonoidElem.isUnit()`
• #### equals

`public boolean equals(Object b)`
Comparison with any other object.
Specified by:
`equals` in interface `Element<BigRational>`
Overrides:
`equals` in class `Object`
Returns:
true if this is equal to b, else false.
`Object.equals(java.lang.Object)`
• #### hashCode

`public int hashCode()`
Hash code for this BigRational.
Specified by:
`hashCode` in interface `Element<BigRational>`
Overrides:
`hashCode` in class `Object`
Returns:
the hashCode.
`Object.hashCode()`
• #### RNRED

`public static BigRational RNRED(BigInteger n,                BigInteger d)`
Rational number reduction to lowest terms.
Parameters:
`n` - BigInteger.
`d` - BigInteger.
Returns:
a/b ~ n/d, gcd(a,b) = 1, b > 0.
• #### reduction

`public static BigRational reduction(BigInteger n,                    BigInteger d)`
Rational number reduction to lowest terms.
Parameters:
`n` - BigInteger.
`d` - BigInteger.
Returns:
a/b ~ n/d, gcd(a,b) = 1, b > 0.
• #### abs

`public BigRational abs()`
Rational number absolute value.
Specified by:
`abs` in interface `AbelianGroupElem<BigRational>`
Returns:
the absolute value of this.
`AbelianGroupElem.abs()`
• #### RNABS

`public static BigRational RNABS(BigRational R)`
Rational number absolute value.
Parameters:
`R` - is a rational number.
Returns:
the absolute value of R.
• #### compareTo

`public int compareTo(BigRational S)`
Rational number comparison.
Specified by:
`compareTo` in interface `Element<BigRational>`
Specified by:
`compareTo` in interface `Comparable<BigRational>`
Parameters:
`S` - BigRational.
Returns:
SIGN(this-S).
• #### RNCOMP

`public static int RNCOMP(BigRational R,         BigRational S)`
Rational number comparison.
Parameters:
`R` - BigRational.
`S` - BigRational.
Returns:
SIGN(R-S).
• #### RNDEN

`public static BigInteger RNDEN(BigRational R)`
Rational number denominator.
Parameters:
`R` - BigRational.
Returns:
R.denominator().
• #### subtract

`public BigRational subtract(BigRational S)`
Rational number difference.
Specified by:
`subtract` in interface `AbelianGroupElem<BigRational>`
Parameters:
`S` - BigRational.
Returns:
this-S.
• #### RNDIF

`public static BigRational RNDIF(BigRational R,                BigRational S)`
Rational number difference.
Parameters:
`R` - BigRational.
`S` - BigRational.
Returns:
R-S.
• #### RNDWR

`public static void RNDWR(BigRational R,         int NL)`
Rational number decimal write. R is a rational number. n is a non-negative integer. R is approximated by a decimal fraction D with n decimal digits following the decimal point and D is written in the output stream. The inaccuracy of the approximation is at most (1/2)*10**-n.
Parameters:
`R` -
`NL` -
• #### RNINT

`public static BigRational RNINT(BigInteger A)`
Rational number from integer.
Parameters:
`A` - BigInteger.
Returns:
A/1.
• #### inverse

`public BigRational inverse()`
Rational number inverse.
Specified by:
`inverse` in interface `MonoidElem<BigRational>`
Returns:
1/this.
`MonoidElem.inverse()`
• #### RNINV

`public static BigRational RNINV(BigRational R)`
Rational number inverse.
Parameters:
`R` - BigRational.
Returns:
1/R.
• #### negate

`public BigRational negate()`
Rational number negative.
Specified by:
`negate` in interface `AbelianGroupElem<BigRational>`
Returns:
-this.
`AbelianGroupElem.negate()`
• #### RNNEG

`public static BigRational RNNEG(BigRational R)`
Rational number negative.
Parameters:
`R` - BigRational.
Returns:
-R.
• #### RNNUM

`public static BigInteger RNNUM(BigRational R)`
Rational number numerator.
Parameters:
`R` - BigRational.
Returns:
R.numerator().
• #### multiply

`public BigRational multiply(BigRational S)`
Rational number product.
Specified by:
`multiply` in interface `MonoidElem<BigRational>`
Parameters:
`S` - BigRational.
Returns:
this*S.
• #### RNPROD

`public static BigRational RNPROD(BigRational R,                 BigRational S)`
Rational number product.
Parameters:
`R` - BigRational.
`S` - BigRational.
Returns:
R*S.
• #### divide

`public BigRational divide(BigRational S)`
Rational number quotient.
Specified by:
`divide` in interface `MonoidElem<BigRational>`
Parameters:
`S` - BigRational.
Returns:
this/S.
• #### RNQ

`public static BigRational RNQ(BigRational R,              BigRational S)`
Rational number quotient.
Parameters:
`R` - BigRational.
`S` - BigRational.
Returns:
R/S.
• #### remainder

`public BigRational remainder(BigRational S)`
Rational number remainder.
Specified by:
`remainder` in interface `MonoidElem<BigRational>`
Parameters:
`S` - BigRational.
Returns:
this-(this/S)*S
• #### quotientRemainder

`public BigRational[] quotientRemainder(BigRational S)`
Quotient and remainder by division of this by S.
Parameters:
`S` - a rational number
Returns:
[this/S, this - (this/S)*S].
• #### random

`public BigRational random(int n)`
Rational number, random. Random integers A, B and a random sign s are generated using BigInteger(n,random) and random.nextBoolen(). Then R = s*A/(B+1), reduced to lowest terms.
Specified by:
`random` in interface `ElemFactory<BigRational>`
Parameters:
`n` - such that 0 ≤ A, B ≤ (2n-1).
Returns:
a random BigRational.
• #### random

`public BigRational random(int n,                 Random rnd)`
Rational number, random. Random integers A, B and a random sign s are generated using BigInteger(n,random) and random.nextBoolen(). Then R = s*A/(B+1), reduced to lowest terms.
Specified by:
`random` in interface `ElemFactory<BigRational>`
Parameters:
`n` - such that 0 ≤ A, B ≤ (2n-1).
`rnd` - is a source for random bits.
Returns:
a random BigRational.
• #### RNRAND

`public static BigRational RNRAND(int NL)`
Rational number, random. Random integers A, B and a random sign s are generated using BigInteger(n,random) and random.nextBoolen(). Then R = s*A/(B+1), reduced to lowest terms.
Parameters:
`NL` - such that 0 ≤ A, B ≤ (2n-1).
Returns:
a random BigRational.
• #### signum

`public int signum()`
Rational number sign.
Specified by:
`signum` in interface `AbelianGroupElem<BigRational>`
Returns:
the sign of this.
`AbelianGroupElem.signum()`
• #### RNSIGN

`public static int RNSIGN(BigRational R)`
Rational number sign.
Parameters:
`R` - BigRational.
Returns:
R.signum().
• #### sum

`public BigRational sum(BigRational S)`
Rational number sum.
Specified by:
`sum` in interface `AbelianGroupElem<BigRational>`
Parameters:
`S` - BigRational.
Returns:
this+S.
• #### RNSUM

`public static BigRational RNSUM(BigRational R,                BigRational S)`
Rational number sum.
Parameters:
`R` - BigRational.
`S` - BigRational.
Returns:
R+S.
• #### parse

`public BigRational parse(String s)`
Parse rational number from String.
Specified by:
`parse` in interface `ElemFactory<BigRational>`
Parameters:
`s` - String.
Returns:
BigRational from s.
• #### parse

`public BigRational parse(Reader r)`
Specified by:
`parse` in interface `ElemFactory<BigRational>`
Parameters:
`r` - Reader.
Returns:
next BigRational from r.
• #### gcd

`public BigRational gcd(BigRational S)`
Rational number greatest common divisor.
Specified by:
`gcd` in interface `RingElem<BigRational>`
Parameters:
`S` - BigRational.
Returns:
gcd(this,S).
• #### egcd

`public BigRational[] egcd(BigRational S)`
BigRational extended greatest common divisor.
Specified by:
`egcd` in interface `RingElem<BigRational>`
Parameters:
`S` - BigRational.
Returns:
[ gcd(this,S), a, b ] with a*this + b*S = gcd(this,S).
• #### setAllIterator

`public void setAllIterator()`
Set the iteration algorithm to all elements.
• #### setNonNegativeIterator

`public void setNonNegativeIterator()`
Set the iteration algorithm to non-negative elements.
• #### setNoDuplicatesIterator

`public void setNoDuplicatesIterator()`
Set the iteration algorithm to no duplicate elements.
• #### setDuplicatesIterator

`public void setDuplicatesIterator()`
Set the iteration algorithm to allow duplicate elements.
• #### iterator

`public Iterator<BigRational> iterator()`
Get a BigRational iterator.
Specified by:
`iterator` in interface `Iterable<BigRational>`
Returns:
a iterator over all rationals.
• #### uniqueIterator

`public Iterator<BigRational> uniqueIterator()`
Get a BigRational iterator with no duplicates.
Returns:
a iterator over all rationals without duplicates.