Skip to content

Commit

Permalink
Merge pull request #40 from amitjamadagni/expect
Browse files Browse the repository at this point in the history
Function expectationvalue added.
  • Loading branch information
acroy committed Mar 14, 2016
2 parents c8fdb89 + 8dbcc76 commit cc2c394
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/arrays/arraymath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,15 @@ tensor(bra::DualVector, ket::AbstractQuVector) = tensor(ket, bra)
commute(a::AbstractQuMatrix, b::AbstractQuMatrix) = (a*b) - (b*a)
anticommute(a::AbstractQuMatrix, b::AbstractQuMatrix) = (a*b) + (b*a)

################
# Expectation #
################
expectationvalue(qarr::AbstractQuVector, op::AbstractQuMatrix) = qarr'*op*qarr
expectationvalue(qarr::AbstractQuMatrix, op::AbstractQuMatrix) = trace(qarr*op)

export normalize,
normalize!,
tensor,
commute,
anticommute
anticommute,
expectationvalue
4 changes: 4 additions & 0 deletions test/multest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ qv1 = normalize!(QuArray(v1))

# Vectorize
@assert vec(qv) == vec(qv')

# Expectation value
@assert expectationvalue(qv1, sigmax) == qv1'*sigmax*qv1
@assert expectationvalue(qm, lowerop(3)) == trace(qm*lowerop(3))

0 comments on commit cc2c394

Please sign in to comment.