Average Error: 9.6 → 0.3
Time: 12.5s
Precision: binary64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
\[\begin{array}{l} \mathbf{if}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1} \leq -3.5683845743712805 \cdot 10^{-11}:\\ \;\;\;\;\frac{\left(x + -1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\left(x + -1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\ \mathbf{elif}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1} \leq 9.26442286059391 \cdot 10^{-22}:\\ \;\;\;\;\frac{2}{{x}^{3}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{7}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(x + -1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + \left(x + x \cdot x\right)}{\left(x + -1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\ \end{array} \]
\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}
\begin{array}{l}
\mathbf{if}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1} \leq -3.5683845743712805 \cdot 10^{-11}:\\
\;\;\;\;\frac{\left(x + -1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + x \cdot \left(1 + x\right)}{\left(x + -1\right) \cdot \left(x \cdot \left(1 + x\right)\right)}\\

\mathbf{elif}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x + -1} \leq 9.26442286059391 \cdot 10^{-22}:\\
\;\;\;\;\frac{2}{{x}^{3}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{7}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(x + -1\right) \cdot \left(x - \left(1 + x\right) \cdot 2\right) + \left(x + x \cdot x\right)}{\left(x + -1\right) \cdot \left(x \cdot \left(1 + x\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
 (if (<=
      (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (+ x -1.0)))
      -3.5683845743712805e-11)
   (/
    (+ (* (+ x -1.0) (- x (* (+ 1.0 x) 2.0))) (* x (+ 1.0 x)))
    (* (+ x -1.0) (* x (+ 1.0 x))))
   (if (<=
        (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (+ x -1.0)))
        9.26442286059391e-22)
     (+ (/ 2.0 (pow x 3.0)) (+ (/ 2.0 (pow x 5.0)) (/ 2.0 (pow x 7.0))))
     (/
      (+ (* (+ x -1.0) (- x (* (+ 1.0 x) 2.0))) (+ x (* x x)))
      (* (+ x -1.0) (* x (+ 1.0 x)))))))
double code(double x) {
	return ((1.0 / (x + 1.0)) - (2.0 / x)) + (1.0 / (x - 1.0));
}
double code(double x) {
	double tmp;
	if ((((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0))) <= -3.5683845743712805e-11) {
		tmp = (((x + -1.0) * (x - ((1.0 + x) * 2.0))) + (x * (1.0 + x))) / ((x + -1.0) * (x * (1.0 + x)));
	} else if ((((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x + -1.0))) <= 9.26442286059391e-22) {
		tmp = (2.0 / pow(x, 3.0)) + ((2.0 / pow(x, 5.0)) + (2.0 / pow(x, 7.0)));
	} else {
		tmp = (((x + -1.0) * (x - ((1.0 + x) * 2.0))) + (x + (x * x))) / ((x + -1.0) * (x * (1.0 + x)));
	}
	return tmp;
}

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 3 regimes
  2. if (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < -3.5683845744e-11

    1. Initial program 0.1

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Using strategy rm
    3. Applied frac-sub_binary64_21330.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. Applied frac-add_binary64_21320.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)}} \]
    5. Simplified0.0

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

    if -3.5683845744e-11 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 9.26442e-22

    1. Initial program 18.9

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

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

    if 9.26442e-22 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    1. Initial program 0.4

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

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

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

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

Reproduce

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