\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:\\
\;\;\;\;\sqrt{0.5 \cdot \frac{{\left(\frac{-1}{x}\right)}^{2}}{\frac{{\left(\frac{-1}{p}\right)}^{2}}{2}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + x \cdot \frac{1}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\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)))) <= -1.0)) {
VAR = sqrt((0.5 * (pow((-1.0 / x), 2.0) / (pow((-1.0 / p), 2.0) / 2.0))));
} else {
VAR = sqrt((0.5 * (1.0 + (x * (1.0 / 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 | 7.8 |
if (/ x (sqrt (+ (* (* 4.0 p) p) (* x x)))) < -1.0Initial program 53.8
rmApplied add-exp-log53.8
rmApplied pow153.8
Applied log-pow53.8
Applied exp-prod53.8
Simplified53.8
Taylor expanded around -inf 44.9
Simplified31.4
if -1.0 < (/ x (sqrt (+ (* (* 4.0 p) p) (* x x)))) Initial program 0.2
rmApplied div-inv0.2
Final simplification7.8
herbie shell --seed 2020102 +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))))))))