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

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

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

\end{array}
double f(double x) {
        double r5034227 = x;
        double r5034228 = r5034227 * r5034227;
        double r5034229 = 1.0;
        double r5034230 = r5034228 + r5034229;
        double r5034231 = sqrt(r5034230);
        double r5034232 = r5034227 + r5034231;
        double r5034233 = log(r5034232);
        return r5034233;
}

double f(double x) {
        double r5034234 = x;
        double r5034235 = -1.0682549790295666;
        bool r5034236 = r5034234 <= r5034235;
        double r5034237 = -0.5;
        double r5034238 = r5034237 / r5034234;
        double r5034239 = 0.125;
        double r5034240 = r5034234 * r5034234;
        double r5034241 = r5034239 / r5034240;
        double r5034242 = r5034241 / r5034234;
        double r5034243 = 0.0625;
        double r5034244 = 5.0;
        double r5034245 = pow(r5034234, r5034244);
        double r5034246 = r5034243 / r5034245;
        double r5034247 = r5034242 - r5034246;
        double r5034248 = r5034238 + r5034247;
        double r5034249 = log(r5034248);
        double r5034250 = 0.01035404049421089;
        bool r5034251 = r5034234 <= r5034250;
        double r5034252 = 0.075;
        double r5034253 = r5034234 * r5034240;
        double r5034254 = -0.16666666666666666;
        double r5034255 = fma(r5034253, r5034254, r5034234);
        double r5034256 = fma(r5034245, r5034252, r5034255);
        double r5034257 = 1.0;
        double r5034258 = hypot(r5034257, r5034234);
        double r5034259 = cbrt(r5034258);
        double r5034260 = r5034259 * r5034259;
        double r5034261 = r5034259 * r5034260;
        double r5034262 = r5034261 + r5034234;
        double r5034263 = log(r5034262);
        double r5034264 = r5034251 ? r5034256 : r5034263;
        double r5034265 = r5034236 ? r5034249 : r5034264;
        return r5034265;
}

Error

Bits error versus x

Target

Original52.2
Target44.7
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.0682549790295666

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

    if -1.0682549790295666 < x < 0.01035404049421089

    1. Initial program 58.7

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

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

    if 0.01035404049421089 < x

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

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

Reproduce

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