wmpy.core.polynomial.Polynomial

class Polynomial(monomials, variables, env)[source]

Bases: object

Internal class representing canonical polynomials. Implemented as a dict, having for each monomial: {key : coefficient} where key is a tuple encoding exponents of the ordered variables.

E.g. {(2,0,1): 3} = “3 * x^2 * y^0 * z^1”

monomials

the monomial dictionary

variables

list of pysmt real variables

ordered_keys

sorted list of monomial keys

mgr

the pysmt formula manager

Default constructor.

Parameters:
  • monomials (dict[tuple[int, ...], float]) – the list of monomials returned by PolynomialParser.walk

  • variables (Collection[FNode]) – list of pysmt real variables

  • env (Environment) – the pysmt environment

Methods

to_numpy

Returns the polynomial as a callable function.

to_pysmt

Returns the polynomial in pysmt format.

Attributes

degree

Returns the degree of the polynomial.

is_zero

Returns true if the polynomial is zero.

property degree: int

Returns the degree of the polynomial.

property is_zero: bool

Returns true if the polynomial is zero.

to_numpy()[source]

Returns the polynomial as a callable function.

This function can be used to evaluate a numpy array.

Return type:

Callable[[ndarray], ndarray]

to_pysmt()[source]

Returns the polynomial in pysmt format.

Return type:

FNode