\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}\begin{array}{l}
\mathbf{if}\;x \le -1.34868568945504563 \cdot 10^{138} \lor \neg \left(x \le -4.7086389988959359 \cdot 10^{125} \lor \neg \left(x \le -140531020550505330000 \lor \neg \left(x \le -454354590.679686964\right)\right)\right):\\
\;\;\;\;e^{\log \left(\log \left(e^{\sqrt{0.5 \cdot \left(1 + x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{\left(\log \left(\sqrt{2} \cdot \sqrt{0.5}\right) + \log \left(\frac{-1}{x}\right)\right) - \log \left(\frac{-1}{p}\right)}\\
\end{array}double code(double p, double x) {
return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
double code(double p, double x) {
double VAR;
if (((x <= -1.3486856894550456e+138) || !((x <= -4.708638998895936e+125) || !((x <= -1.4053102055050533e+20) || !(x <= -454354590.67968696))))) {
VAR = exp(log(log(exp(sqrt((0.5 * (1.0 + (x * (1.0 / sqrt((((4.0 * p) * p) + (x * x))))))))))));
} else {
VAR = exp(((log((sqrt(2.0) * sqrt(0.5))) + log((-1.0 / x))) - log((-1.0 / p))));
}
return VAR;
}




Bits error versus p




Bits error versus x
Results
| Original | 13.1 |
|---|---|
| Target | 13.1 |
| Herbie | 14.0 |
if x < -1.3486856894550456e+138 or -4.708638998895936e+125 < x < -1.4053102055050533e+20 or -454354590.67968696 < x Initial program 12.4
rmApplied div-inv12.6
rmApplied add-log-exp12.6
rmApplied add-exp-log12.6
if -1.3486856894550456e+138 < x < -4.708638998895936e+125 or -1.4053102055050533e+20 < x < -454354590.67968696Initial program 30.2
rmApplied div-inv30.8
rmApplied add-log-exp30.8
rmApplied add-exp-log30.8
Taylor expanded around -inf 46.2
Final simplification14.0
herbie shell --seed 2020100 +o rules:numerics
(FPCore (p x)
:name "Given's Rotation SVD example"
:precision binary64
:pre (< 1e-150 (fabs x) 1e+150)
:herbie-target
(sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1 (/ (* 2 p) x)))))
(sqrt (* 0.5 (+ 1 (/ x (sqrt (+ (* (* 4 p) p) (* x x))))))))