Skip to content

poly

A Python package for polynomials.

>>> from poly import polyval
>>> from fractions import Fraction
>>> p = (Fraction(1, 2), Fraction(3, 4))
>>> x = Fraction(5, 6)
>>> polyval(p, x)
Fraction(9, 8)

Installation

pip install git+https://github.com/goessl/poly.git

Usage

This package heavily depends on and is the natural extension of goessl/vector.

Operation poly sparse
Creation
\(0\) polyzero polyszero
\(1\) polyone polysone
\(x\) polyx polysx
\(x^n\) polymono polymono
\((x^n)_{n\in\mathbb{N}_0}\) polymonos polysmonos
Uniform random polyrand polysrand
Normal random polyrandn polysrandn
From roots polyfromroots polysfromroots
Utility
Degree polydeg polysdeg
Comparison polyeq polyseq
Trimming polytrim polystrim
Conversion
polystod
polydtos
polysympify polyssympify
polyunsympify polysunsympify
Evaluation
Evaluation polyval polysval
polyval_naive
polyval_iterative
Evaluation of basis polyvals
Evaluation at \(x=0\) polyvalzero polysvalzero
Composition polycom polyscom
polycom_naive
polycom_iterative
polycom_horner
Shift polyshift polysshift
Scale polyscale polysscale
Arithmetic
Positive polypos polyspos
Negation polyneg polysneg
Addition polyadd polysadd
Basis addition polyaddc polysaddc
Subtraction polysub polyssub
Scalar multiplication polyscalarmul polysscalarmul
Scalar true division polyscalartruediv polysscalartruediv
Scalar floor division polyscalarfloordiv polysscalarfloordiv
Scalar mod polyscalarmod polysscalarmod
Scalar divmod polyscalardivmod polysscalardivmod
Multiplication polymul polysmul
polymul_naive polysmul_naive
polymul_karatsuba
Multiplication by \(x\) polymulx polysmulx
Exponentiation polypow polyspow
polypow_naive polyspow_naive
polypow_binary polyspow_binary
Powers of polynomials polypows polyspows
Calculus
Differentiation polyder polysder
Integration polyantider polysantider

Design

Coefficient order

Coefficients are stored in ascending order like every sane person would do.

This ways the coefficient indices correspond to the monomial exponent (or the basis index incase of Hermite polynomials).

The newer numpy.polynomial does it this way, the older numpy.poly1d does it in reverse. sympy also does it the wrong way.

Roadmap

  • Modules
  • Hermite polynomials module
  • Sparse module
  • Object oriented module
  • Parallelised module
  • Multivariate module
  • Documentation
  • polymul_karatsuba
  • Consistent See also links; graph view?
  • Consistent use of Horner / Clenshaw
  • Algorithms
  • polysqrt
  • polyroots only if there is a clean algorithm
  • Knuth–Eve evaluation
  • Taylor shift
  • Complexity analysis

License (MIT)

Copyright (c) 2024-2025 Sebastian Gössl

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.