Average Error: 53.2 → 0.2
Time: 6.0s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.9993980925116870972502169934159610420465:\\ \;\;\;\;\log \left(\frac{0.125}{{x}^{3}} - \left(\frac{0.5}{x} - \frac{-0.0625}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 0.001262633341121889183830684366682817199035:\\ \;\;\;\;\left(\log \left(\sqrt{1}\right) + \frac{x}{\sqrt{1}}\right) - \frac{1}{6} \cdot \frac{{x}^{3}}{{\left(\sqrt{1}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{\mathsf{hypot}\left(x, \sqrt{1}\right) + x}\right) + \log \left(\sqrt{\mathsf{fma}\left(\sqrt[3]{\mathsf{hypot}\left(x, \sqrt{1}\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(x, \sqrt{1}\right)}, \sqrt[3]{\mathsf{hypot}\left(x, \sqrt{1}\right)}, x\right)}\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \le -0.9993980925116870972502169934159610420465:\\
\;\;\;\;\log \left(\frac{0.125}{{x}^{3}} - \left(\frac{0.5}{x} - \frac{-0.0625}{{x}^{5}}\right)\right)\\

\mathbf{elif}\;x \le 0.001262633341121889183830684366682817199035:\\
\;\;\;\;\left(\log \left(\sqrt{1}\right) + \frac{x}{\sqrt{1}}\right) - \frac{1}{6} \cdot \frac{{x}^{3}}{{\left(\sqrt{1}\right)}^{3}}\\

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

\end{array}
double f(double x) {
        double r171723 = x;
        double r171724 = r171723 * r171723;
        double r171725 = 1.0;
        double r171726 = r171724 + r171725;
        double r171727 = sqrt(r171726);
        double r171728 = r171723 + r171727;
        double r171729 = log(r171728);
        return r171729;
}

double f(double x) {
        double r171730 = x;
        double r171731 = -0.9993980925116871;
        bool r171732 = r171730 <= r171731;
        double r171733 = 0.125;
        double r171734 = 3.0;
        double r171735 = pow(r171730, r171734);
        double r171736 = r171733 / r171735;
        double r171737 = 0.5;
        double r171738 = r171737 / r171730;
        double r171739 = 0.0625;
        double r171740 = -r171739;
        double r171741 = 5.0;
        double r171742 = pow(r171730, r171741);
        double r171743 = r171740 / r171742;
        double r171744 = r171738 - r171743;
        double r171745 = r171736 - r171744;
        double r171746 = log(r171745);
        double r171747 = 0.0012626333411218892;
        bool r171748 = r171730 <= r171747;
        double r171749 = 1.0;
        double r171750 = sqrt(r171749);
        double r171751 = log(r171750);
        double r171752 = r171730 / r171750;
        double r171753 = r171751 + r171752;
        double r171754 = 0.16666666666666666;
        double r171755 = pow(r171750, r171734);
        double r171756 = r171735 / r171755;
        double r171757 = r171754 * r171756;
        double r171758 = r171753 - r171757;
        double r171759 = hypot(r171730, r171750);
        double r171760 = r171759 + r171730;
        double r171761 = sqrt(r171760);
        double r171762 = log(r171761);
        double r171763 = cbrt(r171759);
        double r171764 = r171763 * r171763;
        double r171765 = fma(r171764, r171763, r171730);
        double r171766 = sqrt(r171765);
        double r171767 = log(r171766);
        double r171768 = r171762 + r171767;
        double r171769 = r171748 ? r171758 : r171768;
        double r171770 = r171732 ? r171746 : r171769;
        return r171770;
}

Error

Bits error versus x

Target

Original53.2
Target45.7
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.9993980925116871

    1. Initial program 62.9

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

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

      \[\leadsto \log \color{blue}{\left(\frac{0.125}{{x}^{3}} - \left(\frac{0.5}{x} - \frac{-0.0625}{{x}^{5}}\right)\right)}\]

    if -0.9993980925116871 < x < 0.0012626333411218892

    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}}}\]

    if 0.0012626333411218892 < x

    1. Initial program 32.6

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

      \[\leadsto \color{blue}{\log \left(e^{\log \left(x + \sqrt{x \cdot x + 1}\right)}\right)}\]
    4. Simplified0.1

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.9993980925116870972502169934159610420465:\\ \;\;\;\;\log \left(\frac{0.125}{{x}^{3}} - \left(\frac{0.5}{x} - \frac{-0.0625}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 0.001262633341121889183830684366682817199035:\\ \;\;\;\;\left(\log \left(\sqrt{1}\right) + \frac{x}{\sqrt{1}}\right) - \frac{1}{6} \cdot \frac{{x}^{3}}{{\left(\sqrt{1}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{\mathsf{hypot}\left(x, \sqrt{1}\right) + x}\right) + \log \left(\sqrt{\mathsf{fma}\left(\sqrt[3]{\mathsf{hypot}\left(x, \sqrt{1}\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(x, \sqrt{1}\right)}, \sqrt[3]{\mathsf{hypot}\left(x, \sqrt{1}\right)}, x\right)}\right)\\ \end{array}\]

Reproduce

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