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

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

\end{array}
double code(double x) {
	return ((double) (((double) ((1.0 / ((double) (x + 1.0))) - (2.0 / x))) + (1.0 / ((double) (x - 1.0)))));
}
double code(double x) {
	double VAR;
	if (((x <= -111.66855799925936) || !(x <= 124.37166462846123))) {
		VAR = ((double) ((2.0 / ((double) pow(x, 7.0))) + ((double) ((2.0 / ((double) pow(x, 5.0))) + (2.0 / ((double) pow(x, 3.0)))))));
	} else {
		VAR = ((double) ((((double) (((double) (x * 1.0)) - ((double) (2.0 * ((double) (x + 1.0)))))) / ((double) (((double) (x * 1.0)) + ((double) (x * x))))) + (1.0 / ((double) (x - 1.0)))));
	}
	return VAR;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -111.668557999259363 or 124.371664628461232 < x

    1. Initial program 19.5

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. 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)}\]
    3. Simplified0.6

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

    if -111.668557999259363 < x < 124.371664628461232

    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.0

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

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

      \[\leadsto \frac{1 \cdot x - \left(1 + x\right) \cdot 2}{\color{blue}{x \cdot \left(1 + x\right)}} + \frac{1}{x - 1}\]
    6. Using strategy rm
    7. Applied distribute-lft-in0.1

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

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

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

Reproduce

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