(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (sqrt (expm1 (log1p (pow (+ (sqrt (+ 1.0 x)) (sqrt x)) -2.0)))))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
return sqrt(expm1(log1p(pow((sqrt((1.0 + x)) + sqrt(x)), -2.0))));
}
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
return Math.sqrt(Math.expm1(Math.log1p(Math.pow((Math.sqrt((1.0 + x)) + Math.sqrt(x)), -2.0))));
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): return math.sqrt(math.expm1(math.log1p(math.pow((math.sqrt((1.0 + x)) + math.sqrt(x)), -2.0))))
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) return sqrt(expm1(log1p((Float64(sqrt(Float64(1.0 + x)) + sqrt(x)) ^ -2.0)))) end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[Sqrt[N[(Exp[N[Log[1 + N[Power[N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\sqrt{1 + x} + \sqrt{x}\right)}^{-2}\right)\right)}
Results
| Original | 29.2 |
|---|---|
| Target | 0.2 |
| Herbie | 0.2 |
Initial program 29.2
Applied egg-rr28.6
Taylor expanded in x around 0 0.2
Applied egg-rr0.2
Applied egg-rr0.2
Final simplification0.2
herbie shell --seed 2022185
(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)))