Average Error: 19.9 → 0.3
Time: 9.9s
Precision: binary64
Cost: 13696
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\frac{\frac{1}{x \cdot {\left(1 + x\right)}^{-0.5} + \sqrt{x}}}{1 + x} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (/ (/ 1.0 (+ (* x (pow (+ 1.0 x) -0.5)) (sqrt x))) (+ 1.0 x)))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	return (1.0 / ((x * pow((1.0 + x), -0.5)) + sqrt(x))) / (1.0 + x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
real(8) function code(x)
    real(8), intent (in) :: x
    code = (1.0d0 / ((x * ((1.0d0 + x) ** (-0.5d0))) + sqrt(x))) / (1.0d0 + x)
end function
public static double code(double x) {
	return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
public static double code(double x) {
	return (1.0 / ((x * Math.pow((1.0 + x), -0.5)) + Math.sqrt(x))) / (1.0 + x);
}
def code(x):
	return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x):
	return (1.0 / ((x * math.pow((1.0 + x), -0.5)) + math.sqrt(x))) / (1.0 + x)
function code(x)
	return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0))))
end
function code(x)
	return Float64(Float64(1.0 / Float64(Float64(x * (Float64(1.0 + x) ^ -0.5)) + sqrt(x))) / Float64(1.0 + x))
end
function tmp = code(x)
	tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
end
function tmp = code(x)
	tmp = (1.0 / ((x * ((1.0 + x) ^ -0.5)) + sqrt(x))) / (1.0 + x);
end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(1.0 / N[(N[(x * N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision] + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + x), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{\frac{1}{x \cdot {\left(1 + x\right)}^{-0.5} + \sqrt{x}}}{1 + x}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.9
Target0.8
Herbie0.3
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation

  1. Initial program 19.9

    \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
  2. Applied egg-rr20.0

    \[\leadsto \color{blue}{\left(\frac{1}{x} - \frac{1}{1 + x}\right) \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}}} \]
  3. Applied egg-rr5.5

    \[\leadsto \color{blue}{\frac{\frac{1 + \left(x - x\right)}{x}}{1 + x}} \cdot \frac{1}{{x}^{-0.5} + {\left(1 + x\right)}^{-0.5}} \]
  4. Applied egg-rr0.4

    \[\leadsto \color{blue}{\frac{\frac{1}{x \cdot \left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)}}{1 + x}} \]
  5. Applied egg-rr0.3

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

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

Alternatives

Alternative 1
Error0.4
Cost26692
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{1 + x}} \leq 5 \cdot 10^{-13}:\\ \;\;\;\;\frac{0.5 \cdot \sqrt{\frac{1}{x}}}{1 + x}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \end{array} \]
Alternative 2
Error6.5
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 0.08382833180574063:\\ \;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{x} \cdot 0.5}{x \cdot \left(1 + x\right)}\\ \end{array} \]
Alternative 3
Error1.0
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 0.08382833180574063:\\ \;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 \cdot \sqrt{\frac{1}{x}}}{1 + x}\\ \end{array} \]
Alternative 4
Error20.4
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 0.08382833180574063:\\ \;\;\;\;\left({x}^{-0.5} + x \cdot 0.5\right) + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x \cdot \left(1 + x\right)}}\\ \end{array} \]
Alternative 5
Error20.5
Cost6980
\[\begin{array}{l} \mathbf{if}\;x \leq 0.08382833180574063:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x \cdot \left(1 + x\right)}}\\ \end{array} \]
Alternative 6
Error21.0
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.08382833180574063:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{x + 0.5}\right) + -1\\ \end{array} \]
Alternative 7
Error21.6
Cost6660
\[\begin{array}{l} \mathbf{if}\;x \leq 7.948415199002043 \cdot 10^{+122}:\\ \;\;\;\;{x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{x + 0.5}\right) + -1\\ \end{array} \]
Alternative 8
Error49.9
Cost576
\[\left(1 + \frac{1}{x + 0.5}\right) + -1 \]
Alternative 9
Error59.3
Cost320
\[\frac{1}{x + 0.5} \]
Alternative 10
Error59.3
Cost192
\[\frac{1}{x} \]
Alternative 11
Error60.3
Cost64
\[2 \]

Error

Reproduce

herbie shell --seed 2022297 
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))

  (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))