Class Polynomial
- java.lang.Object
-
- com.singularsys.extensions.polynomials.AbstractPNode
-
- com.singularsys.extensions.polynomials.Polynomial
-
public class Polynomial extends AbstractPNode
Represents a polynomial. i.e. a sum of terms which are typicallyMonomial
s, but can be anyAbstractPNode
. The order of the terms is specified by the total ordering.- Author:
- Rich Morris Created on 14-Dec-2004
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.singularsys.extensions.polynomials.AbstractPNode
pc
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PNodeI
add(PNodeI node)
Adds a node to this one.PNodeI
add(Polynomial p)
int
compareTo(PNodeI node)
Compares this expression to argument.int
compareTo(Polynomial p)
void
convertToPolyArray(java.lang.String var, java.util.Map<java.lang.Integer,PNodeI> polyArray)
Internal method for extracting coefficientsPNodeI
div(PNodeI node)
Divides this by the argument.boolean
equalsPNode(PNodeI node)
True is nodes represent the same parse treesPNodeI
expand()
complete expansion. (1+x)^2 --> 1+2*x+x^2int
getNTerms()
The number of terms which make up the polynomial.PNodeI
getTerm(int i)
Get the n-th termint
hashCode()
PNodeI
mul(PNodeI node)
Multiplies this by the argument.PNodeI
negate()
negates node i.e.PNodeI
sub(PNodeI node)
Subtracts the argument from this.PNodeI
sub(Polynomial p)
Node
toCompactNode()
A more efficient representation.Node
toNode()
Converts the node to standard Jep format.java.lang.String
toString()
Produces a string representation of the argument.static PNodeI
valueOf(PolynomialCreator pc, PNodeI[] terms)
-
-
-
Method Detail
-
valueOf
public static PNodeI valueOf(PolynomialCreator pc, PNodeI[] terms) throws ParseException
- Throws:
ParseException
-
add
public PNodeI add(PNodeI node) throws ParseException
Description copied from interface:PNodeI
Adds a node to this one.- Specified by:
add
in interfacePNodeI
- Overrides:
add
in classAbstractPNode
- Throws:
ParseException
-
sub
public PNodeI sub(PNodeI node) throws ParseException
Description copied from interface:PNodeI
Subtracts the argument from this.- Specified by:
sub
in interfacePNodeI
- Overrides:
sub
in classAbstractPNode
- Throws:
ParseException
-
add
public PNodeI add(Polynomial p) throws ParseException
- Throws:
ParseException
-
sub
public PNodeI sub(Polynomial p) throws ParseException
- Throws:
ParseException
-
negate
public PNodeI negate() throws ParseException
Description copied from interface:PNodeI
negates node i.e. -x- Throws:
ParseException
-
mul
public PNodeI mul(PNodeI node) throws ParseException
Description copied from interface:PNodeI
Multiplies this by the argument.- Specified by:
mul
in interfacePNodeI
- Overrides:
mul
in classAbstractPNode
- Throws:
ParseException
-
div
public PNodeI div(PNodeI node) throws ParseException
Description copied from interface:PNodeI
Divides this by the argument.- Specified by:
div
in interfacePNodeI
- Overrides:
div
in classAbstractPNode
- Throws:
ParseException
-
equalsPNode
public boolean equalsPNode(PNodeI node)
Description copied from interface:PNodeI
True is nodes represent the same parse trees- Specified by:
equalsPNode
in interfacePNodeI
- Overrides:
equalsPNode
in classAbstractPNode
-
compareTo
public int compareTo(PNodeI node)
Description copied from interface:PNodeI
Compares this expression to argument. Uses a total ordering of expressions. Returns positive if this node comes after the argument.- Specified by:
compareTo
in interfacejava.lang.Comparable<PNodeI>
- Specified by:
compareTo
in interfacePNodeI
- Overrides:
compareTo
in classAbstractPNode
-
compareTo
public int compareTo(Polynomial p)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Description copied from interface:PNodeI
Produces a string representation of the argument.
-
toNode
public Node toNode() throws ParseException
Description copied from interface:PNodeI
Converts the node to standard Jep format.- Throws:
ParseException
-
toCompactNode
public Node toCompactNode() throws ParseException
A more efficient representation. Uses the- Returns:
- Throws:
ParseException
-
expand
public PNodeI expand() throws ParseException
Description copied from interface:PNodeI
complete expansion. (1+x)^2 --> 1+2*x+x^2- Throws:
ParseException
-
getNTerms
public int getNTerms()
The number of terms which make up the polynomial.- Returns:
- the number of terms
-
getTerm
public PNodeI getTerm(int i)
Get the n-th term- Parameters:
i
- index of terms- Returns:
- PNodeI for that term.
-
convertToPolyArray
public void convertToPolyArray(java.lang.String var, java.util.Map<java.lang.Integer,PNodeI> polyArray) throws ParseException
Description copied from interface:PNodeI
Internal method for extracting coefficients- Parameters:
var
- variable namepolyArray
- results added to this map- Throws:
ParseException
-
-