Polynomial Conversion Functions
The conversion module provides helpers that convert between the internal coefficient-array representation of multivariate polynomials and symbolic SymPy expression objects.
poly2sympy()
The poly2sympy()
function converts a polynomial represented as a list of coefficient arrays to a SymPy expression.
- hiten.algorithms.polynomial.conversion.poly2sympy()[source]
Convert a polynomial represented as a list of coefficient arrays to a SymPy expression.
- Parameters:
poly_p (List[numpy.ndarray]) – List of coefficient arrays, where poly_p[d] contains coefficients for degree d
vars_list (List[sympy.Symbol]) – List of SymPy symbols used as variables in the expression
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numpy.ndarray) – List of arrays containing packed multi-indices
- Returns:
SymPy expression equivalent to the input polynomial
- Return type:
sympy.Expr
- Raises:
ValueError – If vars_list does not have exactly N_VARS elements
Notes
This function converts each homogeneous part of the polynomial separately with
hpoly2sympy()
, then combines them into a single SymPy expression.
sympy2poly()
The sympy2poly()
function converts a SymPy expression to a polynomial represented as a list of coefficient arrays.
- hiten.algorithms.polynomial.conversion.sympy2poly()[source]
Convert a SymPy expression to a polynomial represented as a list of coefficient arrays.
- Parameters:
expr (sympy.Expr) – SymPy expression to convert
vars_list (List[sympy.Symbol]) – List of SymPy symbols used as variables in the expression
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numpy.ndarray) – List of arrays containing packed multi-indices
encode_dict_list (List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
List of coefficient arrays, where the d-th element contains coefficients for the homogeneous part of degree d
- Return type:
List[numpy.ndarray]
- Raises:
ValueError – If vars_list does not have exactly N_VARS elements or if the expression’s degree exceeds the precomputed table limits
TypeError – If the expression cannot be converted to a Sympy Poly object or if conversion of coefficients to numeric types fails
IndexError – If the encoded position for a term is out of bounds
Notes
The function works by converting the SymPy expression to a Poly object, then extracting terms and mapping them to the appropriate positions in the coefficient arrays.
hpoly2sympy()
The hpoly2sympy()
function converts a homogeneous polynomial coefficient array to a SymPy expression.
- hiten.algorithms.polynomial.conversion.hpoly2sympy()[source]
Convert a homogeneous polynomial coefficient array to a SymPy expression.
- Parameters:
p (numpy.ndarray) – Coefficient array for a homogeneous polynomial part of a specific degree
vars_list (List[sympy.Symbol]) – List of SymPy symbols used as variables in the expression
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numpy.ndarray) – List of arrays containing packed multi-indices
- Returns:
SymPy expression equivalent to the input homogeneous polynomial
- Return type:
sympy.Expr
- Raises:
ValueError – If the degree cannot be determined from the coefficient array size or if the coefficient array length is inconsistent with the expected size
Notes
This function converts each term of the homogeneous polynomial by decoding the multi-index with
_decode_multiindex()
to determine the exponents, constructing the corresponding monomial, and multiplying it by the coefficient.