public class PolynomialCreator extends java.lang.Object implements ParserVisitor, JepComponent
1+2 x^2+3 x y+4 x sin(y)is represented as
Polynomial([ Monomial(2.0,[PVariable(x)],[2])]), Monomial(3.0,[x,y],[1,1]), Monomial(4.0,[x,Function(sin,arg)],[1,1]) ])
A total ordering of all expressions is used. As the representation is constructed the total ordering of terms is maintained. This helps ensure that polynomials are always in their simplest form and also allows comparison of equations.
The following sequence illustrates current ordering. The ordering follows this sequence
| Modifier and Type | Field and Description |
|---|---|
protected FieldI |
field |
protected FunctionTable |
ft |
PConstant |
infConstant |
protected Jep |
jep |
PConstant |
minusOneConstant |
PConstant |
nanConstant |
protected NodeFactory |
nf |
protected NumberFactory |
numf |
PConstant |
oneConstant |
protected OperatorTableI |
ot |
protected TreeUtils |
tu |
PConstant |
twoConstant |
protected VariableTable |
vt |
PConstant |
zeroConstant |
| Modifier | Constructor and Description |
|---|---|
|
PolynomialCreator()
Constructor when used as a JepComponent.
|
|
PolynomialCreator(FieldI field)
Constructor used as a component with a specified field.
|
protected |
PolynomialCreator(FieldI f,
TreeUtils tu) |
|
PolynomialCreator(Jep j)
Constructor when used as a stand alone class, with default DoubleField.
|
|
PolynomialCreator(Jep j,
FieldI f)
Constructor when used as a stand alone class with specified field
|
| Modifier and Type | Method and Description |
|---|---|
int |
compare(Node node1,
Node node2)
Compares two nodes.
|
PNodeI |
createPoly(Node node)
Converts an expression into the polynomial representation.
|
boolean |
equals(Node node1,
Node node2)
Compares two nodes.
|
Node |
expand(Node node)
Expands an expression.
|
PNodeI |
expand(PNodeI poly)
Expand a PNodeI multiplying out all brackets
|
int |
expandCompare(Node node1,
Node node2)
Expands and compares two expressions.
|
boolean |
expandEquals(Node node1,
Node node2)
Compares two nodes.
|
JepComponent |
getLightWeightInstance()
Gets a light-weight instance suitable for using in multiple threads.
|
NodeFactory |
getNodeFactory() |
OperatorTableI |
getOperatorTable() |
void |
init(Jep j)
Initialize the component.
|
Node |
simplify(Node node)
Simplifies an expression.
|
PNodeI[] |
toCoefficientArray(PNodeI poly,
java.lang.String var)
Finds the coefficients of each power of the variable, these can be polynomials.
|
double[] |
toDoubleArray(PNodeI poly,
java.lang.String var)
Extract the numerical coefficients of a polynomial.
|
double[][] |
toDoubleArray(PNodeI poly,
java.lang.String var1,
java.lang.String var2)
Extract the numerical coefficients of a polynomial in two variables.
|
double[][][] |
toDoubleArray(PNodeI poly,
java.lang.String var1,
java.lang.String var2,
java.lang.String var3)
Extract the numerical coefficients of a polynomial in three variables.
|
Node |
toNode(PNodeI poly)
Convert from a polynomial representation back to standard Jep format.
|
java.lang.Object |
toPNodeArray(PNodeI poly,
java.lang.String... vars)
Coefficients of a polynomial as a multi-dimensional array of PNodeI elements.
|
java.lang.Object |
visit(ASTConstant node,
java.lang.Object data) |
java.lang.Object |
visit(ASTFunNode node,
java.lang.Object data) |
java.lang.Object |
visit(ASTOpNode node,
java.lang.Object data) |
java.lang.Object |
visit(ASTVarNode node,
java.lang.Object data) |
public PConstant zeroConstant
public PConstant oneConstant
public PConstant minusOneConstant
public PConstant twoConstant
public PConstant infConstant
public PConstant nanConstant
protected Jep jep
protected NumberFactory numf
protected TreeUtils tu
protected NodeFactory nf
protected VariableTable vt
protected FunctionTable ft
protected OperatorTableI ot
protected FieldI field
public PolynomialCreator()
init(Jep) method must be called.public PolynomialCreator(FieldI field)
field - field for operations on constants
The init(Jep) method must be called.public PolynomialCreator(Jep j)
j - Jep instancepublic PolynomialCreator(Jep j, FieldI f)
j - Jep instancef - field for operations on constantspublic void init(Jep j)
JepComponentinit in interface JepComponentj - the current Jep instancepublic JepComponent getLightWeightInstance()
JepComponentgetLightWeightInstance in interface JepComponentpublic PNodeI createPoly(Node node) throws ParseException
node - top node of expressionParseException - if expression cannot be converted.
This can happen if the underlying field cannot represent Infinity or NaN
and a constant exprssion with these values is encountered.public Node toNode(PNodeI poly) throws ParseException
poly - ParseException - if expression cannot be converted.public Node simplify(Node node) throws ParseException
node - top node to expression to be simplified.ParseException - if expression cannot be converted.public Node expand(Node node) throws ParseException
(1+x)^3 -> 1+3x+3x^2+x^3node - top node to expression to be simplified.ParseException - if expression cannot be converted.public PNodeI expand(PNodeI poly) throws ParseException
poly - input polynomialParseException - if expression cannot be converted.public int compare(Node node1, Node node2) throws ParseException
node1 - lhs nodenode2 - rhs nodeParseExceptionpublic int expandCompare(Node node1, Node node2) throws ParseException
node1 - lhsnode2 - rhsParseExceptionpublic boolean equals(Node node1, Node node2) throws ParseException
node1 - node2 - ParseExceptionpublic boolean expandEquals(Node node1, Node node2) throws ParseException
node1 - node2 - ParseExceptionpublic PNodeI[] toCoefficientArray(PNodeI poly, java.lang.String var) throws ParseException
poly - The input polynomialvar - the name of the variableParseExceptionpublic java.lang.Object toPNodeArray(PNodeI poly, java.lang.String... vars) throws ParseException
PNodeI[] coeffs = (PNodeI[]) pc.toPNodeArray("a x^2+b x+c","x");
For two variables use
PNodeI[][] coeffs = (PNodeI[][]) pc.toPNodeArray("a x^2+b x y","x","y");
Note the returned array is not guaranteed to have the same number of elements in each row or column.poly - expression to find coefficients ofvars - names of variables to find coefficients ofParseException - if poly does not represent a polynomialpublic double[] toDoubleArray(PNodeI poly, java.lang.String var) throws ParseException
poly - input polynomial. A polynomial in a single variables.var - polynomial variableParseExceptionpublic double[][] toDoubleArray(PNodeI poly, java.lang.String var1, java.lang.String var2) throws ParseException
poly - input polynomial. A polynomial in two variables.var1 - name of first variablevar2 - name of second variableParseExceptionpublic double[][][] toDoubleArray(PNodeI poly, java.lang.String var1, java.lang.String var2, java.lang.String var3) throws ParseException
poly - input polynomial. A polynomial in three variables.var1 - name of first variablevar2 - name of second variablevar3 - name of third variableParseExceptionpublic java.lang.Object visit(ASTConstant node, java.lang.Object data) throws ParseException
visit in interface ParserVisitorParseExceptionpublic java.lang.Object visit(ASTVarNode node, java.lang.Object data) throws ParseException
visit in interface ParserVisitorParseExceptionpublic java.lang.Object visit(ASTFunNode node, java.lang.Object data) throws JepException
visit in interface ParserVisitorJepExceptionpublic java.lang.Object visit(ASTOpNode node, java.lang.Object data) throws JepException
visit in interface ParserVisitorJepExceptionpublic NodeFactory getNodeFactory()
public OperatorTableI getOperatorTable()
Copyright © 2018 Singular Systems http://www.singularsys.com/jep