Average Error: 10.0 → 0.3
Time: 3.4s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -370328111107034.12 \lor \neg \left(x \le 569.334989116714155\right):\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{\frac{x \cdot \left({x}^{4} - {1}^{4}\right)}{x \cdot x + 1 \cdot 1}}\\ \end{array}\]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;x \le -370328111107034.12 \lor \neg \left(x \le 569.334989116714155\right):\\
\;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{x \cdot \left({x}^{4} - {1}^{4}\right)}{x \cdot x + 1 \cdot 1}}\\

\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 <= -370328111107034.1) || !(x <= 569.3349891167142))) {
		VAR = ((double) (((double) (2.0 / ((double) pow(x, 7.0)))) + ((double) (((double) (2.0 / ((double) pow(x, 5.0)))) + ((double) (2.0 / ((double) pow(x, 3.0))))))));
	} else {
		VAR = ((double) (2.0 / ((double) (((double) (x * ((double) (((double) pow(x, 4.0)) - ((double) pow(1.0, 4.0)))))) / ((double) (((double) (x * x)) + ((double) (1.0 * 1.0))))))));
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -370328111107034.12 or 569.334989116714155 < x

    1. Initial program 19.6

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

      \[\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.7

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

    if -370328111107034.12 < x < 569.334989116714155

    1. Initial program 0.8

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

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

      \[\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)}}\]
    5. Simplified0.5

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

      \[\leadsto \frac{\left(x - 1\right) \cdot \left(1 \cdot x - \left(1 + x\right) \cdot 2\right) + 1 \cdot \left(x \cdot \left(1 + x\right)\right)}{\color{blue}{x \cdot \left(x \cdot x - 1 \cdot 1\right)}}\]
    7. Using strategy rm
    8. Applied flip--0.5

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

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

      \[\leadsto \frac{\left(x - 1\right) \cdot \left(1 \cdot x - \left(1 + x\right) \cdot 2\right) + 1 \cdot \left(x \cdot \left(1 + x\right)\right)}{\frac{\color{blue}{x \cdot \left({x}^{4} - {1}^{4}\right)}}{x \cdot x + 1 \cdot 1}}\]
    11. Taylor expanded around 0 0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -370328111107034.12 \lor \neg \left(x \le 569.334989116714155\right):\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{\frac{x \cdot \left({x}^{4} - {1}^{4}\right)}{x \cdot x + 1 \cdot 1}}\\ \end{array}\]

Reproduce

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