Average Error: 19.9 → 0.3
Time: 6.1s
Precision: binary64
Cost: 13953
\[\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}\]
\[\begin{array}{l} \mathbf{if}\;x \leq 72052.32713768836:\\ \;\;\;\;\frac{\frac{1}{x + \sqrt{x \cdot \left(x + 1\right)}}}{\sqrt{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\left(0.5 + x \cdot 2\right) - \frac{0.125}{x}}}{\sqrt{x + 1}}\\ \end{array}\]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\begin{array}{l}
\mathbf{if}\;x \leq 72052.32713768836:\\
\;\;\;\;\frac{\frac{1}{x + \sqrt{x \cdot \left(x + 1\right)}}}{\sqrt{x + 1}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\left(0.5 + x \cdot 2\right) - \frac{0.125}{x}}}{\sqrt{x + 1}}\\

\end{array}
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x 72052.32713768836)
   (/ (/ 1.0 (+ x (sqrt (* x (+ x 1.0))))) (sqrt (+ x 1.0)))
   (/ (/ 1.0 (- (+ 0.5 (* x 2.0)) (/ 0.125 x))) (sqrt (+ x 1.0)))))
double code(double x) {
	return (1.0 / sqrt(x)) - (1.0 / sqrt(x + 1.0));
}
double code(double x) {
	double tmp;
	if (x <= 72052.32713768836) {
		tmp = (1.0 / (x + sqrt(x * (x + 1.0)))) / sqrt(x + 1.0);
	} else {
		tmp = (1.0 / ((0.5 + (x * 2.0)) - (0.125 / x))) / sqrt(x + 1.0);
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Alternatives

Alternative 1
Error0.3
Cost20032
\[\frac{\frac{1}{x + \sqrt{x + 1} \cdot \sqrt{x}}}{\sqrt{x + 1}}\]
Alternative 2
Error0.7
Cost13632
\[\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}\]
Alternative 3
Error0.2
Cost13633
\[\begin{array}{l} \mathbf{if}\;x \leq 3245.9374679211824:\\ \;\;\;\;{x}^{-0.5} - \frac{1}{\sqrt{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\left(0.5 + x \cdot 2\right) - \frac{0.125}{x}}}{\sqrt{x + 1}}\\ \end{array}\]
Alternative 4
Error0.8
Cost7681
\[\begin{array}{l} \mathbf{if}\;x \leq 0.37458255856936945:\\ \;\;\;\;\frac{1}{\sqrt{x}} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\left(0.5 + x \cdot 2\right) - \frac{0.125}{x}}}{\sqrt{x + 1}}\\ \end{array}\]
Alternative 5
Error0.9
Cost7425
\[\begin{array}{l} \mathbf{if}\;x \leq 0.32594028805984276:\\ \;\;\;\;\frac{1}{\sqrt{x}} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x + \left(x + 0.5\right)}}{\sqrt{x + 1}}\\ \end{array}\]
Alternative 6
Error1.2
Cost7169
\[\begin{array}{l} \mathbf{if}\;x \leq 0.4840276672158045:\\ \;\;\;\;\frac{1}{\sqrt{x}} + -1\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.5}{x}}{\sqrt{x + 1}}\\ \end{array}\]
Alternative 7
Error21.3
Cost7041
\[\begin{array}{l} \mathbf{if}\;x \leq 1.0062406200728051:\\ \;\;\;\;\frac{1}{\sqrt{x}} + -1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 8
Error50.0
Cost385
\[\begin{array}{l} \mathbf{if}\;x \leq 2.6706943098737903 \cdot 10^{+102}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\]
Alternative 9
Error60.3
Cost64
\[1\]

Error

Derivation

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

    1. Initial program 0.4

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

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

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

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x} \cdot \sqrt{1 + x}}}\]
    6. Using strategy rm
    7. Applied flip--_binary64_17580.4

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

      \[\leadsto \frac{\frac{\color{blue}{1}}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{x} \cdot \sqrt{1 + x}}\]
    9. Using strategy rm
    10. Applied associate-/r*_binary64_17270.3

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x + \sqrt{x} \cdot \sqrt{x + 1}}}}{\sqrt{1 + x}}\]
    12. Using strategy rm
    13. Applied sqrt-unprod_binary64_18030.3

      \[\leadsto \frac{\frac{1}{x + \color{blue}{\sqrt{x \cdot \left(x + 1\right)}}}}{\sqrt{1 + x}}\]
    14. Simplified0.3

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

    if 72052.327137688364 < x

    1. Initial program 39.7

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

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

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

      \[\leadsto \frac{\sqrt{1 + x} - \sqrt{x}}{\color{blue}{\sqrt{x} \cdot \sqrt{1 + x}}}\]
    6. Using strategy rm
    7. Applied flip--_binary64_175839.2

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

      \[\leadsto \frac{\frac{\color{blue}{1}}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{x} \cdot \sqrt{1 + x}}\]
    9. Using strategy rm
    10. Applied associate-/r*_binary64_17270.5

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x + \sqrt{x} \cdot \sqrt{x + 1}}}}{\sqrt{1 + x}}\]
    12. Taylor expanded around inf 0.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 72052.32713768836:\\ \;\;\;\;\frac{\frac{1}{x + \sqrt{x \cdot \left(x + 1\right)}}}{\sqrt{x + 1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{\left(0.5 + x \cdot 2\right) - \frac{0.125}{x}}}{\sqrt{x + 1}}\\ \end{array}\]

Reproduce

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