\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.1394059361264092 \cdot 10^{138}:\\
\;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \frac{\left(-x \cdot x\right) \cdot \frac{1}{\left(4 \cdot p\right) \cdot p + x \cdot x} + 1 \cdot 1}{1 - x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\right)\\
\mathbf{elif}\;x \le -4.7086389988959359 \cdot 10^{125}:\\
\;\;\;\;e^{\left(\log \left(\sqrt{2} \cdot \sqrt{0.5}\right) + \log \left(\frac{-1}{x}\right)\right) - \log \left(\frac{-1}{p}\right)}\\
\mathbf{elif}\;x \le -140531020550505330000:\\
\;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \frac{\left(-x \cdot x\right) \cdot \frac{1}{\left(4 \cdot p\right) \cdot p + x \cdot x} + 1 \cdot 1}{1 - x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}}}}\right)\\
\mathbf{elif}\;x \le -454354590.679686964:\\
\;\;\;\;e^{\left(\log \left(\sqrt{2} \cdot \sqrt{0.5}\right) + \log \left(\frac{-1}{x}\right)\right) - \log \left(\frac{-1}{p}\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{\sqrt{0.5 \cdot \left(1 + \left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \frac{\sqrt[3]{x}}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}}\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.1394059361264092e+138)) {
VAR = log(exp(sqrt((0.5 * (((-(x * x) * (1.0 / (((4.0 * p) * p) + (x * x)))) + (1.0 * 1.0)) / (1.0 - (x * (1.0 / sqrt((((4.0 * p) * p) + (x * x)))))))))));
} else {
double VAR_1;
if ((x <= -4.708638998895936e+125)) {
VAR_1 = exp(((log((sqrt(2.0) * sqrt(0.5))) + log((-1.0 / x))) - log((-1.0 / p))));
} else {
double VAR_2;
if ((x <= -1.4053102055050533e+20)) {
VAR_2 = log(exp(sqrt((0.5 * (((-(x * x) * (1.0 / (((4.0 * p) * p) + (x * x)))) + (1.0 * 1.0)) / (1.0 - (x * (1.0 / sqrt((((4.0 * p) * p) + (x * x)))))))))));
} else {
double VAR_3;
if ((x <= -454354590.67968696)) {
VAR_3 = exp(((log((sqrt(2.0) * sqrt(0.5))) + log((-1.0 / x))) - log((-1.0 / p))));
} else {
VAR_3 = log(exp(sqrt((0.5 * (1.0 + ((cbrt(x) * cbrt(x)) * (cbrt(x) / sqrt((((4.0 * p) * p) + (x * x))))))))));
}
VAR_2 = VAR_3;
}
VAR_1 = VAR_2;
}
VAR = VAR_1;
}
return VAR;
}




Bits error versus p




Bits error versus x
Results
| Original | 13.1 |
|---|---|
| Target | 13.1 |
| Herbie | 14.1 |
if x < -1.1394059361264092e+138 or -4.708638998895936e+125 < x < -1.4053102055050533e+20Initial program 29.6
rmApplied div-inv30.8
rmApplied add-log-exp30.8
rmApplied flip-+30.8
Simplified31.0
if -1.1394059361264092e+138 < x < -4.708638998895936e+125 or -1.4053102055050533e+20 < x < -454354590.67968696Initial program 30.2
rmApplied div-inv30.9
rmApplied add-log-exp30.9
rmApplied add-exp-log30.9
Taylor expanded around -inf 46.3
if -454354590.67968696 < x Initial program 8.1
rmApplied div-inv8.1
rmApplied add-log-exp8.1
rmApplied add-cube-cbrt8.2
Applied associate-*l*8.2
Simplified8.2
Final simplification14.1
herbie shell --seed 2020100
(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))))))))