Average Error: 52.5 → 0.2
Time: 16.7s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0772372773411123:\\ \;\;\;\;\log \left(\mathsf{fma}\left(\left(\frac{1}{x}\right), \left(\frac{\frac{1}{8}}{x \cdot x} - \frac{1}{2}\right), \left(\frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\right)\\ \mathbf{elif}\;x \le 0.0069584936870517354:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \left(x \cdot \left(x \cdot x\right)\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(\sqrt{\sqrt{\mathsf{hypot}\left(1, x\right) + x}}\right) + \log \left(\sqrt{\sqrt{\mathsf{hypot}\left(1, x\right) + x}}\right)\right) + \log \left(\sqrt{\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.0772372773411123:\\
\;\;\;\;\log \left(\mathsf{fma}\left(\left(\frac{1}{x}\right), \left(\frac{\frac{1}{8}}{x \cdot x} - \frac{1}{2}\right), \left(\frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\right)\\

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

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

\end{array}
double f(double x) {
        double r5520912 = x;
        double r5520913 = r5520912 * r5520912;
        double r5520914 = 1.0;
        double r5520915 = r5520913 + r5520914;
        double r5520916 = sqrt(r5520915);
        double r5520917 = r5520912 + r5520916;
        double r5520918 = log(r5520917);
        return r5520918;
}

double f(double x) {
        double r5520919 = x;
        double r5520920 = -1.0772372773411123;
        bool r5520921 = r5520919 <= r5520920;
        double r5520922 = 1.0;
        double r5520923 = r5520922 / r5520919;
        double r5520924 = 0.125;
        double r5520925 = r5520919 * r5520919;
        double r5520926 = r5520924 / r5520925;
        double r5520927 = 0.5;
        double r5520928 = r5520926 - r5520927;
        double r5520929 = -0.0625;
        double r5520930 = 5.0;
        double r5520931 = pow(r5520919, r5520930);
        double r5520932 = r5520929 / r5520931;
        double r5520933 = fma(r5520923, r5520928, r5520932);
        double r5520934 = log(r5520933);
        double r5520935 = 0.0069584936870517354;
        bool r5520936 = r5520919 <= r5520935;
        double r5520937 = -0.16666666666666666;
        double r5520938 = r5520919 * r5520925;
        double r5520939 = 0.075;
        double r5520940 = fma(r5520939, r5520931, r5520919);
        double r5520941 = fma(r5520937, r5520938, r5520940);
        double r5520942 = hypot(r5520922, r5520919);
        double r5520943 = r5520942 + r5520919;
        double r5520944 = sqrt(r5520943);
        double r5520945 = sqrt(r5520944);
        double r5520946 = log(r5520945);
        double r5520947 = r5520946 + r5520946;
        double r5520948 = log(r5520944);
        double r5520949 = r5520947 + r5520948;
        double r5520950 = r5520936 ? r5520941 : r5520949;
        double r5520951 = r5520921 ? r5520934 : r5520950;
        return r5520951;
}

Error

Bits error versus x

Target

Original52.5
Target45.0
Herbie0.2
\[\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.0772372773411123

    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.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)}\]
    4. Simplified0.2

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

    if -1.0772372773411123 < x < 0.0069584936870517354

    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.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, \left(\left(x \cdot x\right) \cdot x\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\right)\right)}\]

    if 0.0069584936870517354 < x

    1. Initial program 30.4

      \[\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-sqr-sqrt0.1

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

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

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

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

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

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

Reproduce

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