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

\mathbf{elif}\;x \le 0.8907247814494133608675952018529642373323:\\
\;\;\;\;\mathsf{fma}\left(\frac{x \cdot \left(x \cdot x\right)}{1 \cdot \sqrt{1}}, \frac{-1}{6}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(2, x, \frac{0.5}{x} - \frac{0.125}{x \cdot \left(x \cdot x\right)}\right)\right)\\

\end{array}
double f(double x) {
        double r9156893 = x;
        double r9156894 = r9156893 * r9156893;
        double r9156895 = 1.0;
        double r9156896 = r9156894 + r9156895;
        double r9156897 = sqrt(r9156896);
        double r9156898 = r9156893 + r9156897;
        double r9156899 = log(r9156898);
        return r9156899;
}

double f(double x) {
        double r9156900 = x;
        double r9156901 = -1.02659151339998;
        bool r9156902 = r9156900 <= r9156901;
        double r9156903 = 0.125;
        double r9156904 = r9156900 * r9156900;
        double r9156905 = r9156900 * r9156904;
        double r9156906 = r9156903 / r9156905;
        double r9156907 = 0.0625;
        double r9156908 = 5.0;
        double r9156909 = pow(r9156900, r9156908);
        double r9156910 = r9156907 / r9156909;
        double r9156911 = r9156906 - r9156910;
        double r9156912 = 0.5;
        double r9156913 = r9156912 / r9156900;
        double r9156914 = r9156911 - r9156913;
        double r9156915 = log(r9156914);
        double r9156916 = 0.8907247814494134;
        bool r9156917 = r9156900 <= r9156916;
        double r9156918 = 1.0;
        double r9156919 = sqrt(r9156918);
        double r9156920 = r9156918 * r9156919;
        double r9156921 = r9156905 / r9156920;
        double r9156922 = -0.16666666666666666;
        double r9156923 = r9156900 / r9156919;
        double r9156924 = log(r9156919);
        double r9156925 = r9156923 + r9156924;
        double r9156926 = fma(r9156921, r9156922, r9156925);
        double r9156927 = 2.0;
        double r9156928 = r9156913 - r9156906;
        double r9156929 = fma(r9156927, r9156900, r9156928);
        double r9156930 = log(r9156929);
        double r9156931 = r9156917 ? r9156926 : r9156930;
        double r9156932 = r9156902 ? r9156915 : r9156931;
        return r9156932;
}

Error

Bits error versus x

Target

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

    1. Initial program 63.0

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{\mathsf{fma}\left(x, x, 1\right)}\right)}\]
    3. Taylor expanded around -inf 0.2

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

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

    if -1.02659151339998 < x < 0.8907247814494134

    1. Initial program 58.6

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{\mathsf{fma}\left(x, x, 1\right)}\right)}\]
    3. Taylor expanded around 0 0.3

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x \cdot \left(x \cdot x\right)}{1 \cdot \sqrt{1}}, \frac{-1}{6}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)}\]

    if 0.8907247814494134 < x

    1. Initial program 32.1

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{\mathsf{fma}\left(x, x, 1\right)}\right)}\]
    3. Taylor expanded around inf 0.1

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

      \[\leadsto \log \color{blue}{\left(\mathsf{fma}\left(2, x, \frac{0.5}{x} - \frac{0.125}{x \cdot \left(x \cdot x\right)}\right)\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

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

Reproduce

herbie shell --seed 2019174 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic arcsine"

  :herbie-target
  (if (< x 0.0) (log (/ -1.0 (- x (sqrt (+ (* x x) 1.0))))) (log (+ x (sqrt (+ (* x x) 1.0)))))

  (log (+ x (sqrt (+ (* x x) 1.0)))))