Average Error: 30.0 → 0.2
Time: 20.2s
Precision: binary64
Cost: 13380
\[\sqrt{x + 1} - \sqrt{x} \]
\[\begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;1 \ne 0:\\ \;\;\;\;\frac{1}{t_0 + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;t_0 - \sqrt{x}\\ \end{array} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ x 1.0))))
   (if (!= 1.0 0.0) (/ 1.0 (+ t_0 (sqrt x))) (- t_0 (sqrt x)))))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
	double t_0 = sqrt((x + 1.0));
	double tmp;
	if (1.0 != 0.0) {
		tmp = 1.0 / (t_0 + sqrt(x));
	} else {
		tmp = t_0 - sqrt(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) :: t_0
    real(8) :: tmp
    t_0 = sqrt((x + 1.0d0))
    if (1.0d0 /= 0.0d0) then
        tmp = 1.0d0 / (t_0 + sqrt(x))
    else
        tmp = t_0 - sqrt(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 t_0 = Math.sqrt((x + 1.0));
	double tmp;
	if (1.0 != 0.0) {
		tmp = 1.0 / (t_0 + Math.sqrt(x));
	} else {
		tmp = t_0 - Math.sqrt(x);
	}
	return tmp;
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x):
	t_0 = math.sqrt((x + 1.0))
	tmp = 0
	if 1.0 != 0.0:
		tmp = 1.0 / (t_0 + math.sqrt(x))
	else:
		tmp = t_0 - math.sqrt(x)
	return tmp
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function code(x)
	t_0 = sqrt(Float64(x + 1.0))
	tmp = 0.0
	if (1.0 != 0.0)
		tmp = Float64(1.0 / Float64(t_0 + sqrt(x)));
	else
		tmp = Float64(t_0 - sqrt(x));
	end
	return tmp
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
function tmp_2 = code(x)
	t_0 = sqrt((x + 1.0));
	tmp = 0.0;
	if (1.0 ~= 0.0)
		tmp = 1.0 / (t_0 + sqrt(x));
	else
		tmp = t_0 - sqrt(x);
	end
	tmp_2 = tmp;
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[Unequal[1.0, 0.0], N[(1.0 / N[(t$95$0 + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]]
\sqrt{x + 1} - \sqrt{x}
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;1 \ne 0:\\
\;\;\;\;\frac{1}{t_0 + \sqrt{x}}\\

\mathbf{else}:\\
\;\;\;\;t_0 - \sqrt{x}\\


\end{array}

Error

Target

Original30.0
Target0.2
Herbie0.2
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}} \]

Derivation

  1. Initial program 30.0

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Applied egg-rr29.7

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\sqrt{x + 1} + \sqrt{x} \ne 0:\\ \;\;\;\;\frac{{\left(\sqrt{x + 1}\right)}^{2} - {\left(\sqrt{x}\right)}^{2}}{\sqrt{x + 1} + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} - \sqrt{x}\\ } \end{array}} \]
  3. Taylor expanded in x around 0 0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sqrt{x + 1} + \sqrt{x} \ne 0:\\ \;\;\;\;\frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} - \sqrt{x}\\ \end{array} \]
  4. Taylor expanded in x around 0 0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\color{blue}{\left(0.5 \cdot x + 1\right)} + \sqrt{x} \ne 0:\\ \;\;\;\;\frac{1}{\sqrt{x + 1} + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} - \sqrt{x}\\ \end{array} \]
  5. Taylor expanded in x around 0 0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\color{blue}{1} \ne 0:\\ \;\;\;\;\frac{1}{\sqrt{x + 1} + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} - \sqrt{x}\\ \end{array} \]

Alternatives

Alternative 1
Error29.3
Cost13376
\[1 - \left(\left(1 + \sqrt{x}\right) - \sqrt{x + 1}\right) \]
Alternative 2
Error30.0
Cost13120
\[\sqrt{x + 1} - \sqrt{x} \]
Alternative 3
Error30.9
Cost6848
\[0.5 \cdot x - \left(\sqrt{x} + -1\right) \]
Alternative 4
Error31.3
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2023010 
(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)))