(FPCore (x eps) :precision binary64 (- x (sqrt (- (* x x) eps))))
(FPCore (x eps) :precision binary64 (/ (+ (- (* x x) (* x x)) eps) (+ x (sqrt (fma x x (- eps))))))
double code(double x, double eps) {
return x - sqrt(((x * x) - eps));
}
double code(double x, double eps) {
return (((x * x) - (x * x)) + eps) / (x + sqrt(fma(x, x, -eps)));
}
function code(x, eps) return Float64(x - sqrt(Float64(Float64(x * x) - eps))) end
function code(x, eps) return Float64(Float64(Float64(Float64(x * x) - Float64(x * x)) + eps) / Float64(x + sqrt(fma(x, x, Float64(-eps))))) end
code[x_, eps_] := N[(x - N[Sqrt[N[(N[(x * x), $MachinePrecision] - eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, eps_] := N[(N[(N[(N[(x * x), $MachinePrecision] - N[(x * x), $MachinePrecision]), $MachinePrecision] + eps), $MachinePrecision] / N[(x + N[Sqrt[N[(x * x + (-eps)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x - \sqrt{x \cdot x - \varepsilon}
\frac{\left(x \cdot x - x \cdot x\right) + \varepsilon}{x + \sqrt{\mathsf{fma}\left(x, x, -\varepsilon\right)}}
| Original | 23.3 |
|---|---|
| Target | 0.3 |
| Herbie | 0.3 |
Initial program 23.3
Applied egg-rr0.3
Taylor expanded in x around 0 0.3
Simplified0.3
Final simplification0.3
herbie shell --seed 2022210
(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))))