Average Error: 28.9 → 0.3
Time: 3.2m
Precision: 64
Internal Precision: 1344
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;(\left(1 + \frac{3}{x}\right) \cdot \left(\frac{-1}{x \cdot x}\right) + \left(-\frac{3}{x}\right))_* \le -4.612196402366588 \cdot 10^{-14}:\\ \;\;\;\;\frac{x \cdot \left(x - 1\right) - \left(x + 1\right) \cdot \left(x + 1\right)}{\left(x + 1\right) \cdot \left(x - 1\right)}\\ \mathbf{if}\;(\left(1 + \frac{3}{x}\right) \cdot \left(\frac{-1}{x \cdot x}\right) + \left(-\frac{3}{x}\right))_* \le 6.034520012367825 \cdot 10^{-06}:\\ \;\;\;\;(\left(1 + \frac{3}{x}\right) \cdot \left(\frac{-1}{x \cdot x}\right) + \left(-\frac{3}{x}\right))_*\\ \mathbf{else}:\\ \;\;\;\;\frac{(e^{\log_* (1 + \left(x \cdot \left(x - 1\right) - \left(x + 1\right) \cdot \left(x + 1\right)\right))} - 1)^*}{\left(x + 1\right) \cdot \left(x - 1\right)}\\ \end{array}\]

Error

Bits error versus x

Derivation

  1. Split input into 3 regimes
  2. if (fma (+ 1 (/ 3 x)) (/ (- 1) (* x x)) (- (/ 3 x))) < -4.612196402366588e-14

    1. Initial program 0.9

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

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

    if -4.612196402366588e-14 < (fma (+ 1 (/ 3 x)) (/ (- 1) (* x x)) (- (/ 3 x))) < 6.034520012367825e-06

    1. Initial program 59.8

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

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

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

    if 6.034520012367825e-06 < (fma (+ 1 (/ 3 x)) (/ (- 1) (* x x)) (- (/ 3 x)))

    1. Initial program 0.1

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

      \[\leadsto \color{blue}{\frac{x \cdot \left(x - 1\right) - \left(x + 1\right) \cdot \left(x + 1\right)}{\left(x + 1\right) \cdot \left(x - 1\right)}}\]
    4. Using strategy rm
    5. Applied expm1-log1p-u0.1

      \[\leadsto \frac{\color{blue}{(e^{\log_* (1 + \left(x \cdot \left(x - 1\right) - \left(x + 1\right) \cdot \left(x + 1\right)\right))} - 1)^*}}{\left(x + 1\right) \cdot \left(x - 1\right)}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 3.2m)Debug logProfile

herbie shell --seed 2018206 +o rules:numerics
(FPCore (x)
  :name "Asymptote C"
  (- (/ x (+ x 1)) (/ (+ x 1) (- x 1))))