The commutator: [A,B] = A*B - B*A.

class sympy.physics.quantum.commutator.Commutator[source]

The standard commutator, in an unevaluated state.

Evaluating a commutator is defined [R433] as: [A, B] = A*B - B*A. This class returns the commutator in an unevaluated form. To evaluate the commutator, use the .doit() method.

Cannonical ordering of a commutator is [A, B] for A < B. The arguments of the commutator are put into canonical order using __cmp__. If B < A, then [B, A] is returned as -[A, B].


A : Expr

The first argument of the commutator [A,B].

B : Expr

The second argument of the commutator [A,B].


[R433](1, 2)


>>> from sympy.physics.quantum import Commutator, Dagger, Operator
>>> from import x, y
>>> A = Operator('A')
>>> B = Operator('B')
>>> C = Operator('C')

Create a commutator and use .doit() to evaluate it:

>>> comm = Commutator(A, B)
>>> comm
>>> comm.doit()
A*B - B*A

The commutator orders it arguments in canonical order:

>>> comm = Commutator(B, A); comm

Commutative constants are factored out:

>>> Commutator(3*x*A, x*y*B)

Using .expand(commutator=True), the standard commutator expansion rules can be applied:

>>> Commutator(A+B, C).expand(commutator=True)
[A,C] + [B,C]
>>> Commutator(A, B+C).expand(commutator=True)
[A,B] + [A,C]
>>> Commutator(A*B, C).expand(commutator=True)
[A,C]*B + A*[B,C]
>>> Commutator(A, B*C).expand(commutator=True)
[A,B]*C + B*[A,C]

Adjoint operations applied to the commutator are properly applied to the arguments:

>>> Dagger(Commutator(A, B))

Evaluate commutator