Polynomial Algebra Functions

The algebra module provides Numba accelerated helpers for algebraic manipulation of multivariate polynomial coefficient arrays.

_poly_add()

The _poly_add() function adds two polynomial coefficient arrays element-wise.

hiten.algorithms.polynomial.algebra._poly_add()[source]

Add two polynomial coefficient arrays element-wise.

Parameters:
  • p (numpy.ndarray) – Coefficient array of the first polynomial

  • q (numpy.ndarray) – Coefficient array of the second polynomial

  • out (numpy.ndarray) – Output array where the result will be stored

Returns:

The result is stored in the ‘out’ array

Return type:

None

Notes

This function assumes ‘p’, ‘q’, and ‘out’ have the same shape. Performs element-wise addition without any validation checks.

_poly_scale()

The _poly_scale() function scales a polynomial coefficient array by a constant factor.

hiten.algorithms.polynomial.algebra._poly_scale()[source]

Scale a polynomial coefficient array by a constant factor.

Parameters:
  • p (numpy.ndarray) – Coefficient array of the polynomial

  • alpha (numeric) – Scaling factor (can be real or complex)

  • out (numpy.ndarray) – Output array where the result will be stored

Returns:

The result is stored in the ‘out’ array

Return type:

None

Notes

This function assumes ‘p’ and ‘out’ have the same shape. Performs element-wise multiplication without any validation checks.

_poly_mul()

The _poly_mul() function multiplies two polynomials using their coefficient arrays.

hiten.algorithms.polynomial.algebra._poly_mul()[source]

Multiply two polynomials using their coefficient arrays.

Parameters:
  • p (numpy.ndarray) – Coefficient array of the first polynomial

  • deg_p (int) – Degree of the first polynomial

  • q (numpy.ndarray) – Coefficient array of the second polynomial

  • deg_q (int) – Degree of the second 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:

Coefficient array of the product polynomial

Return type:

numpy.ndarray

Notes

This function implements parallel computation of polynomial multiplication using a thread-safe approach. Each thread accumulates partial results in a private array before a final reduction step combines them.

The output polynomial will have degree deg_p + deg_q.

_poly_diff()

The _poly_diff() function computes the partial derivative of a polynomial with respect to a variable.

hiten.algorithms.polynomial.algebra._poly_diff()[source]

Compute the partial derivative of a polynomial with respect to a variable.

Parameters:
  • p (numpy.ndarray) – Coefficient array of the polynomial

  • var (int) – Index of the variable to differentiate with respect to (0 to N_VARS-1)

  • degree (int) – Degree of 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:

Coefficient array of the differentiated polynomial

Return type:

numpy.ndarray

Notes

This function implements parallel computation of polynomial differentiation using a thread-safe approach. The output polynomial will have degree (degree - 1) unless the input is a constant polynomial (degree = 0), in which case the output will also be degree 0 (constant zero).

_poly_poisson()

The _poly_poisson() function computes the Poisson bracket of two polynomials.

hiten.algorithms.polynomial.algebra._poly_poisson()[source]

Compute the Poisson bracket of two polynomials.

Parameters:
  • p (numpy.ndarray) – Coefficient array of the first polynomial

  • deg_p (int) – Degree of the first polynomial

  • q (numpy.ndarray) – Coefficient array of the second polynomial

  • deg_q (int) – Degree of the second 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:

Coefficient array of the Poisson bracket {p, q}

Return type:

numpy.ndarray

Notes

The Poisson bracket {p, q} is defined as:

{p, q} = sum_{i=1}^3 (dp/dq_i * dq/dp_i - dp/dp_i * dq/dq_i)

where q_i are position variables and p_i are momentum variables.

The output polynomial will have degree deg_p + deg_q - 2, unless one of the inputs is a constant, in which case the result is zero.

_get_degree()

The _get_degree() function determines the degree of a polynomial from its coefficient array length.

hiten.algorithms.polynomial.algebra._get_degree()[source]

Determine the degree of a polynomial from its coefficient array length.

Parameters:
Returns:

The degree of the polynomial, or -1 if the coefficient array size doesn’t match any expected size in the psi table

Return type:

int

Notes

This function works by comparing the length of the coefficient array with the expected sizes for each degree from the psi table.

