The MVPolyCube class

This class represents a mutivariate polynomial with a Numpy N-dimensional array, a numpy.ndarray. The array holds the coefficients of the polynomial in the natural, little-endian [1] fashion.

Method list

A list of all methods defined by the subclass. Naturally, all of the methods of the base class are also available.

class mvpoly.cube.MVPolyCube(arg=None, **kwargs)

Return an object of class MVPolyCube with the coefficient array set to the optional coef argument, a numpy.ndarray.

__init__(arg=None, **kwargs)
__getitem__(key)

The get-index method which returns the coefficients of the polynomial by their (zero-based) indices. For the polynomial \(p(x,y) = 2x^2 + y + 3\) we would access the coefficient of \(x^2\) with p[2] or p[2, 0] or p[2, 0, 0] … (trailing zeros are ignored), the coefficient of \(y\) with p[0, 1], p[0, 1, 0], … and the constant term with p[()], p[0], p[0, 0], … (Note that p[] is a Python syntax error). Indices outside the shape of the underlying NumPy array will return zero (without changing shape of the array).

Note that slice indexing will not work here, p[1:3] will result in an error: instead use the coef() method to access the underlying array, p.coef[1:3].

__setitem__(key, value)

As __getitem__(), but setting the coefficient. The underlying array is grown to accomodate the new coefficient if needed.

__add__(other)

Add an MVPolyCube to another, or to a numpy.ndarray, or to a number; return an MVPolyCube.

__radd__(other)

As add, but with the types in the opposite order – this is routed to add.

__neg__()

Negation of a polynomial, return the polynomial with negated coefficients.

__mul__(other)

Convolve our coefficient array with that of other and return an MVPolyCube object initialised with the result.

__rmul__(other)

Reverse order multiply, as add

__eq__(other)

Equality of polynomials.

astype(dtype)

Return a polynomial using the specified dtype for the coefficients.

property coef

The NumPy array of coefficients.

property degrees

Return the maximal degree of each of the variables of the polynomial as a tuple of integers. For a constant (including a zero) polynomial, returns the empty tuple.

property degree

The (total, homogeneous) degree, the maximal sum of the monomial degrees of monomials with nonzero coefficients. Returns \(-1\) for the zero polynomial, \(0\) for a constant polynomial.

eval(*args)

Evaluate the polynomial at the points given by args. There should be as many arguments as the polynomial has variables. The argument can be numbers, or arrays (all of the same shape).

compose(*args)

Compose polynomials. The arguments, which should be MVPolyCube polynomials, are substituted into the corresponding variables of the polynomial.

diff(*args)

Differentiate polynomial. The integer arguments should indicate the number to times to differentiate with respect to the corresponding polynomial variable, hence p.diff(0,1,1) would correspond to \(\partial^2 p / \partial y \partial z\).

int(*args, **kwargs)

Indefinite integral of polynomial. The arguments are as for diff(), but an optional dtype keyword argument can be appended to specify the dtype of the output polynomial.

maxmodnb(**kwargs)

Maximum modulus of the polynomial on the unit ball, this method is only available if the maxmodnb package is installed (and that is in an early stage of development).

property nonzero

Returns a list of 2-element tuples, for each the first being a (monomial) index, the second the corresponding coefficient. The indices have trailing zeros, so the return value for the polynomial \(p(x,y) = 2 + 3x + 4y\) would be [((0, 0), 2), ((1, 0), 3), ((0, 1), 4)].

norm(order)

Returns the norm of the coefficients. The order can be a float (for the p-norm) or any other value accepted by the numpy.linalg.norm() method.

classmethod monomials(n, k, **kwargs)

Return an array of all of the n-variate monomials of (homogeneous) degree less than or equal to k.

classmethod init_from_nonzero(p, dtype)

Create a polynomial from a polynomial of any subclass; this is used internally by the __init__() constructor, but may be useful for direct application.

classmethod variables(n, **kwargs)

Return a n-tuple of each of the variables (x, y, ..) as monomials of an n-variate system.

classmethod variable(i, n, **kwargs)

Return the i-th variable of an n-variate system, (i = 0, …, n-1).

classmethod zero(**kwargs)

Return the zero polynomial.

classmethod one(**kwargs)

Return the unit (1) polynomial.

classmethod lehmer(**kwargs)

Returns the Lehmer polynomial (univariate of degree 10), notable as the polynomial whose Mahler measure is the smallest known measure larger than 1 of a polynomial with integer coefficients.

classmethod rudin_shapiro(n, **kwargs)

Returns the n-th Rudin-Shapiro polynomial (univariate, of degree \(2^n-1\)). These dense polynomials have coefficients which are \(\pm1\) and have a small maximum modulus on the unit disk.

__hash__ = None
classmethod wendland(d, k, **kwargs)

The k-th Wendland polynomial \(p_{d, k}(r)\) for dimension d, this univariate polynomial of degree \(\lfloor d/2 \rfloor + 3k + 1\) is used to define a compactly supported radial basis function with continuous derivatives up to order \(2k\). The calculation of the coefficients uses the recursive method described by Wendland in [2].

Utility functions

Library code for the serious work on the arrays is to be found in the module mvpoly.utils.cube, it is not expected that these functions will be called directly.

mvpoly.util.cube.array_enlarge(a, shape)

Enlarge the numpy.array a with zeros so that the result has the given shape. It is an error to attempt to reduce any dimension with this function.

mvpoly.util.cube.dimension_pad(S, n)

Return a shape tuple extended so that it has n dimensions

mvpoly.util.cube.int(p, d, dtype)

Integrate the multivatiate polynomial whose coefficients are given by the numpy.array argument p and as many times as given by the non-negative tuple d. The final argument, dtype, specifies the data-type of the output; if this is an integer type then the results may be incorrect (due to integer division) so a warning will be issued.

mvpoly.util.cube.diff(p, d)

Differentiate the multivatiate polynomial whose coefficients are given by the numpy.array argument p and as many times as given by the non-negative tuple d.

mvpoly.util.cube.meshgridn(shp, n, v)

Given a shape tuple shp = (s1, s2, … sm), a specified dimension n and a vector v with sn elements, this function returns a numpy.ndarry which has v replicated in the n-th dimension. Thus it it rather like the n-th return value of numpy.meshgrid(), but without constructing the other return values.

mvpoly.util.cube.padded_sum(*args, **kwargs)

Add the numpy.ndarry arguments which may be of differing dimensions and sizes, return a numpy.ndarray. This code is largely based on this Bi Rico’s answer to this Stack Exchange question.

The keyword argument dtype is required, the summands are cast to this type.

mvpoly.util.cube.convn(a, b)

Convolve numpy.ndarry arguments a and b, and return the numpy.ndarry that results.

mvpoly.util.cube.horner(p, dtype=<class 'float'>, *args)

Evaluate polynomial with coefficients array p at all of the points given by the equal-sized arrays args = X, Y, …, (as many as the dimension of p). Returns a numpy.ndarray of the same size.

mvpoly.util.cube.maxmodnb(p, **kwargs)

Return the maximum modulus of the polynomial whose coefficients are given by the array p. Requires the maxmodnb package (not yet released).