Domain for quantum observables - Hermitian operators representing measurable quantities.
Observables in quantum mechanics are represented by Hermitian matrices. This namespace provides functions for creating and manipulating observables, calculating expectation values, and working with composite observables.
Design Philosophy:
Domain for quantum observables - Hermitian operators representing measurable quantities. Observables in quantum mechanics are represented by Hermitian matrices. This namespace provides functions for creating and manipulating observables, calculating expectation values, and working with composite observables. Design Philosophy: - Observables are simple data (matrices) - no complex wrapping - Pure functions for all operations - Compose complex observables from simple primitives - Separate representation, computation, and measurement concerns
(expectation-value observable quantum-state)
Calculate expectation value ⟨ψ|O|ψ⟩ of observable O in state ψ
Parameters:
Returns: Real number representing the expectation value
Example: (expectation-value pauli-z |0⟩) ; returns 1.0
Calculate expectation value ⟨ψ|O|ψ⟩ of observable O in state ψ Parameters: - observable: Hermitian matrix representing the observable - quantum-state: quantum state vector (normalized) Returns: Real number representing the expectation value Example: (expectation-value pauli-z |0⟩) ; returns 1.0
(expectation-value-density-matrix observable density-matrix)
(expectation-value-density-matrix observable density-matrices weights)
Calculate expectation value Tr(ρO) of observable O for density matrix ρ.
For density matrices (mixed states), the expectation value is calculated as the trace of the product of the density matrix and the observable: Tr(ρO).
This function supports both single density matrices and collections of density matrices with optional weights for ensemble averaging.
Parameters:
Returns: For single matrix: Real number representing the expectation value For collection: Map with :mean, :std-dev, :variance, :weights, :individual-values
Examples: (expectation-value-density-matrix pauli-z single-density-matrix) (expectation-value-density-matrix pauli-z [dm1 dm2 dm3]) (expectation-value-density-matrix pauli-z [dm1 dm2] [0.3 0.7])
Calculate expectation value Tr(ρO) of observable O for density matrix ρ. For density matrices (mixed states), the expectation value is calculated as the trace of the product of the density matrix and the observable: Tr(ρO). This function supports both single density matrices and collections of density matrices with optional weights for ensemble averaging. Parameters: - observable: Hermitian matrix representing the observable - density-matrix-or-collection: Either a single density matrix or collection of matrices - weights: (optional) Collection of weights for weighted averaging. If not provided, uniform weighting is used for collections. Returns: For single matrix: Real number representing the expectation value For collection: Map with :mean, :std-dev, :variance, :weights, :individual-values Examples: (expectation-value-density-matrix pauli-z single-density-matrix) (expectation-value-density-matrix pauli-z [dm1 dm2 dm3]) (expectation-value-density-matrix pauli-z [dm1 dm2] [0.3 0.7])
(linear-combination coeffs-observables)
Create a linear combination of observables: Σᵢ cᵢ Oᵢ
Parameters:
Returns: Matrix representing the linear combination
Example: (linear-combination [[0.5 pauli-x] [0.5 pauli-z]])
Create a linear combination of observables: Σᵢ cᵢ Oᵢ Parameters: - coeffs-observables: sequence of [coefficient observable] pairs Returns: Matrix representing the linear combination Example: (linear-combination [[0.5 pauli-x] [0.5 pauli-z]])
(matrix-equal? m1 m2)
Check if two matrices of complex numbers are equal within tolerance
Check if two matrices of complex numbers are equal within tolerance
(measurement-probabilities observable quantum-state)
Calculate measurement probabilities for an observable's eigenvalues using eigendecomposition.
This function computes the probability of measuring each eigenvalue of a Hermitian observable when the system is in the given quantum state. The probabilities are calculated as |⟨vᵢ|ψ⟩|² where vᵢ are the eigenvectors and ψ is the state.
Parameters:
Returns: Map with keys representing eigenvalues and values representing probabilities
Example: (measurement-probabilities pauli-z |+⟩) ; => {1.0 0.5, -1.0 0.5}
Calculate measurement probabilities for an observable's eigenvalues using eigendecomposition. This function computes the probability of measuring each eigenvalue of a Hermitian observable when the system is in the given quantum state. The probabilities are calculated as |⟨vᵢ|ψ⟩|² where vᵢ are the eigenvectors and ψ is the state. Parameters: - observable: Hermitian matrix representing the observable - quantum-state: quantum state vector (normalized) Returns: Map with keys representing eigenvalues and values representing probabilities Example: (measurement-probabilities pauli-z |+⟩) ; => {1.0 0.5, -1.0 0.5}
(pauli-char->matrix pauli-char)
Convert a single Pauli character to its matrix representation
Convert a single Pauli character to its matrix representation
(pauli-string->observable pauli-str)
Convert a Pauli string to an observable matrix
Parameters:
Returns: Matrix representing the tensor product of Pauli matrices
Example: (pauli-string->observable 'XZ') ; creates X ⊗ Z
Convert a Pauli string to an observable matrix Parameters: - pauli-str: string like 'XZYI' representing multi-qubit Pauli operator Returns: Matrix representing the tensor product of Pauli matrices Example: (pauli-string->observable 'XZ') ; creates X ⊗ Z
(tensor-product observables)
Create tensor product of observables: O₁ ⊗ O₂ ⊗ ... ⊗ Oₙ
Parameters:
Returns: Matrix representing the tensor product
Example: (tensor-product [pauli-x pauli-z])
Create tensor product of observables: O₁ ⊗ O₂ ⊗ ... ⊗ Oₙ Parameters: - observables: sequence of observable matrices Returns: Matrix representing the tensor product Example: (tensor-product [pauli-x pauli-z])
(variance observable quantum-state)
Calculate variance of observable: ⟨O²⟩ - ⟨O⟩²
Parameters:
Returns: Real number representing the variance
Calculate variance of observable: ⟨O²⟩ - ⟨O⟩² Parameters: - observable: Hermitian matrix representing the observable - quantum-state: quantum state vector (normalized) Returns: Real number representing the variance
(zero-matrix rows cols)
Create a zero matrix of complex numbers of given dimensions
Create a zero matrix of complex numbers of given dimensions
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |