# Angles between flats

The concept of angles between lines in the plane and between pairs of two lines, two planes or a line and a plane in space can be generalized to arbitrary dimension. This generalization was first discussed by Jordan.[1] For any pair of flats in a Euclidean space of arbitrary dimension one can define a set of mutual angles which are invariant under isometric transformation of the Euclidean space. If the flats do not intersect, their shortest distance is one more invariant.[1] These angles are called canonical[2] or principal.[3] The concept of angles can be generalized to pairs of flats in a finite-dimensional inner product space over the complex numbers.

## Jordan's definition[1]

Let ${\displaystyle F}$ and ${\displaystyle G}$ be flats of dimensions ${\displaystyle k}$ and ${\displaystyle l}$ in the ${\displaystyle n}$-dimensional Euclidean space ${\displaystyle E^{n}}$. By definition, a translation of ${\displaystyle F}$ or ${\displaystyle G}$ does not alter their mutual angles. If ${\displaystyle F}$ and ${\displaystyle G}$ do not intersect, they will do so upon any translation of ${\displaystyle G}$ which maps some point in ${\displaystyle G}$ to some point in ${\displaystyle F}$. It can therefore be assumed without loss of generality that ${\displaystyle F}$ and ${\displaystyle G}$ intersect.

Jordan shows that Cartesian coordinates ${\displaystyle x_{1},\dots ,x_{\rho },}$ ${\displaystyle y_{1},\dots ,y_{\sigma },}$ ${\displaystyle z_{1},\dots ,z_{\tau },}$ ${\displaystyle u_{1},\dots ,u_{\upsilon },}$ ${\displaystyle v_{1},\dots ,v_{\alpha },}$ ${\displaystyle w_{1},\dots ,w_{\alpha }}$ in ${\displaystyle E^{n}}$ can then be defined such that ${\displaystyle F}$ and ${\displaystyle G}$ are described, respectively, by the sets of equations

${\displaystyle x_{1}=0,\dots ,x_{\rho }=0,}$
${\displaystyle u_{1}=0,\dots ,u_{\upsilon }=0,}$
${\displaystyle v_{1}=0,\dots ,v_{\alpha }=0}$

and

${\displaystyle x_{1}=0,\dots ,x_{\rho }=0,}$
${\displaystyle z_{1}=0,\dots ,z_{\tau }=0,}$
${\displaystyle v_{1}\cos \theta _{1}+w_{1}\sin \theta _{1}=0,\dots ,v_{\alpha }\cos \theta _{\alpha }+w_{\alpha }\sin \theta _{\alpha }=0}$

with ${\displaystyle 0<\theta _{i}<\pi /2,i=1,\dots ,\alpha }$. Jordan calls these coordinates canonical. By definition, the angles ${\displaystyle \theta _{i}}$ are the angles between ${\displaystyle F}$ and ${\displaystyle G}$.

The non-negative integers ${\displaystyle \rho ,\sigma ,\tau ,\upsilon ,\alpha }$ are constrained by

${\displaystyle \rho +\sigma +\tau +\upsilon +2\alpha =n,}$
${\displaystyle \sigma +\tau +\alpha =k,}$
${\displaystyle \sigma +\upsilon +\alpha =\ell .}$

For these equations to determine the five non-negative integers completely, besides the dimensions ${\displaystyle n,k}$ and ${\displaystyle \ell }$ and the number ${\displaystyle \alpha }$ of angles ${\displaystyle \theta _{i}}$, the non-negative integer ${\displaystyle \sigma }$ must be given. This is the number of coordinates ${\displaystyle y_{i}}$, whose corresponding axes are those lying entirely within both ${\displaystyle F}$ and ${\displaystyle G}$. The integer ${\displaystyle \sigma }$ is thus the dimension of ${\displaystyle F\cap G}$. The set of angles ${\displaystyle \theta _{i}}$ may be supplemented with ${\displaystyle \sigma }$ angles ${\displaystyle 0}$ to indicate that ${\displaystyle F\cap G}$ has that dimension.

