Average Error: 53.2 → 0.2
Time: 17.2s
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}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\\ \mathbf{elif}\;x \le 0.8907247814494133608675952018529642373323:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{\left(x \cdot x\right) \cdot x}{1}}{\sqrt{1}}, \frac{-1}{6}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{fma}\left(x, 2, \frac{0.5}{x}\right) - \frac{0.125}{\left(x \cdot x\right) \cdot x}\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}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\\

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

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

\end{array}
double f(double x) {
        double r5380969 = x;
        double r5380970 = r5380969 * r5380969;
        double r5380971 = 1.0;
        double r5380972 = r5380970 + r5380971;
        double r5380973 = sqrt(r5380972);
        double r5380974 = r5380969 + r5380973;
        double r5380975 = log(r5380974);
        return r5380975;
}

double f(double x) {
        double r5380976 = x;
        double r5380977 = -1.02659151339998;
        bool r5380978 = r5380976 <= r5380977;
        double r5380979 = 0.125;
        double r5380980 = r5380976 * r5380976;
        double r5380981 = r5380980 * r5380976;
        double r5380982 = r5380979 / r5380981;
        double r5380983 = 0.5;
        double r5380984 = r5380983 / r5380976;
        double r5380985 = r5380982 - r5380984;
        double r5380986 = 0.0625;
        double r5380987 = 5.0;
        double r5380988 = pow(r5380976, r5380987);
        double r5380989 = r5380986 / r5380988;
        double r5380990 = r5380985 - r5380989;
        double r5380991 = log(r5380990);
        double r5380992 = 0.8907247814494134;
        bool r5380993 = r5380976 <= r5380992;
        double r5380994 = 1.0;
        double r5380995 = r5380981 / r5380994;
        double r5380996 = sqrt(r5380994);
        double r5380997 = r5380995 / r5380996;
        double r5380998 = -0.16666666666666666;
        double r5380999 = r5380976 / r5380996;
        double r5381000 = log(r5380996);
        double r5381001 = r5380999 + r5381000;
        double r5381002 = fma(r5380997, r5380998, r5381001);
        double r5381003 = 2.0;
        double r5381004 = fma(r5380976, r5381003, r5380984);
        double r5381005 = r5381004 - r5380982;
        double r5381006 = log(r5381005);
        double r5381007 = r5380993 ? r5381002 : r5381006;
        double r5381008 = r5380978 ? r5380991 : r5381007;
        return r5381008;
}

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}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\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{\frac{\left(x \cdot x\right) \cdot x}{1}}{\sqrt{1}}, \frac{-1}{6}, \log \left(\sqrt{1}\right) + \frac{x}{\sqrt{1}}\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(x, 2, \frac{0.5}{x}\right) - \frac{0.125}{\left(x \cdot x\right) \cdot x}\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}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\\ \mathbf{elif}\;x \le 0.8907247814494133608675952018529642373323:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{\left(x \cdot x\right) \cdot x}{1}}{\sqrt{1}}, \frac{-1}{6}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{fma}\left(x, 2, \frac{0.5}{x}\right) - \frac{0.125}{\left(x \cdot x\right) \cdot x}\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)))))