Average Error: 19.8 → 0.4
Time: 27.8s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \le 3.2859459478 \cdot 10^{-8}:\\ \;\;\;\;\frac{\frac{\left(0.5 \cdot \frac{1}{x} + 0.171875 \cdot \frac{1}{{x}^{3}}\right) - 0.25 \cdot \frac{1}{{x}^{2}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x}} - \sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\\ \end{array}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \le 3.2859459478 \cdot 10^{-8}:\\
\;\;\;\;\frac{\frac{\left(0.5 \cdot \frac{1}{x} + 0.171875 \cdot \frac{1}{{x}^{3}}\right) - 0.25 \cdot \frac{1}{{x}^{2}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x}} - \sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\\

\end{array}
double code(double x) {
	return ((1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))));
}
double code(double x) {
	double temp;
	if ((((1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)))) <= 3.2859459478049025e-08)) {
		temp = (((((0.5 * (1.0 / x)) + (0.171875 * (1.0 / pow(x, 3.0)))) - (0.25 * (1.0 / pow(x, 2.0)))) / sqrt((sqrt(sqrt(x)) * sqrt(sqrt((x + 1.0)))))) / sqrt((sqrt(sqrt(x)) * sqrt(sqrt((x + 1.0))))));
	} else {
		temp = ((1.0 / sqrt(x)) - (sqrt((1.0 / sqrt((x + 1.0)))) * sqrt((1.0 / sqrt((x + 1.0))))));
	}
	return temp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))) < 3.2859459478049025e-08

    1. Initial program 40.7

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

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

      \[\leadsto \frac{1}{\sqrt{x}} - \frac{1}{\color{blue}{\sqrt{\sqrt{x + 1}} \cdot \sqrt{\sqrt{x + 1}}}}\]
    5. Applied associate-/r*51.1

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

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

      \[\leadsto \frac{1}{\color{blue}{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x}}}} - \frac{\frac{1}{\sqrt{\sqrt{x + 1}}}}{\sqrt{\sqrt{x + 1}}}\]
    8. Applied associate-/r*40.8

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{\sqrt{x}}}}{\sqrt{\sqrt{x}}}} - \frac{\frac{1}{\sqrt{\sqrt{x + 1}}}}{\sqrt{\sqrt{x + 1}}}\]
    9. Applied frac-sub40.8

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{\sqrt{x}}} \cdot \sqrt{\sqrt{x + 1}} - \sqrt{\sqrt{x}} \cdot \frac{1}{\sqrt{\sqrt{x + 1}}}}{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}\]
    10. Using strategy rm
    11. Applied add-sqr-sqrt40.8

      \[\leadsto \frac{\frac{1}{\sqrt{\sqrt{x}}} \cdot \sqrt{\sqrt{x + 1}} - \sqrt{\sqrt{x}} \cdot \frac{1}{\sqrt{\sqrt{x + 1}}}}{\color{blue}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}} \cdot \sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}}\]
    12. Applied associate-/r*40.8

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{\sqrt{\sqrt{x}}} \cdot \sqrt{\sqrt{x + 1}} - \sqrt{\sqrt{x}} \cdot \frac{1}{\sqrt{\sqrt{x + 1}}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}}\]
    13. Taylor expanded around inf 0.4

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

    if 3.2859459478049025e-08 < (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0))))

    1. Initial program 0.4

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

      \[\leadsto \frac{1}{\sqrt{x}} - \color{blue}{\sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \le 3.2859459478 \cdot 10^{-8}:\\ \;\;\;\;\frac{\frac{\left(0.5 \cdot \frac{1}{x} + 0.171875 \cdot \frac{1}{{x}^{3}}\right) - 0.25 \cdot \frac{1}{{x}^{2}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}}{\sqrt{\sqrt{\sqrt{x}} \cdot \sqrt{\sqrt{x + 1}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\sqrt{x}} - \sqrt{\frac{1}{\sqrt{x + 1}}} \cdot \sqrt{\frac{1}{\sqrt{x + 1}}}\\ \end{array}\]

Reproduce

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