Consider $J$ an open interval of $\mathbb{R}$.
An inner product on $\mathbb{R}$ is necessarily of the form $(u,v) \in \mathbb{R}^{2} \, \mapsto \, auv$ with $a > 0$. Therefore, a Riemannian metric on $J$ is necessarily of the form
$$ p \in J \, \mapsto \, g_{p} $$
where :
$$ \forall p \in J, \forall (u,v) \in T_{p}J \simeq \mathbb{R}, \, g_{p}(u,v) = f(p) uv $$
with $f$ a smooth, positive function on $J$.
The geodesic equation for this Riemannian metric becomes :
$$ \ddot{\gamma}(t) + \frac{1}{2}\frac{f'\big( \gamma(t) \big)}{f\big( \gamma(t) \big)}\big( \dot{\gamma}(t) \big)^{2} = 0. \tag{$\star$} $$
If, for example, $J=\mathbb{R}$ and $f \equiv 1$, we obtain straight lines as geodesics. My question is the following : can we prescribe a metric on $J$ for which geodesics would not be monotonic (such as the sine or cosine function) ? I cannot find a simple argument to prove (or disprove) it. I am under the impression that, for any choice of $f$, the solutions of $(\star)$ will always be monotonic. There must be missing something here.
A non-monotonic path can always be shortened. To be precise, given $a < b \in J$, and given a piecewise smooth path $\gamma : [0,1] \to J$ such that $\gamma(0)=a$ and $\gamma(1)=b$, if $\gamma$ is not monotonic then it is not one-to-one and so you can always find a shorter path. Since $\gamma$ is not monotonic, one can find $0 \le r < s \le 1$ such that $\gamma(r) = \gamma(s)$ and so that $\gamma$ is not constant on the subinterval $[r,s]$. Then define $\gamma' :[0,1] \to J$ by the formula $$\gamma'(t) = \begin{cases} \gamma(t) & \text{if $t \not\in [r,s]$} \\ \gamma(r)=\gamma(s) &\text{if $t \in [r,s]$} \end{cases} $$ A short calculation shows that the path length integral of $\gamma'$ is equal to the path length integral of $\gamma$ minus the path length integral of the restricted path $\gamma | [r,s]$; the latter is positive because $\gamma$ is non constant on $[r,s]$.