Polynomial Operations
The operations module provides high-level utilities for manipulating multivariate polynomials.
_polynomial_zero_list()
The _polynomial_zero_list()
function creates a list of zero polynomial coefficient arrays up to a maximum degree.
- hiten.algorithms.polynomial.operations._polynomial_zero_list()[source]
Create a list of zero polynomial coefficient arrays up to a maximum degree.
- Parameters:
max_deg (int) – Maximum degree of the polynomials to create
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
- Returns:
A list of length max_deg+1 where the i-th element contains an array of zeros representing the homogeneous part of degree i
- Return type:
List[numpy.ndarray]
Notes
This function is used to initialize polynomial lists. The structure of the returned list is such that the index corresponds to the degree, and each element is an array of zeros with the appropriate size for that degree’s coefficients.
_polynomial_variable()
The _polynomial_variable()
function creates a polynomial representing a single variable.
- hiten.algorithms.polynomial.operations._polynomial_variable()[source]
Create a polynomial representing a single variable.
- Parameters:
idx (int) – Index of the variable (0 to N_VARS-1)
max_deg (int) – Maximum degree to allocate for the polynomial
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numba.typed.List) – List of arrays containing packed multi-indices
encode_dict_list (numba.typed.List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
A list representing the polynomial for the variable x_idx, with arrays for degrees 0 to max_deg
- Return type:
List[numpy.ndarray]
Notes
The result is a polynomial with a single non-zero coefficient corresponding to the monomial x_idx.
_polynomial_variables_list()
The _polynomial_variables_list()
function creates a list of polynomials for each variable in the system.
- hiten.algorithms.polynomial.operations._polynomial_variables_list()[source]
Create a list of polynomials for each variable in the hiten.system.
- Parameters:
max_deg (int) – Maximum degree to allocate for each polynomial
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numba.typed.List) – List of arrays containing packed multi-indices
encode_dict_list (numba.typed.List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
A list of length N_VARS where each element is a polynomial representing one of the system variables
- Return type:
List[List[numpy.ndarray]]
Notes
This function creates polynomials for all variables in the system (typically position and momentum variables in a Hamiltonian system).
_polynomial_add_inplace()
The _polynomial_add_inplace()
function adds or subtracts one polynomial to/from another in-place.
- hiten.algorithms.polynomial.operations._polynomial_add_inplace()[source]
Add or subtract one polynomial to/from another in-place.
- Parameters:
poly_p (List[numpy.ndarray]) – Destination polynomial, modified in-place
poly_q (List[numpy.ndarray]) – Source polynomial to add to the destination
scale (float, optional) – Scaling factor for the source polynomial, default is 1.0
max_deg (int, optional) – Maximum degree to consider, default is -1 (all degrees)
- Returns:
The destination polynomial ‘poly_p’ is modified in-place
- Return type:
None
Notes
If scale=1.0, computes poly_p += poly_q If scale=-1.0, computes poly_p -= poly_q Otherwise, computes poly_p += scale * poly_q
The operation is performed element-wise for each degree up to min(max_deg, len(poly_p), len(poly_q))
_polynomial_multiply()
The _polynomial_multiply()
function multiplies two polynomials.
- hiten.algorithms.polynomial.operations._polynomial_multiply()[source]
Multiply two polynomials.
- Parameters:
poly_p (List[numpy.ndarray]) – First polynomial
poly_q (List[numpy.ndarray]) – Second polynomial
max_deg (int) – Maximum degree for the result
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numba.typed.List) – List of arrays containing packed multi-indices
encode_dict_list (numba.typed.List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
Product polynomial poly_r = poly_p * poly_q, with homogeneous parts up to max_deg
- Return type:
List[numpy.ndarray]
Notes
The multiplication is done by multiplying each homogeneous part of poly_p with each homogeneous part of poly_q, and accumulating the results in the appropriate degree of the output polynomial.
_polynomial_power()
The _polynomial_power()
function raises a polynomial to a power using binary exponentiation.
- hiten.algorithms.polynomial.operations._polynomial_power()[source]
Raise a polynomial to a power using binary exponentiation.
- Parameters:
poly_p (List[numpy.ndarray]) – Base polynomial
k (int) – Exponent (non-negative integer)
max_deg (int) – Maximum degree for the result
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numba.typed.List) – List of arrays containing packed multi-indices
encode_dict_list (numba.typed.List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
Result polynomial poly_r = poly_p^k, with homogeneous parts up to max_deg
- Return type:
List[numpy.ndarray]
Notes
This function uses the binary exponentiation algorithm to compute poly_p^k efficiently in O(log k) multiplications.
For k=0, the result is the constant polynomial 1.
_polynomial_poisson_bracket()
The _polynomial_poisson_bracket()
function computes the Poisson bracket of two polynomials.
- hiten.algorithms.polynomial.operations._polynomial_poisson_bracket()[source]
Compute the Poisson bracket of two polynomials.
- Parameters:
poly_p (List[numpy.ndarray]) – First polynomial
poly_q (List[numpy.ndarray]) – Second polynomial
max_deg (int) – Maximum degree for the result
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numba.typed.List) – List of arrays containing packed multi-indices
encode_dict_list (numba.typed.List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
Poisson bracket {poly_p, poly_q}, with homogeneous parts up to max_deg
- Return type:
List[numpy.ndarray]
Notes
The Poisson bracket {poly_p, poly_q} is computed by combining the Poisson brackets of each homogeneous part of poly_p with each homogeneous part of poly_q.
The degree of the Poisson bracket of terms of degrees d1 and d2 is d1 + d2 - 2.
_polynomial_clean()
The _polynomial_clean()
function creates a new polynomial with small coefficients set to zero.
- hiten.algorithms.polynomial.operations._polynomial_clean()[source]
Create a new polynomial with small coefficients set to zero.
- Parameters:
poly_p (List[numpy.ndarray]) – Input polynomial
tol (float) – Tolerance threshold; coefficients with |value| <= tol will be set to zero
- Returns:
A new polynomial with small coefficients set to zero
- Return type:
List[numpy.ndarray]
Notes
This function creates a copy of the input polynomial with all coefficients having absolute value less than or equal to the tolerance set to zero.
_polynomial_degree()
The _polynomial_degree()
function gets the degree of a polynomial represented as a list of homogeneous parts.
- hiten.algorithms.polynomial.operations._polynomial_degree()[source]
Get the degree of a polynomial represented as a list of homogeneous parts.
The degree is the highest index d for which poly_p[d] contains non-zero coefficients.
- Parameters:
poly_p (List[np.ndarray]) – A list where poly_p[d] is a NumPy array of coefficients for the homogeneous part of degree d.
- Returns:
The degree of the polynomial. Returns -1 if the polynomial is zero.
- Return type:
_polynomial_total_degree()
The _polynomial_total_degree()
function gets the total degree of a polynomial using the _get_degree kernel function.
- hiten.algorithms.polynomial.operations._polynomial_total_degree()[source]
Get the total degree of a polynomial using the _get_degree kernel function.
This function uses the _get_degree kernel to verify the degree of each homogeneous part by checking the coefficient array size, then finds the highest degree with non-zero coefficients.
- Parameters:
poly_p (List[numpy.ndarray]) – A list where poly_p[d] is a NumPy array of coefficients for the homogeneous part of degree d.
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
- Returns:
The total degree of the polynomial. Returns -1 if the polynomial is zero.
- Return type:
Notes
This function provides an alternative to _polynomial_degree() by using the _get_degree kernel function to determine the degree of each homogeneous part based on coefficient array size rather than relying on array indexing.
_polynomial_differentiate()
The _polynomial_differentiate()
function computes the partial derivative of a polynomial with respect to a variable.
- hiten.algorithms.polynomial.operations._polynomial_differentiate()[source]
Compute the partial derivative of a polynomial with respect to a variable.
- Parameters:
poly_p (List[numpy.ndarray]) – Input polynomial
var_idx (int) – Index of the variable to differentiate with respect to (0 to N_VARS-1)
max_deg (int) – Maximum degree of the input polynomial
psi_table (numpy.ndarray) – Combinatorial table for the input polynomial
clmo_table (List[numpy.ndarray]) – List of arrays containing packed multi-indices for the input polynomial
derivative_psi_table (numpy.ndarray) – Combinatorial table for the derivative polynomial
derivative_clmo_table (List[numpy.ndarray]) – List of arrays containing packed multi-indices for the derivative polynomial
encode_dict_list (List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
A tuple containing: - The derivative polynomial - The maximum degree of the derivative polynomial
- Return type:
(List[numpy.ndarray], int)
Notes
The derivative of a term of degree d is a term of degree d-1. The maximum degree of the derivative is max_deg-1 (or 0 if max_deg=0).
_polynomial_jacobian()
The _polynomial_jacobian()
function computes the Jacobian matrix of a polynomial.
- hiten.algorithms.polynomial.operations._polynomial_jacobian()[source]
Compute the Jacobian matrix of a polynomial.
- Parameters:
poly_p (List[np.ndarray]) – Input polynomial
max_deg (int) – Maximum degree of the input polynomial
psi_table (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo_table (List[numpy.ndarray]) – List of arrays containing packed multi-indices
encode_dict_list (List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
A list of length N_VARS where each element is the partial derivative of the input polynomial with respect to one variable
- Return type:
List[List[numpy.ndarray]]
Notes
This function computes all partial derivatives of the input polynomial with respect to each of the N_VARS variables in the hiten.system.
_polynomial_evaluate()
The _polynomial_evaluate()
function evaluates a polynomial at a specific point.
- hiten.algorithms.polynomial.operations._polynomial_evaluate()[source]
Evaluate a polynomial at a specific point.
- Parameters:
poly_p (List[numpy.ndarray]) – Polynomial to evaluate
point (numpy.ndarray) – Array of length N_VARS containing the values of variables where the polynomial should be evaluated
clmo (List[np.ndarray]) – List of arrays containing packed multi-indices
- Returns:
The value of the polynomial at the specified point
- Return type:
numpy.complex128
Notes
This function evaluates the polynomial by summing the evaluations of all its homogeneous parts.
_polynomial_integrate()
The _polynomial_integrate()
function integrates a polynomial with respect to one variable.
- hiten.algorithms.polynomial.operations._polynomial_integrate()[source]
Integrate a polynomial with respect to one variable.
- Parameters:
poly_p (List[numpy.ndarray]) – Input polynomial
var_idx (int) – Index of the variable to integrate with respect to (0 to N_VARS-1)
max_deg (int) – Maximum degree of the input polynomial
psi_table (numpy.ndarray) – Combinatorial table for the input polynomial
clmo_table (List[numpy.ndarray]) – List of arrays containing packed multi-indices for the input polynomial
integral_psi_table (numpy.ndarray) – Combinatorial table for the integral polynomial
integral_clmo_table (List[numpy.ndarray]) – List of arrays containing packed multi-indices for the integral polynomial
encode_dict_list (List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
A tuple containing: - The integral polynomial - The maximum degree of the integral polynomial
- Return type:
(List[numpy.ndarray], int)
Notes
The integral of a term of degree d is a term of degree d+1. The maximum degree of the integral is max_deg+1. The integration constant is set to zero.
_linear_variable_polys()
The _linear_variable_polys()
function creates polynomials for new variables after a linear transformation.
- hiten.algorithms.polynomial.operations._linear_variable_polys()[source]
Create polynomials for new variables after a linear transformation.
- Parameters:
C (numpy.ndarray) – Transformation matrix (6x6) that defines the linear change of variables
max_deg (int) – Maximum degree for polynomial representations
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numba.typed.List) – List of arrays containing packed multi-indices
encode_dict_list (numba.typed.List) – List of dictionaries mapping packed multi-indices to their positions
- Returns:
List of length 6 where each element is a polynomial representing a transformed variable
- Return type:
List[List[numpy.ndarray]]
Notes
This function computes the linear transformation of variables: L_i = sum_j C[i,j] * var_j where var_j are the original variables and L_i are the transformed variables.
_substitute_linear()
The _substitute_linear()
function performs variable substitution in a polynomial using a linear transformation.
- hiten.algorithms.polynomial.operations._substitute_linear()[source]
Perform variable substitution in a polynomial using a linear transformation.
- Parameters:
poly_old (List[numpy.ndarray]) – Polynomial in the original variables
C (numpy.ndarray) – Transformation matrix (6x6) that defines the linear change of variables
max_deg (int) – Maximum degree for polynomial representations
psi (numpy.ndarray) – Combinatorial table from
_init_index_tables()
clmo (numba.typed.List) – List of arrays containing packed multi-indices
encode_dict_list (numba.typed.List) – List of dictionaries mapping packed multi-indices to their positions
tol (float)
- Returns:
Polynomial in the transformed variables
- Return type:
List[numpy.ndarray]
Notes
This function substitutes each original variable with its corresponding transformation defined by the matrix C. For each term in the original polynomial, it computes the product of the transformed variables raised to the appropriate power.
_linear_affine_variable_polys()
The _linear_affine_variable_polys()
function builds polynomials for variables after an affine change of variables.
- hiten.algorithms.polynomial.operations._linear_affine_variable_polys()[source]
Build polynomials for variables after an affine change of variables.
- The transformation implemented is
L_i = sum_j C[i,j] * x_j + shifts[i]
- Parameters:
C (np.ndarray, shape (6,6)) – Linear part of the transformation.
shifts (np.ndarray, shape (6,)) – Constant offsets added to each new variable. Use 0 for variables that are not shifted.
max_deg (int) – Same meaning as in _linear_variable_polys.
psi – Same meaning as in _linear_variable_polys.
clmo – Same meaning as in _linear_variable_polys.
encode_dict_list – Same meaning as in _linear_variable_polys.
- Returns:
Polynomials for the six transformed variables.
- Return type:
List[List[np.ndarray]]
_substitute_affine()
The _substitute_affine()
function substitutes an affine change of variables into a polynomial.
- hiten.algorithms.polynomial.operations._substitute_affine()[source]
Substitute an affine change of variables into a polynomial.
The old variables (x_old) are expressed in terms of the new variables (x) by
x_old_i = sum_j C[i,j] * x_j + shifts[i]
This is a thin wrapper around _substitute_linear; it first builds the variable polynomials that include the constant shifts and then performs the same expansion/accumulation loop.