As part of a numerical algorithm, I want to compute x/\sqrt{y} for real numbers x and y. In general is it preferable to compute x/sqrt(y) or x*sqrt(1/y) or x*1/sqrt(y)?
As a slightly less trivial example, is there an optimal way to compute x/\sqrt{y^3/3}?
If you wanted to do better, you could work out the Taylor series for this specific function and implement it that way, but that seems unlikely to be worth it. This also typically requires splitting the domain into separate regions and doing different series centered around different points and piecing them together in order to get optimal accuracy and speed.
I’m not sure what you mean here — this function does not have a Taylor series in y. It has a multivariate Puiseux series with exactly one term: x/\sqrt{y}. So, that road leads in a circle.
(Unless you mean computing the function near some particular nonzero value of y, and doing a series expansion there? It seems like it would be hard to get a performance boost that way unless you are looking at a very small domain.)
Herbie seems to recommend the x * y^(-0.5) variant, although the (very slight) increase in accuracy detected on the 256-point training set does not seem to be reliably found in the 8000-point test set. I would say that this tends to corroborate the general trend of answers here, that there is no easy way to rewrite x/\sqrt y:
Herbie 1.4 with seed 172253712
Find help on https://herbie.uwplse.org/, exit with Ctrl-D
herbie> (FPCore (x y) :name "x / sqrt(y)" (/ x (sqrt y)))
(FPCore
(x y)
:herbie-status
ex-start
:herbie-time
6874.320068359375
:herbie-error-input
((256 0.27058823529411763) (8000 0.23190398799849982))
:herbie-error-output
((256 0.23921568627450981) (8000 0.24678084760595073))
:name
"x / sqrt(y)"
:precision
binary64
(* x (pow y -0.5)))
However, it looks like your second formula (x/\sqrt{y^3/3}) is already quite good on average, but could still be rewritten significantly more accurately in the (arguably less elegant and undoubtedly more expensive) way described below: