Package com.singularsys.extensions.polynomials
PolynomialCreator pc = new PolynomialCreator(jep); Node simp = pc.simplify(node); Node expand = pc.expand(node); boolean flag = pc.equals(node1,node2); int res = pc.compare(node1,node2); PNodeI poly = pc.createPoly(node);
How it works
The basic idea is to reduce each equation to a canonical form based on a total ordering of the terms.
For example a polynomial in x will always be in the form
a+b x+c x^2+d x^3.
This makes comparison of two polynomials easy as it is just necessary to compare term by term,
whereas it is difficult
to compare x^2-1 with (x+1)*(x-1) without any simplification or reordering is tricky.
As an illustration some of the rules for the ordering are
0<1<2, 5<x, x<x^2<x^3, x<y.
A polynomial is constructed from a set of monomials by arranging the monomials in order. Likewise, a monomial is constructed from a set of variables by arranging the variables in name order.
The algorithm can also work with non-polynomial equations. Functions are order by the name of the function and the ordering of their arguments.
Hence cos(x)<sin(x)<sin(y).
Comparators and Total order
A total ordering of all expressions is used throughout the package, this can either be the default defined below,
one the comparator in the com.singularsys.extensions.polynomials.comparators
package or any class implementing Comparator<PNodeI>.
The ordering of a variables in a monomial or monomials in a polynomial is defined by the ordering. As the representation of an expression 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 default ordering is illustrates by:
- -1 // numbers sorted by values
- 0
- 1 // numbers before monomials
- a^-2 // powers in increasing order, parsed as a^(-2)
- a^-1
- -2 a // monomials with lower coefficient first
- -a
- a
- 2 a
- a^2
- a^3
- a^x // numeric powers before symbolic powers
- b // variables sorted alphabetically
- b c // first term in a monomial tested first
- c
- x-1 // polynomials terms tested in order with higher degree ones first
- x
- x+1
- x+2
- 2 x+1
- x^2+x+1 // polynomials with lower degree come first
- x^2+x+2
- x^2+2 x+1
- x^2 y
- x==1 // polynomials before operators
- 1>x // operators sorted alphabetically
- x>1 // identical operator sorted by first argument
- x>y // then by second argument
- y>x
- cos(a) // functions after operators
- sin(a) //function names sorted alphabetically
- sin(b) // function arguments compared
The ordering defined by the Lexical Comparator LexComparator is very different
here high degree terms in the first variable come first
- x^5+x^4 // polynomials with high order terms in x first
- x^5+x^3 // polynomials sorted by first non identical term
- x^5
- x^4 + x^3
- x^4 + y^5 // terms with x before terms with y
- x^4
- x^3 y^2
- x^3 y
- x^2
- 3 x // identical monomials sorted by coefficient value
- 2 x
- x
- -1 x
- -2 x
- x^-1 // negative
- x^-2
- y+z
- y^-3
- x==1 // polynomials before operators
- x>y // operators sorted alphabetically
- y>x // identical operator sorted first argument
- 1>x
- cos(a) // operators before functions
- sin(a) // function names sorted alphabetically
- sin(b) // function arguments compared
- 3 // numbers last
- 2
- 1
- 0
- -1
- -2
The Graded Lexical Comparator GrlexComparator
sorts by terms with highest degree first
- x^5 // degree 5 terms
- y^5
- x^4 // degree 4 terms
- x^3 y
- x^2 // degree 2 terms
- 3 x // degree 1 terms
- 2 x
- 2 // constants
- 0
- Since:
- Jep 3.5 / Extensions 2.0
- See Also:
-
ClassDescriptionDefault methods, when more specific methods do not work.A base class for polynomial rewriters.Jep function to extract array of coefficients from a polynomial.The
compare(x,y)command.Rewrites polynomials with powers of i, the square root of -1, to a form without i.Theexpand(x)command.Represents an immutable monomial a x^i * y^j * ... * z^k, a constant.A mutable monomial representing a * x^i * y^j * ... * z^k.A mutable polynomial representing a + b + c.Represents a constant.Represents a function.An element in a polynomial representation of an expression.Represents a polynomial.A system for symbolic simplification, expansion and comparison based on conversion to a canonical polynomial representation.Represents an operator.Represents a variable.Thesimplify(x)command.Thesymequals(x,y)command.