Average Error: 52.6 → 0.1
Time: 16.4s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0612400279589977:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} - \left(\frac{\frac{-1}{8}}{x \cdot \left(x \cdot x\right)} + \frac{\frac{1}{2}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.00884177569185373:\\ \;\;\;\;\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{hypot}\left(1, x\right) + x\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \le -1.0612400279589977:\\
\;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} - \left(\frac{\frac{-1}{8}}{x \cdot \left(x \cdot x\right)} + \frac{\frac{1}{2}}{x}\right)\right)\\

\mathbf{elif}\;x \le 0.00884177569185373:\\
\;\;\;\;\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), x\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{hypot}\left(1, x\right) + x\right)\\

\end{array}
double f(double x) {
        double r3683670 = x;
        double r3683671 = r3683670 * r3683670;
        double r3683672 = 1.0;
        double r3683673 = r3683671 + r3683672;
        double r3683674 = sqrt(r3683673);
        double r3683675 = r3683670 + r3683674;
        double r3683676 = log(r3683675);
        return r3683676;
}

double f(double x) {
        double r3683677 = x;
        double r3683678 = -1.0612400279589977;
        bool r3683679 = r3683677 <= r3683678;
        double r3683680 = -0.0625;
        double r3683681 = 5.0;
        double r3683682 = pow(r3683677, r3683681);
        double r3683683 = r3683680 / r3683682;
        double r3683684 = -0.125;
        double r3683685 = r3683677 * r3683677;
        double r3683686 = r3683677 * r3683685;
        double r3683687 = r3683684 / r3683686;
        double r3683688 = 0.5;
        double r3683689 = r3683688 / r3683677;
        double r3683690 = r3683687 + r3683689;
        double r3683691 = r3683683 - r3683690;
        double r3683692 = log(r3683691);
        double r3683693 = 0.00884177569185373;
        bool r3683694 = r3683677 <= r3683693;
        double r3683695 = 0.075;
        double r3683696 = -0.16666666666666666;
        double r3683697 = fma(r3683696, r3683686, r3683677);
        double r3683698 = fma(r3683695, r3683682, r3683697);
        double r3683699 = 1.0;
        double r3683700 = hypot(r3683699, r3683677);
        double r3683701 = r3683700 + r3683677;
        double r3683702 = log(r3683701);
        double r3683703 = r3683694 ? r3683698 : r3683702;
        double r3683704 = r3683679 ? r3683692 : r3683703;
        return r3683704;
}

Error

Bits error versus x

Target

Original52.6
Target44.7
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \lt 0:\\ \;\;\;\;\log \left(\frac{-1}{x - \sqrt{x \cdot x + 1}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \sqrt{x \cdot x + 1}\right)\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -1.0612400279589977

    1. Initial program 61.7

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Simplified60.9

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Taylor expanded around -inf 0.2

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

      \[\leadsto \log \color{blue}{\left(\frac{\frac{-1}{16}}{{x}^{5}} - \left(\frac{\frac{1}{2}}{x} + \frac{\frac{-1}{8}}{\left(x \cdot x\right) \cdot x}\right)\right)}\]

    if -1.0612400279589977 < x < 0.00884177569185373

    1. Initial program 58.8

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Simplified58.8

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Taylor expanded around 0 0.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, \left(x \cdot x\right) \cdot x, x\right)\right)}\]

    if 0.00884177569185373 < x

    1. Initial program 31.1

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Simplified0.2

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.0612400279589977:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} - \left(\frac{\frac{-1}{8}}{x \cdot \left(x \cdot x\right)} + \frac{\frac{1}{2}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.00884177569185373:\\ \;\;\;\;\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{hypot}\left(1, x\right) + x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019152 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic arcsine"

  :herbie-target
  (if (< x 0) (log (/ -1 (- x (sqrt (+ (* x x) 1))))) (log (+ x (sqrt (+ (* x x) 1)))))

  (log (+ x (sqrt (+ (* x x) 1)))))