Ket algebra

The ket layer represents symbolic state-like expressions as finite sums of normally ordered monomials,

\[|\psi\rangle \sim \sum_i c_i M_i,\]

where each \(M_i\) stores creators on the left and annihilators on the right.

The central object is symop.ccr.ket.poly.KetPoly.

Main ideas

There are two main ways to build symbolic ket expressions.

This distinction is important: from_ops does not commute operators, while from_word does.

Constructing from a normal-ordered monomial

import symop.viz as viz

from symop.core.operators import ModeOp
from symop.modes.labels import ModeLabel
from symop.modes.labels.path import Path
from symop.modes.labels.polarization import Polarization
from symop.modes.envelopes import GaussianEnvelope

from symop.ccr.algebra.ket.poly import KetPoly

env = GaussianEnvelope(omega0=1.0, sigma=1.0, tau=0.0)
mode = ModeOp(
    label=ModeLabel(
        path=Path("A"),
        polarization=Polarization.H(),
        envelope=env,
    ),
    user_label="a",
)

psi = KetPoly.from_ops(creators=(mode.cre,))
viz.display(psi)
2026-04-24T11:36:56.570017 image/svg+xml Matplotlib v3.10.9, https://matplotlib.org/

Normal ordering from a word

import symop.viz as viz
from symop.ccr.algebra.ket.poly import KetPoly

expr = KetPoly.from_word(ops=(mode.ann, mode.cre))
viz.display(expr)
2026-04-24T11:36:56.618413 image/svg+xml Matplotlib v3.10.9, https://matplotlib.org/

This expansion contains both the contracted scalar part and the normally ordered operator part.

Main operations

  • symop.ccr.ket.poly.KetPoly.combine_like_terms()

  • symop.ccr.ket.poly.KetPoly.multiply()

  • symop.ccr.ket.poly.KetPoly.apply_word()

  • symop.ccr.ket.poly.KetPoly.inner()

  • symop.ccr.ket.poly.KetPoly.normalize()

Example: symbolic inner product

psi = KetPoly.from_ops(creators=(mode.cre,), coeff=2.0)
phi = KetPoly.from_ops(creators=(mode.cre,), coeff=3.0)

psi.inner(phi)
(6+0j)