Create a polynomial
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
[x1, x2, …]>, <
[x1, x2, …]>, <
[x1, x2, …], <
poly(f) converts a polynomial expression
a polynomial of the kernel domain
The kernel domain
DOM_POLY represents polynomials. The arithmetic
for this data structure is more efficient than the arithmetic for
polynomial expressions. Moreover, this domain allows you to use special
coefficient rings that cannot be represented by expressions. The function
the tool for generating polynomials of this type.
poly(f, [x1, x2, ...], ring) converts the
f to a polynomial in the indeterminates
x2, ... over the specified coefficient ring. The
does not require an expanded form of the expression
The function internally expands expressions.
If you do not specify indeterminates, MuPAD® searches for
them internally. If MuPAD cannot identify indeterminates, it
By default, the
poly function uses the coefficient
ring of arbitrary MuPAD expressions. In this case, you can use
arbitrary MuPAD expressions as coefficients.
f is a domain element, the system calls
the conversion into a polynomial. If
domain elements, the system recursively calls
domain elements inside
f. See Example 11.
poly(p, [x1, x2, ...], ring) converts a polynomial
a polynomial in the indeterminates
x1, x2, ... over
the specified coefficient ring. The indeterminates and the coefficient
ring are part of the data structure
DOM_POLY. Using this function call, you
can change the indeterminates and the coefficient ring of a polynomial.
If you do not specify indeterminates,
the indeterminates of the original polynomial
If you do not specify a coefficient ring,
the ring of the original polynomial
poly(list, [x]) converts a list of coefficients [a0, a1, a2,
…] to a univariate polynomial a0 + a1 x + a2 x2 +
…. See Example 3.
For a univariate polynomial
p, the call
[x]) converts the result of the call
coeff(p, All) back
to a polynomial.
This call is the fastest method to create polynomials of the
the input already has the form that MuPAD uses internally.
The list must contain an element for each nonzero monomial of the polynomial. Therefore, you must use sparse input involving only nonzero terms. In particular, an empty list results in the zero polynomial.
Each element of the list must be a list with two elements: the coefficient of the monomial and the exponent (or exponent vector). For a univariate polynomial in the variable x, the list
corresponds to c1 xe1 + c2 xe2 + …. For a multivariate polynomial, the exponent vectors are lists containing the exponents of all indeterminates of the polynomial. The order of the exponents must be the same as the order given by the list of indeterminates. For a multivariate polynomial in the variables x1, x2, the term list
corresponds to c1 x1e11 x2e12 + c2 x1e21 x2e22 + ….
The order of the elements of the term list does not affect the
resulting polynomial. If you provide multiple entries corresponding
to the same term,
poly adds the coefficients.
This call lets you restore polynomials from the term lists returned
The position of the indeterminates in the input list
x2, ...] determines their order in the resulting polynomial.
If you do not specify indeterminates, MuPAD searches the expression
possible indeterminates and determines their order. See Example 2.
You can perform arithmetical operations on polynomials that have the same indeterminates and the same coefficient ring. Also, you can perform arithmetical operations on polynomials and arithmetical expressions. When you operate on a polynomial and an arithmetical expression, MuPAD internally converts that arithmetical expression to a polynomial and performs the calculation. See Example 1.
poly function does not limit acceptable
indeterminates to identifiers or indexed identifiers. You can use any expression
(except for rational expressions) as an indeterminate. For example,
indeterminates. See Example 5.
After creating a polynomial, the
does not evaluate the coefficients of the polynomial. If the coefficients
contain free identifiers,
poly does not replace
these identifiers with their values. See Example 12.
If any domain of type
DOM_DOMAIN provides arithmetical operations,
you can use that domain as a coefficient ring. See the "Background"
section for details.
If you specify a coefficient domain, MuPAD accepts only
the elements of that domain as coefficients of the polynomial. On
poly tries to convert a polynomial expression
a polynomial over the coefficient ring. For some coefficient rings,
you cannot use arithmetical expressions to represent a polynomial.
The reason is that multiplication with the indeterminates can be an
invalid operation in the ring. In such cases, you can define the polynomial
by using a term list. See Example 7.
poly function creates a polynomial from
a polynomial expression:
p := poly(2*x*(x + 3))
p^2 - p*(p + 1)
You can multiply a polynomial by an arithmetical expression. MuPAD internally
converts the expression to a polynomial of the appropriate type, and
then multiplies polynomials. For example, multiply the polynomial
the constant 5:
Now, multiply the polynomial
p*(x - 1)
If MuPAD cannot convert the expression to a polynomial of the appropriate type, the arithmetical operation between a polynomial and this expression fails:
p*(1/x - 1)
Error: The argument is invalid. [_mult]
You can create a polynomial with parameters. In the following
y is a parameter (not an indeterminate):
poly((x*(y + 1))^2, [x])
If you do not specify indeterminates, MuPAD tries to find indeterminates automatically. The following call converts a multivariate expression to a multivariate polynomial:
poly((x*(y + 1))^2)
Now, specify the order of the indeterminates explicitly:
poly((x*(y + 1))^2, [y, x])
poly function to convert the following
list of coefficients to a univariate polynomial in
The first entry of the list produces the term with the zero exponent.
The last entry produces the term with the highest exponent:
p := poly([1, 2, 3, 4, 5], [x])
To revert the ordering of the coefficients in a polynomial,
Create the following polynomials by term lists:
poly([[c2, 3], [c1, 7], [c3, 0]], [x])
If you provide multiple coefficients corresponding to the same
poly adds those coefficients:
poly([[c2, 3], [c1, 7], [c3, 0], [a, 3]], [x])
For multivariate polynomials, specify exponent vectors by lists:
poly([[c1, [2, 2]], [c2, [2, 1]], [c3, [2, 0]]], [x, y])
You can use expressions as indeterminates:
poly(f(x)*(f(x) + x^2))
The residue class ring
IntMod(7) is a valid
p := poly(9*x^3 + 4*x - 7, [x], IntMod(7))
For computations that involve polynomials over this ring, MuPAD uses modular arithmetic:
However, MuPAD does not return coefficients as elements
of a special domain. Instead, it returns coefficients as plain integers
of the type
To create the following polynomial, combine the input syntax that uses term lists with a specified coefficient ring:
poly([[9, 3], [4, 1], [-2, 0]], [x], IntMod(7))
MuPAD interprets the input coefficients as elements of
the coefficient domain. For example, conversions such as
mod 7 = 2 mod 7 occur on input. You also can use the domain
define an equivalent polynomial. If you use
(7), MuPAD uses
the symmetric modulo function
mods and represents the coefficients
by the numbers - 3, …, 3.
If you use
(7), MuPAD uses
the positive modulo function
represents the coefficients by the numbers 0,
poly([[9, 3], [4, 1], [-2, 0]], [x], Dom::IntegerMod(7))
not allow multiplication with identifiers:
c := Dom::IntegerMod(7)(3)
poly(c*x^2, [x], Dom::IntegerMod(7))
Instead, use the term list to specify the polynomial:
poly([[c, 2]], [x], Dom::IntegerMod(7))
Change the indeterminates in a polynomial:
p:= poly(((a + b)*x - a^2)*x, [x]): p, poly(p, [a, b])
Change the coefficient ring of a polynomial:
p := poly(-4*x + 5*y - 5, [x, y], IntMod(7)): p, poly(p, IntMod(3))
Create a polynomial over the coefficient ring
poly(3*x - y, Dom::Float)
y cannot appear in coefficients
from this ring because it cannot be converted to a floating-point
poly(3*x - y, [x], Dom::Float)
You can overload
poly by its first operand.
For example, create a domain
polyInX that represents
domain polyInX new := () -> new(dom, poly(args(), [x])); print := p -> expr(extop(p, 1)); poly := p -> if args(0) = 1 then print(Unquoted, "polyInX::poly called with 1 argument"); extop(p, 1); else print(Unquoted, "polyInX::poly called with more than 1 argument"); poly(extop(p, 1), args(2..args(0))); end; end_domain: p := polyInX(3*x^2-2)
You can convert the elements of
polynomials of the type
poly method of the domain:
polyInX::poly called with 1 argument
By reacting to additional arguments, the overloading defined above also allows you to create polynomials over other coefficient rings:
poly(p, [x], IntMod(2))
polyInX::poly called with more than 1 argument
Create a polynomial with coefficients containing the identifier
Although you assign the value 1 to
y, MuPAD does
not substitute the new value into the polynomial:
f := poly(x^2 - y, [x]): y := 1: eval(f)
f := mapcoeffs(f, eval)
The coefficient ring: either
A polynomial of type
A list containing coefficients and exponents
A list containing coefficients of a univariate polynomial
The indeterminate of a univariate polynomial
The default ring
To use a domain as a coefficient, the domain must contain the following:
"zero" that provides
the neutral element with respect to addition.
"one" that provides the
neutral element with respect to multiplication.
"_plus" that adds domain
"_negate" that returns
the inverse with respect to addition.
"_mult" that multiplies
"_power" that computes
integer powers of a domain element. Call this method with the domain
element as the first argument and an integer as the second argument.
"gcd" that returns the
greatest common divisor of domain elements.
"diff" that differentiates
a domain element with respect to a variable.
"_divide" that divides
two domain elements. It must return
FAIL if division
is not possible.
"norm" that computes
the norm of a domain element and returns it as a number.
"convert" that converts
an expression to a domain element. The method must return
such conversion is not possible.
The system calls this method to convert the coefficients of polynomial expressions to coefficients of the specified domain. If this method does not exist, you can specify the coefficients only by using domain elements.
"expr" that converts
a domain element to an expression.
The system function
this method to convert a polynomial over the coefficient domain to
a polynomial expression. If this method does not exist,
expr inserts domain
elements into the expression.
You can convert a polynomial over a certain coefficient domain
into a polynomial over the same domain, but a different set of indeterminates.
This conversion is much more efficient when the domain has the axiom
Ax::indetElements. MuPAD implicitly
assumes that this axiom holds for the domain
but not for
Internally, MuPAD stores polynomials of the type
a sparse representation and uses machine integers for the exponents.
This method implies that in a 32-bit environment, the exponent of
each variable in each monomial cannot exceed 231 -