Average Error: 20.1 → 0.1
Time: 9.9s
Precision: binary64
Cost: 26688
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\frac{{x}^{-0.5}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{{x}^{-0.5}}{x + 1} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (*
  (/ (pow x -0.5) (+ (pow x -0.5) (pow (+ x 1.0) -0.5)))
  (/ (pow x -0.5) (+ x 1.0))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	return (pow(x, -0.5) / (pow(x, -0.5) + pow((x + 1.0), -0.5))) * (pow(x, -0.5) / (x + 1.0));
}
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 = ((x ** (-0.5d0)) / ((x ** (-0.5d0)) + ((x + 1.0d0) ** (-0.5d0)))) * ((x ** (-0.5d0)) / (x + 1.0d0))
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 (Math.pow(x, -0.5) / (Math.pow(x, -0.5) + Math.pow((x + 1.0), -0.5))) * (Math.pow(x, -0.5) / (x + 1.0));
}
def code(x):
	return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x):
	return (math.pow(x, -0.5) / (math.pow(x, -0.5) + math.pow((x + 1.0), -0.5))) * (math.pow(x, -0.5) / (x + 1.0))
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((x ^ -0.5) / Float64((x ^ -0.5) + (Float64(x + 1.0) ^ -0.5))) * Float64((x ^ -0.5) / Float64(x + 1.0)))
end
function tmp = code(x)
	tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
end
function tmp = code(x)
	tmp = ((x ^ -0.5) / ((x ^ -0.5) + ((x + 1.0) ^ -0.5))) * ((x ^ -0.5) / (x + 1.0));
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[(N[Power[x, -0.5], $MachinePrecision] / N[(N[Power[x, -0.5], $MachinePrecision] + N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{{x}^{-0.5}}{{x}^{-0.5} + {\left(x + 1\right)}^{-0.5}} \cdot \frac{{x}^{-0.5}}{x + 1}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.1
Target0.7
Herbie0.1
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation

  1. Initial program 20.1

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

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

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

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

    [Start]5.8

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

    associate-/r/ [=>]5.8

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

    +-commutative [=>]5.8

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

    +-inverses [=>]5.8

    \[ \frac{1}{\left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right) \cdot \left(x + x \cdot x\right)} \cdot \left(\color{blue}{0} + 1\right) \]

    metadata-eval [=>]5.8

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

    associate-/r/ [<=]5.8

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

    /-rgt-identity [=>]5.8

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

    distribute-rgt1-in [=>]5.8

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

    +-commutative [<=]5.8

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

    associate-*r* [=>]0.9

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

    associate-/l/ [<=]0.4

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

    *-commutative [=>]0.4

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

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

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

Alternatives

Alternative 1
Error0.2
Cost27076
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{\sqrt{x + 1}} \leq 2 \cdot 10^{-9}:\\ \;\;\;\;\frac{\frac{1}{x}}{\sqrt{\frac{1}{x}} \cdot 1.5 + \sqrt{x} \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \end{array} \]
Alternative 2
Error0.4
Cost13696
\[\frac{\frac{1}{x}}{{x}^{-0.5} \cdot \left(x + 1\right) + \sqrt{x + 1}} \]
Alternative 3
Error0.3
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 125000000:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 4
Error1.0
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 - x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 5
Error2.1
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.5:\\ \;\;\;\;{x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 6
Error1.2
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;{x}^{-0.5} + -1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-1.5}\\ \end{array} \]
Alternative 7
Error31.7
Cost6528
\[{x}^{-0.5} \]

Error

Reproduce

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