Average Error: 30.0 → 0.1
Time: 3.7s
Precision: binary64
\[\sqrt{x + 1} - \sqrt{x} \]
\[\begin{array}{l} t_0 := \sqrt{1 + x}\\ {\left(\mathsf{fma}\left(t_0, \sqrt{x}, 1 + x\right) + \mathsf{fma}\left(t_0, \sqrt{x}, x\right)\right)}^{-0.5} \end{array} \]
\sqrt{x + 1} - \sqrt{x}
\begin{array}{l}
t_0 := \sqrt{1 + x}\\
{\left(\mathsf{fma}\left(t_0, \sqrt{x}, 1 + x\right) + \mathsf{fma}\left(t_0, \sqrt{x}, x\right)\right)}^{-0.5}
\end{array}
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ 1.0 x))))
   (pow (+ (fma t_0 (sqrt x) (+ 1.0 x)) (fma t_0 (sqrt x) x)) -0.5)))
double code(double x) {
	return sqrt(x + 1.0) - sqrt(x);
}
double code(double x) {
	double t_0 = sqrt(1.0 + x);
	return pow((fma(t_0, sqrt(x), (1.0 + x)) + fma(t_0, sqrt(x), x)), -0.5);
}

Error

Bits error versus x

Target

Original30.0
Target0.2
Herbie0.1
\[\frac{1}{\sqrt{x + 1} + \sqrt{x}} \]

Derivation

  1. Initial program 30.0

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Applied flip--_binary6429.7

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

    \[\leadsto \frac{\color{blue}{1}}{\sqrt{x + 1} + \sqrt{x}} \]
  4. Simplified0.2

    \[\leadsto \frac{1}{\color{blue}{\sqrt{1 + x} + \sqrt{x}}} \]
  5. Applied add-sqr-sqrt_binary640.3

    \[\leadsto \color{blue}{\sqrt{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \cdot \sqrt{\frac{1}{\sqrt{1 + x} + \sqrt{x}}}} \]
  6. Applied inv-pow_binary640.3

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

    \[\leadsto \sqrt{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \cdot \color{blue}{{\left(\sqrt{1 + x} + \sqrt{x}\right)}^{\left(\frac{-1}{2}\right)}} \]
  8. Applied inv-pow_binary640.3

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

    \[\leadsto \color{blue}{{\left(\sqrt{1 + x} + \sqrt{x}\right)}^{\left(\frac{-1}{2}\right)}} \cdot {\left(\sqrt{1 + x} + \sqrt{x}\right)}^{\left(\frac{-1}{2}\right)} \]
  10. Applied pow-prod-down_binary640.2

    \[\leadsto \color{blue}{{\left(\left(\sqrt{1 + x} + \sqrt{x}\right) \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)\right)}^{\left(\frac{-1}{2}\right)}} \]
  11. Applied distribute-rgt-in_binary640.2

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

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

    \[\leadsto {\left(\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, 1 + x\right) + \color{blue}{\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, x\right)}\right)}^{\left(\frac{-1}{2}\right)} \]
  14. Final simplification0.1

    \[\leadsto {\left(\mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, 1 + x\right) + \mathsf{fma}\left(\sqrt{1 + x}, \sqrt{x}, x\right)\right)}^{-0.5} \]

Reproduce

herbie shell --seed 2022121 
(FPCore (x)
  :name "2sqrt (example 3.1)"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))

  (- (sqrt (+ x 1.0)) (sqrt x)))