_poly_clean_inplace()

The _poly_clean_inplace() function sets coefficients with absolute value below tolerance to zero (in-place).

hiten.algorithms.polynomial.algebra._poly_clean_inplace()[source]

Set coefficients with absolute value below tolerance to zero (in-place).

Parameters:
  • p (numpy.ndarray) – Coefficient array of the polynomial to clean

  • tol (float) – Tolerance threshold; coefficients with |value| <= tol will be set to zero

Returns:

The array ‘p’ is modified in-place

Return type:

None

Notes

This function operates in-place, modifying the input array directly. Use _poly_clean for an out-of-place version.

_poly_clean()

The _poly_clean() function sets coefficients with absolute value below tolerance to zero (out-of-place).

hiten.algorithms.polynomial.algebra._poly_clean()[source]

Set coefficients with absolute value below tolerance to zero (out-of-place).

Parameters:
  • p (numpy.ndarray) – Coefficient array of the polynomial to clean

  • tol (float) – Tolerance threshold; coefficients with |value| <= tol will be set to zero

  • out (numpy.ndarray) – Output array where the result will be stored

Returns:

The result is stored in the ‘out’ array

Return type:

None

Notes

This function creates a cleaned copy of the input array in ‘out’. Use _poly_clean_inplace for an in-place version.

_poly_evaluate()

The _poly_evaluate() function evaluates a polynomial at a specific point.

hiten.algorithms.polynomial.algebra._poly_evaluate()[source]

Evaluate a polynomial at a specific point.

Parameters:
  • p (numpy.ndarray) – Coefficient array of the polynomial

  • degree (int) – Degree of the polynomial

  • point (numpy.ndarray) – Array of length N_VARS containing the values of variables where the polynomial should be evaluated

  • clmo (numba.typed.List) – 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 unpacking each coefficient’s multi-index, computing the corresponding monomial value, and accumulating the result. The output is always complex to handle both real and complex polynomials.

_evaluate_reduced_monomial()

The _evaluate_reduced_monomial() function evaluates a monomial with modified exponent at specified coordinates.

hiten.algorithms.polynomial.algebra._evaluate_reduced_monomial()[source]

Evaluate a monomial with modified exponent at specified coordinates.

This function computes the value of a monomial x^k at given coordinates, but with the exponent of one specified variable modified by a given amount. This is particularly useful for computing derivatives or integrals of polynomials where individual monomial terms need to be evaluated with adjusted exponents.

Parameters:
  • k (numpy.ndarray) – Multi-index array of shape (6,) containing the exponents for each variable in the monomial. The array represents exponents for variables [q1, q2, q3, p1, p2, p3] corresponding to the 6-dimensional phase space of the restricted three-body problem.

  • coords (numpy.ndarray) – Array of shape (6,) containing the coordinate values where the monomial should be evaluated. Must correspond to the same variable ordering as k.

  • var_idx (int) – Index of the variable (0 <= var_idx < 6) whose exponent should be modified. - 0, 1, 2 correspond to position variables q1, q2, q3 - 3, 4, 5 correspond to momentum variables p1, p2, p3

  • exp_change (int) – Amount by which to change the exponent of the variable at var_idx. Can be positive (increase exponent), negative (decrease exponent), or zero (no change).

Returns:

The value of the modified monomial evaluated at the given coordinates. Returns complex zero if any coordinate is effectively zero (|coord| <= 1e-15) but has a positive exponent in the monomial.

Return type:

numpy.complex128

Notes

The function computes the product:

prod_{i=0}^{5} coords[i]^{exp_i}

where exp_i = k[i] for i != var_idx, and exp_{var_idx} = k[var_idx] + exp_change.

_poly_integrate()

The _poly_integrate() function integrates a polynomial with respect to one variable.

hiten.algorithms.polynomial.algebra._poly_integrate()[source]

Integrate a polynomial with respect to one variable.

Parameters:
  • p (numpy.ndarray) – Coefficient array of the polynomial

  • var (int) – Index of the variable to integrate with respect to (0 to N_VARS-1)

  • degree (int) – Degree of 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:

Coefficient array of the integrated polynomial

Return type:

numpy.ndarray

Notes

The output polynomial will have degree (degree + 1). The integration constant is set to zero.