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

\mathbf{elif}\;x \le 0.0011720548513025719:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \frac{{x}^{3}}{{\left(\sqrt{1}\right)}^{3}}, \log \left(\sqrt{1}\right) + \frac{x}{\sqrt{1}}\right)\\

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

\end{array}
double f(double x) {
        double r111447 = x;
        double r111448 = r111447 * r111447;
        double r111449 = 1.0;
        double r111450 = r111448 + r111449;
        double r111451 = sqrt(r111450);
        double r111452 = r111447 + r111451;
        double r111453 = log(r111452);
        return r111453;
}

double f(double x) {
        double r111454 = x;
        double r111455 = -0.9990009314811332;
        bool r111456 = r111454 <= r111455;
        double r111457 = 1.0;
        double r111458 = r111457 * r111457;
        double r111459 = 3.0;
        double r111460 = pow(r111454, r111459);
        double r111461 = r111458 / r111460;
        double r111462 = 0.125;
        double r111463 = -0.5;
        double r111464 = r111457 / r111454;
        double r111465 = r111463 * r111464;
        double r111466 = fma(r111461, r111462, r111465);
        double r111467 = 0.0625;
        double r111468 = pow(r111457, r111459);
        double r111469 = 5.0;
        double r111470 = pow(r111454, r111469);
        double r111471 = r111468 / r111470;
        double r111472 = r111467 * r111471;
        double r111473 = r111466 - r111472;
        double r111474 = log(r111473);
        double r111475 = 0.001172054851302572;
        bool r111476 = r111454 <= r111475;
        double r111477 = -0.16666666666666666;
        double r111478 = sqrt(r111457);
        double r111479 = pow(r111478, r111459);
        double r111480 = r111460 / r111479;
        double r111481 = log(r111478);
        double r111482 = r111454 / r111478;
        double r111483 = r111481 + r111482;
        double r111484 = fma(r111477, r111480, r111483);
        double r111485 = hypot(r111454, r111478);
        double r111486 = r111454 + r111485;
        double r111487 = sqrt(r111486);
        double r111488 = sqrt(r111487);
        double r111489 = log(r111488);
        double r111490 = r111489 + r111489;
        double r111491 = log(r111487);
        double r111492 = r111490 + r111491;
        double r111493 = r111476 ? r111484 : r111492;
        double r111494 = r111456 ? r111474 : r111493;
        return r111494;
}

Error

Bits error versus x

Target

Original53.2
Target45.1
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;x \lt 0.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 < -0.9990009314811332

    1. Initial program 63.1

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt63.1

      \[\leadsto \log \left(x + \sqrt{x \cdot x + \color{blue}{\sqrt{1} \cdot \sqrt{1}}}\right)\]
    4. Applied hypot-def63.1

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

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

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

    if -0.9990009314811332 < x < 0.001172054851302572

    1. Initial program 58.9

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, \frac{{x}^{3}}{{\left(\sqrt{1}\right)}^{3}}, \log \left(\sqrt{1}\right) + \frac{x}{\sqrt{1}}\right)}\]

    if 0.001172054851302572 < x

    1. Initial program 31.2

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt31.2

      \[\leadsto \log \left(x + \sqrt{x \cdot x + \color{blue}{\sqrt{1} \cdot \sqrt{1}}}\right)\]
    4. Applied hypot-def0.1

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

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

      \[\leadsto \color{blue}{\log \left(\sqrt{x + \mathsf{hypot}\left(x, \sqrt{1}\right)}\right) + \log \left(\sqrt{x + \mathsf{hypot}\left(x, \sqrt{1}\right)}\right)}\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt0.1

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

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

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

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

Reproduce

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

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

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