Orthogonal and Unitary matrices

Both OrthogonalMatrices and UnitaryMatrices have similar formulae and implementations, as are Rotations, as well as unitary matrices with determinant equal to one. These share a common implementation.

Orthogonal matrices

Manifolds.OrthogonalMatrices — Type
 OrthogonalMatrices{n} = GeneralUnitaryMatrices{ℝ, n, AbsoluteDeterminantOneMatrixType}

The manifold of (real) orthogonal $n×n$ matrices $\mathrm{O}(n)$. They are precisely the $n×n$ real matrices $M$ that satisfy

\[ M^{T}M=MM^{T}= \mathrm{I}_n,\]

where $M^{T}$ is the transpose of $M$ and $\mathrm{I}_n$ is the $n×n$ identity matrix. Thus, their columns and rows represent $n$ pairwise orthonormal vectors. Such matrices $M$ have the property that $\lVert \det(M) \rVert = 1$.

This is the same manifold as the Stiefel(n, n, ℝ) manifold.

Constructor

OrthogonalMatrices(n; parameter::Symbol=:type)
source

Unitary matrices

Manifolds.UnitaryMatrices — Type
const UnitaryMatrices{𝔽, T} = GeneralUnitaryMatrices{𝔽, T, AbsoluteDeterminantOneMatrixType}

The manifold $U(n,𝔽)$ of $n×n$ complex matrices (when 𝔽=ℂ) or quaternionic matrices (when 𝔽=ℍ) such that

\[ p^{\mathrm{H}}p = \mathrm{I}_n,\]

where $p^{\mathrm{H}}$ is the conjugate transpose of $p$ and $\mathrm{I}_n$ is the $n×n$ identity matrix. Such matrices p have a property that $\lVert \det(p) \rVert = 1$.

The tangent spaces are given by

\[ T_pU(n) \coloneqq \bigl\{ X \big| pY \text{ where } Y \text{ is skew symmetric, i. e. } Y = -Y^{\mathrm{H}} \bigr\}\]

But note that tangent vectors are represented in the Lie algebra, i.e. just using $Y$ in the representation above. If you prefer the representation as X you can use the Stiefel(n, n, ℂ) manifold.

Constructor

UnitaryMatrices(n, 𝔽::AbstractNumbers=ℂ; parameter::Symbol=:type)

see also OrthogonalMatrices for the real valued case.

source
Base.rand — Method
rand(::UnitaryMatrices; vector_at=nothing, σ::Real=1.0)

Generate a random point on the UnitaryMatrices manifold, if vector_at is nothing, by computing the QR decomposition of an $n×n$ matrix.

Generate a tangent vector at vector_at by projecting a normally distributed matrix onto the tangent space.

source
ManifoldDiff.riemannian_Hessian — Method
riemannian_Hessian(M::UnitaryMatrices, p, G, H, X)

The Riemannian Hessian can be computed by adopting Eq. (5.6) [Ngu23], so very similar to the complex Stiefel manifold. The only difference is, that here the tangent vectors are stored in the Lie algebra, i.e. the update direction is actually $pX$ instead of just $X$ (in Stiefel). and that means the inverse has to be applied to the (Euclidean) Hessian to map it into the Lie algebra.

source
ManifoldsBase.Weingarten — Method
Weingarten(M::UnitaryMatrices, p, X, V)

Compute the Weingarten map $\mathcal W_p$ at p on the UnitaryMatrices M with respect to the tangent vector $X \in T_p\mathcal M$ and the normal vector $V \in N_p\mathcal M$.

The formula is due to [AMT13] given by

\[\mathcal W_p(X,V) = -\frac{1}{2}\bigl(XS + SX\bigr), \qquad S = p^{\mathrm{H}}V.\]

source
ManifoldsBase.get_coordinates — Method
get_coordinates(M::UnitaryMatrices, p, X, B::DefaultOrthonormalBasis)

Extract the unique tangent vector coordinates $X^i$ at point p on UnitaryMatrices from the skew-Hermitian tangent vector X.

For $\mathrm{U}(n)$, coordinates are ordered over the upper triangular part: diagonal entries contribute their imaginary parts, and each strict upper-triangular entry contributes real and imaginary parts, both scaled by $\sqrt{2}$.

