Average Error: 9.7 → 0.2
Time: 4.4s
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 -47.53180757808395:\\ \;\;\;\;\frac{1}{x - 1} + \left(\frac{1}{\sqrt[3]{1 + x} \cdot \sqrt[3]{1 + x}} \cdot \frac{1}{\sqrt[3]{1 + x}} - \frac{2}{x}\right)\\ \mathbf{elif}\;\left(\frac{1}{1 + x} - \frac{2}{x}\right) + \frac{1}{x - 1} \leq 1.0755405800569676 \cdot 10^{-08}:\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x \cdot x}}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x - 1} + \frac{x - \left(1 + x\right) \cdot 2}{x \cdot \left(1 + x\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 -47.53180757808395:\\
\;\;\;\;\frac{1}{x - 1} + \left(\frac{1}{\sqrt[3]{1 + x} \cdot \sqrt[3]{1 + x}} \cdot \frac{1}{\sqrt[3]{1 + x}} - \frac{2}{x}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{x - 1} + \frac{x - \left(1 + x\right) \cdot 2}{x \cdot \left(1 + x\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)))
      -47.53180757808395)
   (+
    (/ 1.0 (- x 1.0))
    (-
     (* (/ 1.0 (* (cbrt (+ 1.0 x)) (cbrt (+ 1.0 x)))) (/ 1.0 (cbrt (+ 1.0 x))))
     (/ 2.0 x)))
   (if (<=
        (+ (- (/ 1.0 (+ 1.0 x)) (/ 2.0 x)) (/ 1.0 (- x 1.0)))
        1.0755405800569676e-08)
     (+ (/ 2.0 (pow x 7.0)) (+ (/ 2.0 (pow x 5.0)) (/ (/ 2.0 (* x x)) x)))
     (+ (/ 1.0 (- x 1.0)) (/ (- x (* (+ 1.0 x) 2.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))) <= -47.53180757808395) {
		tmp = (1.0 / (x - 1.0)) + (((1.0 / (cbrt(1.0 + x) * cbrt(1.0 + x))) * (1.0 / cbrt(1.0 + x))) - (2.0 / x));
	} else if ((((1.0 / (1.0 + x)) - (2.0 / x)) + (1.0 / (x - 1.0))) <= 1.0755405800569676e-08) {
		tmp = (2.0 / pow(x, 7.0)) + ((2.0 / pow(x, 5.0)) + ((2.0 / (x * x)) / x));
	} else {
		tmp = (1.0 / (x - 1.0)) + ((x - ((1.0 + x) * 2.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.7
Target0.3
Herbie0.2
\[\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))) < -47.5318075780839493

    1. Initial program 0.0

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

      \[\leadsto \left(\frac{1}{\color{blue}{\left(\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1}\right) \cdot \sqrt[3]{x + 1}}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    4. Applied add-sqr-sqrt_binary64_14640.0

      \[\leadsto \left(\frac{\color{blue}{\sqrt{1} \cdot \sqrt{1}}}{\left(\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1}\right) \cdot \sqrt[3]{x + 1}} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    5. Applied times-frac_binary64_14480.0

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

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

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

    if -47.5318075780839493 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1))) < 1.07554058006e-8

    1. Initial program 19.8

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

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

      \[\leadsto \color{blue}{\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{{x}^{3}}\right)}\]
    4. Using strategy rm
    5. Applied unpow3_binary64_15080.8

      \[\leadsto \frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{2}{\color{blue}{\left(x \cdot x\right) \cdot x}}\right)\]
    6. Applied associate-/r*_binary64_13860.4

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

    if 1.07554058006e-8 < (+.f64 (-.f64 (/.f64 1 (+.f64 x 1)) (/.f64 2 x)) (/.f64 1 (-.f64 x 1)))

    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_14510.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. Simplified0.1

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

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

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

Reproduce

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