commute#

torchspin.commute(A, B)[source]#

Return the commutator [A, B] = A @ B - B @ A.

Parameters:
  • A (Tensor) – Square matrices of the same shape (torch.Tensor).

  • B (Tensor) – Square matrices of the same shape (torch.Tensor).

Returns:

C (torch.Tensor) – Commutator matrix.

Return type:

Tensor

Examples

>>> import torch
>>> Sx, Sz = sop(0.5, 'x'), sop(0.5, 'z')
>>> commute(Sx, Sz)   # should equal -1j * Sy  (within sign convention)