source

Special Unitary matrices

Manifolds.SpecialUnitaryMatrices — Type
const SpecialUnitaryMatrices{T} = GeneralUnitaryMatrices{ℂ, T, DeterminantOneMatrixType}

The manifold $SU(n)$ of $n×n$ complex matrices such that

\[ p^{\mathrm{H}}p = \mathrm{I}_n \text{ and } \det(p) = 1,\]

where $p^{\mathrm{H}}$ is the conjugate transpose of $p$ and $\mathrm{I}_n$ is the $n×n$ identity matrix.

The tangent spaces are given by

\[ T_pU(n) \coloneqq \bigl\{ X \big| pY \text{ where } Y \text{ is skew symmetric and traceless, i. e. } Y = -Y^{\mathrm{H}} \text{ and } \operatorname{tr}(Y) = 0 \bigr\}\]

But note that tangent vectors are represented in the Lie algebra, i.e. just using $Y$ in the representation above.

Constructor

SpecialUnitaryMatrices(n; parameter::Symbol = :type)

see also Rotations for the real valued case.

source
Base.rand — Method
rand(M::SpecialUnitaryMatrices; vector_at = nothing, σ::Real = 1.0)

Generate a random point on the SpecialUnitaryMatrices M, if vector_at is nothing. The point is drawn as on the UnitaryMatrices from the QR decomposition of an $n×n$ matrix, with its first row divided by the sign of the determinant, so that the determinant is one.

Generate a tangent vector at vector_at by projecting a normally distributed matrix onto the tangent space.

source
ManifoldsBase.is_vector — Method
is_vector(M::SpecialUnitaryMatrices, p, X; atol, rtol, kwargs...)

Check whether X is a tangent vector at p on the SpecialUnitaryMatrices M. That is the case if X lies in the Lie algebra $\mathfrak{su}(n)$ of the skew-Hermitian matrices of trace zero, see Section 3.4, Proposition 3.24 of [Hal15].

The skew-Hermitian check is performed with isapprox, which receives atol, rtol and all further keyword arguments. The trace has to vanish up to max(atol, rtol * sqrt(n) * norm(X)). The relative tolerance rtol refers to the size of X; its default is the one of isapprox.

source

Common functions

Manifolds.AbsoluteDeterminantOneMatrixType — Type
AbsoluteDeterminantOneMatrixType <: AbstractMatrixType

A type to indicate that we require (orthogonal / unitary) matrices with normed determinant, i.e. that the absolute value of the determinant is 1.

source
Base.exp — Method
exp(M::Rotations, p, X)
exp(M::OrthogonalMatrices, p, X)
exp(M::UnitaryMatrices, p, X)

Compute the exponential map, that is, since $X$ is represented in the Lie algebra,

\[exp_p(X) = p\mathrm{e}^X\]

For different sizes, like $n=2,3,4$, there are specialized implementations.

The algorithm used is a more numerically stable form of those proposed in [GX02] and [AR13].

source
Base.exp — Method
exp(M::GeneralUnitaryMatrices{ℝ, TypeParameter{Tuple{3}}}, p::SMatrix, X::SMatrix)

Compute the exponential map on the three by three real GeneralUnitaryMatrices M for static matrices by the Rodrigues formula, Proposition 2.7 in [GQ20],

\[\exp_p X = p\mathrm{e}^X = p\bigl(I + aX + bX^2\bigr), \qquad a = \frac{\sin θ}{θ}, \qquad b = \frac{1 - \cos θ}{θ^2}, \qquad θ = \frac{\lVert X \rVert_p}{\sqrt{2}}.\]

If $θ^2$ evaluates to zero, $a = 1 - θ^2/6$ and $b = 1/2 - θ^2/24$ are used instead, the first two terms of the series of $a$ and $b$ in the proof of Proposition 2.7, page 32, in [GQ20].

source
Base.log — Method
log(M::Rotations, p, X)
log(M::OrthogonalMatrices, p, X)
log(M::UnitaryMatrices, p, X)

Compute the logarithmic map, that is, since the resulting $X$ is represented in the Lie algebra,

\[\log_p q = \log(p^{\mathrm{H}}q)\]

