Package cc.redberry.rings
Class Rationals<E>
java.lang.Object
cc.redberry.rings.Rationals<E>
- All Implemented Interfaces:
IParser<Rational<E>>
,Stringifiable<Rational<E>>
,Ring<Rational<E>>
,Serializable
,Iterable<Rational<E>>
,Comparator<Rational<E>>
public final class Rationals<E> extends Object implements Ring<Rational<E>>
The ring of rationals (Q).
- Since:
- 1.0
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Rational<E>
add(Rational<E> a, Rational<E> b)
Add two elementsBigInteger
cardinality()
Returns the number of elements in this ring (cardinality) or null if ring is infiniteBigInteger
characteristic()
Returns characteristic of this ringint
compare(Rational<E> o1, Rational<E> o2)
Rational<E>
copy(Rational<E> element)
Makes a deep copy of the specified element (for immutable instances the same reference returned).Rational<E>[]
createArray(int length)
Creates generic array of ring elements of specified lengthRational<E>[][]
createArray2d(int length)
Creates 2d array of ring elements of specified lengthRational<E>[][]
createArray2d(int m, int n)
Creates 2d array of ring elements of specified shapeRational<E>[]
divideAndRemainder(Rational<E> dividend, Rational<E> divider)
Returns quotient and remainder ofdividend / divider
boolean
equals(Object o)
FactorDecomposition<Rational<E>>
factor(Rational<E> element)
Factor specified elementFactorDecomposition<Rational<E>>
factorSquareFree(Rational<E> element)
Square-free factorization of specified elementRational<E>
gcd(Rational<E> a, Rational<E> b)
Returns the greatest common divisor of two elementsRational<E>
getNegativeOne()
Returns negative unit element of this ring (minus one)Rational<E>
getOne()
Returns unit element of this ring (one)Rational<E>
getZero()
Returns zero element of this ringint
hashCode()
boolean
isEuclideanRing()
Returns whether this ring is a Euclidean ringboolean
isField()
Returns whether this ring is a fieldboolean
isOne(Rational<E> element)
Tests whether specified element is one (exactly)boolean
isPerfectPower()
Returns whether the cardinality is a perfect power (p^k with k > 1)boolean
isUnit(Rational<E> element)
Tests whether specified element is a ring unitboolean
isZero(Rational<E> element)
Tests whether specified element is zeroIterator<Rational<E>>
iterator()
Returns iterator over ring elements (for finite rings, otherwise throws exception)Rational<E>
mk(long num, long den)
Gives rational with a given numerator and denominatorRational<E>
mk(E num, E den)
Gives rational with a given numerator and denominatorRational<E>
mkDenominator(long den)
Gives rational with a given denominator and unit numeratorRational<E>
mkDenominator(E den)
Gives rational with a given denominator and unit numeratorRational<E>
mkNumerator(long num)
Gives rational with a given numerator and unit denominatorRational<E>
mkNumerator(E num)
Gives rational with a given numerator and unit denominatorRational<E>
multiply(Rational<E> a, Rational<E> b)
Multiplies two elementsRational<E>
negate(Rational<E> element)
Negates the given elementBigInteger
perfectPowerBase()
Returnsbase
so thatcardinality == base^exponent
or null if cardinality is not finiteBigInteger
perfectPowerExponent()
Returnsexponent
so thatcardinality == base^exponent
or null if cardinality is not finiteRational<E>
randomElement(org.apache.commons.math3.random.RandomGenerator rnd)
Returns a random element from this ringRational<E>
randomElementTree(org.apache.commons.math3.random.RandomGenerator rnd)
If this ring has a complicated nested structure, this method guaranties that the resulting random element will reflect ring complicated structure, i.e.Rational<E>
reciprocal(Rational<E> element)
Gives the inverse elementelement ^ (-1)
int
signum(Rational<E> element)
Returns -1 ifelement < 0
, 0 ifelement == 0
and 1 ifelement > 0
, where comparison is specified byComparator.compare(Object, Object)
Rational<E>
subtract(Rational<E> a, Rational<E> b)
Subtractsb
froma
String
toString()
String
toString(IStringifier<Rational<E>> stringifier)
convert this to string with the use of stringifierRational<E>
valueOf(long val)
Returns ring element associated with specifiedlong
Rational<E>
valueOf(Rational<E> val)
Converts a value from other ring to this ring.Rational<E>
valueOfBigInteger(BigInteger val)
Returns ring element associated with specified integerMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface cc.redberry.rings.Ring
abs, add, addMutable, createArray, createArray, createArray, createZeroesArray, createZeroesArray2d, decrement, divideExact, divideExactMutable, divideOrNull, extendedGCD, factorial, fillZeros, firstBezoutCoefficient, gcd, gcd, increment, isFinite, isFiniteField, isMinusOne, isUnitOrZero, lcm, lcm, lcm, max, min, multiply, multiply, multiply, multiplyMutable, negateMutable, parse, pow, pow, pow, quotient, randomElement, randomElementTree, randomNonZeroElement, remainder, setToValueOf, subtractMutable, valueOf
-
Field Details
-
ring
Ring that numerator and denominator belongs to
-
-
Constructor Details
-
Rationals
-
-
Method Details
-
mkNumerator
Gives rational with a given numerator and unit denominator -
mkNumerator
Gives rational with a given numerator and unit denominator -
mkDenominator
Gives rational with a given denominator and unit numerator -
mkDenominator
Gives rational with a given denominator and unit numerator -
mk
Gives rational with a given numerator and denominator -
mk
Gives rational with a given numerator and denominator -
isField
public boolean isField()Description copied from interface:Ring
Returns whether this ring is a field -
isEuclideanRing
public boolean isEuclideanRing()Description copied from interface:Ring
Returns whether this ring is a Euclidean ring- Specified by:
isEuclideanRing
in interfaceRing<E>
- Returns:
- whether this ring is a Euclidean ring
-
cardinality
Description copied from interface:Ring
Returns the number of elements in this ring (cardinality) or null if ring is infinite- Specified by:
cardinality
in interfaceRing<E>
- Returns:
- the number of elements in this ring (cardinality) or null if ring is infinite
-
characteristic
Description copied from interface:Ring
Returns characteristic of this ring- Specified by:
characteristic
in interfaceRing<E>
- Returns:
- characteristic of this ring
-
isPerfectPower
public boolean isPerfectPower()Description copied from interface:Ring
Returns whether the cardinality is a perfect power (p^k with k > 1)- Specified by:
isPerfectPower
in interfaceRing<E>
- Returns:
- whether the cardinality is a perfect power (p^k with k > 1)
-
perfectPowerBase
Description copied from interface:Ring
Returnsbase
so thatcardinality == base^exponent
or null if cardinality is not finite- Specified by:
perfectPowerBase
in interfaceRing<E>
- Returns:
base
so thatcardinality == base^exponent
or null if cardinality is not finite
-
perfectPowerExponent
Description copied from interface:Ring
Returnsexponent
so thatcardinality == base^exponent
or null if cardinality is not finite- Specified by:
perfectPowerExponent
in interfaceRing<E>
- Returns:
exponent
so thatcardinality == base^exponent
or null if cardinality is not finite
-
add
Description copied from interface:Ring
Add two elements -
subtract
Description copied from interface:Ring
Subtractsb
froma
-
multiply
Description copied from interface:Ring
Multiplies two elements -
negate
Description copied from interface:Ring
Negates the given element -
signum
Description copied from interface:Ring
Returns -1 ifelement < 0
, 0 ifelement == 0
and 1 ifelement > 0
, where comparison is specified byComparator.compare(Object, Object)
-
divideAndRemainder
Description copied from interface:Ring
Returns quotient and remainder ofdividend / divider
- Specified by:
divideAndRemainder
in interfaceRing<E>
- Parameters:
dividend
- the dividenddivider
- the divider- Returns:
{quotient, remainder}
-
reciprocal
Description copied from interface:Ring
Gives the inverse elementelement ^ (-1)
- Specified by:
reciprocal
in interfaceRing<E>
- Parameters:
element
- the element- Returns:
element ^ (-1)
-
gcd
Description copied from interface:Ring
Returns the greatest common divisor of two elements -
factorSquareFree
Description copied from interface:Ring
Square-free factorization of specified element- Specified by:
factorSquareFree
in interfaceRing<E>
-
factor
Description copied from interface:Ring
Factor specified element -
getZero
Description copied from interface:Ring
Returns zero element of this ring -
getOne
Description copied from interface:Ring
Returns unit element of this ring (one) -
isZero
Description copied from interface:Ring
Tests whether specified element is zero -
isOne
Description copied from interface:Ring
Tests whether specified element is one (exactly)- Specified by:
isOne
in interfaceRing<E>
- Parameters:
element
- the ring element- Returns:
- whether specified element is exactly one
- See Also:
Ring.isUnit(Object)
-
isUnit
Description copied from interface:Ring
Tests whether specified element is a ring unit- Specified by:
isUnit
in interfaceRing<E>
- Parameters:
element
- the ring element- Returns:
- whether specified element is a ring unit
- See Also:
Ring.isOne(Object)
-
valueOf
Description copied from interface:Ring
Returns ring element associated with specifiedlong
-
valueOfBigInteger
Description copied from interface:Ring
Returns ring element associated with specified integer- Specified by:
valueOfBigInteger
in interfaceRing<E>
- Parameters:
val
- integer- Returns:
- ring element associated with specified integer
-
copy
Description copied from interface:Ring
Makes a deep copy of the specified element (for immutable instances the same reference returned). -
valueOf
Description copied from interface:Ring
Converts a value from other ring to this ring. The result is not guarantied to be a new instance (i.e.val == valueOf(val)
is possible). -
createArray2d
Description copied from interface:Ring
Creates 2d array of ring elements of specified length- Specified by:
createArray2d
in interfaceRing<E>
- Parameters:
length
- array length- Returns:
- 2d array of ring elements of specified
length
-
createArray2d
Description copied from interface:Ring
Creates 2d array of ring elements of specified shape- Specified by:
createArray2d
in interfaceRing<E>
- Parameters:
m
- result lengthn
- length of each array in the result- Returns:
- 2d array E[m][n]
-
compare
- Specified by:
compare
in interfaceComparator<E>
-
getNegativeOne
Description copied from interface:Ring
Returns negative unit element of this ring (minus one)- Specified by:
getNegativeOne
in interfaceRing<E>
- Returns:
- -1
-
createArray
Description copied from interface:Ring
Creates generic array of ring elements of specified length- Specified by:
createArray
in interfaceRing<E>
- Parameters:
length
- array length- Returns:
- array of ring elements of specified
length
-
randomElement
Description copied from interface:Ring
Returns a random element from this ring- Specified by:
randomElement
in interfaceRing<E>
- Parameters:
rnd
- the source of randomness- Returns:
- random element from this ring
-
randomElementTree
Description copied from interface:Ring
If this ring has a complicated nested structure, this method guaranties that the resulting random element will reflect ring complicated structure, i.e. the result will be roughly as complicated as the ring is- Specified by:
randomElementTree
in interfaceRing<E>
- Returns:
- random element from this ring
-
iterator
Description copied from interface:Ring
Returns iterator over ring elements (for finite rings, otherwise throws exception) -
equals
- Specified by:
equals
in interfaceComparator<E>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode() -
toString
Description copied from interface:Stringifiable
convert this to string with the use of stringifier- Specified by:
toString
in interfaceStringifiable<E>
-
toString
-