?

Average Error: 30.24% → 0.64%
Time: 11.5s
Precision: binary64
Cost: 13760

?

\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\frac{\frac{-1}{x \cdot \left({\left(x + 1\right)}^{-0.5} + {x}^{-0.5}\right)}}{-1 - x} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (/ (/ -1.0 (* x (+ (pow (+ x 1.0) -0.5) (pow x -0.5)))) (- -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((x + 1.0), -0.5) + pow(x, -0.5)))) / (-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 * (((x + 1.0d0) ** (-0.5d0)) + (x ** (-0.5d0))))) / ((-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((x + 1.0), -0.5) + Math.pow(x, -0.5)))) / (-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((x + 1.0), -0.5) + math.pow(x, -0.5)))) / (-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(x * Float64((Float64(x + 1.0) ^ -0.5) + (x ^ -0.5)))) / 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 * (((x + 1.0) ^ -0.5) + (x ^ -0.5)))) / (-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[(x * N[(N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision] + N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{\frac{-1}{x \cdot \left({\left(x + 1\right)}^{-0.5} + {x}^{-0.5}\right)}}{-1 - x}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.24%
Target1.03%
Herbie0.64%
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation?

  1. Initial program 30.24

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

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

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

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

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

    [Start]29.57

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

    +-commutative [=>]29.57

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

    associate-+l- [=>]9.25

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

    +-inverses [=>]9.25

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

    metadata-eval [=>]9.25

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

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

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

Alternatives

Alternative 1
Error0.65%
Cost27204
\[\begin{array}{l} t_0 := \sqrt{x + 1}\\ t_1 := \frac{-1}{t_0}\\ \mathbf{if}\;\frac{1}{\sqrt{x}} + t_1 \leq 10^{-12}:\\ \;\;\;\;\frac{\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x}}{\sqrt{x} + t_0}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-0.5} + t_1\\ \end{array} \]
Alternative 2
Error0.66%
Cost13760
\[\frac{\frac{-1}{x}}{\left({\left(x + 1\right)}^{-0.5} + {x}^{-0.5}\right) \cdot \left(-1 - x\right)} \]
Alternative 3
Error8.53%
Cost13444
\[\begin{array}{l} \mathbf{if}\;x \leq 38000000:\\ \;\;\;\;{x}^{-0.5} + \frac{-1}{\sqrt{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{x} \cdot 0.5\right) \cdot \frac{\frac{1 + \left(x - x\right)}{x}}{x + 1}\\ \end{array} \]
Alternative 4
Error8.53%
Cost13380
\[\begin{array}{l} \mathbf{if}\;x \leq 47000000:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{x} \cdot 0.5\right) \cdot \frac{\frac{1 + \left(x - x\right)}{x}}{x + 1}\\ \end{array} \]
Alternative 5
Error9.41%
Cost7492
\[\begin{array}{l} \mathbf{if}\;x \leq 1.2:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{x} \cdot 0.5\right) \cdot \frac{\frac{1 + \left(x - x\right)}{x}}{x + 1}\\ \end{array} \]
Alternative 6
Error10.09%
Cost7236
\[\begin{array}{l} \mathbf{if}\;x \leq 1.2:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{x} \cdot 0.5\right) \cdot \frac{-1}{x \cdot \left(-1 - x\right)}\\ \end{array} \]
Alternative 7
Error10.15%
Cost7172
\[\begin{array}{l} \mathbf{if}\;x \leq 1.7:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{x} \cdot 0.5\right) \cdot \frac{1}{x \cdot x}\\ \end{array} \]
Alternative 8
Error10.17%
Cost7108
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} - \left(1 + x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\sqrt{x} \cdot 0.5\right) \cdot \frac{1}{x \cdot x}\\ \end{array} \]
Alternative 9
Error31.22%
Cost7044
\[\begin{array}{l} \mathbf{if}\;x \leq 2:\\ \;\;\;\;{x}^{-0.5} - \left(1 + x \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;{\left(x \cdot x\right)}^{-0.25}\\ \end{array} \]
Alternative 10
Error45.92%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \left(x - x\right)\right) \cdot \left(\frac{1}{x} + \frac{-0.5}{x \cdot x}\right)\\ \end{array} \]
Alternative 11
Error31.53%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.8:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;{\left(x \cdot x\right)}^{-0.25}\\ \end{array} \]
Alternative 12
Error48.53%
Cost6528
\[{x}^{-0.5} \]
Alternative 13
Error92.6%
Cost704
\[\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x + 0.5} \]
Alternative 14
Error92.62%
Cost576
\[\left(1 + \left(x - x\right)\right) \cdot \frac{1}{x} \]

Error

Reproduce?

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