Average Error: 9.8 → 0.4
Time: 3.3s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{2}{{x}^{7}}\\ t_1 := \frac{2}{{x}^{5}}\\ \mathbf{if}\;x \leq -1.0063945433797883:\\ \;\;\;\;t_1 + \left({\left(\frac{{2}^{0.3333333333333333}}{x}\right)}^{3} + t_0\right)\\ \mathbf{elif}\;x \leq 0.9945083062221113:\\ \;\;\;\;-\mathsf{fma}\left(2, x + {x}^{3}, \frac{2}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(\frac{2}{{x}^{3}} + t_0\right)\\ \end{array} \]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{2}{{x}^{7}}\\
t_1 := \frac{2}{{x}^{5}}\\
\mathbf{if}\;x \leq -1.0063945433797883:\\
\;\;\;\;t_1 + \left({\left(\frac{{2}^{0.3333333333333333}}{x}\right)}^{3} + t_0\right)\\

\mathbf{elif}\;x \leq 0.9945083062221113:\\
\;\;\;\;-\mathsf{fma}\left(2, x + {x}^{3}, \frac{2}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;t_1 + \left(\frac{2}{{x}^{3}} + t_0\right)\\


\end{array}
(FPCore (x)
 :precision binary64
 (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ 2.0 (pow x 7.0))) (t_1 (/ 2.0 (pow x 5.0))))
   (if (<= x -1.0063945433797883)
     (+ t_1 (+ (pow (/ (pow 2.0 0.3333333333333333) x) 3.0) t_0))
     (if (<= x 0.9945083062221113)
       (- (fma 2.0 (+ x (pow x 3.0)) (/ 2.0 x)))
       (+ t_1 (+ (/ 2.0 (pow x 3.0)) t_0))))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	double t_0 = 2.0 / pow(x, 7.0);
	double t_1 = 2.0 / pow(x, 5.0);
	double tmp;
	if (x <= -1.0063945433797883) {
		tmp = t_1 + (pow((pow(2.0, 0.3333333333333333) / x), 3.0) + t_0);
	} else if (x <= 0.9945083062221113) {
		tmp = -fma(2.0, (x + pow(x, 3.0)), (2.0 / x));
	} else {
		tmp = t_1 + ((2.0 / pow(x, 3.0)) + t_0);
	}
	return tmp;
}

Error

Bits error versus x

Target

Original9.8
Target0.3
Herbie0.4
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)} \]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.00639454337978829

    1. Initial program 19.4

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Taylor expanded in x around inf 0.8

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{3}} + \frac{2}{{x}^{7}}\right)} \]
    4. Applied egg-rr0.9

      \[\leadsto \frac{2}{{x}^{5}} + \left(\color{blue}{{\left(\frac{\sqrt[3]{2}}{x}\right)}^{3}} + \frac{2}{{x}^{7}}\right) \]
    5. Applied egg-rr0.5

      \[\leadsto \frac{2}{{x}^{5}} + \left({\left(\frac{\color{blue}{{2}^{0.3333333333333333}}}{x}\right)}^{3} + \frac{2}{{x}^{7}}\right) \]

    if -1.00639454337978829 < x < 0.994508306222111282

    1. Initial program 0.0

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Taylor expanded in x around 0 0.3

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

      \[\leadsto \color{blue}{-\mathsf{fma}\left(2, x + {x}^{3}, \frac{2}{x}\right)} \]

    if 0.994508306222111282 < x

    1. Initial program 19.6

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Taylor expanded in x around inf 0.7

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{3}} + \frac{2}{{x}^{7}}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.0063945433797883:\\ \;\;\;\;\frac{2}{{x}^{5}} + \left({\left(\frac{{2}^{0.3333333333333333}}{x}\right)}^{3} + \frac{2}{{x}^{7}}\right)\\ \mathbf{elif}\;x \leq 0.9945083062221113:\\ \;\;\;\;-\mathsf{fma}\left(2, x + {x}^{3}, \frac{2}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{3}} + \frac{2}{{x}^{7}}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022127 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2.0 (* x (- (* x x) 1.0)))

  (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))