Average Error: 13.9 → 0.8
Time: 2.8s
Precision: binary64
\[\frac{1}{x + 1} - \frac{1}{x}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{1 + x} - \frac{1}{x} \leq -23649614954.58966 \lor \neg \left(\frac{1}{1 + x} - \frac{1}{x} \leq 0\right):\\ \;\;\;\;\frac{1}{1 + x} - \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;{x}^{-2} \cdot \left(\frac{1}{x} - 1\right) - \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 -23649614954.58966 \lor \neg \left(\frac{1}{1 + x} - \frac{1}{x} \leq 0\right):\\
\;\;\;\;\frac{1}{1 + x} - \frac{1}{x}\\

\mathbf{else}:\\
\;\;\;\;{x}^{-2} \cdot \left(\frac{1}{x} - 1\right) - \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)) -23649614954.58966)
         (not (<= (- (/ 1.0 (+ 1.0 x)) (/ 1.0 x)) 0.0)))
   (- (/ 1.0 (+ 1.0 x)) (/ 1.0 x))
   (- (* (pow x -2.0) (- (/ 1.0 x) 1.0)) (/ 1.0 (pow x 4.0)))))
double code(double x) {
	return ((double) ((1.0 / ((double) (x + 1.0))) - (1.0 / x)));
}
double code(double x) {
	double tmp;
	if (((((double) ((1.0 / ((double) (1.0 + x))) - (1.0 / x))) <= -23649614954.58966) || !(((double) ((1.0 / ((double) (1.0 + x))) - (1.0 / x))) <= 0.0))) {
		tmp = ((double) ((1.0 / ((double) (1.0 + x))) - (1.0 / x)));
	} else {
		tmp = ((double) (((double) (((double) pow(x, -2.0)) * ((double) ((1.0 / x) - 1.0)))) - (1.0 / ((double) 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 (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)) < -23649614954.589661 or 0.0 < (- (/ 1.0 (+ x 1.0)) (/ 1.0 x))

    1. Initial program Error: 0.0 bits

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

    if -23649614954.589661 < (- (/ 1.0 (+ x 1.0)) (/ 1.0 x)) < 0.0

    1. Initial program Error: 27.8 bits

      \[\frac{1}{x + 1} - \frac{1}{x}\]
    2. Taylor expanded around inf Error: 2.2 bits

      \[\leadsto \color{blue}{1 \cdot \frac{1}{{x}^{3}} - \left(1 \cdot \frac{1}{{x}^{2}} + 1 \cdot \frac{1}{{x}^{4}}\right)}\]
    3. SimplifiedError: 2.2 bits

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

      \[\leadsto \color{blue}{\frac{\frac{\frac{1}{x} - 1}{x}}{x}} - \frac{1}{{x}^{4}}\]
    6. Using strategy rm
    7. Applied *-un-lft-identityError: 1.6 bits

      \[\leadsto \frac{\frac{\frac{1}{x} - 1}{x}}{\color{blue}{1 \cdot x}} - \frac{1}{{x}^{4}}\]
    8. Applied add-cube-cbrtError: 2.2 bits

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{\frac{\frac{1}{x} - 1}{x}} \cdot \sqrt[3]{\frac{\frac{1}{x} - 1}{x}}\right) \cdot \sqrt[3]{\frac{\frac{1}{x} - 1}{x}}}}{1 \cdot x} - \frac{1}{{x}^{4}}\]
    9. Applied times-fracError: 2.2 bits

      \[\leadsto \color{blue}{\frac{\sqrt[3]{\frac{\frac{1}{x} - 1}{x}} \cdot \sqrt[3]{\frac{\frac{1}{x} - 1}{x}}}{1} \cdot \frac{\sqrt[3]{\frac{\frac{1}{x} - 1}{x}}}{x}} - \frac{1}{{x}^{4}}\]
    10. SimplifiedError: 2.2 bits

      \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{\frac{1}{x} - 1}{x}} \cdot \sqrt[3]{\frac{\frac{1}{x} - 1}{x}}\right)} \cdot \frac{\sqrt[3]{\frac{\frac{1}{x} - 1}{x}}}{x} - \frac{1}{{x}^{4}}\]
    11. Taylor expanded around 0 Error: 2.2 bits

      \[\leadsto \color{blue}{1 \cdot \frac{1}{{x}^{3}} - \left(1 \cdot \frac{1}{{x}^{2}} + 1 \cdot \frac{1}{{x}^{4}}\right)}\]
    12. SimplifiedError: 1.5 bits

      \[\leadsto \color{blue}{{x}^{-2} \cdot \left(\frac{1}{x} - 1\right) - \frac{1}{{x}^{4}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplificationError: 0.8 bits

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

Reproduce

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