org.rubato.math.module
Class PolynomialElement

java.lang.Object
  extended by org.rubato.math.module.RingElement
      extended by org.rubato.math.module.PolynomialElement
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<ModuleElement>, java.lang.Iterable<RingElement>, FreeElement, ModuleElement, PolynomialFreeElement, XMLInputOutput<ModuleElement>

public final class PolynomialElement
extends RingElement
implements PolynomialFreeElement

Elements in a ring of polynomials.

Author:
Gérard Milmeister
See Also:
PolynomialRing, Serialized Form

Constructor Summary
PolynomialElement(PolynomialRing ring, RingElement... coefficients)
          Constructs a polynomial in a specified ring with given coefficents.
PolynomialElement(java.lang.String indeterminate, RingElement... coefficients)
          Constructs a polynomial with given coefficents.
 
Method Summary
 void add(ModuleElement element)
          Adds element to this module element.
 void add(PolynomialElement element)
           
 ModuleElement cast(Module module)
          Tries to cast this element to an element in the given module.
 PolynomialElement clone()
          Returns a deep copy of this module element.
 int compareTo(ModuleElement object)
          Compares this module element with object.
 PolynomialElement difference(ModuleElement element)
          Returns the difference of this module element and element.
 PolynomialElement difference(PolynomialElement element)
           
 void divide(PolynomialElement element)
           
 void divide(RingElement element)
          Replaces this by the solution x of element*x = this, if it exists, otherwise a DivisionException is thrown.
 boolean divides(RingElement element)
          Return true iff the solution x of this*x = element exists.
 boolean equals(java.lang.Object object)
          Returns true iff this element is equal to object.
 RingElement evaluate(RingElement element)
           
 PolynomialElement exgcd(PolynomialElement y, PolynomialElement[] res)
          The extended Euclidean algorithm.
 double[] fold(ModuleElement[] elements)
          Fold elements assuming they are of this same type.
 ModuleElement fromXML(XMLReader reader, org.w3c.dom.Element element)
          Reads XML representation from reader starting with element.
 PolynomialElement gcd(PolynomialElement element)
          Returns the greatest common divisior of this and element.
 RingElement getCoefficient(int power)
           
 Ring getCoefficientRing()
          Returns the ring of the coefficients of the polynomial.
 RingElement[] getCoefficients()
           
 int getDegree()
           
 java.lang.String getElementTypeName()
          Returns the value of the type attribute for this class.
 java.lang.String getIndeterminate()
          Returns the indeterminate of the polynomial.
 RingElement getLeadingCoefficient()
           
 PolynomialRing getModule()
          Returns the module that this module element is an element of.
 PolynomialRing getRing()
          Returns the ring this element is a member of.
static XMLInputOutput<ModuleElement> getXMLInputOutput()
           
 int hashCode()
          Returns the hash code for this module element.
 PolynomialElement inverse()
          Returns the inverse of this ring element, if it has an inverse.
 void invert()
          Inverts this ring element, if it has an inverse.
 boolean isInvertible()
          Returns true if this ring element is invertible.
 boolean isOne()
          Returns true if this ring element is one.
 boolean isZero()
          Returns true iff this element is zero.
 void multiply(PolynomialElement element)
           
 void multiply(RingElement element)
          Multiplies this ring element with element.
 void negate()
          Negate this module element.
 PolynomialElement negated()
          Returns the negative of this module element.
 PolynomialElement product(PolynomialElement element)
           
 PolynomialElement product(RingElement element)
          Returns the product of this ring element with element.
 PolynomialElement quo(PolynomialElement element)
           
 PolynomialElement quorem(PolynomialElement element, PolynomialElement[] remainder)
           
 PolynomialElement quotient(PolynomialElement element)
           
 PolynomialElement quotient(RingElement element)
          Returns the solution x of element*x = this, if it exists, otherwise a DivisionException is thrown.
 PolynomialElement rem(PolynomialElement element)
           
 PolynomialFreeElement resize(int n)
          Returns this free element resized to length n.
 void scale(RingElement element)
          Multiplies this element with element.
 PolynomialElement scaled(RingElement element)
          Returns the product of this element with element.
 java.lang.String stringRep(boolean... parens)
          Returns a string representation of this module element.
 void subtract(ModuleElement element)
          Subtracts element from this module element.
 void subtract(PolynomialElement element)
           
 PolynomialElement sum(ModuleElement element)
          Returns the sum of this module element and element.
 PolynomialElement sum(PolynomialElement element)
           
 java.lang.String toString()
          Returns a human readable string representation of this module element.
 void toXML(XMLWriter writer)
          Outputs XML representation to writer.
 
Methods inherited from class org.rubato.math.module.RingElement
difference, getComponent, getLength, getRingElement, iterator, multiplyCW, power, productCW, sum
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.rubato.math.module.FreeElement
getComponent, getLength, getRingElement, iterator, multiplyCW, productCW
 

Constructor Detail

PolynomialElement

public PolynomialElement(PolynomialRing ring,
                         RingElement... coefficients)
