$\renewcommand{\avg}[1]{\left \langle #1 \right \rangle}$ Suppose we have a probability distribution in two variables $$P_{XY}(x,y) \, .$$ Define the correlation as $$\rho \equiv \frac{\langle \langle X Y \rangle \rangle}{\sqrt{\langle \langle X^2 \rangle \rangle \langle \langle Y^2 \rangle \rangle}} = \frac{\avg{XY} - \avg{X}\avg{Y}}{\sqrt{\left( \avg{X^2} - \avg{X}^2\right) \left( \avg{Y^2} - \avg{Y}^2 \right)}} \, .$$ We want to prove that if $\rho = \pm 1$, then $X$ and $Y$ are connected by a linear relation.
To get started, note that the set of functions of $x$ and $y$ form a vector space, and that the statistical average with respect to $P_{XY}$ is an inner product on that space. In other words, $$ \underbrace{\langle f | g \rangle}_\text{inner product} \equiv \underbrace{\avg{fg}}_\text{statistical average} \equiv \int dx \, dy P_{XY}(x,y) f(x,y) g(x,y) \, .$$
If we choose $f(x,y) = x - \avg{X}$ and $g(x,y) = y - \avg{Y}$, then using the Cauchy-Schwarz inequality $$\left \lvert \left \langle f | g \right \rangle \right\rvert^2 \leq \left \langle f | f \right \rangle \left \langle g | g \right \rangle$$ we find $$\frac{\left \lvert \avg{XY} - \avg{X}\avg{Y} \right\rvert^2}{ \left( \avg{X^2} - \avg{X}^2 \right) \left( \avg{Y^2} - \avg{Y}^2 \right)} \leq 1$$ which implies $-1 \leq \rho \leq 1$.
To saturate the Cauchy-Schwarz inequality, $|f\rangle$ and $|g \rangle$ must be parallel vectors, i.e. $|f \rangle = a |g \rangle$ for some scalar $a$. In other words, we get $|\rho| = 1$ if \begin{align} x - \avg{X} =& a \left( y - \avg{Y} \right) \\ x =& ay + \avg{X} - a \avg{Y} \, . \end{align} This appears to prove that $X$ and $Y$ are linearly related. However, we based this result off of a choice of $|f \rangle$ and $|g\rangle$, which are "dummy" functions subject to our choosing, whereas the statement that $X$ and $Y$ are linearly related would seem to be a statement about $P_{XY}$ itself. How is this discord resolved?