\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 -1:\\
\;\;\;\;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 temp;
if (((x / sqrt((((4.0 * p) * p) + (x * x)))) <= -1.0)) {
temp = exp(((log((sqrt(2.0) * sqrt(0.5))) + log((-1.0 / x))) - log((-1.0 / p))));
} else {
temp = sqrt((0.5 * (1.0 + log(exp((x / sqrt((((4.0 * p) * p) + (x * x)))))))));
}
return temp;
}




Bits error versus p




Bits error versus x
Results
| Original | 13.6 |
|---|---|
| Target | 13.6 |
| Herbie | 8.4 |
if (/ x (sqrt (+ (* (* 4.0 p) p) (* x x)))) < -1.0Initial program 54.4
rmApplied div-inv55.2
rmApplied add-log-exp55.2
rmApplied add-exp-log55.2
Taylor expanded around -inf 33.5
if -1.0 < (/ x (sqrt (+ (* (* 4.0 p) p) (* x x)))) Initial program 0.2
rmApplied add-log-exp0.2
Final simplification8.4
herbie shell --seed 2020057 +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))))))))