Average Error: 29.3 → 0.7
Time: 32.9s
Precision: 64
Internal Precision: 1344
\[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
\[\begin{array}{l} \mathbf{if}\;\frac{-3}{x} - \frac{1 + \frac{3}{x}}{x \cdot x} \le -1.6565827042164526 \cdot 10^{-14}:\\ \;\;\;\;\log \left(e^{\frac{x}{1 + x} - \frac{1 + x}{x - 1}}\right)\\ \mathbf{if}\;\frac{-3}{x} - \frac{1 + \frac{3}{x}}{x \cdot x} \le 9.67597050092789 \cdot 10^{-05}:\\ \;\;\;\;\frac{-3}{x} - \frac{1 + \frac{3}{x}}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(3 + x\right) + 1\\ \end{array}\]

Error

Bits error versus x

Try it out

  1. Inputs

  2. Original Output:

    Herbie Output:

Derivation

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

    1. Initial program 1.0

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

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

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

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

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

    if -1.6565827042164526e-14 < (- (/ (- 3) x) (/ (+ 1 (/ 3 x)) (* x x))) < 9.67597050092789e-05

    1. Initial program 59.7

      \[\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}{\frac{-3}{x} - \frac{1 + \frac{3}{x}}{x \cdot x}}\]

    if 9.67597050092789e-05 < (- (/ (- 3) x) (/ (+ 1 (/ 3 x)) (* x x)))

    1. Initial program 0.1

      \[\frac{x}{x + 1} - \frac{x + 1}{x - 1}\]
    2. Taylor expanded around 0 1.6

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

      \[\leadsto \color{blue}{x \cdot \left(3 + x\right) + 1}\]
  3. Recombined 3 regimes into one program.

Runtime

Time bar (total: 32.9s)Debug logProfile

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