x - \sqrt{x \cdot x - \varepsilon}
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -1.1367628655699785 \cdot 10^{-152}:\\
\;\;\;\;\frac{1}{\frac{x + \mathsf{hypot}\left(\sqrt{-\varepsilon}, x\right)}{\varepsilon}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\varepsilon}{\mathsf{fma}\left(x, 2, \frac{\varepsilon}{x} \cdot -0.5\right)}\\
\end{array}
(FPCore (x eps) :precision binary64 (- x (sqrt (- (* x x) eps))))
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -1.1367628655699785e-152) (/ 1.0 (/ (+ x (hypot (sqrt (- eps)) x)) eps)) (/ eps (fma x 2.0 (* (/ eps x) -0.5)))))
double code(double x, double eps) {
return x - sqrt(((x * x) - eps));
}
double code(double x, double eps) {
double tmp;
if ((x - sqrt(((x * x) - eps))) <= -1.1367628655699785e-152) {
tmp = 1.0 / ((x + hypot(sqrt(-eps), x)) / eps);
} else {
tmp = eps / fma(x, 2.0, ((eps / x) * -0.5));
}
return tmp;
}




Bits error versus x




Bits error versus eps
| Original | 23.9 |
|---|---|
| Target | 0.3 |
| Herbie | 0.8 |
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -1.1367628655699785e-152Initial program 0.7
Applied flip--_binary640.8
Simplified0.5
Simplified0.5
Applied add-sqr-sqrt_binary640.7
Applied associate-/r*_binary640.6
Applied *-un-lft-identity_binary640.6
Applied *-un-lft-identity_binary640.6
Applied times-frac_binary640.6
Applied associate-/l*_binary640.7
Simplified0.5
if -1.1367628655699785e-152 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 58.2
Applied flip--_binary6458.2
Simplified0.0
Simplified34.3
Taylor expanded in x around inf 35.1
Simplified1.3
Final simplification0.8
herbie shell --seed 2022125
(FPCore (x eps)
:name "ENA, Section 1.4, Exercise 4d"
:precision binary64
:pre (and (and (<= 0.0 x) (<= x 1000000000.0)) (and (<= -1.0 eps) (<= eps 1.0)))
:herbie-target
(/ eps (+ x (sqrt (- (* x x) eps))))
(- x (sqrt (- (* x x) eps))))