Jordan's proof applies essentially unaltered when ${\displaystyle E^{n}}$ is replaced with the ${\displaystyle n}$-dimensional inner product space ${\displaystyle \mathbb {C} ^{n}}$ over the complex numbers. (For angles between subspaces, the generalization to ${\displaystyle \mathbb {C} ^{n}}$ is discussed by Galántai and Hegedũs in terms of the below variational characterization.[4])

## Angles between subspaces

Now let ${\displaystyle F}$ and ${\displaystyle G}$ be subspaces of the ${\displaystyle n}$-dimensional inner product space over the real or complex numbers. Geometrically, ${\displaystyle F}$ and ${\displaystyle G}$ are flats, so Jordan's definition of mutual angles applies. When for any canonical coordinate ${\displaystyle \xi }$ the symbol ${\displaystyle {\hat {\xi }}}$ denotes the unit vector of the ${\displaystyle \xi }$ axis, the vectors ${\displaystyle {\hat {y}}_{1},\dots ,{\hat {y}}_{\sigma },}$ ${\displaystyle {\hat {w}}_{1},\dots ,{\hat {w}}_{\alpha },}$ ${\displaystyle {\hat {z}}_{1},\dots ,{\hat {z}}_{\tau }}$ form an orthonormal basis for ${\displaystyle F}$ and the vectors ${\displaystyle {\hat {y}}_{1},\dots ,{\hat {y}}_{\sigma },}$ ${\displaystyle {\hat {w}}'_{1},\dots ,{\hat {w}}'_{\alpha },}$ ${\displaystyle {\hat {u}}_{1},\dots ,{\hat {u}}_{\upsilon }}$ form an orthonormal basis for ${\displaystyle G}$, where

