Generalization of scalar product to k-dimensional subspaces (as opposed to 1-dimensional subspaces, i.e. vectors) This came up in a practical problem (physics).
In the following, we work with real numbers only, and consider every vector to be normalized to 1.
To find how "similar" two vectors are (actually, two lines passing through the origin, I don't care about the direction), one can use the scalar product.  If the two lines are the same, then the scalar product of the corresponding vectors is 1 or -1.  If they are "similar", it's close to 1.  If they're perpendicular, it's 0.
I need a generalization of this "similarity measure" to $k$-dimensional subspaces.
For example, for $k=2$ I have the following problem:  I have vectors $a_1 \perp a_2$ which define a plane in an $n$-dimensional space, and vectors $b_1 \perp b_2$.  I need a measure that 1. tells me how close these planes are to each other, in terms of $a_1, a_2, b_1, b_2$. is a generalization of the simple scalar product (i.e. it's the same as the scalar product  for $k=1$).
 A: Let $V$ be an $n$-dimensional real vector space with an inner product $\langle \cdot,\cdot \rangle$. Then $\Lambda^k (V)$, the $k^{\text{th}}$ exterior product of $V$, inherits an induced inner product defined as follows.
If $\alpha = v_1 \wedge \cdots \wedge v_k$ and $\beta = w_1 \wedge \cdots \wedge w_k$, then $\langle \alpha , \beta \rangle = \det \langle v_i , w_j \rangle$ on decomposable vectors, and then extend by linearity to all of $\Lambda^k(V)$. Now a $k$-dimensional subspace $P$ of $V$ can be represented by a decomposable element $\alpha_P = v_1 \wedge \cdots \wedge v_k$ of $\Lambda^k(V)$, where $v_1, \ldots, v_k$ is a basis for $P$. If the basis is taken to be oriented and orthonormal, then the element $\alpha_P$ is uniquely determined. (Otherwise it is only determined up to a non-zero real scalar, so in general it defines a point in the projectivization $\mathbb P (\Lambda^k(V))$. Since this is a real inner product on a finite-dimensional vector space, it does indeed give you a measure of "how far" two vectors are from being parallel, or in this case, how far two $k$-dimensional subspaces are from being the same.
If $k = 2$ and $a_1, a_2$ and $b_1, b_2$ are two oriented orthonormal bases for two planes $P_a$ and $P_b$ in $V$, then
$$ \langle P_a, P_b \rangle  = \det{\langle a_i, b_j \rangle} = \langle a_1, b_1 \rangle \langle a_2, b_2 \rangle - \langle a_1, b_2 \rangle \langle a_2, b_1 \rangle. $$
You can search for "induced inner product on exterior algebra" or look at any book on differential forms for more details.
A: There is a very simple way to do this which is to consider the projector onto each subspace, $\Pi_A$ and $\Pi_B$, where we have
$$\Pi_A = \sum_j a_j a_j^T$$
and similarly for $\Pi_B$. Since all of your vectors spanning your subspace are orthogonal and normalized, this is indeed a rank-$k$ projector. Then you can just consider the Hilbert-Schmidt inner product,
$$\langle A , B \rangle = \mathrm{Tr}(A^T B)$$
and this will give you a measure of how similar the two spaces are. If you first divide each projector by the square root of it's rank, then this quantity is normalized so that it is 1 if and only if the two subspaces are equal. 
A: The set of all $k$-dimensional subspaces of $\mathbb{R}^n$ is called Grassmannian $\mathrm{Gr}(k,n)$ and can be given a structure of a smooth manifold. That gives you a topological notion of nearness, but there is more. There is a homogeneous Riemannian metric on this manifold that can be expressed quite explicitly - details can be found in this article by Yuri Neretin. Or you can try this one by Sheng Jiang which may be more accessible for you.
A: Let $V$ be an inner product space. The tensor product $V^{\otimes k}$ is equipped with an inner product induced from that of $V$ (obtained by contracting via the inner product $k$ times). Concretely, if $e_1, ... e_n$ is an orthonormal basis for $V$ then all sequences of tensor products of the $e_i$ form an orthonormal basis for $V^{\otimes k}$. Now, $V^{\otimes k}$ has a canonical subspace, the space of antisymmetric tensors $\text{Alt}^k(V)$ (not to be confused with the exterior power, which is a quotient of $V^{\otimes k}$ rather than a subspace), and the above inner product induces an inner product on antisymmetric tensors. Finally, given an orthonormal basis $f_1, ... f_k$ of a $k$-dimensional subspace $W$ of $V$, the antisymmetrization
$$f_1 \wedge ... \wedge f_k = \frac{1}{\sqrt{k!}} \sum_{\sigma \in S_k} \text{sgn}(\sigma) f_{\sigma(1)} \otimes ... \otimes f_{\sigma(k)}$$
associates to $W$ an element of $\text{Alt}^k(V)$ invariant up to oriented change of orthonormal basis. I think the inner product of these elements has the property you want. 
