Qapply#

Logic for applying operators to states.

Todo: * Sometimes the final result needs to be expanded, we should do this by hand.

sympy.physics.quantum.qapply.qapply(e, **options)[source]#

Apply operators to states in a quantum expression.

Parameters:

e : Expr

The expression containing operators and states. This expression tree will be walked to find operators acting on states symbolically.

options : dict

A dict of key/value pairs that determine how the operator actions are carried out.

The following options are valid:

  • dagger: try to apply Dagger operators to the left (default: False).

  • ip_doit: call .doit() in inner products when they are encountered (default: True).

Returns:

e : Expr

The original expression, but with the operators applied to states.

Examples

>>> from sympy.physics.quantum import qapply, Ket, Bra
>>> b = Bra('b')
>>> k = Ket('k')
>>> A = k * b
>>> A
|k><b|
>>> qapply(A * b.dual / (b * b.dual))
|k>
>>> qapply(k.dual * A / (k.dual * k), dagger=True)
<b|
>>> qapply(k.dual * A / (k.dual * k))
<k|*|k><b|/<k|k>