Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Polynomials in SymPy

It seems that implementation of polynomials in sympy and symengine could be closely parallel.

There should be three kinds of polynomials: (standard) polynomials, Laurent polynomials, and Puiseux polynomials, thus adding a "fourth dimension" to the classification in the wiki ( They can also be used for representing (truncated) series of respective types.

It is possible to implement all three kinds of polynomials with exponents, or index vectors, that consist of nonnegative integers. In sympy these vectors are tuples; in symengine they could be packed into (long) integers to accelerate the execution.

Laurent polynomials may also have negative exponents. The index vectors could contain negative integers. In sympy that would probably make no difference, but in symengine the packing and unpacking operations would be less efficient because of the necessary sign manipulations. However, there is an alternative. The exponents in a Laurent series are bounded below. A Laurent polynomial could be implemented as an ordinary polynomial p together with a monomial m (i.e. a vector of nonnegative integers, one for each generator) such that the Laurent polynomia would be p/m. The algebraic operations, converters and printers of the Laurent polynomial class would have take into account the shifts in the exponents.

The implementation of Puiseux polynomials by means of vectors of rational numbers would be rather inefficient even in sympy. In this case it is again possible to use polynomials with integral exponents. The exponents in a Puiseux series are rational, but their denominators are bounded, by definition. Hence, for each Puiseux series, there exists a vector of positive integers (lcm's of the denominators) such that the rational exponents of the series will become integral after multiplication by these integers. Again, the operations, converters and printers would have to be defined specifically for the Puiseux polynomial class.

In summary:

  • A Laurent polynomial is represented by a polynomial together with a vector of integers (monomial).
  • A Puiseux polynomial is represented by a Laurent polynomial and a vector of lcm integers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.