Average Error: 52.7 → 0.1
Time: 18.9s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0816386065582386:\\ \;\;\;\;\log \left(\left(\frac{\frac{1}{8}}{\left(x \cdot x\right) \cdot x} - \frac{\frac{1}{16}}{{x}^{5}}\right) - \frac{\frac{1}{2}}{x}\right)\\ \mathbf{elif}\;x \le 0.008829676865362644:\\ \;\;\;\;\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, \left(x \cdot x\right) \cdot x, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{fma}\left(\sqrt[3]{x} \cdot \sqrt[3]{x}, \sqrt[3]{x}, \left(\sqrt[3]{\mathsf{hypot}\left(1, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right)\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \le -1.0816386065582386:\\
\;\;\;\;\log \left(\left(\frac{\frac{1}{8}}{\left(x \cdot x\right) \cdot x} - \frac{\frac{1}{16}}{{x}^{5}}\right) - \frac{\frac{1}{2}}{x}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(\sqrt[3]{x} \cdot \sqrt[3]{x}, \sqrt[3]{x}, \left(\sqrt[3]{\mathsf{hypot}\left(1, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right)\right)\\

\end{array}
double f(double x) {
        double r5960085 = x;
        double r5960086 = r5960085 * r5960085;
        double r5960087 = 1.0;
        double r5960088 = r5960086 + r5960087;
        double r5960089 = sqrt(r5960088);
        double r5960090 = r5960085 + r5960089;
        double r5960091 = log(r5960090);
        return r5960091;
}

double f(double x) {
        double r5960092 = x;
        double r5960093 = -1.0816386065582386;
        bool r5960094 = r5960092 <= r5960093;
        double r5960095 = 0.125;
        double r5960096 = r5960092 * r5960092;
        double r5960097 = r5960096 * r5960092;
        double r5960098 = r5960095 / r5960097;
        double r5960099 = 0.0625;
        double r5960100 = 5.0;
        double r5960101 = pow(r5960092, r5960100);
        double r5960102 = r5960099 / r5960101;
        double r5960103 = r5960098 - r5960102;
        double r5960104 = 0.5;
        double r5960105 = r5960104 / r5960092;
        double r5960106 = r5960103 - r5960105;
        double r5960107 = log(r5960106);
        double r5960108 = 0.008829676865362644;
        bool r5960109 = r5960092 <= r5960108;
        double r5960110 = 0.075;
        double r5960111 = -0.16666666666666666;
        double r5960112 = fma(r5960111, r5960097, r5960092);
        double r5960113 = fma(r5960110, r5960101, r5960112);
        double r5960114 = cbrt(r5960092);
        double r5960115 = r5960114 * r5960114;
        double r5960116 = 1.0;
        double r5960117 = hypot(r5960116, r5960092);
        double r5960118 = cbrt(r5960117);
        double r5960119 = r5960118 * r5960118;
        double r5960120 = r5960119 * r5960118;
        double r5960121 = fma(r5960115, r5960114, r5960120);
        double r5960122 = log(r5960121);
        double r5960123 = r5960109 ? r5960113 : r5960122;
        double r5960124 = r5960094 ? r5960107 : r5960123;
        return r5960124;
}

Error

Bits error versus x

Target

Original52.7
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.0816386065582386

    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. Using strategy rm
    4. Applied add-cube-cbrt61.6

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

      \[\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)}\]
    6. Simplified0.3

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

    if -1.0816386065582386 < x < 0.008829676865362644

    1. Initial program 58.8

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

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

    if 0.008829676865362644 < x

    1. Initial program 31.6

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

      \[\leadsto \log \left(x + \color{blue}{\left(\sqrt[3]{\mathsf{hypot}\left(1, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right)}}\right)\]
    5. Using strategy rm
    6. Applied add-cube-cbrt0.1

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

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

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

Reproduce

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