5

The formal question:

Given $f(x)$, a continuous-but-not-necessarily-differentiable-everywhere function.

Define $g(x)$ as:

$$g(x) = \begin{cases} 0 & \text{if } x \leq 0 \\ \int_0^x \max(f(x) - f(t), 0) \, \mathrm{d}t & \text{if } x > 0 \end{cases}$$

Is $g(x)$ continuous and differentiable everywhere?


Context: I have a path in 2D space built out of connected line segments, and a robot with some position (not necessarily on the path). I need to assign a "marker" on the path to the robot's current position to know which direction it wants to go next.

I have a measure of how close the robot is to the marker (squared Euclidean distance) and for some window on the path. This is $f(x)$; it's continuous but not differentiable because the path makes hard turns wherever we move from one segment to the next.

I want to use that to measure how "good" the marker is. That is, I want to introduce a penalty into the solver for making a bad choice of marker when there was an earlier choice which would have been better (I don't need to care about better later choices).

A choice of marker is bad if there is a closer point on the path it could have selected, so I'd like to use $g(x)$ as my penalty for selecting a bad marker (note that when $f(x)$ is the minimum value of $f$ over $[0,x]$, it's $0$). Since the solver uses gradient descent, I can only work with differentiable functions.


Example:

Take $f(x) = |x-1|$.

Then

$$g(x) = \begin{cases} 0 & \text{if } x < 1 \\ (x-1)^2 & \text{if } 1 \leq x < 2 \\ (x-1)^2 - \frac{(x-2)^2}{2} & \text{if } x \geq 2 \end{cases}$$

Which is indeed continuous and differentiable everywhere. In general it intuitively seems like this should always be true, but it doesn't follow directly from FTOC because of that $f(x)$ inside the integrand.

PrincessEev
  • 51,605
dspyz
  • 932

1 Answers1

3

Sadly, no.

A counterexample is $$ f(x) = \Big| |x-1| - 1 \Big| $$

Here, we have $f(x)$:

enter image description here

Here is $g(x)$:

enter image description here

And here is $g'(x)$, with a discontinuity at $x=1$ and hence clearly not differentiable there:

enter image description here


That said, I don't have a great motivation for how I came up with this counterexample other than playing around in Desmos and seeing what stuck.

PrincessEev
  • 51,605
  • I'm playing with Desmos now also and I notice that I see non-differentiable peaks but no non-differentiable troughs. Seeing as how I care about the solver being able to find local minima, this may actually still be okay. Given that f(x) is positive, is it possible for g to have a discontinuous derivative which is also a local minimum? – dspyz Sep 02 '24 at 01:50
  • Oh, I found one: f(x) = |sin(x)| + 0.5x – dspyz Sep 02 '24 at 01:54