Proving that $|\text{Cor}(X,Y)|=1$ only when $Y=a+bX$ for non-random $a,b$ It is easy to verify the fact that $|\text{Cor}(X,Y)|=1$ when $Y=a+bX$ for arbitrary constants $a, b$. But how to go about proving this, without invoking steps from the proof of Jensen's inequality. Here is what I have done so far.

My Attempt:
Let $Y=g(X)$ and solving for $|\text{Cov}(X,Y)|=\sqrt{\text{Var}(X)\text{Var}(Y)}$ using $\text{Cov}(X,Y)=\text{E}[XY]-\text{E}[X]\text{E}[Y]$, the following equality holds.
$$\left(\text{E}[Xg(X)]\right)^2-2\text{E}[X]\text{E}[g(X)]\text{E}[Xg(X)]=\text{E}[X^2]\text{E}[(g(X))^2]-\left(\text{E}[X]\right)^2\text{E}[(g(X))^2]-\text{E}[X^2]\left(\text{E}[g(X)]\right)^2$$

This equation seems over-complicated. How to go about proving that $g(X)$ is linear? Any hints are appreciated. Thanks 
 A: There may be a good reason for the complications, because the equivalence is not generally true.  For it to hold, you have to assume $X$ has nonzero variance and that both $X$ and $Y$ have finite variances, and even then by assuming the correlation of $X$ and $Y$ is $\pm 1$ you can only conclude there exist numbers $a$ and $b$ for which there is a 100% chance that $Y=a+bX,$ not that equality holds everywhere.  In the other direction, you also have to allow that when $b=0,$ the correlation between $Y$ and $a+bX$ is zero.
The following account shows why these assumptions are needed.

Abbreviating $$\sqrt{\operatorname{Var}{Z}} = \sigma_Z$$
for random variables $Z,$ apply the relation
$$\operatorname{Cov}(X,Y) = \sigma_X\sigma_Y\operatorname{Cor}(X,Y)\tag{1}$$
to compute
$$\operatorname{Var}(\sigma_X Y \mp \sigma_Y X) = (\sigma^2_X)\operatorname{Var}{Y} \mp 2 \sigma_X\sigma_Y \operatorname{Cov}(X,Y) + (\sigma_Y)^2 \operatorname{Var}(X).\tag{2}$$

Supposing $\operatorname{Cor}(X,Y) = \pm 1,$ relation $(1)$ implies
$$\operatorname{Cov}(X,Y) = \pm \sigma_X\sigma_Y,$$
which reduces $(2)$ to
$$\operatorname{Var}(\sigma_X Y \mp \sigma_Y X) = (\sigma^2_X)(\sigma^2_Y) \mp 2 \sigma_X\sigma_Y (\pm 1) + (\sigma_Y)^2 (\sigma_X^2) = 0.\tag{3}$$
At this point use the fact that when $Z$ is a random variable (like the one on the left hand side of $(3)$) for which $\operatorname{Var}(Z)=0,$ you can deduce there is a constant $\mu$ for which $\Pr(Z = \mu) = 1.$  (How you prove this fact depends on your definition of variance and whether you know relevant inequalities like the Chebyshev Inequality.)
If you assume both $X$ and $Y$ have finite variances, this proves there exist numbers $\mu,$ $\alpha = \sigma_X,$ and $\beta = \pm\sigma_Y$ for which
$$\Pr(\alpha Y + \beta X = \mu) = 1.$$
If $\alpha = \sigma_X \ne 0,$ you can set $a = \mu/\alpha$ and $b = -\beta/\alpha$ and obtain

$$\Pr(Y = a + bX) = \Pr(\alpha Y + \beta X = \mu) = 1.$$

Thus, it's not necessarily the case that $Y=a+bX,$ but when $\sigma_X\ne 0$ the chance that $Y$ differs from $a+bX$ is zero. 
When $\sigma_X = 0,$ you can use $(1)$ to demonstrate the correlation between $X$ and $Y$ is not defined (because any number would work in relation $(1),$ which reduces to $0 = 0\, \operatorname{Cor}(X,Y).$)

Going in the other direction, when $Y = a+bX,$ just use properties of covariance to compute
$$\sigma^2_Y = b^2 \sigma^2_X$$
and (from $(1)$)
$$b\, \sigma^2_X = \operatorname{Cov}(X,Y) = \sigma_X\sigma_Y\operatorname{Cor}(X,Y)$$
and solve for $\operatorname{Cor}(X,Y).$  The solution depends on whether $b=0$ or not.

Finally, an interesting example of the distinction between two random variables being equal and just having 100% chance of equality is the following.  Let the interval $[0,1]$ of real numbers with its Borel sets be the probability space and let $\Pr$ be the usual (uniform) probability measure on the interval. Let $X(t)=t$ (which obviously is a random variable) and define $Y(t)=X(t)$ when $t$ is irrational and otherwise $Y(t)=0$ (which also is a random variable).  $Y$ differs from $X$ on infinitely many numbers, but nevertheless the correlation coefficient of $X$ and $Y$ is $1$ and, indeed, $\Pr(Y=X) = 1.$
