symop.polynomial.rewrites.substitution¶
Symbolic rewrite utilities for CCR polynomial representations.
This module provides generic substitution and expansion routines for polynomial objects used in the canonical commutation relation (CCR) algebra implementation. The functions allow ladder operators appearing inside polynomial expressions to be replaced by linear combinations of other operators.
The rewrite process follows three conceptual steps:
Local substitution Each ladder operator is replaced using a user-provided substitution function mapping
a -> sum_i c_i * b_i.Word expansion Substitutions are applied to every operator in a word, producing a cartesian product of all substitution choices.
Normal ordering The resulting operator words are normal ordered using the CCR normal-ordering routine, producing monomials compatible with the symbolic polynomial representation.
The utilities support rewriting of the following CCR polynomial types:
KetPoly: symbolic ket polynomialsDensityPoly: symbolic density polynomialsOpPoly: operator polynomials
The substitution logic is shared across these representations, ensuring consistent symbolic manipulation across states, operators, and channels.
Notes
These routines operate purely at the symbolic algebra level. They do not perform numerical evaluation or truncation of Hilbert spaces.
Small coefficient terms can be pruned using the eps parameter during
intermediate expansion.
Functions
|
Expand a word of ladder operators using a substitution rule. |
|
Rewrite a density polynomial using ladder-operator substitutions. |
|
Apply a ladder-operator substitution to a |
|
Rewrite an operator polynomial using ladder-operator substitution. |
- _normalize_word_to_monomials(word: Sequence[LadderOp], *, eps: float) list[tuple[complex, Monomial]]¶
Convert an operator word into normal-ordered monomials.
- Parameters:
- Returns:
List of
(coefficient, monomial)pairs obtained after normal ordering the operator word.- Return type:
Notes
Normal ordering is performed using the CCR ordering routine
ket_from_word.
- expand_word_substitution(word: Sequence[LadderOp], subst_fn: Callable[[LadderOp], Sequence[tuple[complex, LadderOp]]], *, eps: float = 0.0) list[tuple[complex, tuple[LadderOp, ...]]]¶
Expand a word of ladder operators using a substitution rule.
Each operator in the input word is replaced using
subst_fn. The substitutions are combined via a cartesian product, generating all possible operator words resulting from the replacements.- Parameters:
word (
Sequence[LadderOp]) – Sequence of ladder operators forming the operator word.subst_fn (
Callable[[LadderOp],Sequence[tuple[complex,LadderOp]]]) – Substitution function mapping a ladder operator to a sequence of(coefficient, operator)pairs representing a linear combination replacement.eps (
float) – Optional pruning threshold. Intermediate products with absolute coefficient smaller thanepsare discarded.
- Returns:
List of
(coefficient, new_word)pairs, wherenew_wordis a tuple of substituted ladder operators.- Return type:
Notes
This routine does not perform normal ordering. It only performs substitution and expansion of operator words.
- rewrite_densitypoly(rho: DensityPoly, left_subst_fn: Callable[[LadderOp], Sequence[tuple[complex, LadderOp]]], right_subst_fn: Callable[[LadderOp], Sequence[tuple[complex, LadderOp]]] | None = None, *, eps: float = 1e-12) DensityPoly¶
Rewrite a density polynomial using ladder-operator substitutions.
Substitutions are applied independently to the left and right monomials of each density term.
- Parameters:
rho (
DensityPoly) – Input density polynomial.left_subst_fn (
Callable[[LadderOp],Sequence[tuple[complex,LadderOp]]]) – Substitution function applied to ladder operators appearing in left monomials.right_subst_fn (
Callable[[LadderOp],Sequence[tuple[complex,LadderOp]]] |None) – Optional substitution function for right monomials. IfNone,left_subst_fnis used for both sides.eps (
float) – Numerical pruning threshold used during intermediate expansions.
- Returns:
Rewritten density polynomial with substitutions applied and like terms combined.
- Return type:
DensityPolyProtocol
Notes
The rewrite process proceeds as:
Expand substitutions for left and right words.
Normal order each resulting word.
Form the cartesian product of left/right monomial combinations.
Construct new density terms from the resulting monomials.
- rewrite_ketpoly(poly: KetPoly, subst_fn: Callable[[LadderOp], Sequence[tuple[complex, LadderOp]]], *, eps: float = 1e-12) KetPoly¶
Apply a ladder-operator substitution to a
KetPoly.Each ladder operator appearing in the polynomial’s monomials is replaced using
subst_fn. The resulting expressions are expanded and normal ordered.- Parameters:
- Returns:
New polynomial with substitutions applied and terms combined.
- Return type:
Notes
The output is always returned as the concrete
KetPolyalgebra implementation, even if the input object satisfies only theKetPolyProtocol.
- rewrite_oppoly(op: OpPoly, subst_fn: Callable[[LadderOp], Sequence[tuple[complex, LadderOp]]], *, eps: float = 1e-12) OpPoly¶
Rewrite an operator polynomial using ladder-operator substitution.
- Parameters:
- Returns:
Operator polynomial with substitutions applied and like terms combined.
- Return type:
OpPolyProtocol
Notes
Unlike state polynomials, operator polynomials do not require normal ordering during rewriting because the operator word structure is preserved.