Average Error: 13.9 → 0.7
Time: 1.9s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{1 + x} - \frac{1}{x} \leq -14019661722.627342 \lor \neg \left(\frac{1}{1 + x} - \frac{1}{x} \leq 0\right):\\ \;\;\;\;\frac{1}{1 + x} - \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{x} + -1}{x}}{x} + \frac{-1}{{x}^{4}}\\ \end{array}\]
\frac{1}{x + 1} - \frac{1}{x}
\begin{array}{l}
\mathbf{if}\;\frac{1}{1 + x} - \frac{1}{x} \leq -14019661722.627342 \lor \neg \left(\frac{1}{1 + x} - \frac{1}{x} \leq 0\right):\\
\;\;\;\;\frac{1}{1 + x} - \frac{1}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\frac{1}{x} + -1}{x}}{x} + \frac{-1}{{x}^{4}}\\

\end{array}
(FPCore (x) :precision binary64 (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))
(FPCore (x)
 :precision binary64
 (if (or (<= (- (/ 1.0 (+ 1.0 x)) (/ 1.0 x)) -14019661722.627342)
         (not (<= (- (/ 1.0 (+ 1.0 x)) (/ 1.0 x)) 0.0)))
   (- (/ 1.0 (+ 1.0 x)) (/ 1.0 x))
   (+ (/ (/ (+ (/ 1.0 x) -1.0) x) x) (/ -1.0 (pow x 4.0)))))
double code(double x) {
	return (1.0 / (x + 1.0)) - (1.0 / x);
}
double code(double x) {
	double tmp;
	if ((((1.0 / (1.0 + x)) - (1.0 / x)) <= -14019661722.627342) || !(((1.0 / (1.0 + x)) - (1.0 / x)) <= 0.0)) {
		tmp = (1.0 / (1.0 + x)) - (1.0 / x);
	} else {
		tmp = ((((1.0 / x) + -1.0) / x) / x) + (-1.0 / pow(x, 4.0));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 1 x)) < -14019661722.627342 or 0.0 < (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 1 x))

    1. Initial program 0.0

      \[\frac{1}{x + 1} - \frac{1}{x}\]

    if -14019661722.627342 < (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 1 x)) < 0.0

    1. Initial program 27.6

      \[\frac{1}{x + 1} - \frac{1}{x}\]
    2. Taylor expanded around inf 2.0

      \[\leadsto \color{blue}{\frac{1}{{x}^{3}} - \left(\frac{1}{{x}^{2}} + \frac{1}{{x}^{4}}\right)}\]
    3. Simplified2.0

      \[\leadsto \color{blue}{\frac{\frac{1}{x} + -1}{x \cdot x} + \frac{-1}{{x}^{4}}}\]
    4. Using strategy rm
    5. Applied associate-/r*_binary641.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{1 + x} - \frac{1}{x} \leq -14019661722.627342 \lor \neg \left(\frac{1}{1 + x} - \frac{1}{x} \leq 0\right):\\ \;\;\;\;\frac{1}{1 + x} - \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\frac{1}{x} + -1}{x}}{x} + \frac{-1}{{x}^{4}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020224 
(FPCore (x)
  :name "2frac (problem 3.3.1)"
  :precision binary64
  (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)))