Is every such function convex or concave? I was pondering convex functions today, and the following questions naturally posed themselves. Call a function $f : \mathbb{R} \rightarrow \mathbb{R}$ $2$-limited iff for all $m,c \in \mathbb{R},$ the cardinality of $\{x \in \mathbb{R} \mid f(x)=mx+c\}$ is at most $2.$
Question 0. Is every continuous 2-limited function $f : \mathbb{R} \rightarrow \mathbb{R}$ convex or concave?
Question 1. Assuming the answer to the above question is "yes," does there exist a (necessarily discontinuous) $2$-limited function $f : \mathbb{R} \rightarrow \mathbb{R}$ that is neither convex nor concave?
 A: For Question 1:
Take the hyperbola $f(x) = \sqrt{1+x^2}$ through $(0,1)$ with asymptotes $y = \pm x$. Then define
$$g(x) =
\begin{cases}
f(x),  & \text{if $x \ne 0$} \\
0, & \text{if $x = 0$}  \\
\end{cases}
$$
Then $g$ is neither convex nor concave. But any line through the discontinuous point $(0,0)$ meets the hyperbola at most once, so $g$ is $2$-limited.
A: For Question 0:
We are given a continious function $f(x)$ with the 2-limited property. Draw a line $l(x)=f(0)+x\left(f(1)-f(0)\right)$ between $f(0)$ and $f(1)$ and decide whether $f(\frac{1}{2})$ lies above or under the line. It is not possible that $f(\frac{1}{2})$ lies on the line, that violates the 2-limited property.
From now assume that $f(\frac{1}{2})$ lies under the line (i.e. $f(\frac{1}{2})<l(\frac{1}{2}))$; if not, consider $-f(x)$, and notice that changing sign does not change the concave/convex-property.
From this follows that $f(x)<l(x)$ for every $x \in (0,1)$. Suppose otherwise, and $f(y)\geq l(y)$, $y \in (0,1)$. Then, from the intermediate-value-theorem, follows that $f(x)$ and $l(x)$ have another intersection, (not always strictly) between $\frac{1}{2}$ and $y$.
Analogous follows that $f(x)>l(x)$ for every $x\notin[0,1]$.
Now we choose another line $m(x)$ between $f(x_1)$ and $f(x_2)$, $x_1<x_2$. Assume that $l(x)$ and $m(x)$ don't have the same derivative.
To justify this; if $x_1<0 \land x_2>1$, draw a line from $f(x_1)$ to $f(0)$ and a line from $f(0)$ to $f(x_2)$. If $x_1\in(0,1) \land x_2>1$ or $x_1<0 \land x_2\in(0,1)$, $l$ and $m$ don't have the same derivative. If $x_1,x_2\in(0,1)$, draw $l$ between two different points $y_1$ and $y_2$, such that $x_1,x_2\in(y_1,y_2)$ does not happen. If $x_1,x_2<0$ or $x_1,x_2>1$, draw a line from $x_1$ to $1$ or from $0$ to $x_2$; these lines have three intersections with $f(x)$.
Because $l$ and $m$ don't have the same derivative, follows $l(x)<m(x)$ for large $x$, either negative or positive. Assume negative, otherwise, consider $f(-x)$.
From this follows that $f(x)>m(x)$ for every $x<x_1$. We know this is the case for large $|x|$, when $x$ is negative. If there exists $y<x_1$ with $f(y)\leq m(y)$, there is another intersection for $z\leq y$.
Now we want $f(x)<m(x)$ for every $x\in (x_1,x_2)$. Suppose otherwise, then we have $y\in (x_1,x_2)$ with $f(y)>m(y)$. If $f(y)=m(y)$ there is another intersection, this cannot happen. For this, we draw a line $n(x)$ from $f(x_1-\epsilon)$ to $f(x_2)$, $\epsilon>0$, $\epsilon$ small. Notice that $f(x_1-\epsilon)>f(x_1)$. Because $f(x_1)$ lies under the line, and $f(y)$ lies above the line (how to make this precise?), we have another intersection.
So we conclude that $f(x)<m(x)$ for every $x\in (x_1,x_2)$ and convexity is proven.
A: For Question $0$:
Suppose points $A,B,C$ are witnesses to the non-concavity of $f$; that is, they are points on the graph of $f$ such that $x_A < x_B < x_C$ and $y_B < y_A + \dfrac{x_B-x_A}{x_C-x_A}(y_C-y_A)$. This is the picture:

Claim: If $f$ is $2$-limited, the graph of $f$ can't enter the interior of the shaded regions. (We call the union of these two shaded regions the forbidden zone for $A,B,C$.)
To see this for the right-hand shaded region, divide it up into three sub-regions:

If $P$ is a point on the graph of $f$ in region $1$, then draw a line through $P$ and $C$, as shown; by the continuity of $f$, this line will cross the graph of $f$ somewhere between $A$ and $B$, contradicting the $2$-limited condition.
Similarly, if $P$ is in region $2$, draw a line through $P$ and $A$; this line will cross the graph of $f$ somewhere between $B$ and $C$.
And if $P$ is in region $3$, the line $AB$ will cross the graph of $f$ between $C$ and $P$.
A similar argument applies to the left-hand shaded region. This establishes the claim.
Similarly, if $D,E,F$ are witnesses to the non-convexity of $f$, then the graph of $f$ can't enter the interior of the shaded region in this diagram:

Now, if $f$ is neither concave nor convex, then there exist witnesses $A,B,C$ to its non-concavity, and witnesses $D,E,F$ to its non-convexity.
Each of the corresponding forbidden zones covers more than $180^{\circ}$. So for large enough $R$, they must intersect for $x > R$ or $x < -R$. For such $x$, the point $(x,f(x))$ has nowhere to go; a contradiction.
QED
