| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13888 |
\[\frac{-1}{\left(-1 - x\right) \cdot \left({x}^{-0.5} + {\left(x + 1\right)}^{-0.5}\right)} \cdot \frac{1}{x}
\]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (if (<= x 85000000.0) (- (pow x -0.5) (pow (+ x 1.0) -0.5)) (/ (/ 1.0 x) (+ (sqrt x) (sqrt (+ x 1.0))))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
double tmp;
if (x <= 85000000.0) {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
} else {
tmp = (1.0 / x) / (sqrt(x) + sqrt((x + 1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 85000000.0d0) then
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
else
tmp = (1.0d0 / x) / (sqrt(x) + sqrt((x + 1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
public static double code(double x) {
double tmp;
if (x <= 85000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
} else {
tmp = (1.0 / x) / (Math.sqrt(x) + Math.sqrt((x + 1.0)));
}
return tmp;
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x): tmp = 0 if x <= 85000000.0: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) else: tmp = (1.0 / x) / (math.sqrt(x) + math.sqrt((x + 1.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 <= 85000000.0) tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); else tmp = Float64(Float64(1.0 / x) / Float64(sqrt(x) + sqrt(Float64(x + 1.0)))); end return tmp end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= 85000000.0) tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); else tmp = (1.0 / x) / (sqrt(x) + sqrt((x + 1.0))); end tmp_2 = 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, 85000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \leq 85000000:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{x}}{\sqrt{x} + \sqrt{x + 1}}\\
\end{array}
Results
| Original | 19.6 |
|---|---|
| Target | 0.6 |
| Herbie | 0.4 |
if x < 8.5e7Initial program 0.6
Applied egg-rr0.3
Simplified0.3
[Start]0.3 | \[ {x}^{-0.5} + \left(-{\left(1 + x\right)}^{-0.5}\right)
\] |
|---|---|
sub-neg [<=]0.3 | \[ \color{blue}{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}
\] |
if 8.5e7 < x Initial program 39.4
Applied egg-rr10.5
Taylor expanded in x around inf 0.5
Applied egg-rr1.3
Simplified0.5
[Start]1.3 | \[ {\left(x \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)\right)}^{-1}
\] |
|---|---|
unpow-1 [=>]1.3 | \[ \color{blue}{\frac{1}{x \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}}
\] |
associate-/r* [=>]0.5 | \[ \color{blue}{\frac{\frac{1}{x}}{\sqrt{x} + \sqrt{1 + x}}}
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13888 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 13760 |
| Alternative 3 | |
|---|---|
| Error | 0.8 |
| Cost | 13508 |
| Alternative 4 | |
|---|---|
| Error | 5.0 |
| Cost | 13380 |
| Alternative 5 | |
|---|---|
| Error | 5.6 |
| Cost | 7364 |
| Alternative 6 | |
|---|---|
| Error | 17.9 |
| Cost | 7108 |
| Alternative 7 | |
|---|---|
| Error | 18.0 |
| Cost | 6980 |
| Alternative 8 | |
|---|---|
| Error | 20.6 |
| Cost | 6916 |
| Alternative 9 | |
|---|---|
| Error | 30.1 |
| Cost | 6788 |
| Alternative 10 | |
|---|---|
| Error | 30.5 |
| Cost | 6720 |
| Alternative 11 | |
|---|---|
| Error | 31.8 |
| Cost | 6528 |
| Alternative 12 | |
|---|---|
| Error | 59.3 |
| Cost | 192 |
herbie shell --seed 2023018
(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)))))