Average Error: 19.7 → 0.1
Time: 3.6s
Precision: binary64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 7800:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x} \cdot \left(\frac{0.3125}{x \cdot x} + \left(0.5 + \frac{-0.375}{x}\right)\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x 7800.0)
   (- (pow x -0.5) (pow (+ x 1.0) -0.5))
   (* (/ (pow x -0.5) x) (+ (/ 0.3125 (* x x)) (+ 0.5 (/ -0.375 x))))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	double tmp;
	if (x <= 7800.0) {
		tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
	} else {
		tmp = (pow(x, -0.5) / x) * ((0.3125 / (x * x)) + (0.5 + (-0.375 / x)));
	}
	return tmp;
}
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
    real(8) :: tmp
    if (x <= 7800.0d0) then
        tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
    else
        tmp = ((x ** (-0.5d0)) / x) * ((0.3125d0 / (x * x)) + (0.5d0 + ((-0.375d0) / x)))
    end if
    code = tmp
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) {
	double tmp;
	if (x <= 7800.0) {
		tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
	} else {
		tmp = (Math.pow(x, -0.5) / x) * ((0.3125 / (x * x)) + (0.5 + (-0.375 / x)));
	}
	return tmp;
}
def code(x):
	return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x):
	tmp = 0
	if x <= 7800.0:
		tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5)
	else:
		tmp = (math.pow(x, -0.5) / x) * ((0.3125 / (x * x)) + (0.5 + (-0.375 / x)))
	return tmp
function code(x)
	return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0))))
end
function code(x)
	tmp = 0.0
	if (x <= 7800.0)
		tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5));
	else
		tmp = Float64(Float64((x ^ -0.5) / x) * Float64(Float64(0.3125 / Float64(x * x)) + Float64(0.5 + Float64(-0.375 / x))));
	end
	return tmp
end
function tmp = code(x)
	tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 7800.0)
		tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5);
	else
		tmp = ((x ^ -0.5) / x) * ((0.3125 / (x * x)) + (0.5 + (-0.375 / x)));
	end
	tmp_2 = tmp;
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_] := If[LessEqual[x, 7800.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[x, -0.5], $MachinePrecision] / x), $MachinePrecision] * N[(N[(0.3125 / N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(0.5 + N[(-0.375 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \leq 7800:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;\frac{{x}^{-0.5}}{x} \cdot \left(\frac{0.3125}{x \cdot x} + \left(0.5 + \frac{-0.375}{x}\right)\right)\\


\end{array}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 0.4

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

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

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

    if 7800 < x

    1. Initial program 40.1

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

      \[\leadsto \color{blue}{{\left(\sqrt[3]{{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}}\right)}^{3}} \]
    3. Applied egg-rr40.0

      \[\leadsto \color{blue}{{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}} \]
    4. Taylor expanded in x around -inf 64.0

      \[\leadsto \color{blue}{\left(0.5 \cdot \frac{e^{-0.5 \cdot \left(\log -1 - \log \left(\frac{-1}{x}\right)\right)}}{x} + 0.3125 \cdot \frac{e^{-0.5 \cdot \left(\log -1 - \log \left(\frac{-1}{x}\right)\right)}}{{x}^{3}}\right) - 0.375 \cdot \frac{e^{-0.5 \cdot \left(\log -1 - \log \left(\frac{-1}{x}\right)\right)}}{{x}^{2}}} \]
    5. Simplified0.2

      \[\leadsto \color{blue}{\frac{{x}^{-0.5}}{x} \cdot \left(\frac{0.3125}{x \cdot x} - \left(\frac{0.375}{x} + -0.5\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7800:\\ \;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{{x}^{-0.5}}{x} \cdot \left(\frac{0.3125}{x \cdot x} + \left(0.5 + \frac{-0.375}{x}\right)\right)\\ \end{array} \]

Reproduce

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