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

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

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

\end{array}
double f(double x) {
        double r6341703 = x;
        double r6341704 = r6341703 * r6341703;
        double r6341705 = 1.0;
        double r6341706 = r6341704 + r6341705;
        double r6341707 = sqrt(r6341706);
        double r6341708 = r6341703 + r6341707;
        double r6341709 = log(r6341708);
        return r6341709;
}

double f(double x) {
        double r6341710 = x;
        double r6341711 = -1.061520745717705;
        bool r6341712 = r6341710 <= r6341711;
        double r6341713 = 0.125;
        double r6341714 = r6341713 / r6341710;
        double r6341715 = r6341710 * r6341710;
        double r6341716 = r6341714 / r6341715;
        double r6341717 = 0.5;
        double r6341718 = r6341717 / r6341710;
        double r6341719 = r6341716 - r6341718;
        double r6341720 = 0.0625;
        double r6341721 = 5.0;
        double r6341722 = pow(r6341710, r6341721);
        double r6341723 = r6341720 / r6341722;
        double r6341724 = r6341719 - r6341723;
        double r6341725 = log(r6341724);
        double r6341726 = 0.009904032332962092;
        bool r6341727 = r6341710 <= r6341726;
        double r6341728 = 0.075;
        double r6341729 = -0.16666666666666666;
        double r6341730 = r6341715 * r6341710;
        double r6341731 = fma(r6341729, r6341730, r6341710);
        double r6341732 = fma(r6341728, r6341722, r6341731);
        double r6341733 = 1.0;
        double r6341734 = hypot(r6341733, r6341710);
        double r6341735 = cbrt(r6341734);
        double r6341736 = r6341735 * r6341735;
        double r6341737 = r6341735 * r6341736;
        double r6341738 = r6341737 + r6341710;
        double r6341739 = log(r6341738);
        double r6341740 = r6341727 ? r6341732 : r6341739;
        double r6341741 = r6341712 ? r6341725 : r6341740;
        return r6341741;
}

Error

Bits error versus x

Target

Original52.6
Target45.0
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.061520745717705

    1. Initial program 61.6

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt61.7

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

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

    if -1.061520745717705 < x < 0.009904032332962092

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

    if 0.009904032332962092 < x

    1. Initial program 31.6

      \[\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 add-cube-cbrt0.0

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

Reproduce

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