Skip to main content

expval

Method of Operator.

Overloads

NameDescription
expval(const State rhs) -> complexComputes the expectation value of an Operator for a given state. Calculates <ψ\psi|O|ψ\psi>, where ψ\psi is a quantum state and OO is an operator.
expval(const RealMatrix rhs) -> realComputes the expectation value of an Operator in a given real state. Calculates <ψ\psi|O|ψ\psi>, where ψ\psi is a state vector and OO is an operator.
expval(const ComplexMatrix rhs) -> complexComputes the expectation value of an Operator in a given complex state. Calculates <ψ\psi|O|ψ\psi>.

expval(const State rhs) -> complex

Computes the expectation value of an Operator for a given state. Calculates <ψ\psi|O|ψ\psi>, where ψ\psi is a quantum state and OO is an operator.

Parameters

  • rhs: The state (ψ\psi) in which the expectation value is computed.

Returns

The (complex) expectation value of the operator in the state.

Example


var state = Qbit("000101")
var value = expval(X(0), state) // Compute <state|X(0)|state>

expval(const RealMatrix rhs) -> real

Computes the expectation value of an Operator in a given real state. Calculates <ψ\psi|O|ψ\psi>, where ψ\psi is a state vector and OO is an operator.

Parameters

  • rhs: The real state vector (ψ\psi) in which the expectation value is computed.

Returns

The real expectation value of the operator in the state.

Example

var state = vector([4], as_real) // Create a real state vector, $\psi$ 
var value = expval(X(0), state) // Compute <state|X(0)|state>

expval(const ComplexMatrix rhs) -> complex

Computes the expectation value of an Operator in a given complex state. Calculates <ψ\psi|O|ψ\psi>.

Parameters

  • rhs: The complex state vector in which the expectation value is computed.

Returns

The complex expectation value of the operator in the state.

Example

var state = vector([4])          // Create a complex state vector
var value = expval(X(0), state) // Compute <state|X(0)|state>