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

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

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

\end{array}
double f(double x) {
        double r7087058 = x;
        double r7087059 = r7087058 * r7087058;
        double r7087060 = 1.0;
        double r7087061 = r7087059 + r7087060;
        double r7087062 = sqrt(r7087061);
        double r7087063 = r7087058 + r7087062;
        double r7087064 = log(r7087063);
        return r7087064;
}

double f(double x) {
        double r7087065 = x;
        double r7087066 = -1.0481361170547778;
        bool r7087067 = r7087065 <= r7087066;
        double r7087068 = 0.125;
        double r7087069 = r7087068 / r7087065;
        double r7087070 = r7087065 * r7087065;
        double r7087071 = r7087069 / r7087070;
        double r7087072 = -0.5;
        double r7087073 = r7087072 / r7087065;
        double r7087074 = 0.0625;
        double r7087075 = 5.0;
        double r7087076 = pow(r7087065, r7087075);
        double r7087077 = r7087074 / r7087076;
        double r7087078 = r7087073 - r7087077;
        double r7087079 = r7087071 + r7087078;
        double r7087080 = log(r7087079);
        double r7087081 = 0.007871312528259618;
        bool r7087082 = r7087065 <= r7087081;
        double r7087083 = -0.16666666666666666;
        double r7087084 = r7087065 * r7087083;
        double r7087085 = 0.075;
        double r7087086 = fma(r7087085, r7087076, r7087065);
        double r7087087 = fma(r7087084, r7087070, r7087086);
        double r7087088 = 1.0;
        double r7087089 = hypot(r7087088, r7087065);
        double r7087090 = r7087089 + r7087065;
        double r7087091 = log(r7087090);
        double r7087092 = r7087082 ? r7087087 : r7087091;
        double r7087093 = r7087067 ? r7087080 : r7087092;
        return r7087093;
}

Error

Bits error versus x

Target

Original52.4
Target44.4
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.0481361170547778

    1. Initial program 61.5

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

      \[\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(\left(\frac{\frac{-1}{2}}{x} - \frac{\frac{1}{16}}{{x}^{5}}\right) + \frac{\frac{\frac{1}{8}}{x}}{x \cdot x}\right)}\]

    if -1.0481361170547778 < x < 0.007871312528259618

    1. Initial program 58.6

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

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

    if 0.007871312528259618 < x

    1. Initial program 30.0

      \[\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. Recombined 3 regimes into one program.
  4. Final simplification0.1

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

Reproduce

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