org.spaceroots.mantissa.algebra
Class Polynomial.Rational

java.lang.Object
  extended byorg.spaceroots.mantissa.algebra.Polynomial
      extended byorg.spaceroots.mantissa.algebra.Polynomial.Rational
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
OrthogonalPolynomial
Enclosing class:
Polynomial

public static class Polynomial.Rational
extends Polynomial

This class implements polynomials with one unknown and rational coefficients.

In addition to classical algebra operations, euclidian division and remainder are handled.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.spaceroots.mantissa.algebra.Polynomial
Polynomial.DivisionResult, Polynomial.Double, Polynomial.Rational
 
Field Summary
protected  RationalNumber[] a
          Coefficients array.
 
Constructor Summary
Polynomial.Rational()
          Simple constructor.
Polynomial.Rational(long value)
          Simple constructor.
Polynomial.Rational(long a1, long a0)
          Simple constructor.
Polynomial.Rational(long a2, long a1, long a0)
          Simple constructor.
Polynomial.Rational(long a3, long a2, long a1, long a0)
          Simple constructor.
Polynomial.Rational(RationalNumber value)
          Simple constructor.
Polynomial.Rational(RationalNumber[] a)
          Simple constructor.
Polynomial.Rational(RationalNumber c, int degree)
          Simple constructor.
Polynomial.Rational(RationalNumber a1, RationalNumber a0)
          Simple constructor.
Polynomial.Rational(RationalNumber a2, RationalNumber a1, RationalNumber a0)
          Simple constructor.
Polynomial.Rational(RationalNumber a3, RationalNumber a2, RationalNumber a1, RationalNumber a0)
          Simple constructor.
 
Method Summary
 Polynomial.Rational add(Polynomial.Rational p)
          Add a polynomial to the instance
static Polynomial.DivisionResult euclidianDivision(Polynomial.Rational dividend, Polynomial.Rational divisor)
          Perform the euclidian division of two polynomials.
 RationalNumber[] getCoefficients()
          Get the coefficients of the polynomial.
 int getDegree()
          Get the polynomial degree.
 BigInteger getDenominatorsLCM()
          Get the Least Common Multiple of the coefficients denominators.
 Polynomial getDerivative()
          Get the derivative of the instance with respect to the unknown.
 boolean isIdentity()
          Check if the instance is the identity polynomial.
 boolean isOne()
          Check if the instance is the constant unit polynomial.
 boolean isZero()
          Check if the instance is the null polynomial.
 Polynomial multiply(long l)
          Multiply the instance by a constant.
 Polynomial.Rational multiply(Polynomial.Rational p)
          Multiply the instance by a polynomial.
 Polynomial multiply(RationalNumber r)
          Multiply the instance by a constant.
 Polynomial negate()
          Negate the instance.
 Polynomial.Rational subtract(Polynomial.Rational p)
          Subtract a polynomial from the instance.
 String toString()
          Returns a string representation of the polynomial.
 double valueAt(double x)
          Get the value of the polynomial for a specified unknown.
 
Methods inherited from class org.spaceroots.mantissa.algebra.Polynomial
divide, divide, divide, multiply
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

a

protected RationalNumber[] a
Coefficients array.

Constructor Detail

Polynomial.Rational

public Polynomial.Rational()
Simple constructor. Build a null polynomial


Polynomial.Rational

public Polynomial.Rational(long value)
Simple constructor. Build a constant polynomial

Parameters:
value - constant value of the polynomial

Polynomial.Rational

public Polynomial.Rational(RationalNumber value)
Simple constructor. Build a constant polynomial

Parameters:
value - constant value of the polynomial

Polynomial.Rational

public Polynomial.Rational(long a1,
                           long a0)
Simple constructor. Build a first degree polynomial

Parameters:
a1 - leeding degree coefficient
a0 - constant term

Polynomial.Rational

public Polynomial.Rational(RationalNumber a1,
                           RationalNumber a0)
Simple constructor. Build a first degree polynomial

Parameters:
a1 - leeding degree coefficient
a0 - constant term

Polynomial.Rational

public Polynomial.Rational(long a2,
                           long a1,
                           long a0)
Simple constructor. Build a second degree polynomial

Parameters:
a2 - leeding degree coefficient
a1 - first degree coefficient
a0 - constant term

Polynomial.Rational

public Polynomial.Rational(RationalNumber a2,
                           RationalNumber a1,
                           RationalNumber a0)
Simple constructor. Build a second degree polynomial

Parameters:
a2 - leeding degree coefficient
a1 - first degree coefficient
a0 - constant term

Polynomial.Rational

public Polynomial.Rational(long a3,
                           long a2,
                           long a1,
                           long a0)
Simple constructor. Build a third degree polynomial

