Average Error: 29.3 → 0.2
Time: 1.9m
Precision: 64
Internal Precision: 1344
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \le 9.675970500933051 \cdot 10^{-05}:\\ \;\;\;\;(\left(\frac{3}{x} + 1\right) \cdot \left(\frac{-1}{x \cdot x}\right) + \left(\frac{-3}{x}\right))_*\\ \mathbf{else}:\\ \;\;\;\;(\left(\frac{-\left(1 + x\right)}{(\left(x \cdot x\right) \cdot x + \left(-1\right))_*}\right) \cdot \left((\left(1 + x\right) \cdot x + 1)_*\right) + \left(\frac{x}{1 + x}\right))_*\\ \end{array}\]

Error

Bits error versus x

Try it out

  1. Inputs

  2. Original Output:

    Herbie Output:

Derivation

  1. Split input into 2 regimes
  2. if (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))) < 9.675970500933051e-05

    1. Initial program 58.7

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Taylor expanded around inf 0.6

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

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

    if 9.675970500933051e-05 < (- (/ x (+ x 1)) (/ (+ x 1) (- x 1)))

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied flip3--0.1

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

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\frac{x + 1}{{x}^{3} - {1}^{3}} \cdot \left(x \cdot x + \left(1 \cdot 1 + x \cdot 1\right)\right)}\]
    5. Applied div-inv0.1

      \[\leadsto \color{blue}{x \cdot \frac{1}{x + 1}} - \frac{x + 1}{{x}^{3} - {1}^{3}} \cdot \left(x \cdot x + \left(1 \cdot 1 + x \cdot 1\right)\right)\]
    6. Applied prod-diff0.1

      \[\leadsto \color{blue}{(x \cdot \left(\frac{1}{x + 1}\right) + \left(-\left(x \cdot x + \left(1 \cdot 1 + x \cdot 1\right)\right) \cdot \frac{x + 1}{{x}^{3} - {1}^{3}}\right))_* + (\left(-\left(x \cdot x + \left(1 \cdot 1 + x \cdot 1\right)\right)\right) \cdot \left(\frac{x + 1}{{x}^{3} - {1}^{3}}\right) + \left(\left(x \cdot x + \left(1 \cdot 1 + x \cdot 1\right)\right) \cdot \frac{x + 1}{{x}^{3} - {1}^{3}}\right))_*}\]
    7. Applied simplify0.1

      \[\leadsto \color{blue}{(\left(\frac{-\left(1 + x\right)}{(\left(x \cdot x\right) \cdot x + \left(-1\right))_*}\right) \cdot \left((\left(1 + x\right) \cdot x + 1)_*\right) + \left(\frac{x}{1 + x}\right))_*} + (\left(-\left(x \cdot x + \left(1 \cdot 1 + x \cdot 1\right)\right)\right) \cdot \left(\frac{x + 1}{{x}^{3} - {1}^{3}}\right) + \left(\left(x \cdot x + \left(1 \cdot 1 + x \cdot 1\right)\right) \cdot \frac{x + 1}{{x}^{3} - {1}^{3}}\right))_*\]
    8. Applied simplify0.1

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;\frac{x}{1 + x} - \frac{1 + x}{x - 1} \le 9.675970500933051 \cdot 10^{-05}:\\ \;\;\;\;(\left(\frac{3}{x} + 1\right) \cdot \left(\frac{-1}{x \cdot x}\right) + \left(\frac{-3}{x}\right))_*\\ \mathbf{else}:\\ \;\;\;\;(\left(\frac{-\left(1 + x\right)}{(\left(x \cdot x\right) \cdot x + \left(-1\right))_*}\right) \cdot \left((\left(1 + x\right) \cdot x + 1)_*\right) + \left(\frac{x}{1 + x}\right))_*\\ \end{array}}\]

Runtime

Time bar (total: 1.9m)Debug logProfile

herbie shell --seed '#(1072361757 3390613284 2339397988 1175251238 145061547 3101881848)' +o rules:numerics
(FPCore (x)
  :name "Asymptote C"
  (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))