Average Error: 9.7 → 0.2
Time: 13.2s
Precision: 64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -102.94433550507199:\\ \;\;\;\;\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)\\ \mathbf{elif}\;x \le 99.938672500306552:\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\frac{1}{x}, \left(-2\right) + 2, \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) + \frac{-2}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -102.94433550507199:\\
\;\;\;\;\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)\\

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

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

\end{array}
double code(double x) {
	return ((double) (((double) (((double) (1.0 / ((double) (x + 1.0)))) - ((double) (2.0 / x)))) + ((double) (1.0 / ((double) (x - 1.0))))));
}
double code(double x) {
	double VAR;
	if ((x <= -102.94433550507199)) {
		VAR = ((double) fma(2.0, ((double) (1.0 / ((double) pow(x, 7.0)))), ((double) fma(2.0, ((double) (1.0 / ((double) pow(x, 5.0)))), ((double) (((double) (2.0 / ((double) (x * x)))) / x))))));
	} else {
		double VAR_1;
		if ((x <= 99.93867250030655)) {
			VAR_1 = ((double) (1.0 * ((double) fma(((double) (1.0 / x)), ((double) (((double) -(2.0)) + 2.0)), ((double) (((double) (((double) (1.0 / ((double) (x - 1.0)))) + ((double) (1.0 / ((double) (x + 1.0)))))) + ((double) (((double) -(2.0)) / x))))))));
		} else {
			VAR_1 = ((double) fma(2.0, ((double) (1.0 / ((double) pow(x, 7.0)))), ((double) fma(2.0, ((double) (1.0 / ((double) pow(x, 5.0)))), ((double) (2.0 / ((double) pow(x, 3.0))))))));
		}
		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 < -102.94433550507199

    1. Initial program 20.1

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

      \[\leadsto \left(\frac{1}{x + 1} - \color{blue}{2 \cdot \frac{1}{x}}\right) + \frac{1}{x - 1}\]
    4. Applied *-un-lft-identity20.1

      \[\leadsto \left(\color{blue}{1 \cdot \frac{1}{x + 1}} - 2 \cdot \frac{1}{x}\right) + \frac{1}{x - 1}\]
    5. Applied prod-diff20.1

      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right)\right)} + \frac{1}{x - 1}\]
    6. Applied associate-+l+20.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)}\]
    7. 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)}\]
    8. 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)}\]
    9. Using strategy rm
    10. Applied unpow30.6

      \[\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)\]
    11. 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)\]

    if -102.94433550507199 < x < 99.93867250030655

    1. Initial program 0.0

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

      \[\leadsto \left(\frac{1}{x + 1} - \color{blue}{2 \cdot \frac{1}{x}}\right) + \frac{1}{x - 1}\]
    4. Applied *-un-lft-identity0.0

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

      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right)\right)} + \frac{1}{x - 1}\]
    6. Applied associate-+l+0.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity0.0

      \[\leadsto \mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \color{blue}{1 \cdot \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)}\]
    9. Applied *-un-lft-identity0.0

      \[\leadsto \color{blue}{1 \cdot \mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right)} + 1 \cdot \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)\]
    10. Applied distribute-lft-out0.0

      \[\leadsto \color{blue}{1 \cdot \left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)\right)}\]
    11. Simplified0.0

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

    if 99.93867250030655 < x

    1. Initial program 19.8

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

      \[\leadsto \left(\frac{1}{x + 1} - \color{blue}{2 \cdot \frac{1}{x}}\right) + \frac{1}{x - 1}\]
    4. Applied *-un-lft-identity19.8

      \[\leadsto \left(\color{blue}{1 \cdot \frac{1}{x + 1}} - 2 \cdot \frac{1}{x}\right) + \frac{1}{x - 1}\]
    5. Applied prod-diff19.8

      \[\leadsto \color{blue}{\left(\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right)\right)} + \frac{1}{x - 1}\]
    6. Applied associate-+l+19.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(1, \frac{1}{x + 1}, -\frac{1}{x} \cdot 2\right) + \left(\mathsf{fma}\left(-\frac{1}{x}, 2, \frac{1}{x} \cdot 2\right) + \frac{1}{x - 1}\right)}\]
    7. Taylor expanded around inf 0.6

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

      \[\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)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -102.94433550507199:\\ \;\;\;\;\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)\\ \mathbf{elif}\;x \le 99.938672500306552:\\ \;\;\;\;1 \cdot \mathsf{fma}\left(\frac{1}{x}, \left(-2\right) + 2, \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right) + \frac{-2}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \frac{1}{{x}^{7}}, \mathsf{fma}\left(2, \frac{1}{{x}^{5}}, \frac{2}{{x}^{3}}\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020113 +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))))