| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 13248 |
\[\frac{1}{\sqrt{x} + \sqrt{1 + x}}
\]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (pow (+ (sqrt x) (sqrt (+ 1.0 x))) -1.0))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
return pow((sqrt(x) + sqrt((1.0 + x))), -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x + 1.0d0)) - sqrt(x)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = (sqrt(x) + sqrt((1.0d0 + x))) ** (-1.0d0)
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
return Math.pow((Math.sqrt(x) + Math.sqrt((1.0 + x))), -1.0);
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): return math.pow((math.sqrt(x) + math.sqrt((1.0 + x))), -1.0)
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) return Float64(sqrt(x) + sqrt(Float64(1.0 + x))) ^ -1.0 end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
function tmp = code(x) tmp = (sqrt(x) + sqrt((1.0 + x))) ^ -1.0; end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[Power[N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
{\left(\sqrt{x} + \sqrt{1 + x}\right)}^{-1}
Results
| Original | 29.5 |
|---|---|
| Target | 0.2 |
| Herbie | 0.2 |
Initial program 29.5
Applied egg-rr28.8
Taylor expanded in x around 0 0.2
Applied egg-rr0.2
Final simplification0.2
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Error | 26.6 |
| Cost | 6912 |
| Alternative 3 | |
|---|---|
| Error | 26.4 |
| Cost | 6720 |
| Alternative 4 | |
|---|---|
| Error | 30.8 |
| Cost | 64 |

herbie shell --seed 2022308
(FPCore (x)
:name "2sqrt (example 3.1)"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))