Let $f$ be a real valued function. Prove the set of points $x\in\mathbb{R}$ such that $F(y)\leq F(x)\leq F(z)$ for all $x\leq z$, $y\leq x$ is Borel. Question: Let $F:\mathbb{R}\rightarrow\mathbb{R}$ be any function (not necessarily measurable, continuous, or anything else.  Prove the set of points $x\in\mathbb{R}$ such that $F(y)\leq F(x)\leq F(z)$ for all $x\leq z$, $y\leq x$ is Borel.
This question was asked here: Prove a function is Borel set, so I am trying to go off the hint in the most recent comment, but I can't seem to quite wrap my head around it.  I like what the first comment said about getting a "line" of sorts, but I just can't seem to wrap my head around what I am trying to see graphically.  Any help would be greatly appreciated!
 A: Hmm I don't really understand the hint either (and as Vercingetorix pointed out, the hint seems to be wrong...), but the following should work I think.
Take $A$ to be the complement of your set (suffices to show that this complement is Borel), i.e. $A$ is the set of all $x \in \mathbb{R}$ such that there exists either $z > x$ with $F(z) < F(x)$ or there exists $y < x$ with $F(y) > F(x)$.
If $A$ is empty then there's nothing to do. So suppose $x \in A$ and suppose first that there exists $z > x$ with $F(z) < F(x)$. Then for $z > z' > x$, we have $z' \in A$ because otherwise $F(x) > F(z) \geq F(z') \geq F(x)$, a contradiction. Noting that $z$ itself then has to be in $A$ also, we have then that the closed interval with endpoints $z,x$, i.e. $[x,z]$, is entirely contained in $A$. Likewise if there exists $y < x$ with $F(y) > F(x)$ then $[y,x] \subseteq A$.
From here it's easy to see that $A$ is a countable union of intervals. One standard way to organize this is to consider the equivalence relation $\sim$ on $A$ where we write $x \sim y$ with $x,y \in A$ if the closed interval with endpoints $x,y$ is entirely contained in $A$. Each equivalence class of $\sim$ on $A$ is a certain union of closed intervals containing some fixed point $x$, so is an interval in its own right. What the above paragraph implies then is that each equivalence class of $A$ is a nondegenerate interval, so that we can express $A = \cup_{i \in I} J_i$ as a disjoint union of nondegenerate intervals $J_i$'s. But being nondegenerate, one can pick out, for each $i \in I$, a rational number $r_i \in J_i$, giving an injection $I \to \mathbb{Q}$, $i \mapsto r_i$, so $I$ is countable, so $A$ is Borel, so your set $\mathbb{R} \setminus A$ is Borel.
