I want to calculate a power difference, $x^a - y^a$, where $a$ can be large, and the numbers $x,y$ are of similar magnitude. What's a sound numerical way to approach this?
Note: $x,y,a$ are all positive real numbers (not integers in general).
I want to calculate a power difference, $x^a - y^a$, where $a$ can be large, and the numbers $x,y$ are of similar magnitude. What's a sound numerical way to approach this?
Note: $x,y,a$ are all positive real numbers (not integers in general).
I would suggest the following. Let $y > x$. Write $d = y^a-x^a = y^a (1-(x/y)^a)$. Then take the log: $$\log(d) = a \log(y) + \log(1-(x/y)^a).$$
You are guaranteed to be able to compute $\log(1-(x/y)^a)$ as accurately as you like since the taylor series of log around 1 has radius 1. It becomes a matter of taking the exponential of this expression. If this overflows then you have a problem in general--that is, the difference is just not going to be representable in floating point numbers.
EDIT: To give a better suggestion I'd have to see some example computations you are doing/intending to do.