| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 13248 |
\[\frac{1}{\sqrt{1 + x} + \sqrt{x}}
\]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x) :precision binary64 (if (<= x 0.006821137785407271) (- (sqrt (+ 1.0 x)) (sqrt x)) (/ 1.0 (/ 1.0 (* 0.5 (sqrt (/ 1.0 x)))))))
double code(double x) {
return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
double tmp;
if (x <= 0.006821137785407271) {
tmp = sqrt((1.0 + x)) - sqrt(x);
} else {
tmp = 1.0 / (1.0 / (0.5 * sqrt((1.0 / x))));
}
return tmp;
}
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
real(8) :: tmp
if (x <= 0.006821137785407271d0) then
tmp = sqrt((1.0d0 + x)) - sqrt(x)
else
tmp = 1.0d0 / (1.0d0 / (0.5d0 * sqrt((1.0d0 / x))))
end if
code = tmp
end function
public static double code(double x) {
return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
public static double code(double x) {
double tmp;
if (x <= 0.006821137785407271) {
tmp = Math.sqrt((1.0 + x)) - Math.sqrt(x);
} else {
tmp = 1.0 / (1.0 / (0.5 * Math.sqrt((1.0 / x))));
}
return tmp;
}
def code(x): return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x): tmp = 0 if x <= 0.006821137785407271: tmp = math.sqrt((1.0 + x)) - math.sqrt(x) else: tmp = 1.0 / (1.0 / (0.5 * math.sqrt((1.0 / x)))) return tmp
function code(x) return Float64(sqrt(Float64(x + 1.0)) - sqrt(x)) end
function code(x) tmp = 0.0 if (x <= 0.006821137785407271) tmp = Float64(sqrt(Float64(1.0 + x)) - sqrt(x)); else tmp = Float64(1.0 / Float64(1.0 / Float64(0.5 * sqrt(Float64(1.0 / x))))); end return tmp end
function tmp = code(x) tmp = sqrt((x + 1.0)) - sqrt(x); end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.006821137785407271) tmp = sqrt((1.0 + x)) - sqrt(x); else tmp = 1.0 / (1.0 / (0.5 * sqrt((1.0 / x)))); end tmp_2 = tmp; end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := If[LessEqual[x, 0.006821137785407271], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 / N[(0.5 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\sqrt{x + 1} - \sqrt{x}
\begin{array}{l}
\mathbf{if}\;x \leq 0.006821137785407271:\\
\;\;\;\;\sqrt{1 + x} - \sqrt{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{1}{0.5 \cdot \sqrt{\frac{1}{x}}}}\\
\end{array}
Results
| Original | 29.4 |
|---|---|
| Target | 0.2 |
| Herbie | 0.9 |
if x < 0.00682113778540727102Initial program 0.0
if 0.00682113778540727102 < x Initial program 59.2
Applied egg-rr57.9
Taylor expanded in x around 0 0.3
Applied egg-rr19.8
Taylor expanded in x around inf 1.8
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 0.2 |
| Cost | 13248 |
| Alternative 2 | |
|---|---|
| Error | 1.1 |
| Cost | 7108 |
| Alternative 3 | |
|---|---|
| Error | 1.1 |
| Cost | 6980 |
| Alternative 4 | |
|---|---|
| Error | 2.1 |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Error | 1.4 |
| Cost | 6852 |
| Alternative 6 | |
|---|---|
| Error | 30.7 |
| Cost | 64 |

herbie shell --seed 2022306
(FPCore (x)
:name "Main:bigenough3 from C"
:precision binary64
:herbie-target
(/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))
(- (sqrt (+ x 1.0)) (sqrt x)))