Proof: A function is convex iff it is convex when restricted to any line .. 
Let $f\colon \Bbb R^n\to \Bbb R$ be a function. Then, $f$ is convex if
and only if the function $g\colon\mathbb{R} \to \mathbb{R}$ defined as $g(t) \triangleq
f(x+tv)$, with domain
$$
\operatorname{dom}(g)=\{t\mid x+tv \in \operatorname{dom}(f), x\in \operatorname{dom}(f), v\in \mathbb{R}^n\},
$$
is convex in $t$.


It says that: a function is convex if and only if it is convex when restricted to any line that intersects its domain. My question was how to prove it?
Reference: Steven Boyd, Convex Optimization, Cambridge University Press,
Page 67.


The "$\Rightarrow$" part is easy.
The other direction can be proven by contradiction:
Assume that $f$ is not convex. Then,
$\operatorname{dom}(f)$ is not convex or there exist $x,y \in \operatorname{dom}(f)$ and $\lambda \in (0,1)$ with $f( \lambda \, x + (1-\lambda) \, y ) > \lambda \, f(x) + (1-\lambda) \, f(y)$.


*

*If $\operatorname{dom}(f)$ is not convex, there exist $x,y \in \operatorname{dom}(f)$ and $\lambda \in (0,1)$ with $\lambda \, x + (1-\lambda) \, y \not\in \operatorname{dom}(f)$. Now, set $v = y - x$ and use the $g$ as in the statement of the theorem. Then, it is easy to check that $\operatorname{dom}(g)$ is not convex, since it contains $0$ and $1$, but not $1-\lambda$.

*In the other case, you can define $g$ in the same way and get $g(1-\lambda) > \lambda \, g(0) + (1-\lambda) \, g(1)$.
In both cases, we obtained a contradiction to the convexity of $g$.
