Average Error: 10.5 → 0.2
Time: 4.8s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\begin{array}{l} t_0 := \frac{2}{{x}^{9}}\\ t_1 := \frac{2}{{x}^{5}}\\ t_2 := \frac{2}{{x}^{7}}\\ \mathbf{if}\;x \leq -10420091.783946034:\\ \;\;\;\;t_1 + \left(t_2 + \left(\frac{\frac{2}{x \cdot x}}{x} + t_0\right)\right)\\ \mathbf{elif}\;x \leq 128487391.2932317:\\ \;\;\;\;\begin{array}{l} t_3 := x \cdot \left(x + 1\right)\\ \frac{\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \left(x - 1\right) + t_3}{\left(x - 1\right) \cdot t_3} \end{array}\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(t_2 + \left(t_0 + \frac{2}{{x}^{3}}\right)\right)\\ \end{array} \]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
t_0 := \frac{2}{{x}^{9}}\\
t_1 := \frac{2}{{x}^{5}}\\
t_2 := \frac{2}{{x}^{7}}\\
\mathbf{if}\;x \leq -10420091.783946034:\\
\;\;\;\;t_1 + \left(t_2 + \left(\frac{\frac{2}{x \cdot x}}{x} + t_0\right)\right)\\

\mathbf{elif}\;x \leq 128487391.2932317:\\
\;\;\;\;\begin{array}{l}
t_3 := x \cdot \left(x + 1\right)\\
\frac{\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \left(x - 1\right) + t_3}{\left(x - 1\right) \cdot t_3}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;t_1 + \left(t_2 + \left(t_0 + \frac{2}{{x}^{3}}\right)\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 9.0)))
        (t_1 (/ 2.0 (pow x 5.0)))
        (t_2 (/ 2.0 (pow x 7.0))))
   (if (<= x -10420091.783946034)
     (+ t_1 (+ t_2 (+ (/ (/ 2.0 (* x x)) x) t_0)))
     (if (<= x 128487391.2932317)
       (let* ((t_3 (* x (+ x 1.0))))
         (/ (+ (* (- x (* 2.0 (+ x 1.0))) (- x 1.0)) t_3) (* (- x 1.0) t_3)))
       (+ t_1 (+ t_2 (+ t_0 (/ 2.0 (pow x 3.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, 9.0);
	double t_1 = 2.0 / pow(x, 5.0);
	double t_2 = 2.0 / pow(x, 7.0);
	double tmp;
	if (x <= -10420091.783946034) {
		tmp = t_1 + (t_2 + (((2.0 / (x * x)) / x) + t_0));
	} else if (x <= 128487391.2932317) {
		double t_3 = x * (x + 1.0);
		tmp = (((x - (2.0 * (x + 1.0))) * (x - 1.0)) + t_3) / ((x - 1.0) * t_3);
	} else {
		tmp = t_1 + (t_2 + (t_0 + (2.0 / pow(x, 3.0))));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original10.5
Target0.3
Herbie0.2
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)} \]

Derivation

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

    1. Initial program 20.3

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

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

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

      \[\leadsto \frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{7}} + \left(\frac{2}{\color{blue}{\left(x \cdot x\right) \cdot x}} + \frac{2}{{x}^{9}}\right)\right) \]
    5. Applied associate-/r*_binary640.1

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

    if -10420091.783946034 < x < 128487391.2932317

    1. Initial program 0.6

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Applied frac-sub_binary640.6

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

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

    if 128487391.2932317 < x

    1. Initial program 20.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -10420091.783946034:\\ \;\;\;\;\frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{7}} + \left(\frac{\frac{2}{x \cdot x}}{x} + \frac{2}{{x}^{9}}\right)\right)\\ \mathbf{elif}\;x \leq 128487391.2932317:\\ \;\;\;\;\frac{\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \left(x - 1\right) + x \cdot \left(x + 1\right)}{\left(x - 1\right) \cdot \left(x \cdot \left(x + 1\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{{x}^{5}} + \left(\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{9}} + \frac{2}{{x}^{3}}\right)\right)\\ \end{array} \]

Reproduce

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