Average Error: 19.4 → 3.3
Time: 6.7s
Precision: binary64
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}} \]
\[\begin{array}{l} t_0 := {x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\ t_1 := \sqrt{\frac{1}{x}}\\ t_2 := \mathsf{fma}\left(2, t_1, t_1\right)\\ t_3 := {\left({x}^{-0.25}\right)}^{2}\\ \mathbf{if}\;x \leq 386923.8565851494:\\ \;\;\;\;\left|t_0\right|\\ \mathbf{elif}\;x \leq 1.1577094350749208 \cdot 10^{+154}:\\ \;\;\;\;\mathsf{fma}\left(1.125, \sqrt{\frac{1}{{x}^{7}}} \cdot \frac{1}{{t_2}^{2}}, 1.5 \cdot \frac{1}{\left(x \cdot x\right) \cdot t_2}\right) - 1.5 \cdot \frac{1}{{x}^{3} \cdot t_2}\\ \mathbf{elif}\;x \leq 3.3300363174486925 \cdot 10^{+201}:\\ \;\;\;\;t_0 + \left(\mathsf{fma}\left(0.5, \frac{t_3}{x}, \mathsf{fma}\left(0.375, \frac{{x}^{-0.5}}{x \cdot x}, 0.3125 \cdot \frac{t_3}{{x}^{3}}\right)\right) - \left(\mathsf{fma}\left(0.3125, \frac{{x}^{-0.5}}{{x}^{3}}, \mathsf{fma}\left(0.375, \frac{t_3}{x \cdot x}, t_3\right)\right) - \frac{{x}^{-0.5}}{x} \cdot \left(x - 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right)}\\ \end{array} \]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
t_0 := {x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
t_1 := \sqrt{\frac{1}{x}}\\
t_2 := \mathsf{fma}\left(2, t_1, t_1\right)\\
t_3 := {\left({x}^{-0.25}\right)}^{2}\\
\mathbf{if}\;x \leq 386923.8565851494:\\
\;\;\;\;\left|t_0\right|\\

\mathbf{elif}\;x \leq 1.1577094350749208 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(1.125, \sqrt{\frac{1}{{x}^{7}}} \cdot \frac{1}{{t_2}^{2}}, 1.5 \cdot \frac{1}{\left(x \cdot x\right) \cdot t_2}\right) - 1.5 \cdot \frac{1}{{x}^{3} \cdot t_2}\\

\mathbf{elif}\;x \leq 3.3300363174486925 \cdot 10^{+201}:\\
\;\;\;\;t_0 + \left(\mathsf{fma}\left(0.5, \frac{t_3}{x}, \mathsf{fma}\left(0.375, \frac{{x}^{-0.5}}{x \cdot x}, 0.3125 \cdot \frac{t_3}{{x}^{3}}\right)\right) - \left(\mathsf{fma}\left(0.3125, \frac{{x}^{-0.5}}{{x}^{3}}, \mathsf{fma}\left(0.375, \frac{t_3}{x \cdot x}, t_3\right)\right) - \frac{{x}^{-0.5}}{x} \cdot \left(x - 0.5\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;e^{\log \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right)}\\


\end{array}
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (pow x -0.5) (pow (+ x 1.0) -0.5)))
        (t_1 (sqrt (/ 1.0 x)))
        (t_2 (fma 2.0 t_1 t_1))
        (t_3 (pow (pow x -0.25) 2.0)))
   (if (<= x 386923.8565851494)
     (fabs t_0)
     (if (<= x 1.1577094350749208e+154)
       (-
        (fma
         1.125
         (* (sqrt (/ 1.0 (pow x 7.0))) (/ 1.0 (pow t_2 2.0)))
         (* 1.5 (/ 1.0 (* (* x x) t_2))))
        (* 1.5 (/ 1.0 (* (pow x 3.0) t_2))))
       (if (<= x 3.3300363174486925e+201)
         (+
          t_0
          (-
           (fma
            0.5
            (/ t_3 x)
            (fma
             0.375
             (/ (pow x -0.5) (* x x))
             (* 0.3125 (/ t_3 (pow x 3.0)))))
           (-
            (fma
             0.3125
             (/ (pow x -0.5) (pow x 3.0))
             (fma 0.375 (/ t_3 (* x x)) t_3))
            (* (/ (pow x -0.5) x) (- x 0.5)))))
         (exp (log (- (pow x -0.5) (pow (+ 1.0 x) -0.5)))))))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
	double t_0 = pow(x, -0.5) - pow((x + 1.0), -0.5);
	double t_1 = sqrt((1.0 / x));
	double t_2 = fma(2.0, t_1, t_1);
	double t_3 = pow(pow(x, -0.25), 2.0);
	double tmp;
	if (x <= 386923.8565851494) {
		tmp = fabs(t_0);
	} else if (x <= 1.1577094350749208e+154) {
		tmp = fma(1.125, (sqrt((1.0 / pow(x, 7.0))) * (1.0 / pow(t_2, 2.0))), (1.5 * (1.0 / ((x * x) * t_2)))) - (1.5 * (1.0 / (pow(x, 3.0) * t_2)));
	} else if (x <= 3.3300363174486925e+201) {
		tmp = t_0 + (fma(0.5, (t_3 / x), fma(0.375, (pow(x, -0.5) / (x * x)), (0.3125 * (t_3 / pow(x, 3.0))))) - (fma(0.3125, (pow(x, -0.5) / pow(x, 3.0)), fma(0.375, (t_3 / (x * x)), t_3)) - ((pow(x, -0.5) / x) * (x - 0.5))));
	} else {
		tmp = exp(log((pow(x, -0.5) - pow((1.0 + x), -0.5))));
	}
	return tmp;
}

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 4 regimes
  2. if x < 386923.85658514942

    1. Initial program 0.4

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

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

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

    if 386923.85658514942 < x < 1.1577094350749208e154

    1. Initial program 59.4

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

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

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

      \[\leadsto \color{blue}{\left(1.125 \cdot \left(\frac{1}{{\left(2 \cdot \sqrt{\frac{1}{x}} + {\left(\frac{1}{x}\right)}^{0.5}\right)}^{2}} \cdot \sqrt{\frac{1}{{x}^{7}}}\right) + 1.5 \cdot \frac{1}{\left(2 \cdot \sqrt{\frac{1}{x}} + {\left(\frac{1}{x}\right)}^{0.5}\right) \cdot {x}^{2}}\right) - 1.5 \cdot \frac{1}{\left(2 \cdot \sqrt{\frac{1}{x}} + {\left(\frac{1}{x}\right)}^{0.5}\right) \cdot {x}^{3}}} \]
    5. Simplified0.7

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

    if 1.1577094350749208e154 < x < 3.33003631744869248e201

    1. Initial program 58.8

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

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

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

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

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

    if 3.33003631744869248e201 < x

    1. Initial program 4.5

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

      \[\leadsto \color{blue}{e^{\log \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right)}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification3.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 386923.8565851494:\\ \;\;\;\;\left|{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\right|\\ \mathbf{elif}\;x \leq 1.1577094350749208 \cdot 10^{+154}:\\ \;\;\;\;\mathsf{fma}\left(1.125, \sqrt{\frac{1}{{x}^{7}}} \cdot \frac{1}{{\left(\mathsf{fma}\left(2, \sqrt{\frac{1}{x}}, \sqrt{\frac{1}{x}}\right)\right)}^{2}}, 1.5 \cdot \frac{1}{\left(x \cdot x\right) \cdot \mathsf{fma}\left(2, \sqrt{\frac{1}{x}}, \sqrt{\frac{1}{x}}\right)}\right) - 1.5 \cdot \frac{1}{{x}^{3} \cdot \mathsf{fma}\left(2, \sqrt{\frac{1}{x}}, \sqrt{\frac{1}{x}}\right)}\\ \mathbf{elif}\;x \leq 3.3300363174486925 \cdot 10^{+201}:\\ \;\;\;\;\left({x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\right) + \left(\mathsf{fma}\left(0.5, \frac{{\left({x}^{-0.25}\right)}^{2}}{x}, \mathsf{fma}\left(0.375, \frac{{x}^{-0.5}}{x \cdot x}, 0.3125 \cdot \frac{{\left({x}^{-0.25}\right)}^{2}}{{x}^{3}}\right)\right) - \left(\mathsf{fma}\left(0.3125, \frac{{x}^{-0.5}}{{x}^{3}}, \mathsf{fma}\left(0.375, \frac{{\left({x}^{-0.25}\right)}^{2}}{x \cdot x}, {\left({x}^{-0.25}\right)}^{2}\right)\right) - \frac{{x}^{-0.5}}{x} \cdot \left(x - 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;e^{\log \left({x}^{-0.5} - {\left(1 + x\right)}^{-0.5}\right)}\\ \end{array} \]

Reproduce

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