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




Bits error versus p




Bits error versus x
Results
| Original | 13.2 |
|---|---|
| Target | 13.2 |
| Herbie | 5.8 |
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 53.4
Taylor expanded around -inf 31.1
Simplified23.2
rmApplied associate-/l*_binary64_275123.1
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 0.2
rmApplied add-log-exp_binary64_28450.2
Applied add-log-exp_binary64_28450.2
Applied sum-log_binary64_28970.2
Simplified0.2
rmApplied add-sqr-sqrt_binary64_28280.2
Applied log-prod_binary64_28920.2
Final simplification5.8
herbie shell --seed 2021044
(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))))))))