Average Error: 29.4 → 0.2
Time: 3.4s
Precision: binary64
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \le 8.4395697880213 \cdot 10^{-6}:\\ \;\;\;\;-\left(\frac{3}{x} + \frac{1 + \frac{3}{x}}{x \cdot x}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{1}{x + 1} - \frac{x + 1}{x - 1}\\ \end{array}\]

Error

Bits error versus x

Derivation

  1. Split input into 2 regimes
  2. if (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))) < 8.4395697880213e-6

    1. Initial program 58.9

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Using strategy rm
    3. Applied add-log-exp58.9

      \[\leadsto \frac{x}{x + 1} - \color{blue}{\log \left(e^{\frac{x + 1}{x - 1}}\right)}\]
    4. Applied add-log-exp58.9

      \[\leadsto \color{blue}{\log \left(e^{\frac{x}{x + 1}}\right)} - \log \left(e^{\frac{x + 1}{x - 1}}\right)\]
    5. Applied diff-log58.9

      \[\leadsto \color{blue}{\log \left(\frac{e^{\frac{x}{x + 1}}}{e^{\frac{x + 1}{x - 1}}}\right)}\]
    6. Simplified58.9

      \[\leadsto \log \color{blue}{\left(e^{\frac{x}{x + 1} - \frac{x + 1}{x - 1}}\right)}\]
    7. Taylor expanded around inf 0.6

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

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

    if 8.4395697880213e-6 < (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0)))

    1. Initial program 0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{x + 1} - \frac{x + 1}{x - 1} \le 8.4395697880213 \cdot 10^{-6}:\\ \;\;\;\;-\left(\frac{3}{x} + \frac{1 + \frac{3}{x}}{x \cdot x}\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{1}{x + 1} - \frac{x + 1}{x - 1}\\ \end{array}\]

Reproduce

herbie shell --seed 2020179 
(FPCore (x)
  :name "Asymptote C"
  :precision binary64
  (- (/ x (+ x 1.0)) (/ (+ x 1.0) (- x 1.0))))