\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{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.9999999996172134:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot {\left(\frac{-1}{x} \cdot \left(-p\right)\right)}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot e^{\log \left(\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} + 1\right)}}\\
\end{array}(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
(FPCore (p x)
:precision binary64
(if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9999999996172134)
(sqrt (* 0.5 (* 2.0 (pow (* (/ -1.0 x) (- p)) 2.0))))
(sqrt
(* 0.5 (exp (log (+ (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) 1.0)))))))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 tmp;
if ((x / sqrt((p * (4.0 * p)) + (x * x))) <= -0.9999999996172134) {
tmp = sqrt(0.5 * (2.0 * pow(((-1.0 / x) * -p), 2.0)));
} else {
tmp = sqrt(0.5 * exp(log((x / sqrt((p * (4.0 * p)) + (x * x))) + 1.0)));
}
return tmp;
}




Bits error versus p




Bits error versus x
Results
| Original | 13.4 |
|---|---|
| Target | 13.4 |
| Herbie | 5.6 |
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99999999961721342Initial program 53.7
rmApplied add-exp-log_binary64_216253.7
Simplified53.7
Taylor expanded around -inf 44.9
Simplified22.3
if -0.99999999961721342 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 0.1
rmApplied add-exp-log_binary64_21620.1
Simplified0.1
Final simplification5.6
herbie shell --seed 2020346
(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.0 (/ (* 2.0 p) x)))))
(sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))