Linopt
Linear optics circuit calculator
Functions | Variables
Matrix

Various matrix-related functions. More...

Functions

Complex linopt::permanent (const Matrix &M)
 Calculates permanent of a square matrix. More...
 
void linopt::hurwitzParametrization (Matrix &M, const Point &x)
 Fills a unitary matrix according to the Hurwitz parametrization. More...
 
Matrix linopt::hurwitzParametrization (const Point &x)
 Returns a matrix parametrized according to the Hurwitz parametrization. More...
 
void linopt::expHermiteParametrization (Matrix &M, const Point &x)
 Fills a unitary matrix according to the exponential-Hermitian parametrization. More...
 
Matrix linopt::expHermiteParametrization (const Point &x)
 Returns a matrix parametrized according to the exponential-Hermitian parametrization. More...
 
Real linopt::matrixFidelity (const Matrix &A, const Matrix &B)
 Calculates normalized fidelity between two matrices. More...
 
bool linopt::isColumnUnitary (const Matrix &M, Real eps=defaultEpsilon)
 Tests whether a matrix is column-unitary. More...
 
bool linopt::isRowUnitary (const Matrix &M, Real eps=defaultEpsilon)
 Tests whether a matrix is row-unitary. More...
 
bool linopt::isUnitary (const Matrix &M, Real eps=defaultEpsilon)
 Tests whether a matrix is unitary. More...
 

Variables

constexpr Real linopt::defaultEpsilon = 1e-15
 Default precision for numeric comparison operations.
 

Detailed Description

Various matrix-related functions.

Function Documentation

◆ expHermiteParametrization() [1/2]

void linopt::expHermiteParametrization ( Matrix &  M,
const Point &  x 
)

Fills a unitary matrix according to the exponential-Hermitian parametrization.

Parameters
[out]M– an \( N \times N \) matrix to store the result. If it has improper size it will be resized.
[in]x– an array of \( N^2 \) parameters.

The exponential-Hermitian parametrization of a unitary matrix is based on the relation

\[ M = \exp(i H(x)). \]

If \( H \) is Hermitian then \( M \) is unitary. Since \( H \) is Hermitian it can be parametrized by its matrix elements. First elements of x contain the real-valued diagonal of \( H \), then the upper triangular part is specified. For example, \( 4 \times 4 \) Hermitian matrix is parametrized in the following way

\[ H(x) = \begin{pmatrix} x[0] & x[4]+ix[5] & x[6]+ix[7] & x[8]+ix[9] \\ x[4]-ix[5] & x[1] & x[10]+ix[11] & x[12]+ix[13] \\ x[6]-ix[7] & x[10]-ix[11] & x[2] & x[14]+ix[15] \\ x[8]-ix[9] & x[12]-ix[13] & x[14]-ix[15] & x[3] \end{pmatrix}. \]

Exceptions
Ifsize of x is not a square of some integer number \( N \), then WrongSize is thrown.

◆ expHermiteParametrization() [2/2]

Matrix linopt::expHermiteParametrization ( const Point &  x)

Returns a matrix parametrized according to the exponential-Hermitian parametrization.

Parameters
[in]x– an array of parameters.
Returns
Unitary matrix parametrized by x.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ hurwitzParametrization() [1/2]

void linopt::hurwitzParametrization ( Matrix &  M,
const Point &  x 
)

Fills a unitary matrix according to the Hurwitz parametrization.

Parameters
[out]M– an \( N \times N \) matrix to store the result. If it has an improper size it will be resized.
[in]x– an array of \( N^2 \) parameters.

Hurwitz parametrization is capable to parametrize any unitary matrix of size \( N \times N \) with \( N^2 \) parameters x. The essential feature of this parametrization is that a uniform ensemble of random points inside a unit hypercube \( 0 \le x_i < 1, i = 1, \dots, N^2 \) is mapped onto a Haar-uniform ensemble of random unitary matrices. Therefore this parametrization can be used, for example, to sample random matrices from a circular unitary ensemble (CUE). Or it can be used when optimizing over the space of all unitary matrices. In some sense it maps the space of unitary matrices onto a unit hypercube with least possible "distorsion".

Parameters x may lie outside the unit hypercube. If so, they are effectively moved back to the hypercube by means of a peridic function. The parametrization is continuous on boundaries, but not smooth.

Exceptions
Ifsize of x is not a square of some integer number \( N \), then WrongSize is thrown.
See also
K. Życzkowski and M. Kus "Random unitary matrices." J. Phys. A: Math. Gen. 27, pp. 4235-4245 (1994), https://doi.org/10.1088/0305-4470/27/12/028

◆ hurwitzParametrization() [2/2]

Matrix linopt::hurwitzParametrization ( const Point &  x)

Returns a matrix parametrized according to the Hurwitz parametrization.

Parameters
[in]x– an array of parameters.
Returns
Unitary matrix parametrized by x.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ isColumnUnitary()

bool linopt::isColumnUnitary ( const Matrix &  M,
Real  eps = defaultEpsilon 
)

Tests whether a matrix is column-unitary.

Parameters
[in]M– matrix to test.
[in]eps– accuracy within test is performed.
Returns
true if the matrix M is a column-unitary one with the given accuracy, false otherwise.

A matrix \( M \) is called column unitary if \( M^\dagger M = 1 \).

See also
isRowUnitary(), isUnitary()

◆ isRowUnitary()

bool linopt::isRowUnitary ( const Matrix &  M,
Real  eps = defaultEpsilon 
)

Tests whether a matrix is row-unitary.

Parameters
[in]M– matrix to test.
[in]eps– accuracy within test is performed.
Returns
true if the matrix M is a row-unitary one with the given accuracy, false otherwise.

A matrix \( M \) is called row unitary if \( M M^\dagger = 1 \).

See also
isColumnUnitary(), isUnitary()

◆ isUnitary()

bool linopt::isUnitary ( const Matrix &  M,
Real  eps = defaultEpsilon 
)

Tests whether a matrix is unitary.

Parameters
[in]M– matrix to test.
[in]eps– accuracy within test is performed.
Returns
true if the matrix M is a unitary one with the given accuracy, false otherwise.

A square matrix \( M \) is called unitary if it is both column and row unitary.

See also
isColumnUnitary(), isRowUnitary()

◆ matrixFidelity()

Real linopt::matrixFidelity ( const Matrix &  A,
const Matrix &  B 
)

Calculates normalized fidelity between two matrices.

Parameters
[in]A– first matrix.
[in]B– second matrix.
Returns
Calculated fidelity.

Normalized fidelity \( F(A, B) \) between two matrices \( A \) and \( B \) is defined as follows:

\[ \newcommand{\Tr}{\mathrm{Tr}} F(A, B) = \frac{|\Tr(A^\dagger B)|^2}{\Tr(A^\dagger A) \Tr(B^\dagger B)}. \]

Exceptions
Ifmatrix sizes do not match WrongSize is thrown.

◆ permanent()

Complex linopt::permanent ( const Matrix &  M)

Calculates permanent of a square matrix.

Parameters
[in]M– matrix to calculate its permanent.
Returns
Computed permanent.

Calculates permanent of a square \( N \times N \) matrix M. Internally the function uses Glynn formula with Gray code summation technique. Complexity is \( O(N \times 2^N) \).

Todo:
Parallel version.
See also
David G.Glynn "The permanent of a square matrix." Eur. J. Combin. 31, pp. 1887-1891 (2010), https://doi.org/10.1016/j.ejc.2010.01.010