Average Error: 9.7 → 0.2
Time: 5.1s
Precision: 64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -107.94411106005032:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)\\ \mathbf{elif}\;x \le 111.33784045281939:\\ \;\;\;\;\mathsf{fma}\left(\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left({x}^{3} + {1}^{3}\right) \cdot x}, x \cdot x + \left(1 \cdot 1 - x \cdot 1\right), \frac{1}{x - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{\frac{2}{x \cdot x}}{x}\right)\right)\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -107.94411106005032:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)\\

\mathbf{elif}\;x \le 111.33784045281939:\\
\;\;\;\;\mathsf{fma}\left(\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left({x}^{3} + {1}^{3}\right) \cdot x}, x \cdot x + \left(1 \cdot 1 - x \cdot 1\right), \frac{1}{x - 1}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{\frac{2}{x \cdot x}}{x}\right)\right)\\

\end{array}
double code(double x) {
	return (((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0)));
}
double code(double x) {
	double VAR;
	if ((x <= -107.94411106005032)) {
		VAR = fma(2.0, (1.0 / pow(x, 7.0)), fma(2.0, (1.0 / pow(x, 5.0)), (2.0 / pow(x, 3.0))));
	} else {
		double VAR_1;
		if ((x <= 111.33784045281939)) {
			VAR_1 = fma((((1.0 * x) - ((x + 1.0) * 2.0)) / ((pow(x, 3.0) + pow(1.0, 3.0)) * x)), ((x * x) + ((1.0 * 1.0) - (x * 1.0))), (1.0 / (x - 1.0)));
		} else {
			VAR_1 = fma(2.0, (1.0 / pow(x, 7.0)), fma(2.0, (1.0 / pow(x, 5.0)), ((2.0 / (x * x)) / x)));
		}
		VAR = VAR_1;
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

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

    1. Initial program 19.6

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

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

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

    if -107.94411106005032 < x < 111.33784045281939

    1. Initial program 0.0

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied frac-sub0.1

      \[\leadsto \color{blue}{\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1}\]
    4. Using strategy rm
    5. Applied flip3-+0.1

      \[\leadsto \frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\color{blue}{\frac{{x}^{3} + {1}^{3}}{x \cdot x + \left(1 \cdot 1 - x \cdot 1\right)}} \cdot x} + \frac{1}{x - 1}\]
    6. Applied associate-*l/0.1

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

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

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

    if 111.33784045281939 < x

    1. Initial program 18.9

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)}\]
    4. Using strategy rm
    5. Applied unpow30.5

      \[\leadsto \mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{\color{blue}{\left(x \cdot x\right) \cdot x}}\right)\right)\]
    6. Applied associate-/r*0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -107.94411106005032:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)\\ \mathbf{elif}\;x \le 111.33784045281939:\\ \;\;\;\;\mathsf{fma}\left(\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left({x}^{3} + {1}^{3}\right) \cdot x}, x \cdot x + \left(1 \cdot 1 - x \cdot 1\right), \frac{1}{x - 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{\frac{2}{x \cdot x}}{x}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020103 +o rules:numerics
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2 (* x (- (* x x) 1)))

  (+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))))