Feasible inner products with two unit vectors (source code)

= Feasible inner products with two unit vectors

Let $y,z$ be linearly independent unit <vectors> in a real <Hilbert space>, and write $c=\langle y,z\rangle$, so $|c|<1$. Given desired <inner products> $p=\langle x,y\rangle$ and $q=\langle x,z\rangle$, the unique least-norm solution lies in $\operatorname{span}\{y,z\}$ and is
$$
x_0=\frac{p-cq}{1-c^2}y+\frac{q-cp}{1-c^2}z,\qquad
\|x_0\|^2=\frac{p^2-2cpq+q^2}{1-c^2}.
$$
Solve the two-by-two <Gram matrix> system to obtain these coefficients. Every solution is $x=x_0+w$ with $w$ orthogonal to both $y,z$, so the <Pythagorean theorem> gives $\|x\|^2=\|x_0\|^2+\|w\|^2$.

If the orthogonal complement of their span contains a nonzero <vector>, a unit solution exists exactly when $\|x_0\|^2\leq1$: choose $w$ with length $\sqrt{1-\|x_0\|^2}$. In a two-dimensional ambient space the complement is zero, so a unit solution instead requires equality. For example, $p=q=0$ satisfies the inequality but cannot be attained by a unit <vector> in the plane spanned by $y,z$. For a solution of <norm> at most1, the inequality is the criterion in either dimension.