Constructs a polynomial in a specified ring with given coefficents. The array of coefficients contains the coefficient of power n at index n.

Parameters:
ring - the ring of polynomials
coefficients - elements of the coefficient ring

PolynomialElement

public PolynomialElement(java.lang.String indeterminate,
                         RingElement... coefficients)
Constructs a polynomial with given coefficents. The array of coefficients contains the coefficient of power n at index n. The polynomial ring is inferred from the coefficients, which must all be elements of the the same ring.

Parameters:
coefficients - elements of the coefficient ring
Method Detail

isOne

public boolean isOne()
Description copied from class: RingElement
Returns true if this ring element is one.

Specified by:
isOne in class RingElement

isZero

public boolean isZero()
Description copied from interface: ModuleElement
Returns true iff this element is zero.

Specified by:
isZero in interface ModuleElement

sum

public PolynomialElement sum(ModuleElement element)
                      throws DomainException
Description copied from interface: ModuleElement
Returns the sum of this module element and element.

Specified by:
sum in interface ModuleElement
Throws:
DomainException - if element is not in domain

sum

public PolynomialElement sum(PolynomialElement element)
                      throws DomainException
Throws:
DomainException

add

public void add(ModuleElement element)
         throws DomainException
Description copied from interface: ModuleElement
Adds element to this module element. This is a destructive operation.

Specified by:
add in interface ModuleElement
Throws:
DomainException - if element is not in domain

add

public void add(PolynomialElement element)
         throws DomainException
Throws:
DomainException

difference

public PolynomialElement difference(ModuleElement element)
                             throws DomainException
Description copied from interface: ModuleElement
Returns the difference of this module element and element.

Specified by:
difference in interface ModuleElement
Throws:
DomainException - if element is not in domain

difference

public PolynomialElement difference(PolynomialElement element)
                             throws DomainException
Throws:
DomainException

subtract

public void subtract(ModuleElement element)
              throws DomainException
Description copied from interface: ModuleElement
Subtracts element from this module element. This is a destructive operation.

Specified by:
subtract in interface ModuleElement
Throws:
DomainException - if element is not in domain

subtract

public void subtract(PolynomialElement element)
              throws DomainException
Throws:
DomainException

negated

public PolynomialElement negated()
Description copied from interface: ModuleElement
Returns the negative of this module element.

Specified by:
negated in interface ModuleElement

negate

public void negate()
Description copied from interface: ModuleElement
Negate this module element. This is a destructive operation.

Specified by:
negate in interface ModuleElement

scaled

public PolynomialElement scaled(RingElement element)
                         throws DomainException
Description copied from interface: ModuleElement
Returns the product of this element with element.

Specified by:
scaled in interface ModuleElement
Throws:
DomainException - if element is not in domain

scale

public void scale(RingElement element)
           throws DomainException
Description copied from interface: ModuleElement
Multiplies this element with element. This is a destructive operation.

Specified by:
scale in interface ModuleElement
Throws:
DomainException - if element is not in domain

product

public PolynomialElement product(RingElement element)
                          throws DomainException
Description copied from class: RingElement
Returns the product of this ring element with element.

Specified by:
product in class RingElement
Throws:
DomainException - if element is not in domain

product

public PolynomialElement product(PolynomialElement element)
                          throws DomainException
Throws:
DomainException

multiply

public void multiply(RingElement element)
              throws DomainException
Description copied from class: RingElement
Multiplies this ring element with element.

Specified by:
multiply in class RingElement
Throws:
DomainException - if element is not in domain

multiply

public void multiply(PolynomialElement element)
              throws DomainException
Throws:
DomainException

isInvertible

public boolean isInvertible()
Description copied from class: RingElement
Returns true if this ring element is invertible.

Specified by:
isInvertible in class RingElement

inverse

public PolynomialElement inverse()
Description copied from class: RingElement
Returns the inverse of this ring element, if it has an inverse.

Specified by:
inverse in class RingElement

invert

public void invert()
Description copied from class: RingElement
Inverts this ring element, if it has an inverse.

Specified by:
invert in class RingElement

quotient

public PolynomialElement quotient(RingElement element)
                           throws DomainException,
                                  DivisionException
Description copied from class: RingElement
Returns the solution x of element*x = this, if it exists, otherwise a DivisionException is thrown.

Specified by:
quotient in class RingElement
Throws:
DomainException
DivisionException

quotient

public PolynomialElement quotient(PolynomialElement element)
                           throws DomainException,
                                  DivisionException
Throws:
DomainException
DivisionException

divide

public void divide(RingElement element)
            throws DomainException,
                   DivisionException
Description copied from class: RingElement
Replaces this by the solution x of element*x = this, if it exists, otherwise a DivisionException is thrown.

Specified by:
divide in class RingElement
Throws:
DomainException
DivisionException

divide

public void divide(PolynomialElement element)
            throws DomainException,
                   DivisionException
Throws:
DomainException
DivisionException

divides

public boolean divides(RingElement element)
Description copied from class: RingElement
Return true iff the solution x of this*x = element exists.

Specified by:
divides in class RingElement

quorem

