\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}\;\frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}} \le -0.99999999999685452:\\
\;\;\;\;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}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \log \left(e^{\frac{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 / sqrt((((4.0 * p) * p) + (x * x)))) <= -0.9999999999968545)) {
VAR = exp(((log((sqrt(2.0) * sqrt(0.5))) + log((-1.0 / x))) - log((-1.0 / p))));
} else {
VAR = sqrt((0.5 * (1.0 + log(exp((x / sqrt((((4.0 * p) * p) + (x * x)))))))));
}
return VAR;
}




Bits error versus p




Bits error versus x
Results
| Original | 13.3 |
|---|---|
| Target | 13.3 |
| Herbie | 8.5 |
if (/ x (sqrt (+ (* (* 4.0 p) p) (* x x)))) < -0.9999999999968545Initial program 54.2
rmApplied div-inv55.4
rmApplied add-log-exp55.4
rmApplied add-exp-log55.4
Taylor expanded around -inf 34.6
if -0.9999999999968545 < (/ x (sqrt (+ (* (* 4.0 p) p) (* x x)))) Initial program 0.1
rmApplied add-log-exp0.1
Final simplification8.5
herbie shell --seed 2020103
(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))))))))