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

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

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

\end{array}
double f(double x) {
        double r5121306 = x;
        double r5121307 = r5121306 * r5121306;
        double r5121308 = 1.0;
        double r5121309 = r5121307 + r5121308;
        double r5121310 = sqrt(r5121309);
        double r5121311 = r5121306 + r5121310;
        double r5121312 = log(r5121311);
        return r5121312;
}

double f(double x) {
        double r5121313 = x;
        double r5121314 = -1.0766262960951323;
        bool r5121315 = r5121313 <= r5121314;
        double r5121316 = -0.0625;
        double r5121317 = 5.0;
        double r5121318 = pow(r5121313, r5121317);
        double r5121319 = r5121316 / r5121318;
        double r5121320 = 1.0;
        double r5121321 = r5121320 / r5121313;
        double r5121322 = 0.125;
        double r5121323 = r5121322 / r5121313;
        double r5121324 = -0.5;
        double r5121325 = fma(r5121321, r5121323, r5121324);
        double r5121326 = r5121325 * r5121321;
        double r5121327 = r5121319 + r5121326;
        double r5121328 = log(r5121327);
        double r5121329 = 0.007552790026349609;
        bool r5121330 = r5121313 <= r5121329;
        double r5121331 = 0.075;
        double r5121332 = -0.16666666666666666;
        double r5121333 = r5121313 * r5121332;
        double r5121334 = r5121313 * r5121333;
        double r5121335 = fma(r5121313, r5121334, r5121313);
        double r5121336 = fma(r5121318, r5121331, r5121335);
        double r5121337 = hypot(r5121320, r5121313);
        double r5121338 = r5121337 + r5121313;
        double r5121339 = log(r5121338);
        double r5121340 = r5121330 ? r5121336 : r5121339;
        double r5121341 = r5121315 ? r5121328 : r5121340;
        return r5121341;
}

Error

Bits error versus x

Target

Original52.0
Target44.4
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.0766262960951323

    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. Using strategy rm
    4. Applied add-cube-cbrt61.0

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

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

      \[\leadsto \log \color{blue}{\left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    8. 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)}\]
    9. Simplified0.2

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

    if -1.0766262960951323 < x < 0.007552790026349609

    1. Initial program 58.7

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

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

    if 0.007552790026349609 < x

    1. Initial program 29.2

      \[\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 \color{blue}{\left(\left(\sqrt[3]{x + \mathsf{hypot}\left(1, x\right)} \cdot \sqrt[3]{x + \mathsf{hypot}\left(1, x\right)}\right) \cdot \sqrt[3]{x + \mathsf{hypot}\left(1, x\right)}\right)}\]
    5. Using strategy rm
    6. Applied add-log-exp0.1

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

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

Reproduce

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