Average Error: 29.4 → 0.2
Time: 6.0s
Precision: binary64
Cost: 26048
\[\sqrt{x + 1} - \sqrt{x} \]
\[{\left({\left(\sqrt{x} + \sqrt{1 + x}\right)}^{2}\right)}^{-0.5} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x)
 :precision binary64
 (pow (pow (+ (sqrt x) (sqrt (+ 1.0 x))) 2.0) -0.5))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
double code(double x) {
	return pow(pow((sqrt(x) + sqrt((1.0 + x))), 2.0), -0.5);
}
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))) ** 2.0d0) ** (-0.5d0)
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.pow((Math.sqrt(x) + Math.sqrt((1.0 + x))), 2.0), -0.5);
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
def code(x):
	return math.pow(math.pow((math.sqrt(x) + math.sqrt((1.0 + x))), 2.0), -0.5)
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))) ^ 2.0) ^ -0.5
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
function tmp = code(x)
	tmp = ((sqrt(x) + sqrt((1.0 + x))) ^ 2.0) ^ -0.5;
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
code[x_] := N[Power[N[Power[N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], -0.5], $MachinePrecision]
\sqrt{x + 1} - \sqrt{x}
{\left({\left(\sqrt{x} + \sqrt{1 + x}\right)}^{2}\right)}^{-0.5}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 29.4

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Applied egg-rr28.8

    \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{\sqrt{x + 1} + \sqrt{x}}} \]
  3. Applied egg-rr28.9

    \[\leadsto \frac{x + \left(1 - x\right)}{\color{blue}{{\left({\left(x + 1\right)}^{1.5}\right)}^{0.3333333333333333}} + \sqrt{x}} \]
  4. Taylor expanded in x around 0 11.5

    \[\leadsto \frac{\color{blue}{1}}{{\left({\left(x + 1\right)}^{1.5}\right)}^{0.3333333333333333} + \sqrt{x}} \]
  5. Applied egg-rr0.2

    \[\leadsto \color{blue}{{\left({\left(\sqrt{1 + x} + \sqrt{x}\right)}^{2}\right)}^{-0.5}} \]
  6. Final simplification0.2

    \[\leadsto {\left({\left(\sqrt{x} + \sqrt{1 + x}\right)}^{2}\right)}^{-0.5} \]

Alternatives

Alternative 1
Error0.4
Cost13252
\[\begin{array}{l} \mathbf{if}\;x \leq 14707591.402461676:\\ \;\;\;\;\sqrt{1 + x} - \sqrt{x}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\ \end{array} \]
Alternative 2
Error0.2
Cost13248
\[\frac{1}{\sqrt{x} + \sqrt{1 + x}} \]
Alternative 3
Error1.0
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 0.0029421815227809534:\\ \;\;\;\;1 + \left(x \cdot 0.5 - \sqrt{x}\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\ \end{array} \]
Alternative 4
Error1.4
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 0.0029421815227809534:\\ \;\;\;\;\frac{1}{1 + \sqrt{x}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \sqrt{\frac{1}{x}}\\ \end{array} \]
Alternative 5
Error26.3
Cost6720
\[\frac{1}{1 + \sqrt{x}} \]
Alternative 6
Error30.8
Cost64
\[1 \]

Error

Reproduce

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