\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\begin{array}{l}
t_0 := \frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}}\\
\mathbf{if}\;t_0 \leq -0.9999999999987923:\\
\;\;\;\;\left|\frac{p}{x}\right|\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \log \left(e^{t_0 + 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
(let* ((t_0 (/ x (sqrt (+ (* p (* 4.0 p)) (* x x))))))
(if (<= t_0 -0.9999999999987923)
(fabs (/ p x))
(sqrt (* 0.5 (log (exp (+ t_0 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 t_0 = x / sqrt((p * (4.0 * p)) + (x * x));
double tmp;
if (t_0 <= -0.9999999999987923) {
tmp = fabs(p / x);
} else {
tmp = sqrt(0.5 * log(exp(t_0 + 1.0)));
}
return tmp;
}




Bits error versus p




Bits error versus x
Results
| Original | 13.5 |
|---|---|
| Target | 13.5 |
| Herbie | 0.1 |
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.9999999999987923Initial program 53.5
Taylor expanded around -inf 31.2
Simplified22.9
rmApplied add-sqr-sqrt_binary6423.1
Simplified23.0
Simplified0.5
rmApplied rem-square-sqrt_binary640.0
if -0.9999999999987923 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 0.1
rmApplied add-log-exp_binary640.1
Final simplification0.1
herbie shell --seed 2021205
(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))))))))