Class Polynomial
java.lang.Object
com.singularsys.extensions.polynomials.AbstractPNode
com.singularsys.extensions.polynomials.Polynomial
- All Implemented Interfaces:
PNodeI,Serializable,Comparable<PNodeI>
Represents a polynomial.
i.e. a sum of terms which are typically
Monomials, but can be any AbstractPNode. The order of the terms is specified by the total ordering.- Author:
- Rich Morris Created on 14-Dec-2004
- See Also:
-
Field Summary
Fields inherited from class com.singularsys.extensions.polynomials.AbstractPNode
pc -
Method Summary
Modifier and TypeMethodDescriptionReturns the sum of this node and argumentadd(Polynomial p) intCompares this expression to argument.intvoidconvertToPolyArray(String var, Map<Integer, PNodeI> polyArray) Internal method for extracting coefficientsDivides this by the argument.booleanequalsPNode(PNodeI node) True is nodes represent the same parse treesexpand()complete expansion. (1+x)^2 --> 1+2*x+x^2intThe number of terms which make up the polynomial.getTerm(int i) Get the n-th terminthashCode()Multiplies this by the argument.negate()negates node i.e.Returns the difference between this node and argumentsub(Polynomial p) substitute(PVariable var, PNodeI sub) Substitute all occurrence of variable with its replacement.A more efficient representation.toNode()Converts the node to standard Jep format.toString()Produces a string representation of the argument.toString(NumberFormat nf) static PNodeIvalueOf(PolynomialCreator pc, PNodeI[] terms)
-
Method Details
-
valueOf
- Throws:
ParseException
-
add
Description copied from class:AbstractPNodeReturns the sum of this node and argument- Specified by:
addin interfacePNodeI- Overrides:
addin classAbstractPNode- Parameters:
node- to add- Returns:
- node representing the sum
- Throws:
ParseException- on error
-
sub
Description copied from class:AbstractPNodeReturns the difference between this node and argument- Specified by:
subin interfacePNodeI- Overrides:
subin classAbstractPNode- Parameters:
node- to subtract- Returns:
- node representing the difference
- Throws:
ParseException- on error
-
add
- Throws:
ParseException
-
sub
- Throws:
ParseException
-
negate
Description copied from interface:PNodeInegates node i.e. -x- Throws:
ParseException
-
mul
Description copied from interface:PNodeIMultiplies this by the argument.- Specified by:
mulin interfacePNodeI- Overrides:
mulin classAbstractPNode- Throws:
ParseException
-
div
Description copied from interface:PNodeIDivides this by the argument.- Specified by:
divin interfacePNodeI- Overrides:
divin classAbstractPNode- Throws:
ParseException
-
equalsPNode
Description copied from interface:PNodeITrue is nodes represent the same parse trees- Specified by:
equalsPNodein interfacePNodeI- Overrides:
equalsPNodein classAbstractPNode
-
compareTo
Description copied from interface:PNodeICompares this expression to argument. Uses a total ordering of expressions. Returns positive if this node comes after the argument.- Specified by:
compareToin interfaceComparable<PNodeI>- Specified by:
compareToin interfacePNodeI- Overrides:
compareToin classAbstractPNode
-
compareTo
-
hashCode
public int hashCode() -
toString
Description copied from interface:PNodeIProduces a string representation of the argument. -
toNode
Description copied from interface:PNodeIConverts the node to standard Jep format.- Throws:
ParseException
-
toCompactNode
A more efficient representation. Uses the- Returns:
- Throws:
ParseException
-
expand
Description copied from interface:PNodeIcomplete 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
Get the n-th term- Parameters:
i- index of terms- Returns:
- PNodeI for that term.
-
convertToPolyArray
Description copied from interface:PNodeIInternal method for extracting coefficients- Parameters:
var- variable namepolyArray- results added to this map- Throws:
ParseException
-
substitute
Description copied from interface:PNodeISubstitute all occurrence of variable with its replacement.- Parameters:
var- the variablesub- the replacement- Returns:
- Throws:
ParseException
-
toString
-