| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 13764 |
\[\begin{array}{l}
t_0 := x - \sqrt{x \cdot x - \varepsilon}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{-154}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\varepsilon}{x}}{2}\\
\end{array}
\]
(FPCore (x eps) :precision binary64 (- x (sqrt (- (* x x) eps))))
(FPCore (x eps) :precision binary64 (if (<= (- x (sqrt (- (* x x) eps))) -5e-154) (- x (sqrt (fma x x (- eps)))) (/ (/ eps x) 2.0)))
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))) <= -5e-154) {
tmp = x - sqrt(fma(x, x, -eps));
} else {
tmp = (eps / x) / 2.0;
}
return tmp;
}
function code(x, eps) return Float64(x - sqrt(Float64(Float64(x * x) - eps))) end
function code(x, eps) tmp = 0.0 if (Float64(x - sqrt(Float64(Float64(x * x) - eps))) <= -5e-154) tmp = Float64(x - sqrt(fma(x, x, Float64(-eps)))); else tmp = Float64(Float64(eps / x) / 2.0); end return tmp end
code[x_, eps_] := N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := If[LessEqual[N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -5e-154], N[(x - N[Sqrt[N[(x * x + (-eps)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(eps / x), $MachinePrecision] / 2.0), $MachinePrecision]]
x - \sqrt{x \cdot x - \varepsilon}
\begin{array}{l}
\mathbf{if}\;x - \sqrt{x \cdot x - \varepsilon} \leq -5 \cdot 10^{-154}:\\
\;\;\;\;x - \sqrt{\mathsf{fma}\left(x, x, -\varepsilon\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\varepsilon}{x}}{2}\\
\end{array}
| Original | 24.6 |
|---|---|
| Target | 0.3 |
| Herbie | 1.0 |
if (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) < -5.0000000000000002e-154Initial program 0.8
Simplified0.8
if -5.0000000000000002e-154 < (-.f64 x (sqrt.f64 (-.f64 (*.f64 x x) eps))) Initial program 58.7
Simplified58.7
Taylor expanded in x around inf 59.6
Applied egg-rr1.4
| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 13764 |
| Alternative 2 | |
|---|---|
| Error | 8.7 |
| Cost | 6788 |
| Alternative 3 | |
|---|---|
| Error | 35.4 |
| Cost | 320 |
| Alternative 4 | |
|---|---|
| Error | 35.3 |
| Cost | 320 |
| Alternative 5 | |
|---|---|
| Error | 61.3 |
| Cost | 64 |

herbie shell --seed 2022325
(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))))