Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/QuantumInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ function traceout! end

function variance end

"""
commutator(A, B)

Compute the commutator [A, B] = AB - BA of two operators.
"""
function commutator end

"""
anticommutator(A, B)

Compute the anticommutator {A, B} = AB + BA of two operators.
"""
function anticommutator end

##
# Qubit specific
##
Expand Down
43 changes: 43 additions & 0 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,46 @@ directsum(a::AbstractOperator...) = reduce(directsum, a)
ptrace(a::AbstractOperator, index) = arithmetic_unary_error("Partial trace", a)
_index_complement(b::CompositeBasis, indices) = complement(length(b.bases), indices)
reduced(a, indices) = ptrace(a, _index_complement(basis(a), indices))

# Commutator and anticommutator operations
"""
commutator(A, B)

Compute the commutator [A, B] = AB - BA of two operators.

# Arguments
- `A::AbstractOperator`: First operator
- `B::AbstractOperator`: Second operator

# Returns
The commutator [A, B] = AB - BA

# Examples
```julia
σx = sigmax()
σy = sigmay()
comm = commutator(σx, σy) # Returns 2i*σz
```
"""
commutator(A::AbstractOperator, B::AbstractOperator) = A*B - B*A

"""
anticommutator(A, B)

Compute the anticommutator {A, B} = AB + BA of two operators.

# Arguments
- `A::AbstractOperator`: First operator
- `B::AbstractOperator`: Second operator

# Returns
The anticommutator {A, B} = AB + BA

# Examples
```julia
σx = sigmax()
σz = sigmaz()
anticomm = anticommutator(σx, σz) # Returns zero for Pauli matrices
```
"""
anticommutator(A::AbstractOperator, B::AbstractOperator) = A*B + B*A
Loading