Average Error: 9.7 → 0.4
Time: 3.5m
Precision: 64
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right) \le -5.201256207142199:\\ \;\;\;\;\left((\left(\frac{-\sqrt[3]{2}}{\sqrt[3]{x}}\right) \cdot \left(\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right) + \left(\frac{\sqrt[3]{2}}{\sqrt[3]{x}} \cdot \frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right))_* + \frac{1}{x - 1}\right) + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\\ \mathbf{elif}\;\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right) \le 0.0:\\ \;\;\;\;\left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x}}{x \cdot x}\right) + \frac{2}{{x}^{7}}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(x - (x \cdot 2 + 2)_*\right) \cdot \left(x - 1\right) + \left((x \cdot x + x)_*\right))_*}{(x \cdot x + -1)_* \cdot x}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))) < -5.201256207142199

    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-cbrt1.4

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

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

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

      \[\leadsto \left(\frac{1}{\color{blue}{\frac{x \cdot x - 1 \cdot 1}{x - 1}}} - \frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{\sqrt[3]{2}}{\sqrt[3]{x}}\right) + \frac{1}{x - 1}\]
    7. Applied associate-/r/2.4

      \[\leadsto \left(\color{blue}{\frac{1}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right)} - \frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{\sqrt[3]{2}}{\sqrt[3]{x}}\right) + \frac{1}{x - 1}\]
    8. Applied prod-diff2.4

      \[\leadsto \color{blue}{\left((\left(\frac{1}{x \cdot x - 1 \cdot 1}\right) \cdot \left(x - 1\right) + \left(-\frac{\sqrt[3]{2}}{\sqrt[3]{x}} \cdot \frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right))_* + (\left(-\frac{\sqrt[3]{2}}{\sqrt[3]{x}}\right) \cdot \left(\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right) + \left(\frac{\sqrt[3]{2}}{\sqrt[3]{x}} \cdot \frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right))_*\right)} + \frac{1}{x - 1}\]
    9. Applied associate-+l+2.4

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

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

    if -5.201256207142199 < (+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))) < 0.0

    1. Initial program 19.0

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

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

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

    if 0.0 < (+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1)))

    1. Initial program 1.3

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
    2. Using strategy rm
    3. Applied frac-sub1.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-add0.9

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

      \[\leadsto \frac{\color{blue}{(\left(x - (x \cdot 2 + 2)_*\right) \cdot \left(x - 1\right) + \left((x \cdot x + x)_*\right))_*}}{\left(\left(x + 1\right) \cdot x\right) \cdot \left(x - 1\right)}\]
    6. Simplified1.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right) \le -5.201256207142199:\\ \;\;\;\;\left((\left(\frac{-\sqrt[3]{2}}{\sqrt[3]{x}}\right) \cdot \left(\frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right) + \left(\frac{\sqrt[3]{2}}{\sqrt[3]{x}} \cdot \frac{\sqrt[3]{2} \cdot \sqrt[3]{2}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right))_* + \frac{1}{x - 1}\right) + \left(\frac{1}{x + 1} - \frac{2}{x}\right)\\ \mathbf{elif}\;\frac{1}{x - 1} + \left(\frac{1}{x + 1} - \frac{2}{x}\right) \le 0.0:\\ \;\;\;\;\left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x}}{x \cdot x}\right) + \frac{2}{{x}^{7}}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(x - (x \cdot 2 + 2)_*\right) \cdot \left(x - 1\right) + \left((x \cdot x + x)_*\right))_*}{(x \cdot x + -1)_* \cdot x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019100 +o rules:numerics
(FPCore (x)
  :name "3frac (problem 3.3.3)"

  :herbie-target
  (/ 2 (* x (- (* x x) 1)))

  (+ (- (/ 1 (+ x 1)) (/ 2 x)) (/ 1 (- x 1))))