| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13888 |
\[\frac{1}{x} \cdot \frac{1}{\left(1 + x\right) \cdot \left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)}
\]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (if (<= x 5e+41) (/ 1.0 (* (+ (pow x -0.5) (pow (+ 1.0 x) -0.5)) (* x (+ 1.0 x)))) (/ (pow x -0.5) (fma x 2.0 2.0))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
double tmp;
if (x <= 5e+41) {
tmp = 1.0 / ((pow(x, -0.5) + pow((1.0 + x), -0.5)) * (x * (1.0 + x)));
} else {
tmp = pow(x, -0.5) / fma(x, 2.0, 2.0);
}
return tmp;
}
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) tmp = 0.0 if (x <= 5e+41) tmp = Float64(1.0 / Float64(Float64((x ^ -0.5) + (Float64(1.0 + x) ^ -0.5)) * Float64(x * Float64(1.0 + x)))); else tmp = Float64((x ^ -0.5) / fma(x, 2.0, 2.0)); end return tmp end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, 5e+41], N[(1.0 / N[(N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] * N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] / N[(x * 2.0 + 2.0), $MachinePrecision]), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{+41}:\\
\;\;\;\;\frac{1}{\left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{\mathsf{fma}\left(x, 2, 2\right)}\\
\end{array}
| Original | 19.8 |
|---|---|
| Target | 0.7 |
| Herbie | 0.3 |
if x < 5.00000000000000022e41Initial program 5.9
Applied egg-rr6.1
Applied egg-rr0.5
Applied egg-rr10.5
Simplified0.5
if 5.00000000000000022e41 < x Initial program 37.9
Applied egg-rr37.9
Taylor expanded in x around inf 37.9
Applied egg-rr11.1
Applied egg-rr0.2
Simplified0.1
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13888 |
| Alternative 2 | |
|---|---|
| Error | 0.4 |
| Cost | 13444 |
| Alternative 3 | |
|---|---|
| Error | 0.4 |
| Cost | 13380 |
| Alternative 4 | |
|---|---|
| Error | 1.0 |
| Cost | 13316 |
| Alternative 5 | |
|---|---|
| Error | 1.2 |
| Cost | 7044 |
| Alternative 6 | |
|---|---|
| Error | 1.0 |
| Cost | 7044 |
| Alternative 7 | |
|---|---|
| Error | 1.3 |
| Cost | 6852 |
| Alternative 8 | |
|---|---|
| Error | 30.1 |
| Cost | 6788 |
| Alternative 9 | |
|---|---|
| Error | 59.3 |
| Cost | 192 |
| Alternative 10 | |
|---|---|
| Error | 62.8 |
| Cost | 64 |

herbie shell --seed 2022318
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))