3frac (problem 3.3.3)

Percentage Accurate: 84.5% → 99.9%
Time: 7.2s
Alternatives: 7
Speedup: TODO×

Specification

?
\[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]

Your Program's Arguments

Results

Enter valid numbers for all inputs

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Target

Original84.5%
Target99.5%
Herbie99.9%
\[\frac{2}{x \cdot \left(x \cdot x - 1\right)} \]

Alternative 1?

\[\frac{\frac{-2}{x}}{1 - x \cdot x} \]
Derivation
  1. Initial program 85.9%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Step-by-step derivation
    1. frac-sub57.9%

      \[\leadsto \color{blue}{\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1} \]
    2. div-inv57.4%

      \[\leadsto \color{blue}{\left(1 \cdot x - \left(x + 1\right) \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1} \]
    3. /-rgt-identity57.4%

      \[\leadsto \left(1 \cdot x - \color{blue}{\frac{x + 1}{1}} \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x} + \frac{1}{x - 1} \]
    4. *-un-lft-identity57.4%

      \[\leadsto \left(\color{blue}{x} - \frac{x + 1}{1} \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x} + \frac{1}{x - 1} \]
    5. /-rgt-identity57.4%

      \[\leadsto \left(x - \color{blue}{\left(x + 1\right)} \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x} + \frac{1}{x - 1} \]
    6. +-commutative57.4%

      \[\leadsto \left(x - \color{blue}{\left(1 + x\right)} \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x} + \frac{1}{x - 1} \]
    7. *-commutative57.4%

      \[\leadsto \left(x - \left(1 + x\right) \cdot 2\right) \cdot \frac{1}{\color{blue}{x \cdot \left(x + 1\right)}} + \frac{1}{x - 1} \]
    8. +-commutative57.4%

      \[\leadsto \left(x - \left(1 + x\right) \cdot 2\right) \cdot \frac{1}{x \cdot \color{blue}{\left(1 + x\right)}} + \frac{1}{x - 1} \]
  3. Applied egg-rr57.4%

    \[\leadsto \color{blue}{\left(x - \left(1 + x\right) \cdot 2\right) \cdot \frac{1}{x \cdot \left(1 + x\right)}} + \frac{1}{x - 1} \]
  4. Step-by-step derivation
    1. *-commutative57.4%

      \[\leadsto \left(x - \color{blue}{2 \cdot \left(1 + x\right)}\right) \cdot \frac{1}{x \cdot \left(1 + x\right)} + \frac{1}{x - 1} \]
    2. +-commutative57.4%

      \[\leadsto \left(x - 2 \cdot \color{blue}{\left(x + 1\right)}\right) \cdot \frac{1}{x \cdot \left(1 + x\right)} + \frac{1}{x - 1} \]
    3. associate-/r*59.0%

      \[\leadsto \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \color{blue}{\frac{\frac{1}{x}}{1 + x}} + \frac{1}{x - 1} \]
    4. +-commutative59.0%

      \[\leadsto \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{\color{blue}{x + 1}} + \frac{1}{x - 1} \]
  5. Simplified59.0%

    \[\leadsto \color{blue}{\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{x + 1}} + \frac{1}{x - 1} \]
  6. Step-by-step derivation
    1. +-commutative59.0%

      \[\leadsto \color{blue}{\frac{1}{x - 1} + \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{x + 1}} \]
    2. frac-2neg59.0%

      \[\leadsto \color{blue}{\frac{-1}{-\left(x - 1\right)}} + \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{x + 1} \]
    3. metadata-eval59.0%

      \[\leadsto \frac{\color{blue}{-1}}{-\left(x - 1\right)} + \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{x + 1} \]
    4. associate-*r/85.6%

      \[\leadsto \frac{-1}{-\left(x - 1\right)} + \color{blue}{\frac{\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{1}{x}}{x + 1}} \]
    5. frac-add84.5%

      \[\leadsto \color{blue}{\frac{-1 \cdot \left(x + 1\right) + \left(-\left(x - 1\right)\right) \cdot \left(\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{1}{x}\right)}{\left(-\left(x - 1\right)\right) \cdot \left(x + 1\right)}} \]
  7. Applied egg-rr85.6%

    \[\leadsto \color{blue}{\frac{\left(-1 + \left(-x\right)\right) + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)}} \]
  8. Step-by-step derivation
    1. neg-mul-185.6%

      \[\leadsto \frac{\left(-1 + \color{blue}{-1 \cdot x}\right) + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
    2. metadata-eval85.6%

      \[\leadsto \frac{\left(\color{blue}{-1 \cdot 1} + -1 \cdot x\right) + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
    3. distribute-lft-in85.6%

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(1 + x\right)} + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
    4. +-commutative85.6%

      \[\leadsto \frac{-1 \cdot \color{blue}{\left(x + 1\right)} + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
    5. *-commutative85.6%

      \[\leadsto \frac{\color{blue}{\left(x + 1\right) \cdot -1} + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
    6. *-commutative85.6%

      \[\leadsto \frac{\left(x + 1\right) \cdot -1 + \color{blue}{\frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
    7. +-commutative85.6%

      \[\leadsto \frac{\color{blue}{\frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right) + \left(x + 1\right) \cdot -1}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
    8. *-commutative85.6%

      \[\leadsto \frac{\frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right) + \left(x + 1\right) \cdot -1}{\color{blue}{\left(x + 1\right) \cdot \left(1 - x\right)}} \]
    9. +-commutative85.6%

      \[\leadsto \frac{\color{blue}{\left(x + 1\right) \cdot -1 + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
    10. distribute-rgt1-in85.6%

      \[\leadsto \frac{\color{blue}{\left(-1 + x \cdot -1\right)} + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
    11. *-commutative85.6%

      \[\leadsto \frac{\left(-1 + \color{blue}{-1 \cdot x}\right) + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
    12. neg-mul-185.6%

      \[\leadsto \frac{\left(-1 + \color{blue}{\left(-x\right)}\right) + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
    13. unsub-neg85.6%

      \[\leadsto \frac{\color{blue}{\left(-1 - x\right)} + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
  9. Simplified85.6%

    \[\leadsto \color{blue}{\frac{\left(-1 - x\right) + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)}} \]
  10. Taylor expanded in x around 0 99.9%

    \[\leadsto \frac{\color{blue}{\frac{-2}{x}}}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
  11. Taylor expanded in x around 0 99.9%

    \[\leadsto \frac{\frac{-2}{x}}{\color{blue}{1 + -1 \cdot {x}^{2}}} \]
  12. Step-by-step derivation
    1. mul-1-neg99.9%

      \[\leadsto \frac{\frac{-2}{x}}{1 + \color{blue}{\left(-{x}^{2}\right)}} \]
    2. unsub-neg99.9%

      \[\leadsto \frac{\frac{-2}{x}}{\color{blue}{1 - {x}^{2}}} \]
    3. unpow299.9%

      \[\leadsto \frac{\frac{-2}{x}}{1 - \color{blue}{x \cdot x}} \]
  13. Simplified99.9%

    \[\leadsto \frac{\frac{-2}{x}}{\color{blue}{1 - x \cdot x}} \]
  14. Final simplification99.9%

    \[\leadsto \frac{\frac{-2}{x}}{1 - x \cdot x} \]

Alternative 2?

\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{\frac{-2}{x}}{x \cdot \left(-x\right)}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot x - \frac{2}{x}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if x < -1 or 1 < x

    1. Initial program 71.7%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Step-by-step derivation
      1. frac-sub15.1%

        \[\leadsto \color{blue}{\frac{1 \cdot x - \left(x + 1\right) \cdot 2}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1} \]
      2. div-inv14.2%

        \[\leadsto \color{blue}{\left(1 \cdot x - \left(x + 1\right) \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x}} + \frac{1}{x - 1} \]
      3. /-rgt-identity14.2%

        \[\leadsto \left(1 \cdot x - \color{blue}{\frac{x + 1}{1}} \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x} + \frac{1}{x - 1} \]
      4. *-un-lft-identity14.2%

        \[\leadsto \left(\color{blue}{x} - \frac{x + 1}{1} \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x} + \frac{1}{x - 1} \]
      5. /-rgt-identity14.2%

        \[\leadsto \left(x - \color{blue}{\left(x + 1\right)} \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x} + \frac{1}{x - 1} \]
      6. +-commutative14.2%

        \[\leadsto \left(x - \color{blue}{\left(1 + x\right)} \cdot 2\right) \cdot \frac{1}{\left(x + 1\right) \cdot x} + \frac{1}{x - 1} \]
      7. *-commutative14.2%

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

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

      \[\leadsto \color{blue}{\left(x - \left(1 + x\right) \cdot 2\right) \cdot \frac{1}{x \cdot \left(1 + x\right)}} + \frac{1}{x - 1} \]
    4. Step-by-step derivation
      1. *-commutative14.2%

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

        \[\leadsto \left(x - 2 \cdot \color{blue}{\left(x + 1\right)}\right) \cdot \frac{1}{x \cdot \left(1 + x\right)} + \frac{1}{x - 1} \]
      3. associate-/r*17.3%

        \[\leadsto \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \color{blue}{\frac{\frac{1}{x}}{1 + x}} + \frac{1}{x - 1} \]
      4. +-commutative17.3%

        \[\leadsto \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{\color{blue}{x + 1}} + \frac{1}{x - 1} \]
    5. Simplified17.3%

      \[\leadsto \color{blue}{\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{x + 1}} + \frac{1}{x - 1} \]
    6. Step-by-step derivation
      1. +-commutative17.3%

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

        \[\leadsto \color{blue}{\frac{-1}{-\left(x - 1\right)}} + \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{x + 1} \]
      3. metadata-eval17.3%

        \[\leadsto \frac{\color{blue}{-1}}{-\left(x - 1\right)} + \left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{\frac{1}{x}}{x + 1} \]
      4. associate-*r/71.0%

        \[\leadsto \frac{-1}{-\left(x - 1\right)} + \color{blue}{\frac{\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{1}{x}}{x + 1}} \]
      5. frac-add68.8%

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(x + 1\right) + \left(-\left(x - 1\right)\right) \cdot \left(\left(x - 2 \cdot \left(x + 1\right)\right) \cdot \frac{1}{x}\right)}{\left(-\left(x - 1\right)\right) \cdot \left(x + 1\right)}} \]
    7. Applied egg-rr70.9%

      \[\leadsto \color{blue}{\frac{\left(-1 + \left(-x\right)\right) + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)}} \]
    8. Step-by-step derivation
      1. neg-mul-170.9%

        \[\leadsto \frac{\left(-1 + \color{blue}{-1 \cdot x}\right) + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
      2. metadata-eval70.9%

        \[\leadsto \frac{\left(\color{blue}{-1 \cdot 1} + -1 \cdot x\right) + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
      3. distribute-lft-in70.9%

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(1 + x\right)} + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
      4. +-commutative70.9%

        \[\leadsto \frac{-1 \cdot \color{blue}{\left(x + 1\right)} + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
      5. *-commutative70.9%

        \[\leadsto \frac{\color{blue}{\left(x + 1\right) \cdot -1} + \left(1 - x\right) \cdot \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
      6. *-commutative70.9%

        \[\leadsto \frac{\left(x + 1\right) \cdot -1 + \color{blue}{\frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
      7. +-commutative70.9%

        \[\leadsto \frac{\color{blue}{\frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right) + \left(x + 1\right) \cdot -1}}{\left(1 - x\right) \cdot \left(x + 1\right)} \]
      8. *-commutative70.9%

        \[\leadsto \frac{\frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right) + \left(x + 1\right) \cdot -1}{\color{blue}{\left(x + 1\right) \cdot \left(1 - x\right)}} \]
      9. +-commutative70.9%

        \[\leadsto \frac{\color{blue}{\left(x + 1\right) \cdot -1 + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
      10. distribute-rgt1-in70.9%

        \[\leadsto \frac{\color{blue}{\left(-1 + x \cdot -1\right)} + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
      11. *-commutative70.9%

        \[\leadsto \frac{\left(-1 + \color{blue}{-1 \cdot x}\right) + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
      12. neg-mul-170.9%

        \[\leadsto \frac{\left(-1 + \color{blue}{\left(-x\right)}\right) + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
      13. unsub-neg70.9%

        \[\leadsto \frac{\color{blue}{\left(-1 - x\right)} + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
    9. Simplified70.9%

      \[\leadsto \color{blue}{\frac{\left(-1 - x\right) + \frac{x - \mathsf{fma}\left(x, 2, 2\right)}{x} \cdot \left(1 - x\right)}{\left(x + 1\right) \cdot \left(1 - x\right)}} \]
    10. Taylor expanded in x around 0 99.9%

      \[\leadsto \frac{\color{blue}{\frac{-2}{x}}}{\left(x + 1\right) \cdot \left(1 - x\right)} \]
    11. Taylor expanded in x around inf 98.5%

      \[\leadsto \frac{\frac{-2}{x}}{\color{blue}{-1 \cdot {x}^{2}}} \]
    12. Step-by-step derivation
      1. mul-1-neg98.5%

        \[\leadsto \frac{\frac{-2}{x}}{\color{blue}{-{x}^{2}}} \]
      2. unpow298.5%

        \[\leadsto \frac{\frac{-2}{x}}{-\color{blue}{x \cdot x}} \]
    13. Simplified98.5%

      \[\leadsto \frac{\frac{-2}{x}}{\color{blue}{-x \cdot x}} \]

    if -1 < x < 1

    1. Initial program 100.0%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Taylor expanded in x around 0 99.5%

      \[\leadsto \color{blue}{-2 \cdot x - 2 \cdot \frac{1}{x}} \]
    3. Step-by-step derivation
      1. associate-*r/99.5%

        \[\leadsto -2 \cdot x - \color{blue}{\frac{2 \cdot 1}{x}} \]
      2. metadata-eval99.5%

        \[\leadsto -2 \cdot x - \frac{\color{blue}{2}}{x} \]
    4. Simplified99.5%

      \[\leadsto \color{blue}{-2 \cdot x - \frac{2}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{\frac{-2}{x}}{x \cdot \left(-x\right)}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot x - \frac{2}{x}\\ \end{array} \]

Alternative 3?

\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{1}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\left(-x\right) - \frac{2}{x}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if x < -1 or 1 < x

    1. Initial program 71.7%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Taylor expanded in x around inf 69.9%

      \[\leadsto \color{blue}{\frac{-1}{x}} + \frac{1}{x - 1} \]
    3. Taylor expanded in x around inf 60.9%

      \[\leadsto \color{blue}{\frac{1}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. unpow260.9%

        \[\leadsto \frac{1}{\color{blue}{x \cdot x}} \]
    5. Simplified60.9%

      \[\leadsto \color{blue}{\frac{1}{x \cdot x}} \]

    if -1 < x < 1

    1. Initial program 100.0%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Taylor expanded in x around 0 99.3%

      \[\leadsto \left(\color{blue}{1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    3. Taylor expanded in x around 0 99.3%

      \[\leadsto \color{blue}{-1 \cdot x - 2 \cdot \frac{1}{x}} \]
    4. Step-by-step derivation
      1. neg-mul-199.3%

        \[\leadsto \color{blue}{\left(-x\right)} - 2 \cdot \frac{1}{x} \]
      2. associate-*r/99.3%

        \[\leadsto \left(-x\right) - \color{blue}{\frac{2 \cdot 1}{x}} \]
      3. metadata-eval99.3%

        \[\leadsto \left(-x\right) - \frac{\color{blue}{2}}{x} \]
    5. Simplified99.3%

      \[\leadsto \color{blue}{\left(-x\right) - \frac{2}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{1}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\left(-x\right) - \frac{2}{x}\\ \end{array} \]

Alternative 4?

\[\begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{1}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x}\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if x < -1 or 1 < x

    1. Initial program 71.7%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Taylor expanded in x around inf 69.9%

      \[\leadsto \color{blue}{\frac{-1}{x}} + \frac{1}{x - 1} \]
    3. Taylor expanded in x around inf 60.9%

      \[\leadsto \color{blue}{\frac{1}{{x}^{2}}} \]
    4. Step-by-step derivation
      1. unpow260.9%

        \[\leadsto \frac{1}{\color{blue}{x \cdot x}} \]
    5. Simplified60.9%

      \[\leadsto \color{blue}{\frac{1}{x \cdot x}} \]

    if -1 < x < 1

    1. Initial program 100.0%

      \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
    2. Taylor expanded in x around 0 99.2%

      \[\leadsto \color{blue}{\frac{-2}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\frac{1}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{x}\\ \end{array} \]

Alternative 5?

\[-1 + \left(1 - \frac{2}{x}\right) \]
Derivation
  1. Initial program 85.9%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Taylor expanded in x around 0 51.7%

    \[\leadsto \left(\color{blue}{1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  3. Taylor expanded in x around 0 84.6%

    \[\leadsto \left(1 - \frac{2}{x}\right) + \color{blue}{-1} \]
  4. Final simplification84.6%

    \[\leadsto -1 + \left(1 - \frac{2}{x}\right) \]

Alternative 6?

\[\frac{-2}{x} \]
Derivation
  1. Initial program 85.9%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Taylor expanded in x around 0 52.6%

    \[\leadsto \color{blue}{\frac{-2}{x}} \]
  3. Final simplification52.6%

    \[\leadsto \frac{-2}{x} \]

Alternative 7?

\[1 \]
Derivation
  1. Initial program 85.9%

    \[\left(\frac{1}{x + 1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  2. Taylor expanded in x around 0 51.7%

    \[\leadsto \left(\color{blue}{1} - \frac{2}{x}\right) + \frac{1}{x - 1} \]
  3. Taylor expanded in x around inf 3.3%

    \[\leadsto \color{blue}{1} \]
  4. Final simplification3.3%

    \[\leadsto 1 \]

Reproduce

?
herbie shell --seed 2023166 
(FPCore (x)
  :name "3frac (problem 3.3.3)"
  :precision binary64

  :herbie-target
  (/ 2.0 (* x (- (* x x) 1.0)))

  (+ (- (/ 1.0 (+ x 1.0)) (/ 2.0 x)) (/ 1.0 (- x 1.0))))