Skip to main content

commutator

commutator(const Operator A, const Operator B) -> Operator

Computes the commutator of two quantum operators [A,B] = AB - BA. Returns zero operator for identical operators or operators acting on disjoint sites.

Parameters

  • A: The first operator (left operand).
  • B: The second operator (right operand).

Returns

The resulting commutator operator. Returns zero for commuting operators, otherwise returns the computed commutator with complex coefficients.

Example

var comm = commutator(X(0), Y(0))   // Non-zero commutator
var zero1 = commutator(X(0), X(0)) // Zero (identical operators)
var zero2 = commutator(X(0), Y(1)) // Zero (disjoint sites)