Parameters:
a3 - leeding degree coefficient
a2 - second degree coefficient
a1 - first degree coefficient
a0 - constant term

Polynomial.Rational

public Polynomial.Rational(RationalNumber a3,
                           RationalNumber a2,
                           RationalNumber a1,
                           RationalNumber a0)
Simple constructor. Build a third degree polynomial

Parameters:
a3 - leeding degree coefficient
a2 - second degree coefficient
a1 - first degree coefficient
a0 - constant term

Polynomial.Rational

public Polynomial.Rational(RationalNumber[] a)
Simple constructor. Build a polynomial from its coefficients

Parameters:
a - coefficients array, the a[0] array element is the constant term while the a[a.length-1] element is the leeding degree coefficient. The array is copied in a new array, so it can be changed once the constructor as returned.

Polynomial.Rational

public Polynomial.Rational(RationalNumber c,
                           int degree)
Simple constructor. Build a one term polynomial from one coefficient and the corresponding degree

Parameters:
c - coefficient
degree - degree associated with the coefficient
Method Detail

isZero

public boolean isZero()
Check if the instance is the null polynomial.

Specified by:
isZero in class Polynomial
Returns:
true if the polynomial is null

isOne

public boolean isOne()
Check if the instance is the constant unit polynomial.

Specified by:
isOne in class Polynomial
Returns:
true if the polynomial is the constant unit polynomial

isIdentity

public boolean isIdentity()
Check if the instance is the identity polynomial.

Specified by:
isIdentity in class Polynomial
Returns:
true if the polynomial is the identity polynomial

getDegree

public int getDegree()
Get the polynomial degree.

Specified by:
getDegree in class Polynomial
Returns:
degree

getCoefficients

public RationalNumber[] getCoefficients()
Get the coefficients of the polynomial.

Returns:
a copy of the coefficients array, the array element at index 0 is the constant term while the element at index a.length-1 is the leading degree coefficient

add

public Polynomial.Rational add(Polynomial.Rational p)
Add a polynomial to the instance

Parameters:
p - polynomial to add
Returns:
a new polynomial which is the sum of the instance and p

subtract

public Polynomial.Rational subtract(Polynomial.Rational p)
Subtract a polynomial from the instance.

Parameters:
p - polynomial to subtract
Returns:
a new polynomial which is the difference the instance minus p

negate

public Polynomial negate()
Negate the instance.

Specified by:
negate in class Polynomial
Returns:
a new polynomial

multiply

public Polynomial.Rational multiply(Polynomial.Rational p)
Multiply the instance by a polynomial.

Parameters:
p - polynomial to multiply by
Returns:
a new polynomial

multiply

public Polynomial multiply(long l)
Multiply the instance by a constant.

Specified by:
multiply in class Polynomial
Parameters:
l - constant to multiply by
Returns:
a new polynomial

multiply

public Polynomial multiply(RationalNumber r)
Multiply the instance by a constant.

Specified by:
multiply in class Polynomial
Parameters:
r - constant to multiply by
Returns:
a new polynomial

valueAt

public double valueAt(double x)
Get the value of the polynomial for a specified unknown.

Specified by:
valueAt in class Polynomial
Parameters:
x - value of the unknown
Returns:
value of the polynomial

getDerivative

public Polynomial getDerivative()
Get the derivative of the instance with respect to the unknown. The derivative of a n degree polynomial is a n-1 degree polynomial of the same type.

Specified by:
getDerivative in class Polynomial
Returns:
a new polynomial which is the derivative of the instance

euclidianDivision

public static Polynomial.DivisionResult euclidianDivision(Polynomial.Rational dividend,
                                                          Polynomial.Rational divisor)
Perform the euclidian division of two polynomials.

Parameters:
dividend - numerator polynomial
divisor - denominator polynomial
Returns:
an object containing the quotient and the remainder of the division

getDenominatorsLCM

public BigInteger getDenominatorsLCM()
Get the Least Common Multiple of the coefficients denominators. This number is the smallest integer by which we should multiply the instance to get a polynomial whose coefficients are all integers.

Returns:
the Least Common Multiple of the coefficients denominators

toString

public String toString()
Returns a string representation of the polynomial.

The representation is user oriented. Terms are displayed lowest degrees first. The multiplications signs, coefficients equals to one and null terms are not displayed (except if the polynomial is 0, in which case the 0 constant term is displayed). Addition of terms with negative coefficients are replaced by subtraction of terms with positive coefficients except for the first displayed term (i.e. we display -3 for a constant negative polynomial, but 1 - 3 x + x^2 if the negative coefficient is not the first one displayed).

Returns:
a string representation of the polynomial


Copyright © 2001-2007 Luc Maisonobe. All Rights Reserved.