Average Error: 29.4 → 0.9
Time: 5.1s
Precision: binary64
Cost: 13252
\[\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} \]
(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}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original29.4
Target0.2
Herbie0.9
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}} \]

Derivation

  1. Split input into 2 regimes
  2. if x < 0.00682113778540727102

    1. Initial program 0.0

      \[\sqrt{x + 1} - \sqrt{x} \]

    if 0.00682113778540727102 < x

    1. Initial program 59.2

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Applied egg-rr57.9

      \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{\sqrt{x + 1} + \sqrt{x}}} \]
    3. Taylor expanded in x around 0 0.3

      \[\leadsto \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}} \]
    4. Applied egg-rr19.8

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{\left(\left(x + 1\right) + x\right) - \mathsf{hypot}\left(x, \sqrt{x}\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}}}}} \]
    5. Taylor expanded in x around inf 1.8

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \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} \]

Alternatives

Alternative 1
Error0.2
Cost13248
\[\frac{1}{\sqrt{1 + x} + \sqrt{x}} \]
Alternative 2
Error1.1
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006821137785407271:\\ \;\;\;\;1 + \left(x \cdot 0.5 - \sqrt{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{1}{0.5 \cdot \sqrt{\frac{1}{x}}}}\\ \end{array} \]
Alternative 3
Error1.1
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006821137785407271:\\ \;\;\;\;1 + \left(x \cdot 0.5 - \sqrt{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 4
Error2.1
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006821137785407271:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 5
Error1.4
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 0.006821137785407271:\\ \;\;\;\;\frac{1}{1 + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x} \cdot 2}\\ \end{array} \]
Alternative 6
Error30.7
Cost64
\[1 \]

Error

Reproduce

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)))