I'm trying to think through the sensitivity of atan2 to errors in its inputs and I've run into a disconnect that I don't quite understand.
I know that you can compute the relative condition number of a differential function $f$ as:
$$\kappa(\vec{x}) = \frac{\Vert\mathbb{J}_f(\vec{x})\Vert}{\Vert f(\vec{x})\Vert/\Vert \vec{x}\Vert}$$
Where the norm on the Jacobian is the induced norm.
For $atan(x)$ you end up with simply the derivative $\frac{1}{1+x^2}$ so it works out to: $$\kappa(x) = \frac{x}{(1+x^2)atan(x)}$$
Which is very nicely behaved:
If I look at it on the unit circle and compute K(y/x), it looks well behaved too:
However, looking at atan2(y,x) = atan(y/x), you end up with:
$$\mathbb{J}(y,x) = \{\frac{-y}{x^2+y^2}, \frac{x}{x^2+y^2}\}$$
It turns out the induced $L_2$ norm for this is 1, and in my particular case, my x and y values are indeed a sine and cosine pair so $\Vert <x,y>\Vert = \sqrt{x^2+y^2} = 1$
This leaves you with $\kappa(y,x) = \frac{1}{\vert atan2(y,x)\vert}$ which is less well behaved for positive x and y near zero:
I believe the math here but I'm struggling to interpret the results in a consistent way, since atan2 is fundamentally just atan with logic to interpret the sign correctly.
Why does atan2 seem to get very sensitive near zero and atan doesn't?
Edit: Made atan2 and related equations consistently (y,x) order.
Condition number shows how relative perturbation of the argument(s) result in relative change in function value.
You show that atan is good conditioned, so any perturbation of $x$ cannot result in bigger relative perturbation of $\operatorname{atan} x$. I was suprised that for nonlinear functions $\kappa$ may be less than 1, for linear ones that is impossible.
Let's study how atan2 is sensitive to perturbation of $x$ and $y$ separately: $$ \kappa_x(y, x) = \frac{|\operatorname{atan2}(y, x+\delta x)-\operatorname{atan2}(y, x)| / |\delta x|}{|\operatorname{atan2}(y, x)| / \|(x, y)\|} = \frac{|y|}{|\operatorname{atan2}(y, x)|} $$ Mathematica defines atan2 with branch cut along $(-\infty, 0]$, so atan2 near $y = 0$, $x = 1$ behaves like $\operatorname{atan2}(y, x) \approx y$, so $\kappa_x \approx 1$.
Similarly $$ \kappa_y(y, x) = \frac{|x|}{|\operatorname{atan2}(y, x)|}. $$ Near $x = 1, y = 0$ we have $\kappa_y = |x/y| \to \infty$. There's no magic in this result. The relative perturbation of function is like $\delta y / y$, while relative perturbation of the argument is $\delta y/1$ (thanks to $x$). Sure thing $\delta y / y$ may be big, while $\delta y$ remain quite small.
The difference in $\operatorname{atan} \frac{y}{x}$ and $\operatorname{atan2}(y, x)$ the condition numbers essentially contain different $\|x\|$ in their definition, the former has $|y/x|$, while the latter has $\|(x, y)\| = 1$.