4
$\begingroup$

If $\mathbf{u}$ and $\mathbf{v}$ are vectors in real 3-dimensional space, here are two formulas for computing the angle between them:

$$\theta = \operatorname{atan2}\left( \|\mathbf{u}\times\mathbf{v}\|, \mathbf{u}•\mathbf{v} \right)$$

$$\theta = 2\, \operatorname{atan2}\left( \left\| \, \|\mathbf{v}\|\,\mathbf{u} - \|\mathbf{u}\|\,\mathbf{v}\, \right\|, \left\|\, \|\mathbf{v}\|\,\mathbf{u} + \|\mathbf{u}\|\,\mathbf{v}\,\right\| \right)$$

An answer to this question gives a sort of hand-waving argument that the first formula is inferior due to the cancellations involved in the computation of the cross product. Is there an objective way to demonstrate that one formula is numerically superior to the other?

$\endgroup$

1 Answer 1

0
$\begingroup$

It's possible, but proof is much harder than empirical evidence, and certainly harder than "hand-waving." :)

For this specific question, they're both based on $atan2$, so it comes down to proving things about the accuracy of the arguments. These types of proofs generally involve writing the computed operations (multiply, addition, subtraction etc.) in terms of their exact value plus error terms, and then showing that the accumulated error from one formula must be >= the error of the other.

However, it's often the case that you can't prove anything that rigorously for the simple reason that one formula isn't universally better. Rather, it might be generally better across most inputs, maybe even much better, but there are certain inputs for which the other gives a more accurate result. With such a counterexample, it's clear that you would be unable to prove the overall superiority of one of the formulas, and instead you'd have to try to prove that it's only typically better, which is even harder to do.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .