Class Rational<E>

• All Implemented Interfaces:
`Stringifiable<Rational<E>>`, `Serializable`, `Comparable<Rational<E>>`

```public class Rational<E>
extends Object
implements Comparable<Rational<E>>, Stringifiable<Rational<E>>, Serializable```
Serialized Form
• Field Summary

Fields
Modifier and Type Field Description
`Ring<E>` `ring`
The ring.
• Constructor Summary

Constructors
Constructor Description
```Rational​(Ring<E> ring, E numerator)```
```Rational​(Ring<E> ring, E numerator, E denominator)```
• Method Summary

Modifier and Type Method Description
`Rational<E>` `abs()`
Returns the absolute value of this `Rational`.
`Rational<E>` `add​(Rational<E> that)`
`Rational<E>` `add​(E that)`
`int` `compareTo​(Rational<E> object)`
`E` `denominator()`
Denominator of this rational
`Rational<E>` `divide​(Rational<E> oth)`
Divide this by oth
`Rational<E>` `divide​(E oth)`
Divide this by oth
`boolean` `equals​(Object o)`
`FactorDecomposition<E>` `factorDenominator()`
Factor decomposition of denominator
`FactorDecomposition<E>` `factorNumerator()`
Factor decomposition of denominator
`int` `hashCode()`
`boolean` `isIntegral()`
whether this rational is integral
`boolean` `isOne()`
whether this rational is one
`boolean` `isZero()`
whether this rational is zero
`<O> Rational<O>` ```map​(Ring<O> ring, Function<E,​O> function)```
Maps rational to a new ring
`Rational<E>` `map​(Function<E,​E> function)`
Maps rational
`Rational<E>` `multiply​(Rational<E> oth)`
Multiply this by oth
`Rational<E>` `multiply​(E oth)`
Multiply this by oth
`Rational<E>` `negate()`
Negate this fraction
`Rational<E>[]` `normal()`
Reduces this rational to normal form by doing division with remainder, that is if ```numerator = div * denominator + rem``` then the array `(div, rem/denominator)` will be returned.
`E` `numerator()`
Numerator of this rational
`E` `numeratorExact()`
Numerator of this rational
`static <E> Rational<E>` `one​(Ring<E> ring)`
Constructs one
`Rational<E>` `pow​(int exponent)`
Raise this in a power `exponent`
`Rational<E>` `pow​(long exponent)`
Raise this in a power `exponent`
`Rational<E>` `pow​(BigInteger exponent)`
Raise this in a power `exponent`
`Rational<E>` `reciprocal()`
Reciprocal of this
`int` `signum()`
Signum of this rational
`Stream<E>` `stream()`
Stream of numerator and denominator
`Rational<E>` `subtract​(Rational<E> that)`
`Rational<E>` `subtract​(E that)`
Subtract that from this
`String` `toString()`
`String` `toString​(IStringifier<Rational<E>> stringifier)`
convert this to string with the use of stringifier
`String` `toStringFactors​(IStringifier<Rational<E>> stringifier)`
`static <E> Rational<E>` `zero​(Ring<E> ring)`
Constructs zero
• Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`
• Field Detail

• ring

`public final Ring<E> ring`
The ring.
• Constructor Detail

• Rational

```public Rational​(Ring<E> ring,
E numerator)```
• Rational

```public Rational​(Ring<E> ring,
E numerator,
E denominator)```
• Method Detail

• zero

`public static <E> Rational<E> zero​(Ring<E> ring)`
Constructs zero
• one

`public static <E> Rational<E> one​(Ring<E> ring)`
Constructs one
• isZero

`public boolean isZero()`
whether this rational is zero
• isOne

`public boolean isOne()`
whether this rational is one
• isIntegral

`public boolean isIntegral()`
whether this rational is integral
• numerator

`public E numerator()`
Numerator of this rational
• numeratorExact

`public E numeratorExact()`
Numerator of this rational
• denominator

`public E denominator()`
Denominator of this rational
• factorDenominator

`public FactorDecomposition<E> factorDenominator()`
Factor decomposition of denominator
• factorNumerator

`public FactorDecomposition<E> factorNumerator()`
Factor decomposition of denominator
• normal

`public Rational<E>[] normal()`
Reduces this rational to normal form by doing division with remainder, that is if ```numerator = div * denominator + rem``` then the array `(div, rem/denominator)` will be returned. If either div or rem is zero an singleton array with this instance will be returned.
• signum

`public int signum()`
Signum of this rational
• reciprocal

`public Rational<E> reciprocal()`
Reciprocal of this
• multiply

`public Rational<E> multiply​(Rational<E> oth)`
Multiply this by oth
• divide

`public Rational<E> divide​(Rational<E> oth)`
Divide this by oth
• multiply

`public Rational<E> multiply​(E oth)`
Multiply this by oth
• divide

`public Rational<E> divide​(E oth)`
Divide this by oth
• negate

`public Rational<E> negate()`
Negate this fraction

`public Rational<E> add​(Rational<E> that)`
• subtract

`public Rational<E> subtract​(Rational<E> that)`

`public Rational<E> add​(E that)`
• subtract

`public Rational<E> subtract​(E that)`
Subtract that from this
• compareTo

`public int compareTo​(Rational<E> object)`
Specified by:
`compareTo` in interface `Comparable<E>`
• pow

`public Rational<E> pow​(int exponent)`
Raise this in a power `exponent`
Parameters:
`exponent` - exponent
• pow

`public Rational<E> pow​(long exponent)`
Raise this in a power `exponent`
Parameters:
`exponent` - exponent
• pow

`public Rational<E> pow​(BigInteger exponent)`
Raise this in a power `exponent`
Parameters:
`exponent` - exponent
• map

```public <O> Rational<O> map​(Ring<O> ring,
Function<E,​O> function)```
Maps rational to a new ring
• map

`public Rational<E> map​(Function<E,​E> function)`
Maps rational
• stream

`public Stream<E> stream()`
Stream of numerator and denominator
• equals

`public boolean equals​(Object o)`
Overrides:
`equals` in class `Object`
• hashCode

`public int hashCode()`
Overrides:
`hashCode` in class `Object`
• toString

`public String toString​(IStringifier<Rational<E>> stringifier)`
Description copied from interface: `Stringifiable`
convert this to string with the use of stringifier
Specified by:
`toString` in interface `Stringifiable<E>`
• toStringFactors

`public String toStringFactors​(IStringifier<Rational<E>> stringifier)`
• toString

`public String toString()`
Overrides:
`toString` in class `Object`