which is projected onto the skew symmetric matrices for numerical stability.

source
Base.log — Method
log(M::Rotations, p, q)

Compute the logarithmic map on the Rotations manifold M which is given by

\[\log_p q = \log(p^{\mathrm{T}}q)\]

where $\log$ denotes the matrix logarithm. For numerical stability, the result is projected onto the set of skew symmetric matrices.

For antipodal rotations the function returns deterministically one of the tangent vectors that point at q.

source
Base.log — Method
log(M::SpecialUnitaryMatrices, p, q)

Compute the logarithmic map on the SpecialUnitaryMatrices M.

Let $p^{\mathrm{H}}q = V\operatorname{diag}(e^{\mathrm{i}θ_1}, …, e^{\mathrm{i}θ_n})V^{\mathrm{H}}$ with $-π < θ_1 ≤ … ≤ θ_n ≤ π$. Since $\det(p^{\mathrm{H}}q) = 1$, the angles sum to $2πζ$ for an integer $ζ$, and

\[\log_p q = V\operatorname{diag}(\mathrm{i}φ_1, …, \mathrm{i}φ_n)V^{\mathrm{H}},\]

where $φ_j = θ_j - 2π$ for the $ζ$ largest angles if $ζ > 0$, $φ_j = θ_j + 2π$ for the $-ζ$ smallest angles if $ζ < 0$, and $φ_j = θ_j$ otherwise. This is the logarithm of $p^{\mathrm{H}}q$ in $\mathfrak{su}(n)$ of minimal norm, Theorems 1 and 2 and Lemma 1 in [Tal26].

source
Manifolds._exp_half — Method
_exp_half(::GeneralUnitaryMatrices{ℝ, TypeParameter{Tuple{3}}}, d)

Calculate exp(d / 2) for the three by three real matrices, that is Rotations(3) and OrthogonalMatrices(3), by the Rodrigues formula, Proposition 2.7 in [GQ20]. For d / 2 it reads I + (a / 2) d + (b / 4) d^2 with a = sin(θ) / θ, b = (1 - cos(θ)) / θ^2 and θ = norm(d) / (2 * sqrt(2)). If θ^2 evaluates to zero, a = 1 - θ^2 / 6 and b = 1 / 2 - θ^2 / 24 are used instead, the first two terms of the series of a and b in the proof of Proposition 2.7, page 32, in [GQ20].

source
Manifolds.cos_angles_4d_rotation_matrix — Method
cos_angles_4d_rotation_matrix(R)

4D rotations can be described by two orthogonal planes that are unchanged by the action of the rotation (vectors within a plane rotate only within the plane). The cosines of the two angles $α,β$ of rotation about these planes may be obtained from the distinct real parts of the eigenvalues of the rotation matrix. This function computes these more efficiently by solving the system

\[\begin{aligned} \cos α + \cos β &= \frac{1}{2} \operatorname{tr}(R)\\ \cos α \cos β &= \frac{1}{8} \operatorname{tr}(R)^2 - \frac{1}{16} \operatorname{tr}((R - R^T)^2) - 1. \end{aligned}\]

By convention, the returned values are sorted in decreasing order. See also angles_4d_skew_sym_matrix.

source
Manifolds.volume_density — Method
volume_density(M::GeneralUnitaryMatrices{ℝ, TypeParameter{Tuple{3}}}, p, X)

Compute the volume density on O(3)/SO(3). With the rotation angle $θ = \frac{\lVert X\rVert}{\sqrt{2}}$ it is the reciprocal of Eq. (5) in [FdHDF19], that is

\[\frac{2\bigl(1-\cos θ\bigr)}{θ^2} = \left(\frac{\sin\frac{θ}{2}}{\frac{θ}{2}}\right)^2.\]

source
Manifolds.volume_density — Method
volume_density(M::GeneralUnitaryMatrices{ℝ}, p, X)

Compute volume density function of M, i.e. determinant of the differential of exponential map exp(M, p, X). It is derived from Eq. (4.1) and Corollary 4.4 in [CLLD22]. See also Theorem 4.1 in [FdHDF19], (note that it uses a different convention).

source
ManifoldsBase.embed — Method
embed(M::GeneralUnitaryMatrices, p, X)