public PolynomialElement quorem(PolynomialElement element,
                                PolynomialElement[] remainder)
                         throws DomainException,
                                DivisionException
Throws:
DomainException
DivisionException

quo

public PolynomialElement quo(PolynomialElement element)
                      throws DomainException,
                             DivisionException
Throws:
DomainException
DivisionException

rem

public PolynomialElement rem(PolynomialElement element)
                      throws DomainException,
                             DivisionException
Throws:
DomainException
DivisionException

gcd

public PolynomialElement gcd(PolynomialElement element)
                      throws DomainException,
                             DivisionException
Returns the greatest common divisior of this and element.

Throws:
DomainException
DivisionException

exgcd

public PolynomialElement exgcd(PolynomialElement y,
                               PolynomialElement[] res)
                        throws DomainException,
                               DivisionException
The extended Euclidean algorithm.

Parameters:
res - is an array of polynomials that will contain two values such that: res[0]*x + res[1]*y = gcd(x,y)
Returns:
the greatest common divisor of x and y, always non negative
Throws:
DomainException
DivisionException

evaluate

public RingElement evaluate(RingElement element)
                     throws DomainException
Throws:
DomainException

getModule

public PolynomialRing getModule()
Description copied from interface: ModuleElement
Returns the module that this module element is an element of.

Specified by:
getModule in interface ModuleElement

getRing

public PolynomialRing getRing()
Description copied from class: RingElement
Returns the ring this element is a member of.

Overrides:
getRing in class RingElement

getCoefficients

public RingElement[] getCoefficients()

getCoefficient

public RingElement getCoefficient(int power)

getLeadingCoefficient

public RingElement getLeadingCoefficient()

getDegree

public int getDegree()

getCoefficientRing

public Ring getCoefficientRing()
Description copied from interface: PolynomialFreeElement
Returns the ring of the coefficients of the polynomial.

Specified by:
getCoefficientRing in interface PolynomialFreeElement

getIndeterminate

public java.lang.String getIndeterminate()
Description copied from interface: PolynomialFreeElement
Returns the indeterminate of the polynomial.

Specified by:
getIndeterminate in interface PolynomialFreeElement

resize

public PolynomialFreeElement resize(int n)
Description copied from interface: FreeElement
Returns this free element resized to length n. If the new length n is greater than the old length, the new values are filled with the zero of the underlying ring. If the new length n is less than the old length, the vector of values is simply truncated.

Specified by:
resize in interface FreeElement

equals

public boolean equals(java.lang.Object object)
Description copied from interface: ModuleElement
Returns true iff this element is equal to object.

Specified by:
equals in interface ModuleElement
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(ModuleElement object)
Description copied from interface: ModuleElement
Compares this module element with object.

Specified by:
compareTo in interface java.lang.Comparable<ModuleElement>
Specified by:
compareTo in interface ModuleElement
Overrides:
compareTo in class RingElement

clone

public PolynomialElement clone()
Description copied from interface: ModuleElement
Returns a deep copy of this module element.

Specified by:
clone in interface ModuleElement
Specified by:
clone in class RingElement

stringRep

public java.lang.String stringRep(boolean... parens)
Description copied from interface: ModuleElement
Returns a string representation of this module element. The representation is meant to be parseable. If the argument parens is present then the the representation is parenthesized if necessary.

Specified by:
stringRep in interface ModuleElement
Specified by:
stringRep in class RingElement

toString

public java.lang.String toString()
Description copied from interface: ModuleElement
Returns a human readable string representation of this module element. The representation is not meant to be parseable.

Specified by:
toString in interface ModuleElement
Overrides:
toString in class java.lang.Object

fold

public double[] fold(ModuleElement[] elements)
Description copied from interface: ModuleElement
Fold elements assuming they are of this same type.

Specified by:
fold in interface ModuleElement

cast

public ModuleElement cast(Module module)
Description copied from interface: ModuleElement
Tries to cast this element to an element in the given module.

Specified by:
cast in interface ModuleElement
Returns:
a new module element in the required module and null if the cast cannot be performed.

toXML

public void toXML(XMLWriter writer)
Description copied from interface: XMLInputOutput
Outputs XML representation to writer.

Specified by:
toXML in interface XMLInputOutput<ModuleElement>

fromXML

public ModuleElement fromXML(XMLReader reader,
                             org.w3c.dom.Element element)
Description copied from interface: XMLInputOutput
Reads XML representation from reader starting with element.

Specified by:
fromXML in interface XMLInputOutput<ModuleElement>
Returns:
an object of type T or null if parsing failed

getXMLInputOutput

public static XMLInputOutput<ModuleElement> getXMLInputOutput()

getElementTypeName

public java.lang.String getElementTypeName()
Description copied from interface: XMLInputOutput
Returns the value of the type attribute for this class.

Specified by:
getElementTypeName in interface XMLInputOutput<ModuleElement>

hashCode

public int hashCode()
Description copied from interface: ModuleElement
Returns the hash code for this module element.

Specified by:
hashCode in interface ModuleElement
Overrides:
hashCode in class java.lang.Object