Counting the number of times a periodic function crosses the $x$-axis Suppose $f(x)$ is a smooth periodic function with period $T$ and suppose the function crosses the $x$-axis at a finite number of points $x_i \in [0,T)$, $i=1,2,\ldots,N$, within a single period $T$, where $f(x_i) = 0$ and $f'(x_i) \neq 0 \ \forall i$.
It seems intuitively obvious to me that $N$ should be even: as the function is periodic, when it cross below the $x$-axis it must cross back at some point within the period, however I do not know how to show this mathematically.
Moreover, the number of crossings from above should equal the number of crossings from below, i.e.
$$ \sum_{i=1}^N \mathrm{sgn}(f'(x_i)) = 0.$$
Again, this is intuitive, but I do not know how I could calculate this mathematically. Any hints would be appreciated as I would like to try and derive this myself.
 A: This answer assumes the following version of the question: there are $N\in\mathbb{N}$ points $x_1,\ldots,x_N\in[0,T)$ where $f(x_i)=0$ and $f'(x_i)\ne 0$, and there are no other zeros (so in particular there is no $x$ such that $f(x)=0$ and $f'(x)=0$). As mentioned in the comments to the question, if we do not make these assumptions then there are counterexamples, since a function can "cross the $x$-axis" (being first above it then below it) while having derivative $0$ at the crossing point, which messes up the count so that we may get $N$ that is odd.
Assume without loss of generality that $f(0)>0$. (The case $f(0)=0$ follows similarly;  I'm leaving out the detail because you said you want to derive this yourself. Let me know if you need more detail.)
At the first crossing point $x_1$ we have $f'(x_1)\ne 0$ so by smoothness there is a neighbourhood around $x_1$ such that $f'(x)>0$ or $f'(x)<0$. Since $f(0)>0$ and this is the first crossing point we have $f'(x)<0$ for all $x$ in a neighbourhood of $x_1$. This means $f$ is decreasing there and so there is some point $p>x_1$ such that $f(p)<0$ and such that there is no zero between $x_1$ and $p$. (Such $p$ exists since we are assuming there is only a finite number $N$ of zeros in $[0,T)$.)
By periodicity $f(T)>0$, so by the intermediate value theorem there must exist some $p<x_2<T$ such that $f(x_2)=0$, so that there are at least two zeros. If there is a third one $x_3$ you repeat the argument.
This same explanation also shows that your second claim is also true, that is, that the function alternates between being decreasing and increasing at the points $x_i$.
