Average Error: 9.7 → 0.1
Time: 35.3s
Precision: 64
Internal Precision: 128
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.473404934801497 \cdot 10^{+77}:\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x \cdot x}}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{(\left(x \cdot x - x\right) \cdot x + \left(x \cdot x - x\right))_*}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 2 regimes
  2. if x < -1.473404934801497e+77

    1. Initial program 7.5

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

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

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

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

      \[\leadsto (\color{blue}{\left(\frac{1}{(x \cdot x + -1)_*}\right)} \cdot \left(x - 1\right) + \left(-\frac{2}{x}\right))_* + \frac{1}{x - 1}\]
    7. 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)}\]
    8. Simplified0.0

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

    if -1.473404934801497e+77 < x

    1. Initial program 10.3

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

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

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

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

      \[\leadsto (\color{blue}{\left(\frac{1}{(x \cdot x + -1)_*}\right)} \cdot \left(x - 1\right) + \left(-\frac{2}{x}\right))_* + \frac{1}{x - 1}\]
    7. Using strategy rm
    8. Applied div-inv20.4

      \[\leadsto (\left(\frac{1}{(x \cdot x + -1)_*}\right) \cdot \left(x - 1\right) + \left(-\frac{2}{x}\right))_* + \color{blue}{1 \cdot \frac{1}{x - 1}}\]
    9. Applied *-un-lft-identity20.4

      \[\leadsto \color{blue}{1 \cdot (\left(\frac{1}{(x \cdot x + -1)_*}\right) \cdot \left(x - 1\right) + \left(-\frac{2}{x}\right))_*} + 1 \cdot \frac{1}{x - 1}\]
    10. Applied distribute-lft-out20.4

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

      \[\leadsto 1 \cdot \color{blue}{\left(\frac{-2}{x} + \left(\frac{1}{x - 1} + \frac{1}{x + 1}\right)\right)}\]
    12. Using strategy rm
    13. Applied frac-add20.2

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

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

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

      \[\leadsto 1 \cdot \frac{(-2 \cdot \left(x \cdot x + -1\right) + \left(x \cdot x\right))_* + x \cdot x}{\color{blue}{(\left(x \cdot x - x\right) \cdot x + \left(x \cdot x - x\right))_*}}\]
    17. Taylor expanded around 0 0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.473404934801497 \cdot 10^{+77}:\\ \;\;\;\;\frac{2}{{x}^{7}} + \left(\frac{2}{{x}^{5}} + \frac{\frac{2}{x \cdot x}}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{(\left(x \cdot x - x\right) \cdot x + \left(x \cdot x - x\right))_*}\\ \end{array}\]

Reproduce

herbie shell --seed 2019050 +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))))