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

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

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

\end{array}
double f(double x) {
        double r1591359 = x;
        double r1591360 = r1591359 * r1591359;
        double r1591361 = 1.0;
        double r1591362 = r1591360 + r1591361;
        double r1591363 = sqrt(r1591362);
        double r1591364 = r1591359 + r1591363;
        double r1591365 = log(r1591364);
        return r1591365;
}

double f(double x) {
        double r1591366 = x;
        double r1591367 = -1.076228701950242;
        bool r1591368 = r1591366 <= r1591367;
        double r1591369 = -0.5;
        double r1591370 = r1591369 / r1591366;
        double r1591371 = 0.125;
        double r1591372 = r1591371 / r1591366;
        double r1591373 = r1591366 * r1591366;
        double r1591374 = r1591372 / r1591373;
        double r1591375 = -0.0625;
        double r1591376 = 5.0;
        double r1591377 = pow(r1591366, r1591376);
        double r1591378 = r1591375 / r1591377;
        double r1591379 = r1591374 + r1591378;
        double r1591380 = r1591370 + r1591379;
        double r1591381 = log(r1591380);
        double r1591382 = 0.006188922223074722;
        bool r1591383 = r1591366 <= r1591382;
        double r1591384 = r1591373 * r1591366;
        double r1591385 = -0.16666666666666666;
        double r1591386 = 0.075;
        double r1591387 = fma(r1591386, r1591377, r1591366);
        double r1591388 = fma(r1591384, r1591385, r1591387);
        double r1591389 = 1.0;
        double r1591390 = hypot(r1591389, r1591366);
        double r1591391 = r1591390 + r1591366;
        double r1591392 = log(r1591391);
        double r1591393 = r1591383 ? r1591388 : r1591392;
        double r1591394 = r1591368 ? r1591381 : r1591393;
        return r1591394;
}

Error

Bits error versus x

Target

Original52.6
Target44.6
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.076228701950242

    1. Initial program 61.8

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

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

      \[\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.1

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

    if -1.076228701950242 < x < 0.006188922223074722

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

    if 0.006188922223074722 < x

    1. Initial program 30.9

      \[\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.076228701950242:\\ \;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} + \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 0.006188922223074722:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{6}, \mathsf{fma}\left(\frac{3}{40}, {x}^{5}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{hypot}\left(1, x\right) + x\right)\\ \end{array}\]

Reproduce

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