Average Error: 19.7 → 10.6
Time: 27.3s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 6940.77878829129895:\\ \;\;\;\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{{x}^{3} + {1}^{3}}} \cdot \sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(0.3125 \cdot \left(\sqrt{\frac{1}{{x}^{7}}} \cdot {\left(\sqrt{1}\right)}^{2}\right) + 0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot {\left(\sqrt{1}\right)}^{2}\right)\right) - 0.375 \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot {\left(\sqrt{1}\right)}^{2}\right)\\ \end{array}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \le 6940.77878829129895:\\
\;\;\;\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{{x}^{3} + {1}^{3}}} \cdot \sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}\\

\mathbf{else}:\\
\;\;\;\;\left(0.3125 \cdot \left(\sqrt{\frac{1}{{x}^{7}}} \cdot {\left(\sqrt{1}\right)}^{2}\right) + 0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot {\left(\sqrt{1}\right)}^{2}\right)\right) - 0.375 \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot {\left(\sqrt{1}\right)}^{2}\right)\\

\end{array}
double code(double x) {
	return ((1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))));
}
double code(double x) {
	double VAR;
	if ((x <= 6940.778788291299)) {
		VAR = ((1.0 / sqrt(x)) - ((1.0 / sqrt((pow(x, 3.0) + pow(1.0, 3.0)))) * sqrt(((x * x) + ((1.0 * 1.0) - (x * 1.0))))));
	} else {
		VAR = (((0.3125 * (sqrt((1.0 / pow(x, 7.0))) * pow(sqrt(1.0), 2.0))) + (0.5 * (sqrt((1.0 / pow(x, 3.0))) * pow(sqrt(1.0), 2.0)))) - (0.375 * (sqrt((1.0 / pow(x, 5.0))) * pow(sqrt(1.0), 2.0))));
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original19.7
Target0.7
Herbie10.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 < 6940.778788291299

    1. Initial program 0.4

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
    2. Using strategy rm
    3. Applied flip3-+0.4

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{\color{blue}{\frac{{x}^{3} + {1}^{3}}{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}}}}\]
    4. Applied sqrt-div0.4

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\frac{\sqrt{{x}^{3} + {1}^{3}}}{\sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}}}}\]
    5. Applied associate-/r/0.4

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

    if 6940.778788291299 < x

    1. Initial program 39.7

      \[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt39.7

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{\color{blue}{\sqrt{x + 1} \cdot \sqrt{x + 1}}}}\]
    4. Applied sqrt-prod47.9

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}}}\]
    5. Applied add-sqr-sqrt47.9

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}}\]
    6. Applied times-frac51.7

      \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}} \cdot \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}}\]
    7. Applied add-sqr-sqrt45.6

      \[\leadsto \color{blue}{\sqrt{\frac{1}{\sqrt{x}}} \cdot \sqrt{\frac{1}{\sqrt{x}}}} - \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}} \cdot \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}\]
    8. Applied difference-of-squares45.6

      \[\leadsto \color{blue}{\left(\sqrt{\frac{1}{\sqrt{x}}} + \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}\right) \cdot \left(\sqrt{\frac{1}{\sqrt{x}}} - \frac{\sqrt{1}}{\sqrt{\sqrt{x + 1}}}\right)}\]
    9. Taylor expanded around inf 21.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 6940.77878829129895:\\ \;\;\;\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{{x}^{3} + {1}^{3}}} \cdot \sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(0.3125 \cdot \left(\sqrt{\frac{1}{{x}^{7}}} \cdot {\left(\sqrt{1}\right)}^{2}\right) + 0.5 \cdot \left(\sqrt{\frac{1}{{x}^{3}}} \cdot {\left(\sqrt{1}\right)}^{2}\right)\right) - 0.375 \cdot \left(\sqrt{\frac{1}{{x}^{5}}} \cdot {\left(\sqrt{1}\right)}^{2}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020105 +o rules:numerics
(FPCore (x)
  :name "2isqrt (example 3.6)"
  :precision binary64

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

  (- (/ 1 (sqrt x)) (/ 1 (sqrt (+ x 1)))))