[Numpy-discussion] Polynomial Improvements

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Apr 20 15:57:23 EDT 2021

On Tue, 20 Apr 2021 at 19:21, Robert <bobbyocean at gmail.com> wrote:
> I am new to contributing to open source projects and not sure where to begin
> (maybe emailing this distro?). In any case, the main improvement I would
> like to work on would be adding multivariate polynomials/differentials to
> numpy. I would love any insight into the current status and intensions of
> numpy polynomial implementations.
> 1) why do we have np.polynomial and np.lib.polynomial? which one is older?
> is there a desire to see these merged?
> 2) why does np.polynomial.Polynomial have a domain and window? they appear
> to have no implementation (except the chebyshev interpolation) as far as I
> can tell? what is their intended use? why is their no variable
> representation implemented like in np.polynomial and is not installed to
> numpy directly, @set_module('numpy')?
> 3) how many improvements are allowed to be done all at once? is there an
> expectation of waiting before improving implementations or code?
> Thinking further down the road, how much is too much to add to numpy? I
> would like to see multivariate implemented, but after that it would be nice
> to have a collection of known polynomials like standard, pochhammer,
> cyclotomic, hermite, lauguerre, legendre, chebyshev, jacobi. After that it
> would be of interest to extend .diff() to really be a differential operator
> (implemented as sequences of polynomials) and to allow differential
> constructions. Then things like this would be possible:
>     x = np.poly1d([1,0])
>     D = np.diff1d([1,0])
>     assert Hermite(78) == (2*x - D)(Hermite(77))
> Or if series were implemented then we would see things like:
>     assert Hermite(189) == (-1)**189 * Exp(x**2)*(D**189)(Exp(-x**2))
>     assert Hermite(189) == Exp(-D**2)(x**189)(2*x)
> 4) at what point does numpy polynomial material belong in scipy material and
> visa-versa?

The distinction between numpy and scipy comes from the way things have
worked out over time to some extent. I expect that if numpy was being
rewritten today it wouldn't have any polynomial functions.

Are you aware of sympy? What you are suggesting seems more appropriate
for a symbolic library rather than a numerical one. SymPy already has
most of this e.g.:

In [47]: x = Symbol('x')

In [48]: h78 = hermite(78, x)

In [49]: h77 = hermite(77, x)

In [50]: h78 == expand(2*x*h77 - h77.diff(x))
Out[50]: True

Being a symbolic library sympy can handle Hermite polynomials of symbolic order:

In [51]: n = Symbol('n')

In [52]: hermite(n, x)
Out[52]: hermite(n, x)

In [53]: hermite(n, x).diff(x)
Out[53]: 2⋅n⋅hermite(n - 1, x)

There is also support for series etc.


More information about the NumPy-Discussion mailing list