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

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

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

\end{array}
double f(double x) {
        double r5525453 = x;
        double r5525454 = r5525453 * r5525453;
        double r5525455 = 1.0;
        double r5525456 = r5525454 + r5525455;
        double r5525457 = sqrt(r5525456);
        double r5525458 = r5525453 + r5525457;
        double r5525459 = log(r5525458);
        return r5525459;
}

double f(double x) {
        double r5525460 = x;
        double r5525461 = -1.0681179944727555;
        bool r5525462 = r5525460 <= r5525461;
        double r5525463 = -0.5;
        double r5525464 = r5525463 / r5525460;
        double r5525465 = 0.125;
        double r5525466 = r5525460 * r5525460;
        double r5525467 = r5525465 / r5525466;
        double r5525468 = r5525467 / r5525460;
        double r5525469 = 0.0625;
        double r5525470 = 5.0;
        double r5525471 = pow(r5525460, r5525470);
        double r5525472 = r5525469 / r5525471;
        double r5525473 = r5525468 - r5525472;
        double r5525474 = r5525464 + r5525473;
        double r5525475 = log(r5525474);
        double r5525476 = 0.007740212044415701;
        bool r5525477 = r5525460 <= r5525476;
        double r5525478 = 0.075;
        double r5525479 = r5525460 * r5525466;
        double r5525480 = -0.16666666666666666;
        double r5525481 = fma(r5525479, r5525480, r5525460);
        double r5525482 = fma(r5525471, r5525478, r5525481);
        double r5525483 = 1.0;
        double r5525484 = hypot(r5525483, r5525460);
        double r5525485 = r5525484 + r5525460;
        double r5525486 = sqrt(r5525485);
        double r5525487 = log(r5525486);
        double r5525488 = r5525487 + r5525487;
        double r5525489 = r5525477 ? r5525482 : r5525488;
        double r5525490 = r5525462 ? r5525475 : r5525489;
        return r5525490;
}

Error

Bits error versus x

Target

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

    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}{2}}{x} + \left(\frac{\frac{\frac{1}{8}}{x \cdot x}}{x} - \frac{\frac{1}{16}}{{x}^{5}}\right)\right)}\]

    if -1.0681179944727555 < x < 0.007740212044415701

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

    if 0.007740212044415701 < x

    1. Initial program 30.5

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

      \[\leadsto \log \color{blue}{\left(\sqrt{x + \mathsf{hypot}\left(1, x\right)} \cdot \sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)}\]
    5. Applied log-prod0.1

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

Reproduce

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