Average Error: 52.7 → 0.1
Time: 23.7s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0529948069434159:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} - \left(\frac{\frac{1}{2}}{x} + \frac{\frac{-1}{8}}{x \cdot \left(x \cdot x\right)}\right)\right)\\ \mathbf{elif}\;x \le 0.008689025353366112:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), \mathsf{fma}\left(\frac{3}{40}, {x}^{5}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(1, x\right) + x\right)\right)\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \le -1.0529948069434159:\\
\;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} - \left(\frac{\frac{1}{2}}{x} + \frac{\frac{-1}{8}}{x \cdot \left(x \cdot x\right)}\right)\right)\\

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

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

\end{array}
double f(double x) {
        double r6563465 = x;
        double r6563466 = r6563465 * r6563465;
        double r6563467 = 1.0;
        double r6563468 = r6563466 + r6563467;
        double r6563469 = sqrt(r6563468);
        double r6563470 = r6563465 + r6563469;
        double r6563471 = log(r6563470);
        return r6563471;
}

double f(double x) {
        double r6563472 = x;
        double r6563473 = -1.0529948069434159;
        bool r6563474 = r6563472 <= r6563473;
        double r6563475 = -0.0625;
        double r6563476 = 5.0;
        double r6563477 = pow(r6563472, r6563476);
        double r6563478 = r6563475 / r6563477;
        double r6563479 = 0.5;
        double r6563480 = r6563479 / r6563472;
        double r6563481 = -0.125;
        double r6563482 = r6563472 * r6563472;
        double r6563483 = r6563472 * r6563482;
        double r6563484 = r6563481 / r6563483;
        double r6563485 = r6563480 + r6563484;
        double r6563486 = r6563478 - r6563485;
        double r6563487 = log(r6563486);
        double r6563488 = 0.008689025353366112;
        bool r6563489 = r6563472 <= r6563488;
        double r6563490 = -0.16666666666666666;
        double r6563491 = 0.075;
        double r6563492 = fma(r6563491, r6563477, r6563472);
        double r6563493 = fma(r6563490, r6563483, r6563492);
        double r6563494 = 1.0;
        double r6563495 = hypot(r6563494, r6563472);
        double r6563496 = r6563495 + r6563472;
        double r6563497 = log1p(r6563496);
        double r6563498 = expm1(r6563497);
        double r6563499 = log(r6563498);
        double r6563500 = r6563489 ? r6563493 : r6563499;
        double r6563501 = r6563474 ? r6563487 : r6563500;
        return r6563501;
}

Error

Bits error versus x

Target

Original52.7
Target44.9
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.0529948069434159

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

    if -1.0529948069434159 < x < 0.008689025353366112

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

    if 0.008689025353366112 < x

    1. Initial program 31.7

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Using strategy rm
    4. Applied expm1-log1p-u0.0

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

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

Reproduce

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