Average Error: 52.6 → 0.1
Time: 11.8s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0580774043529224:\\ \;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} + \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 0.00612647097016585:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{6}, \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.0580774043529224:\\
\;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} + \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\\

\mathbf{elif}\;x \le 0.00612647097016585:\\
\;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{6}, \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 r2056126 = x;
        double r2056127 = r2056126 * r2056126;
        double r2056128 = 1.0;
        double r2056129 = r2056127 + r2056128;
        double r2056130 = sqrt(r2056129);
        double r2056131 = r2056126 + r2056130;
        double r2056132 = log(r2056131);
        return r2056132;
}

double f(double x) {
        double r2056133 = x;
        double r2056134 = -1.0580774043529224;
        bool r2056135 = r2056133 <= r2056134;
        double r2056136 = -0.5;
        double r2056137 = r2056136 / r2056133;
        double r2056138 = 0.125;
        double r2056139 = r2056138 / r2056133;
        double r2056140 = r2056133 * r2056133;
        double r2056141 = r2056139 / r2056140;
        double r2056142 = -0.0625;
        double r2056143 = 5.0;
        double r2056144 = pow(r2056133, r2056143);
        double r2056145 = r2056142 / r2056144;
        double r2056146 = r2056141 + r2056145;
        double r2056147 = r2056137 + r2056146;
        double r2056148 = log(r2056147);
        double r2056149 = 0.00612647097016585;
        bool r2056150 = r2056133 <= r2056149;
        double r2056151 = r2056140 * r2056133;
        double r2056152 = -0.16666666666666666;
        double r2056153 = 0.075;
        double r2056154 = fma(r2056153, r2056144, r2056133);
        double r2056155 = fma(r2056151, r2056152, r2056154);
        double r2056156 = 1.0;
        double r2056157 = hypot(r2056156, r2056133);
        double r2056158 = r2056157 + r2056133;
        double r2056159 = log(r2056158);
        double r2056160 = r2056150 ? r2056155 : r2056159;
        double r2056161 = r2056135 ? r2056148 : r2056160;
        return r2056161;
}

Error

Bits error versus x

Target

Original52.6
Target45.1
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.0580774043529224

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

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

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

    if -1.0580774043529224 < x < 0.00612647097016585

    1. Initial program 58.9

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

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

    if 0.00612647097016585 < x

    1. Initial program 30.5

      \[\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. Using strategy rm
    4. Applied +-commutative0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.0580774043529224:\\ \;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} + \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \frac{\frac{-1}{16}}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 0.00612647097016585:\\ \;\;\;\;\mathsf{fma}\left(\left(x \cdot x\right) \cdot x, \frac{-1}{6}, \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 2019154 +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)))))