Average Error: 52.3 → 0.2
Time: 22.8s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0506541446768847:\\ \;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} - \left(\frac{\frac{1}{16}}{{x}^{5}} - \frac{\frac{1}{8}}{x \cdot \left(x \cdot x\right)}\right)\right)\\ \mathbf{elif}\;x \le 0.007354863103659162:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot \frac{-1}{6}\right), \left(x \cdot x\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\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.0506541446768847:\\
\;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} - \left(\frac{\frac{1}{16}}{{x}^{5}} - \frac{\frac{1}{8}}{x \cdot \left(x \cdot x\right)}\right)\right)\\

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

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

\end{array}
double f(double x) {
        double r22048412 = x;
        double r22048413 = r22048412 * r22048412;
        double r22048414 = 1.0;
        double r22048415 = r22048413 + r22048414;
        double r22048416 = sqrt(r22048415);
        double r22048417 = r22048412 + r22048416;
        double r22048418 = log(r22048417);
        return r22048418;
}

double f(double x) {
        double r22048419 = x;
        double r22048420 = -1.0506541446768847;
        bool r22048421 = r22048419 <= r22048420;
        double r22048422 = -0.5;
        double r22048423 = r22048422 / r22048419;
        double r22048424 = 0.0625;
        double r22048425 = 5.0;
        double r22048426 = pow(r22048419, r22048425);
        double r22048427 = r22048424 / r22048426;
        double r22048428 = 0.125;
        double r22048429 = r22048419 * r22048419;
        double r22048430 = r22048419 * r22048429;
        double r22048431 = r22048428 / r22048430;
        double r22048432 = r22048427 - r22048431;
        double r22048433 = r22048423 - r22048432;
        double r22048434 = log(r22048433);
        double r22048435 = 0.007354863103659162;
        bool r22048436 = r22048419 <= r22048435;
        double r22048437 = -0.16666666666666666;
        double r22048438 = r22048419 * r22048437;
        double r22048439 = 0.075;
        double r22048440 = fma(r22048439, r22048426, r22048419);
        double r22048441 = fma(r22048438, r22048429, r22048440);
        double r22048442 = 1.0;
        double r22048443 = hypot(r22048442, r22048419);
        double r22048444 = r22048443 + r22048419;
        double r22048445 = log(r22048444);
        double r22048446 = r22048436 ? r22048441 : r22048445;
        double r22048447 = r22048421 ? r22048434 : r22048446;
        return r22048447;
}

Error

Bits error versus x

Target

Original52.3
Target44.5
Herbie0.2
\[\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.0506541446768847

    1. Initial program 61.6

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt61.7

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

      \[\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)}\]
    6. Simplified0.3

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

    if -1.0506541446768847 < x < 0.007354863103659162

    1. Initial program 58.9

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

      \[\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(\left(x \cdot \frac{-1}{6}\right), \left(x \cdot x\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\right)\right)}\]

    if 0.007354863103659162 < x

    1. Initial program 29.9

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt0.1

      \[\leadsto \log \left(x + \color{blue}{\left(\sqrt[3]{\mathsf{hypot}\left(1, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}}\right)\]
    5. Using strategy rm
    6. Applied add-exp-log0.1

      \[\leadsto \log \color{blue}{\left(e^{\log \left(x + \left(\sqrt[3]{\mathsf{hypot}\left(1, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right)}\right)}\]
    7. Applied rem-log-exp0.1

      \[\leadsto \color{blue}{\log \left(x + \left(\sqrt[3]{\mathsf{hypot}\left(1, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right)}\]
    8. Simplified0.1

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

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

Reproduce

herbie shell --seed 2019124 +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)))))