?

Average Error: 69.2% → 99.6%
Time: 21.5s
Precision: binary64
Cost: 13380.00

?

\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 160000:\\ \;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{x} - \frac{0.375}{x \cdot x}}{\sqrt{x}}\\ \end{array} \]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x 160000.0)
   (- (pow x -0.5) (pow (+ 1.0 x) -0.5))
   (/ (- (/ 0.5 x) (/ 0.375 (* x x))) (sqrt x))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	double tmp;
	if (x <= 160000.0) {
		tmp = pow(x, -0.5) - pow((1.0 + x), -0.5);
	} else {
		tmp = ((0.5 / x) - (0.375 / (x * x))) / sqrt(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 <= 160000.0d0) then
        tmp = (x ** (-0.5d0)) - ((1.0d0 + x) ** (-0.5d0))
    else
        tmp = ((0.5d0 / x) - (0.375d0 / (x * x))) / sqrt(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 <= 160000.0) {
		tmp = Math.pow(x, -0.5) - Math.pow((1.0 + x), -0.5);
	} else {
		tmp = ((0.5 / x) - (0.375 / (x * x))) / Math.sqrt(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 <= 160000.0:
		tmp = math.pow(x, -0.5) - math.pow((1.0 + x), -0.5)
	else:
		tmp = ((0.5 / x) - (0.375 / (x * x))) / math.sqrt(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 <= 160000.0)
		tmp = Float64((x ^ -0.5) - (Float64(1.0 + x) ^ -0.5));
	else
		tmp = Float64(Float64(Float64(0.5 / x) - Float64(0.375 / Float64(x * x))) / sqrt(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 <= 160000.0)
		tmp = (x ^ -0.5) - ((1.0 + x) ^ -0.5);
	else
		tmp = ((0.5 / x) - (0.375 / (x * x))) / sqrt(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, 160000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(1.0 + x), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.5 / x), $MachinePrecision] - N[(0.375 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \leq 160000:\\
\;\;\;\;{x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.5}{x} - \frac{0.375}{x \cdot x}}{\sqrt{x}}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original69.2%
Target99.0%
Herbie99.6%
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}} \]

Derivation?

  1. Split input into 2 regimes
  2. if x < 1.6e5

    1. Initial program 99.4

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

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

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

      [Start]99.8

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

      sub-neg [<=]99.8

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

    if 1.6e5 < x

    1. Initial program 38.1

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}}}{-\sqrt{1 + x}} \cdot -1} \]
    3. Simplified38.1

      \[\leadsto \color{blue}{\frac{1 - \frac{\sqrt{x}}{\sqrt{1 + x}}}{\sqrt{x}}} \]
      Proof

      [Start]38.1

      \[ \frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}}}{-\sqrt{1 + x}} \cdot -1 \]

      associate-*l/ [=>]38.1

      \[ \color{blue}{\frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}} \cdot -1}{-\sqrt{1 + x}}} \]

      associate-/l* [=>]38.1

      \[ \color{blue}{\frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}}}{\frac{-\sqrt{1 + x}}{-1}}} \]

      metadata-eval [<=]38.1

      \[ \frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}}}{\frac{-\sqrt{1 + x}}{\color{blue}{\frac{1}{-1}}}} \]

      associate-/l* [<=]38.1

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

      *-commutative [<=]38.1

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

      mul-1-neg [=>]38.1

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

      remove-double-neg [=>]38.1

      \[ \frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}}}{\frac{\color{blue}{\sqrt{1 + x}}}{1}} \]

      /-rgt-identity [=>]38.1

      \[ \frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{x}}}{\color{blue}{\sqrt{1 + x}}} \]

      associate-/l/ [=>]38.1

      \[ \color{blue}{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{1 + x} \cdot \sqrt{x}}} \]

      associate-/r* [=>]38.1

      \[ \color{blue}{\frac{\frac{\sqrt{1 + x} - \sqrt{x}}{\sqrt{1 + x}}}{\sqrt{x}}} \]

      div-sub [=>]38.1

      \[ \frac{\color{blue}{\frac{\sqrt{1 + x}}{\sqrt{1 + x}} - \frac{\sqrt{x}}{\sqrt{1 + x}}}}{\sqrt{x}} \]

      *-inverses [=>]38.1

      \[ \frac{\color{blue}{1} - \frac{\sqrt{x}}{\sqrt{1 + x}}}{\sqrt{x}} \]
    4. Taylor expanded in x around inf 99.5

      \[\leadsto \frac{\color{blue}{0.5 \cdot \frac{1}{x} - 0.375 \cdot \frac{1}{{x}^{2}}}}{\sqrt{x}} \]
    5. Simplified99.5

      \[\leadsto \frac{\color{blue}{\frac{0.5}{x} - \frac{0.375}{x \cdot x}}}{\sqrt{x}} \]
      Proof

      [Start]99.5

      \[ \frac{0.5 \cdot \frac{1}{x} - 0.375 \cdot \frac{1}{{x}^{2}}}{\sqrt{x}} \]

      associate-*r/ [=>]99.5

      \[ \frac{\color{blue}{\frac{0.5 \cdot 1}{x}} - 0.375 \cdot \frac{1}{{x}^{2}}}{\sqrt{x}} \]

      metadata-eval [=>]99.5

      \[ \frac{\frac{\color{blue}{0.5}}{x} - 0.375 \cdot \frac{1}{{x}^{2}}}{\sqrt{x}} \]

      associate-*r/ [=>]99.5

      \[ \frac{\frac{0.5}{x} - \color{blue}{\frac{0.375 \cdot 1}{{x}^{2}}}}{\sqrt{x}} \]

      metadata-eval [=>]99.5

      \[ \frac{\frac{0.5}{x} - \frac{\color{blue}{0.375}}{{x}^{2}}}{\sqrt{x}} \]

      unpow2 [=>]99.5

      \[ \frac{\frac{0.5}{x} - \frac{0.375}{\color{blue}{x \cdot x}}}{\sqrt{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.6

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

Alternatives

Alternative 1
Error99.0%
Cost26368.00
\[\frac{1}{\frac{\mathsf{hypot}\left(x, \sqrt{x}\right)}{\frac{1}{\sqrt{x} + \sqrt{1 + x}}}} \]
Alternative 2
Error99.6%
Cost26304.00
\[\frac{\frac{-1}{\sqrt{x} + \sqrt{1 + x}}}{-\mathsf{hypot}\left(x, \sqrt{x}\right)} \]
Alternative 3
Error98.9%
Cost7236.00
\[\begin{array}{l} \mathbf{if}\;x \leq 1.4:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{x} - \frac{0.375}{x \cdot x}}{\sqrt{x}}\\ \end{array} \]
Alternative 4
Error98.4%
Cost7172.00
\[\begin{array}{l} \mathbf{if}\;x \leq 1.7:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{1 + x \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x}\\ \end{array} \]
Alternative 5
Error98.4%
Cost7044.00
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;{x}^{-0.5} + \left(-1 + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x}\\ \end{array} \]
Alternative 6
Error98.1%
Cost6916.00
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{{x}^{-0.5}}{x}\\ \end{array} \]
Alternative 7
Error98.1%
Cost6852.00
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x}}\\ \end{array} \]
Alternative 8
Error53.2%
Cost6788.00
\[\begin{array}{l} \mathbf{if}\;x \leq 0.7:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{0.5 + \left(x + \frac{-0.125}{x}\right)}\\ \end{array} \]
Alternative 9
Error97.5%
Cost6788.00
\[\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;-1 + {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{{x}^{1.5}}\\ \end{array} \]
Alternative 10
Error50.7%
Cost6528.00
\[{x}^{-0.5} \]
Alternative 11
Error7.4%
Cost192.00
\[\frac{1}{x} \]
Alternative 12
Error1.9%
Cost64.00
\[-1 \]

Error

Reproduce?

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