Class Rational<E>

java.lang.Object
cc.redberry.rings.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
See Also:
Serialized Form
  • Field Details

    • ring

      public final Ring<E> ring
      The ring.
  • Constructor Details

    • Rational

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

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

    • 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
    • abs

      public Rational<E> abs()
      Returns the absolute value of this Rational.
      Returns:
      the absolute value as a 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
    • add

      public Rational<E> add​(Rational<E> that)
      Add that to this
    • subtract

      public Rational<E> subtract​(Rational<E> that)
      Add that to this
    • add

      public Rational<E> add​(E that)
      Add that to this
    • 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