${\displaystyle {\hat {w}}'_{i}={\hat {w}}_{i}\cos \theta _{i}+{\hat {v}}_{i}\sin \theta _{i},\quad i=1,\dots ,\alpha .}$

Being related to canonical coordinates, these basic vectors may be called canonical.

When ${\displaystyle a_{i},i=1,\dots ,k}$ denote the canonical basic vectors for ${\displaystyle F}$ and ${\displaystyle b_{i},i=1,\dots ,l}$ the canonical basic vectors for ${\displaystyle G}$ then the inner product ${\displaystyle \langle a_{i},b_{j}\rangle }$ vanishes for any pair of ${\displaystyle i}$ and ${\displaystyle j}$ except the following ones.

{\displaystyle {\begin{aligned}&\langle {\hat {y}}_{i},{\hat {y}}_{i}\rangle =1,&&i=1,\dots ,\sigma ,\\&\langle {\hat {w}}_{i},{\hat {w}}'_{i}\rangle =\cos \theta _{i},&&i=1,\dots ,\alpha .\end{aligned}}}

With the above ordering of the basic vectors, the matrix of the inner products ${\displaystyle \langle a_{i},b_{j}\rangle }$ is thus diagonal. In other words, if ${\displaystyle (a'_{i},i=1,\dots ,k)}$ and ${\displaystyle (b'_{i},i=1,\dots ,\ell )}$ are arbitrary orthonormal bases in ${\displaystyle F}$ and ${\displaystyle G}$ then the real, orthogonal or unitary transformations from the basis ${\displaystyle (a'_{i})}$ to the basis ${\displaystyle (a_{i})}$ and from the basis ${\displaystyle (b'_{i})}$ to the basis ${\displaystyle (b_{i})}$ realize a singular value decomposition of the matrix of inner products ${\displaystyle \langle a'_{i},b'_{j}\rangle }$. The diagonal matrix elements ${\displaystyle \langle a_{i},b_{i}\rangle }$ are the singular values of the latter matrix. By the uniqueness of the singular value decomposition, the vectors ${\displaystyle {\hat {y}}_{i}}$ are then unique up to a real, orthogonal or unitary transformation among them, and the vectors ${\displaystyle {\hat {w}}_{i}}$ and ${\displaystyle {\hat {w}}'_{i}}$ (and hence ${\displaystyle {\hat {v}}_{i}}$) are unique up to equal real, orthogonal or unitary transformations applied simultaneously to the sets of the vectors ${\displaystyle {\hat {w}}_{i}}$ associated with a common value of ${\displaystyle \theta _{i}}$ and to the corresponding sets of vectors ${\displaystyle {\hat {w}}'_{i}}$ (and hence to the corresponding sets of ${\displaystyle {\hat {v}}_{i}}$).

A singular value ${\displaystyle 1}$ can be interpreted as ${\displaystyle \cos \,0}$ corresponding to the angles ${\displaystyle 0}$ introduced above and associated with ${\displaystyle F\cap G}$ and a singular value ${\displaystyle 0}$ can be interpreted as ${\displaystyle \cos \pi /2}$ corresponding to right angles between the orthogonal spaces ${\displaystyle F\cap G^{\bot }}$ and ${\displaystyle F^{\bot }\cap G}$, where superscript ${\displaystyle \bot }$ denotes the orthogonal complement.

## Variational characterization[3]

The variational characterization of singular values and vectors implies as a special case a variational characterization of the angles between subspaces and their associated canonical vectors. This characterization includes the angles ${\displaystyle 0}$ and ${\displaystyle \pi /2}$ introduced above and orders the angles by increasing value. It can be given the form of the below alternative definition. In this context, it is customary to talk of principal angles and vectors.

### Definition

Let ${\displaystyle V}$ be an inner product space. Given two subspaces ${\displaystyle {\mathcal {U}},{\mathcal {W}}}$ with ${\displaystyle \dim({\mathcal {U}})=k\leq \dim({\mathcal {W}}):=\ell }$, there exists then a sequence of ${\displaystyle k}$ angles ${\displaystyle 0\leq \theta _{1}\leq \theta _{2}\leq \cdots \leq \theta _{k}\leq \pi /2}$ called the principal angles, the first one defined as

${\displaystyle \theta _{1}:=\min \left\{\arccos \left(\left.{\frac {|\langle u,w\rangle |}{\|u\|\|w\|}}\right)\,\right|\,u\in {\mathcal {U}},w\in {\mathcal {W}}\right\}=\angle (u_{1},w_{1}),}$

where ${\displaystyle \langle \cdot ,\cdot \rangle }$ is the inner product and ${\displaystyle \|\cdot \|}$ the induced norm. The vectors ${\displaystyle u_{1}}$ and ${\displaystyle w_{1}}$ are the corresponding principal vectors.

The other principal angles and vectors are then defined recursively via

${\displaystyle \theta _{i}:=\min \left\{\left.\arccos \left({\frac {|\langle u,w\rangle |}{\|u\|\|w\|}}\right)\,\right|\,u\in {\mathcal {U}},~w\in {\mathcal {W}},~u\perp u_{j},~w\perp w_{j}\quad \forall j\in \{1,\ldots ,i-1\}\right\}.}$

This means that the principal angles ${\displaystyle (\theta _{1},\ldots ,\theta _{k})}$ form a set of minimized angles between the two subspaces, and the principal vectors in each subspace are orthogonal to each other.

### Examples

#### Geometric example

Geometrically, subspaces are flats (points, lines, planes etc.) that include the origin, thus any two subspaces intersect at least in the origin. Two two-dimensional subspaces ${\displaystyle {\mathcal {U}}}$ and ${\displaystyle {\mathcal {W}}}$ generate a set of two angles. In a three-dimensional Euclidean space, the subspaces ${\displaystyle {\mathcal {U}}}$ and ${\displaystyle {\mathcal {W}}}$ are either identical, or their intersection forms a line. In the former case, both ${\displaystyle \theta _{1}=\theta _{2}=0}$. In the latter case, only ${\displaystyle \theta _{1}=0}$, where vectors ${\displaystyle u_{1}}$ and ${\displaystyle w_{1}}$ are on the line of the intersection ${\displaystyle {\mathcal {U}}\cap {\mathcal {W}}}$ and have the same direction. The angle ${\displaystyle \theta _{2}>0}$ will be the angle between the subspaces ${\displaystyle {\mathcal {U}}}$ and ${\displaystyle {\mathcal {W}}}$ in the orthogonal complement to ${\displaystyle {\mathcal {U}}\cap {\mathcal {W}}}$. Imagining the angle between two planes in 3D, one intuitively thinks of the largest angle, ${\displaystyle \theta _{2}>0}$.

#### Algebraic example

In 4-dimensional real coordinate space R4, let the two-dimensional subspace ${\displaystyle {\mathcal {U}}}$ be spanned by ${\displaystyle u_{1}=(1,0,0,0)}$ and ${\displaystyle u_{2}=(0,1,0,0)}$, and let the two-dimensional subspace ${\displaystyle {\mathcal {W}}}$ be spanned by ${\displaystyle w_{1}=(1,0,0,a)/{\sqrt {1+a^{2}}}}$ and ${\displaystyle w_{2}=(0,1,b,0)/{\sqrt {1+b^{2}}}}$ with some real ${\displaystyle a}$ and ${\displaystyle b}$ such that ${\displaystyle |a|<|b|}$. Then ${\displaystyle u_{1}}$ and ${\displaystyle w_{1}}$ are, in fact, the pair of principal vectors corresponding to the angle ${\displaystyle \theta _{1}}$ with ${\displaystyle \cos(\theta _{1})=1/{\sqrt {1+a^{2}}}}$, and ${\displaystyle u_{2}}$ and ${\displaystyle w_{2}}$ are the principal vectors corresponding to the angle ${\displaystyle \theta _{2}}$ with ${\displaystyle \cos(\theta _{2})=1/{\sqrt {1+b^{2}}}.}$

To construct a pair of subspaces with any given set of ${\displaystyle k}$ angles ${\displaystyle \theta _{1},\ldots ,\theta _{k}}$ in a ${\displaystyle 2k}$ (or larger) dimensional Euclidean space, take a subspace ${\displaystyle {\mathcal {U}}}$ with an orthonormal basis ${\displaystyle (e_{1},\ldots ,e_{k})}$ and complete it to an orthonormal basis ${\displaystyle (e_{1},\ldots ,e_{n})}$ of the Euclidean space, where ${\displaystyle n\geq 2k}$. Then, an orthonormal basis of the other subspace ${\displaystyle {\mathcal {W}}}$ is, e.g.,

${\displaystyle (\cos(\theta _{1})e_{1}+\sin(\theta _{1})e_{k+1},\ldots ,\cos(\theta _{k})e_{k}+\sin(\theta _{k})e_{2k}).}$

## Basic properties

• If the largest angle is zero, one subspace is a subset of the other.
• If the largest angle is ${\displaystyle \pi /2}$, there is at least one vector in one subspace perpendicular to the other subspace.
• If the smallest angle is zero, the subspaces intersect at least in a line.
• If the smallest angle is ${\displaystyle \pi /2}$, the subspaces are orthogonal.
• The number of angles equal to zero is the dimension of the space where the two subspaces intersect.

• Non-trivial (different from ${\displaystyle 0}$ and ${\displaystyle \pi /2}$ [5]) angles between two subspaces are the same as the non-trivial angles between their orthogonal complements.[6][7]
• Non-trivial angles between the subspaces ${\displaystyle {\mathcal {U}}}$ and ${\displaystyle {\mathcal {W}}}$ and the corresponding non-trivial angles between the subspaces ${\displaystyle {\mathcal {U}}}$ and ${\displaystyle {\mathcal {W}}^{\perp }}$ sum up to ${\displaystyle \pi /2}$.[6][7]
• The angles between subspaces satisfy the triangle inequality in terms of majorization and thus can be used to define a distance on the set of all subspaces turning the set into a metric space.[8]
• The sine of the angles between subspaces satisfy the triangle inequality in terms of majorization and thus can be used to define a distance on the set of all subspaces turning the set into a metric space.[6] For example, the sine of the largest angle is known as a gap between subspaces.[9]

## Extensions

The notion of the angles and some of the variational properties can be naturally extended to arbitrary inner products[10] and subspaces with infinite dimensions.[7]

## Computation

Historically, the principal angles and vectors first appear in the context of canonical correlation and were originally computed using SVD of corresponding covariance matrices. However, as first noticed in[3], the canonical correlation is related to the cosine of the principal angles, which is ill-conditioned for small angles, leading to very inaccurate computation of highly correlated principal vectors in finite precision computer arithmetic. The sine-based algorithm[3] fixes this issue, but creates a new problem of very inaccurate computation of highly uncorrelated principal vectors, since the sine function is ill-conditioned for angles close to π/2. To produce accurate principal vectors in computer arithmetic for the full range of the principal angles, the combined technique[10] first compute all principal angles and vectors using the classical cosine-based approach, and then recomputes the principal angles smaller than π/4 and the corresponding principal vectors using the sine-based approach[3]. The combined technique[10] is implemented in open-source libraries Octave[11] and SciPy[12] and contributed [13] and [14] to MATLAB.

## References

1. ^ a b c Jordan, C. (1875). "Essai sur la géométrie à ${\displaystyle n}$ dimensions". Bull. Soc. Math. France. 3: 103.
2. ^ Afriat, S. N. (1957). "Orthogonal and oblique projectors and the characterization of pairs of vector spaces". Math. Proc. Cambridge Philos. Soc. 53 (4): 800. doi:10.1017/S0305004100032916.
3. Björck, Å.; Golub, G. H. (1973). "Numerical Methods for Computing Angles Between Linear Subspaces". Math. Comp. 27 (123): 579. doi:10.2307/2005662. JSTOR 2005662.
4. ^ Galántai, A.; Hegedũs, Cs. J. (2006). "Jordan's principal angles in complex vector spaces". Numer. Linear Algebra Appl. 13 (7): 589–598. CiteSeerX 10.1.1.329.7525. doi:10.1002/nla.491.
5. ^ Halmos, P.R. (1969), "Two subspaces", Trans. Amer. Math. Soc., 144: 381–389, doi:10.1090/S0002-9947-1969-0251519-5
6. ^ a b c Knyazev, A.V.; Argentati, M.E. (2006), "Majorization for Changes in Angles Between Subspaces, Ritz Values, and Graph Laplacian Spectra", SIAM J. Matrix Anal. Appl., 29 (1): 15–32, CiteSeerX 10.1.1.331.9770, doi:10.1137/060649070
7. ^ a b c Knyazev, A.V.; Jujunashvili, A.; Argentati, M.E. (2010), "Angles between infinite dimensional subspaces with applications to the Rayleigh–Ritz and alternating projectors methods", Journal of Functional Analysis, 259 (6): 1323–1345, arXiv:0705.1023, doi:10.1016/j.jfa.2010.05.018
8. ^ Qiu, L.; Zhang, Y.; Li, C.-K. (2005), "Unitarily invariant metrics on the Grassmann space", SIAM Journal on Matrix Analysis and Applications, 27 (2): 507–531, doi:10.1137/040607605
9. ^ Kato, D.T. (1996), Perturbation Theory for Linear Operators, Springer, New York
10. ^ a b c Knyazev, A.V.; Argentati, M.E. (2002), "Principal Angles between Subspaces in an A-Based Scalar Product: Algorithms and Perturbation Estimates", SIAM Journal on Scientific Computing, 23 (6): 2009–2041, CiteSeerX 10.1.1.73.2914, doi:10.1137/S1064827500377332
11. ^ Octave function subspace
12. ^ SciPy linear-algebra function subspace_angles
13. ^ MATLAB FileExchange function subspace
14. ^ MATLAB FileExchange function subspacea