5

I'm interested in a formula that I founded in a Discord post:

Given a function $f\in C^\infty$, then the number of real roots of $f$ inside the interval $[a,b]$ is: $$N=\operatorname{round}\left(\pi^{-1}\left(-\arctan\left(\frac{f'(a)}{f(a)}\right)+\int_{a}^{b}\frac{f'(t)^2-f(t)f''(t)}{f(t)^2+f'(t)^2}\,dt\right)\right)$$ With $\operatorname{round}(\cdot)$ rounds the input to nearest integer.

They mentioned that they used winding number integral to come up with this formula, but I have no knowledge in such thing. I don't know how to prove it since the $\operatorname{round}$ and $\arctan$ complicates thing.

Any idea?

Thinh Dinh
  • 8,233

1 Answers1

5

This formula is really like pull the wool over someone's eye.

It is just a machinery, an algorithmic formula that counts the passages over the $x$ axis. It is an algorithm in disguise, written as a formula.

It is a clever trick, and it looks much less mysterious after one sees that: $$\frac{d}{dt}\left(-\arctan\left(\frac{f'(t)}{f(t)}\right)\right) = \frac{f'(t)^2-f(t)f''(t)}{f(t)^2+f'(t)^2}$$

So we may rewrite $$-\arctan\left(\frac{f'(a)}{f(a)}\right)+\int_{a}^{b}\frac{f'(t)^2-f(t)f''(t)}{f(t)^2+f'(t)^2}\,dt$$

as

$$-g(f(a)) + \int_a^b \frac{d}{dt}g(f(t)) dt$$

with $$g(f(t)) = -\arctan\left(\frac{f'(t)}{f(t)}\right)$$

And it's easy to see that

$$-g(f(a)) + \int_a^b \frac{d}{dt}g(f(t)) dt = g(f(b))$$

So why bother with the integral formula ??? Why bother if what it is in the end is just $$g(f(b)) = -\arctan\left(\frac{f'(b)}{f(b)}\right)$$

Well, here comes the clever trick.

First of all, we want to use the $\arctan$ because it's a function with a domain of $\mathbb{R}$ and a limited image, while it's monotonic. If we use $\arctan\left(\frac{1}{f(t)}\right)$ we have a function that "passes through" $\frac{\pi}{2}$ every time $f(t)$ crosses the $x$ axis.

But the problem of the $\arctan$ is that it goes from $\frac{\pi}{2}$ to $-\frac{\pi}{2}$ if the $f(t)$ crosses the $x$ axis from the positive side to negative and viceversa (from $-\frac{\pi}{2}$ to $\frac{\pi}{2}$ when the function crosses from negative to positive).

We don't want the viceversa. What we want instead is something that wraps from $\frac{\pi}{2}$ to $-\frac{\pi}{2}$ when the $f(x)$ crosses the $x$ axis, in whatever direction. We never want the $\arctan$ to wrap in the opposite direction.

So, here it is $\arctan\left(\frac{f'(t)}{f(t)}\right)$, which does exactly this. Whenever $f(t)$ crosses the $x$ axis, it wrap from $\frac{\pi}{2}$ to $-\frac{\pi}{2}$ and it never wraps in the other direction.

So far so good. But next, we really don't want the arctan to wrap. What we would like to have, instead, is a function that continues in the same direction without wrapping. Instead of wrapping, we would like the arctan to continue growing as if it add to itself an offset of $\pi$ at every wrap.

In this way, every $\pi$ times, it means that the function $f(t)$ crosses the $x$ axis. What we have to do is to look at the value of the unwrapping arctan and divide by $\pi$.

And for this we have $$\int_{a}^{b}\frac{f'(t)^2-f(t)f''(t)}{f(t)^2+f'(t)^2}\,dt$$

All what it is the formula above is an "unwrapping arctan". Since it's the integral of the derivative of the arctan, it's just the arctan in disguise, but with the remarkable feature that it doesn't wrap, it continues to grow. All the tiny $d f(x)$ are added continuously without wrapping as the integral "evolves".

Then, all we have to do in the end is to divide by $\pi$ and round all up, so that in the end we have a neat number.

And the starting point $-\arctan\left(\frac{f'(a)}{f(a)}\right)$ is precisely the starting point. It avoids to have a wrong result (+1 or -1 the exact result) after we round the partial result.

Plotting some easy example like this: https://www.desmos.com/calculator/yr4ljmpcmr really help to visualize the machinery behind the formula.

And that's all, I think. A really clever trick.