Average Error: 58.5 → 0.6
Time: 17.8s
Precision: 64
\[\frac{1}{2} \cdot \log \left(\frac{1 + x}{1 - x}\right)\]
\[\frac{1}{2} \cdot \mathsf{fma}\left(2, x \cdot \left(x - \frac{x}{1 \cdot 1}\right), \mathsf{fma}\left(2, x, \log 1\right)\right)\]
\frac{1}{2} \cdot \log \left(\frac{1 + x}{1 - x}\right)
\frac{1}{2} \cdot \mathsf{fma}\left(2, x \cdot \left(x - \frac{x}{1 \cdot 1}\right), \mathsf{fma}\left(2, x, \log 1\right)\right)
double f(double x) {
        double r42554 = 1.0;
        double r42555 = 2.0;
        double r42556 = r42554 / r42555;
        double r42557 = x;
        double r42558 = r42554 + r42557;
        double r42559 = r42554 - r42557;
        double r42560 = r42558 / r42559;
        double r42561 = log(r42560);
        double r42562 = r42556 * r42561;
        return r42562;
}

double f(double x) {
        double r42563 = 1.0;
        double r42564 = 2.0;
        double r42565 = r42563 / r42564;
        double r42566 = x;
        double r42567 = r42563 * r42563;
        double r42568 = r42566 / r42567;
        double r42569 = r42566 - r42568;
        double r42570 = r42566 * r42569;
        double r42571 = log(r42563);
        double r42572 = fma(r42564, r42566, r42571);
        double r42573 = fma(r42564, r42570, r42572);
        double r42574 = r42565 * r42573;
        return r42574;
}

Error

Bits error versus x

Derivation

  1. Initial program 58.5

    \[\frac{1}{2} \cdot \log \left(\frac{1 + x}{1 - x}\right)\]
  2. Taylor expanded around 0 0.6

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

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

    \[\leadsto \frac{1}{2} \cdot \mathsf{fma}\left(2, x \cdot \left(x - \frac{x}{1 \cdot 1}\right), \mathsf{fma}\left(2, x, \log 1\right)\right)\]

Reproduce

herbie shell --seed 2019325 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic arc-(co)tangent"
  :precision binary64
  (* (/ 1 2) (log (/ (+ 1 x) (- 1 x)))))