Printing Module
The printing module provides functions for formatting mathematical expressions, polynomial coefficients, and other numerical data for display purposes.
This module provides functions for formatting mathematical expressions, polynomial coefficients, and other numerical data for display purposes. It includes utilities for formatting monomials, complex coefficients, and polynomial tables. All formatting functions are designed to produce clean, readable output for mathematical expressions and numerical data.
Formatting Functions
Functions for formatting mathematical expressions and numerical data.
- hiten.utils.printing._monomial_to_string(exps)[source]
Convert a tuple of exponents to a formatted monomial string.
- Parameters:
exps (tuple[int, ...]) – Tuple of exponents for each variable (q1, q2, q3, p1, p2, p3).
- Returns:
Formatted string representation of the monomial.
- Return type:
Notes
For each variable with non-zero exponent: - If exponent is 1, only the variable name is included - If exponent is greater than 1, the variable and exponent are included - Variables are separated by spaces - If all exponents are zero, returns “1”
Examples
>>> _monomial_to_string((1, 2, 0, 0, 0, 3)) 'q1 q2^2 p3^3' >>> _monomial_to_string((0, 0, 0, 0, 0, 0)) '1'
- hiten.utils.printing._fmt_coeff(c, width=25)[source]
Format a complex coefficient as a right-justified string.
- Parameters:
- Returns:
Formatted string representation of the complex coefficient.
- Return type:
Notes
Three different formats are used: - Real numbers (|imag| < 1e-14): “ <real>” - Pure imaginary (|real| < 1e-14): “ <imag>i” - Complex: “ <real>+<imag>i”
All numbers use scientific notation with 16 digits of precision. The result is right-justified to the specified width.
Examples
>>> _fmt_coeff(1.23 + 4.56j, width=15) ' 1.230000e+00+4.560000e+00i' >>> _fmt_coeff(2.5, width=10) ' 2.500000e+00'
- hiten.utils.printing._format_poly_table(poly, clmo, degree=None)[source]
Create a formatted table of center manifold Hamiltonian coefficients.
- Parameters:
poly (list of numpy.ndarray) – List of coefficient arrays reduced to the center manifold. Each array contains coefficients for a specific degree.
clmo (numpy.ndarray) – Array containing packed multi-indices for coefficient lookup.
degree (int, Iterable[int], str, or None, optional) – Degree filter for the coefficient table. If None or “all”, includes all available degrees. If int, includes only that degree. If Iterable[int], includes the specified degrees.
- Returns:
Formatted string table of Hamiltonian coefficients.
- Return type:
Notes
Each row shows the exponents (q1, p1, q2, p2, q3, p3) and the corresponding coefficient (hk) in scientific notation. The table is formatted in two columns for better readability.
Examples
>>> poly = [np.array([]), np.array([]), np.array([1.0, 2.0])] >>> clmo = np.array([[0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]]) >>> _format_poly_table(poly, clmo, degree=2) 'q1 p1 q2 p2 q3 p3 hk ...'