Embed the tangent vector X at point p in M from its Lie algebra representation (set of skew matrices) into the Riemannian submanifold representation

The formula reads

\[X_{\text{embedded}} = p * X\]

source
ManifoldsBase.exp_fused! — Method
exp_fused!(M::GeneralUnitaryMatrices{ℝ, TypeParameter{Tuple{3}}}, q, p, X, t::Real)

Compute $\exp_p(tX)$ on the three by three real GeneralUnitaryMatrices M and store the result in q, by the Rodrigues formula, Proposition 2.7 in [GQ20],

\[\exp_p(tX) = p\mathrm{e}^{tX} = p\bigl(I + a\,tX + b\,t^2X^2\bigr), \qquad a = \frac{\sin θ}{θ}, \qquad b = \frac{1 - \cos θ}{θ^2}, \qquad θ = \frac{\lvert t \rvert \lVert X \rVert_p}{\sqrt{2}}.\]

If $θ^2$ evaluates to zero, $a = 1 - θ^2/6$ and $b = 1/2 - θ^2/24$ are used instead, the first two terms of the series of $a$ and $b$ in the proof of Proposition 2.7, page 32, in [GQ20].

source
ManifoldsBase.get_coordinates — Method
get_coordinates(M::Rotations, p, X)
get_coordinates(M::OrthogonalMatrices, p, X)
get_coordinates(M::UnitaryMatrices, p, X)

Extract the unique tangent vector components $X^i$ at point p on Rotations $\mathrm{SO}(n)$ from the matrix representation X of the tangent vector.

The basis on the Lie algebra $𝔰𝔬(n)$ is chosen such that for $\mathrm{SO}(2)$, $X^1 = θ = X_{21}$ is the angle of rotation, and for $\mathrm{SO}(3)$, $(X^1, X^2, X^3) = (X_{32}, X_{13}, X_{21}) = θ u$ is the angular velocity and axis-angle representation, where $u$ is the unit vector along the axis of rotation.

For $\mathrm{SO}(n)$ where $n ≥ 4$, the additional elements of $X^i$ are $X^{j (j - 3)/2 + k + 1} = X_{jk}$, for $j ∈ [4,n], k ∈ [1,j)$.

source
ManifoldsBase.inverse_retract — Method
inverse_retract(M::Rotations, p, q, ::PolarInverseRetraction)
inverse_retract(M::OrthogonalMatrices, p, q, ::PolarInverseRetraction)

Compute a vector X (as an element of the Lie algebra) from the tangent space $T_p\mathcal M$ of the point p on the real GeneralUnitaryMatrices manifold M. This covers the Rotations and the OrthogonalMatrices, and with X the point q is reached by the PolarRetraction from the point p after time 1.

The formula reads

\[\operatorname{retr}^{-1}_p(q) = -\frac{1}{2}(p^{\mathrm{T}}qs - (p^{\mathrm{T}}qs)^{\mathrm{T}})\]

where $s$ is the solution to the Sylvester equation

$p^{\mathrm{T}}qs + s(p^{\mathrm{T}}q)^{\mathrm{T}} + 2I_n = 0.$

The polar retraction does not leave the connected component of p, since $\operatorname{retr}_p(X) = p (I + X)(I - X^2)^{-1/2}$ and $\det(I + X) > 0$. Hence the inverse is only defined for p and q with $\det(p^{\mathrm{T}}q) > 0$, and a DomainError is thrown otherwise.

source
ManifoldsBase.inverse_retract — Method
inverse_retract(M::Rotations, p, q, ::QRInverseRetraction)
inverse_retract(M::OrthogonalMatrices, p, q, ::QRInverseRetraction)

Compute a vector X (as an element of the Lie algebra) from the tangent space $T_p\mathcal M$ of the point p on the real GeneralUnitaryMatrices manifold M. This covers the Rotations and the OrthogonalMatrices, and with X the point q is reached by the QRRetraction from the point p after time 1.

The QR retraction does not leave the connected component of p, since $\operatorname{retr}_p(X) = p \operatorname{qf}(I + X)$ and $\det(\operatorname{qf}(I + X)) = 1$. Hence the inverse is only defined for p and q with $\det(p^{\mathrm{T}}q) > 0$, and a DomainError is thrown otherwise.

