Average Error: 9.6 → 0.1
Time: 3.2m
Precision: 64
Internal Precision: 1088
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -119.37622627819111:\\ \;\;\;\;\frac{2}{{x}^{5}} + \left(\frac{1}{x \cdot x} \cdot \frac{2}{x} + \frac{2}{{x}^{7}}\right)\\ \mathbf{elif}\;x \le 123.20341290138498:\\ \;\;\;\;\frac{(\left(x - (x \cdot 2 + 2)_*\right) \cdot \left(x - 1\right) + \left(x + x \cdot x\right))_*}{\left(x - 1\right) \cdot (x \cdot x + x)_*}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\frac{2}{x}}{x \cdot x} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}\\ \end{array}\]

Error

Bits error versus x

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -119.37622627819111

    1. Initial program 19.8

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

      \[\leadsto \color{blue}{\left(\frac{\frac{2}{x}}{x \cdot x} + \frac{2}{{x}^{7}}\right) + \frac{2}{{x}^{5}}}\]
    4. Using strategy rm
    5. Applied div-inv0.1

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

    if -119.37622627819111 < x < 123.20341290138498

    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. Applied frac-add0.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 - (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. Simplified0.0

      \[\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 + x)_* \cdot \left(x - 1\right)}}\]

    if 123.20341290138498 < x

    1. Initial program 19.3

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

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

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

Runtime

Time bar (total: 3.2m)Debug logProfile

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