Prelude:atanh from fay-base-0.20.0.1

Percentage Accurate: 100.0% → 100.0%
Time: 1.4s
Alternatives: 5
Speedup: 7.0×

Specification

?
\[\frac{x + 1}{1 - x} \]

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 5 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.

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\frac{x + 1}{1 - x} \]
Derivation
  1. Initial program 100.0%

    \[\frac{x + 1}{1 - x} \]
  2. Final simplification100.0%

    \[\leadsto \frac{x + 1}{1 - x} \]

Alternative 2: 98.3% accurate, 0.8× speedup?

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

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto -1 + \left(-\frac{\color{blue}{2}}{x}\right) \]
      5. distribute-neg-frac98.9%

        \[\leadsto -1 + \color{blue}{\frac{-2}{x}} \]
      6. metadata-eval98.9%

        \[\leadsto -1 + \frac{\color{blue}{-2}}{x} \]
    4. Simplified98.9%

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

    if -1 < x < 1

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.1%

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

Alternative 3: 98.8% accurate, 0.8× speedup?

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

    1. Initial program 100.0%

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

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

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

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

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

        \[\leadsto -1 + \left(-\frac{\color{blue}{2}}{x}\right) \]
      5. distribute-neg-frac98.9%

        \[\leadsto -1 + \color{blue}{\frac{-2}{x}} \]
      6. metadata-eval98.9%

        \[\leadsto -1 + \frac{\color{blue}{-2}}{x} \]
    4. Simplified98.9%

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

    if -2 < x < 1

    1. Initial program 100.0%

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

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

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

Alternative 4: 97.6% accurate, 1.4× speedup?

\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
Derivation
  1. Split input into 2 regimes
  2. if x < -1 or 1 < x

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{-1} \]

    if -1 < x < 1

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]

Alternative 5: 49.7% accurate, 7.0× speedup?

\[-1 \]
Derivation
  1. Initial program 100.0%

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

    \[\leadsto \color{blue}{-1} \]
  3. Final simplification49.8%

    \[\leadsto -1 \]

Reproduce

?
herbie shell --seed 2023167 
(FPCore (x)
  :name "Prelude:atanh from fay-base-0.20.0.1"
  :precision binary64
  (/ (+ x 1.0) (- 1.0 x)))