source
ManifoldsBase.parallel_transport_direction — Method
parallel_transport_direction(M::GeneralUnitaryMatrices, p, X, d)

Compute the parallel transport of X from p in direction d on the GeneralUnitaryMatrices M. This covers the Rotations, the OrthogonalMatrices, the UnitaryMatrices and the SpecialUnitaryMatrices, with tangent vectors represented in the Lie algebra. The formula, provided in [Ren11] for the rotations, reads

\[\mathcal P_{q\gets p}X = q^{\mathrm{H}}p \operatorname{Exp}(d/2) X \operatorname{Exp}(d/2),\]

where $q = \exp_p d$ and $\operatorname{Exp}$ denotes the matrix exponential.

source
ManifoldsBase.project — Method
project(M::OrthogonalMatrices, p, X)
project(M::Rotations, p, X)
project(M::UnitaryMatrices, p, X)

Orthogonally project the tangent vector $X ∈ 𝔽^{n×n}$, $\mathbb F ∈ \{\mathbb R, \mathbb C\}$ to the tangent space of M at p, and change the representer to use the corresponding Lie algebra, i.e. we compute

\[ \operatorname{proj}_p(X) = \frac{p^{\mathrm{H}} X - (p^{\mathrm{H}} X)^{\mathrm{H}}}{2}.\]

source
ManifoldsBase.retract — Method
retract(M::Rotations, p, X, ::PolarRetraction)
retract(M::OrthogonalMatrices, p, X, ::PolarRetraction)

Compute the SVD-based retraction on the Rotations and OrthogonalMatrices M from p in direction X (as an element of the Lie algebra) and is a second-order approximation of the exponential map. Let

\[USV = p + pX\]

be the singular value decomposition, then the formula reads

\[\operatorname{retr}_p X = UV^\mathrm{T}.\]

source

Footnotes and References

[AMT13]
P.-A. Absil, R. Mahony and J. Trumpf. An Extrinsic Look at the Riemannian Hessian. In: Geometric Science of Information, edited by F. Nielsen and F. Barbaresco (Springer Berlin Heidelberg, 2013); pp. 361–368.
[AR13]
D. Andrica and R.-A. Rohan. Computing the Rodrigues coefficients of the exponential map of the Lie groups of matrices. Balkan Journal of Geometry and Its Applications 18, 1–10 (2013).
[CLLD22]
E. Chevallier, D. Li, Y. Lu and D. B. Dunson. Exponential-wrapped distributions on symmetric spaces. ArXiv Preprint (2022).
[FdHDF19]
L. Falorsi, P. de Haan, T. R. Davidson and P. Forré. Reparameterizing Distributions on Lie Groups. In: Proceedings of the Twenty-Second International Conference on Artificial Intelligence and Statistics, Vol. 89 of Proceedings of Machine Learning Research (PMLR, 2019); pp. 3244–3253.
[GX02]
J. Gallier and D. Xu. Computing exponentials of skew-symmetric matrices and logarithms of orthogonal matrices. International Journal of Robotics and Automation 17, 1–11 (2002).
[GQ20]
[Hal15]
B. C. Hall. Lie Groups, Lie Algebras, and Representations: An Elementary Introduction. Graduate Texts in Mathematics (Springer International Publishing, 2015).
[Ngu23]
D. Nguyen. Operator-Valued Formulas for Riemannian Gradient and Hessian and Families of Tractable Metrics in Riemannian Optimization. Journal of Optimization Theory and Applications 198, 135–164 (2023), arXiv:2009.10159.
[Ren11]
Q. Rentmeesters. A gradient method for geodesic data fitting on some symmetric Riemannian manifolds. In: IEEE Conference on Decision and Control and European Control Conference (2011); pp. 7141–7146.
[Tal26]
S. Talaganis. Drift-Adapted Lattice Geodesics for Quantum Gate Synthesis: Exact Global Optima for Full-Isotropic SU(n) and Weighted Commuting Sectors. Universe 12, 219 (2026).
[ZS03]
K. Życzkowski and H.-J. Sommers. Hilbert–Schmidt volume of the set of mixed quantum states. Journal of Physics A: Mathematical and General 36, 10115–10130 (2003).