Average Error: 19.8 → 5.7
Time: 3.9s
Precision: 64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \le 10784.107655470898:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}, \frac{-1}{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{\frac{3}{2}}\right)}, \frac{1}{\sqrt{x}}\right) + \sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)} \cdot \left(\frac{-1}{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{\frac{3}{2}}\right)} + \frac{1}{\sqrt{{x}^{3} + {1}^{3}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 \cdot \left(1 \cdot \left(\left(\frac{1}{{x}^{2}} + \frac{1}{{x}^{4}}\right) - \frac{1}{{x}^{3}}\right)\right)}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}\\ \end{array}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \le 10784.107655470898:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}, \frac{-1}{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{\frac{3}{2}}\right)}, \frac{1}{\sqrt{x}}\right) + \sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)} \cdot \left(\frac{-1}{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{\frac{3}{2}}\right)} + \frac{1}{\sqrt{{x}^{3} + {1}^{3}}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1 \cdot \left(1 \cdot \left(\left(\frac{1}{{x}^{2}} + \frac{1}{{x}^{4}}\right) - \frac{1}{{x}^{3}}\right)\right)}{\frac{1}{\sqrt{x}} + \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 VAR;
	if ((x <= 10784.107655470898)) {
		VAR = (fma(sqrt(((x * x) + ((1.0 * 1.0) - (x * 1.0)))), (-1.0 / hypot(pow(1.0, 1.5), pow(x, 1.5))), (1.0 / sqrt(x))) + (sqrt(((x * x) + ((1.0 * 1.0) - (x * 1.0)))) * ((-1.0 / hypot(pow(1.0, 1.5), pow(x, 1.5))) + (1.0 / sqrt((pow(x, 3.0) + pow(1.0, 3.0)))))));
	} else {
		VAR = ((1.0 * (1.0 * (((1.0 / pow(x, 2.0)) + (1.0 / pow(x, 4.0))) - (1.0 / pow(x, 3.0))))) / ((1.0 / sqrt(x)) + (1.0 / sqrt((x + 1.0)))));
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    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)}}\]
    6. Applied div-inv0.4

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{\sqrt{x}}, -\sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)} \cdot \frac{1}{\sqrt{{x}^{3} + {1}^{3}}}\right) + \mathsf{fma}\left(-\sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}, \frac{1}{\sqrt{{x}^{3} + {1}^{3}}}, \sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)} \cdot \frac{1}{\sqrt{{x}^{3} + {1}^{3}}}\right)}\]
    8. Simplified0.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}, \frac{-1}{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{\frac{3}{2}}\right)}, \frac{1}{\sqrt{x}}\right)} + \mathsf{fma}\left(-\sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}, \frac{1}{\sqrt{{x}^{3} + {1}^{3}}}, \sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)} \cdot \frac{1}{\sqrt{{x}^{3} + {1}^{3}}}\right)\]
    9. Simplified0.4

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

    if 10784.107655470898 < x

    1. Initial program 39.9

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le 10784.107655470898:\\ \;\;\;\;\mathsf{fma}\left(\sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}, \frac{-1}{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{\frac{3}{2}}\right)}, \frac{1}{\sqrt{x}}\right) + \sqrt{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)} \cdot \left(\frac{-1}{\mathsf{hypot}\left({1}^{\frac{3}{2}}, {x}^{\frac{3}{2}}\right)} + \frac{1}{\sqrt{{x}^{3} + {1}^{3}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 \cdot \left(1 \cdot \left(\left(\frac{1}{{x}^{2}} + \frac{1}{{x}^{4}}\right) - \frac{1}{{x}^{3}}\right)\right)}{\frac{1}{\sqrt{x}} + \frac{1}{\sqrt{x + 1}}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020071 +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)))))