This namespace uses the sparse exponent representation introduced in emmy.polynomial.exponent
to build up a polynomial arithmetic package using Clojure vectors. emmy.polynomial
uses this representation to represent polynomial terms in the [[Polynomial]] data structure.
Polynomials are sums of monomial terms; a monomial is a pair of some non-zero coefficient and a product of some number of variables, each raised to some power. The latter are represented by the "exponents" data structure defined in emmy.polynomial.exponent
.
More concisely, polynomials are linear combinations of the exponents.
Terms are represented as pairs of [, ].
Polynomial Terms
Polynomials are represented as ordered vectors of terms. the empty vector needs no ordering:
For multiple terms, terms are ordered with a monomial order. emmy.polynomial.exponent
supplies a few of these that you can choose. Set the ordering via the [[monomial-order]] dynamic variable.
The next-simplest polynomial is a constant polynomial:
Univariate polynomials can be specified by a sequence of their coefficients:
When multivariate polynomials have high arity, it can be quite a task to supply every possible term. [[sparse->terms]] allows you to specify a mapping of exponents => coefficient, where "exponents" can be:
emmy.polynomial.exponent
{variable-index, power}
[3 0 1]
for Loading....We can make polynomials. What can we do with them?
The main operations we want are +
, *
and -
. We can also divide polynomials; the catch is that we always have to return an explicit remainder as well.
Multiplication works by multiplying the polynomial on the right by each term on the left and summing up all results. These operations are split into two functions:
Division works by examining each term of u
(in descending order) and checking whether or not the lead term of v
can divide into it. If it can, the algorithm performs the division and tries again with u-(new-term*v)
, on down until no terms remain.
See the Wikipedia article on Polynomial long division for more details.