QMath

QBase.QMathModule

A QBase.jl submodule providing general purpose mathematics useful to quantum mechanics.

Exports:

Matrices:

Combinatorics:

Probability:

source

Matrices

QBase.QMath.partial_traceFunction
partial_trace(
    ρ::AbstractMatrix, subsystem_dims::Vector{Int64}, subsystem_id::Int64
) :: AbstractMatrix

Performs the partial trace on matrix ρ with respect to the subsystem at the specified subsystem_id. The partial trace is a quantum operation $\mathcal{E}$ mapping the input Hilbert space to the output Hilbert space, $\mathcal{E} \; : \; \mathcal{H}_X \rightarrow \mathcal{H}_Y$. A quantum operation admits the operator sum representation, $\mathcal{E}(\rho) = \sum_i E_i \rho E_i^{\dagger}$. For example, given a 3-qubit system with density matrix $\rho_{ABC}$, the partial trace with respect to system $B$, is explicitly,

\[\rho_{AC} = \text{Tr}_B[\rho_{ABC}] = \mathcal{E}_B(\rho_{ABC}) = \sum_i E_i \rho_{ABC} E_i^{\dagger}\]

where $E_i = \mathbb{I}_A \otimes \langle i |_B \otimes\mathbb{I}_C$, represents the Kraus operators for the quantum operation and $\rho_{AC}$ is the reduced density operator remaining after system $B$ is traced out.

Inputs:

  • ρ : The matrix on which the partial trace is performed. This matrix should be square and have dimension equal to the product of the subsystem_dims.
  • subsystem_dims : A vector containing positive integer elements which specify the dimension of each subsystem. E.g. A 3-qubit system has subsystem_dims = [2,2,2], a system containing a qubit and a qutrit has subsystem_dims = [2,3].
  • subsystem_id : A positive integer indexing the subsystem_dims vector to signify the subsytem which the partial trace will trace out.

Output:

  • The reduced matrix which results after the partial trace is performed on ρ. This matrix is square and has dimension of product of subsystem_dims with the element corresponding to subsystem_id removed.

A DomainError is thrown if ρ is not square or of proper dimension.

source
QBase.QMath.commutesFunction
commutes(A :: Matrix, B :: Matrix) :: Bool

Returns true if matrix A commutes with matrix B. Two matrices commute if A*B == B*A. The matrices must have compatible dimensions:

  • A: Matrix, mxn dimensions
  • B: Matrix, nxm dimensions

A DomainError is thrown if the matrices are not compatible.

source
QBase.QMath.is_positive_semidefiniteFunction
is_positive_semidefinite(matrix :: Matrix) :: Bool

Returns true if the supplied matrix is positive semidefinite (all eigen values are real and greater than or equal to 0).

A DomainError is thrown if the provided matrix is not square.

source

Combinatorics

QBase.QMath.stirling2Function
stirling2( n :: Int64, k :: Int64  ) :: Int64

Counts the number of ways to partition n items into k unlabelled groups. This quantity is known as Stirling's number of the 2nd kind.

Throws a DomainError if inputs do not satisfy n ≥ k ≥ 1.

source
QBase.QMath.stirling2_partitionsFunction
stirling2_partitions( n :: Int64, k :: Int64 ) :: Vector{Vector{Vector{Int64}}}

Enumerates the unique partitions of n items into k unlabelled sets. Each partition is a vector containing a set of k vectors designating each group.

This recursive algorithm was inspired by this blog.

source
QBase.QMath.stirling2_matricesFunction
stirling2_matrices( n :: Int64, k :: Int64 ) :: Vector{Matrix{Int64}}

Generates the set of matrices with k rows and n columns where rows correspond to the groups and columns are the grouped elements. A non-zero element designates that the column id is grouped into the corresponding row.

A DomainError is thrown if n ≥ k ≥ 1 is not satisfied.

source
QBase.QMath.n_choose_k_matricesFunction
n_choose_k_matrices( n :: Int64, k :: Int64 ) :: Vector{Matrix{Int64}}

Generates a set of n by k matrices which represent all combinations of selecting k columns from n rows. Each column, contains a single non-zero element and k rows contain a non-zero element.

A DomainError is thrown if n ≥ k ≥ 1 is not satisfied.

source
QBase.QMath.base_n_valFunction
base_n_val(
    num_array :: Vector{Int64},
    base :: Int64;
    big_endian=true :: Bool
) :: Int64

Given an array representing a number in base-n returns the value of that number in base-10.

Inputs:

  • num_array - Vector containing semi-positive integers less than base.
  • base - The base-n number represented by num_array.
  • big_endian - true if most significant place is at index 1, else false.
source

Probability

QBase.QMath.is_probability_distributionFunction
is_probability_distribution( probabilities :: Vector ) :: Bool

Returns true if the provided vector is a valid probability distribution:

  • sum(probabilities) ≈ 1
  • p[i] ≥ 0 ∀ i
source
QBase.QMath.is_conditional_distributionFunction
is_conditional_distribution( probabilities :: Matrix ) :: Bool

Returns true if the provided matrix is a valid conditional probability distribution. Each column corresponds to probabilisitic outcomes conditioned for a distinct input.

source
QBase.QMath.MarginalsType
Marginals( probabilities :: Vector ) <: AbstractVector{Float64}

A struct representing a marginal probability distribution function. All elements in the marginal distribution must be positive and their sum must be one.

source
QBase.QMath.ConditionalsType
Conditionals( probabilities :: Matrix ) <: AbstractMatrix{Float64}

A struct representing a conditional probability distribution function. Conditionals are organized in a matrix with rows correpsonding to outputs and columns corresponding to inputs. For example if there are $M$ inputs and $N$ outputs, the corresponding conditionals matrix takes the form:

\[\begin{bmatrix} p(1|1) & \dots & p(1|M) \\ \vdots & \ddots & \vdots \\ p(N|1) & \dots & p(N|M) \\ \end{bmatrix}\]
source