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

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

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

\end{array}
double f(double x) {
        double r4498282 = x;
        double r4498283 = r4498282 * r4498282;
        double r4498284 = 1.0;
        double r4498285 = r4498283 + r4498284;
        double r4498286 = sqrt(r4498285);
        double r4498287 = r4498282 + r4498286;
        double r4498288 = log(r4498287);
        return r4498288;
}

double f(double x) {
        double r4498289 = x;
        double r4498290 = -1.0651328544879792;
        bool r4498291 = r4498289 <= r4498290;
        double r4498292 = -0.0625;
        double r4498293 = 5.0;
        double r4498294 = pow(r4498289, r4498293);
        double r4498295 = r4498292 / r4498294;
        double r4498296 = 0.125;
        double r4498297 = r4498289 * r4498289;
        double r4498298 = r4498296 / r4498297;
        double r4498299 = r4498298 / r4498289;
        double r4498300 = 0.5;
        double r4498301 = r4498300 / r4498289;
        double r4498302 = r4498299 - r4498301;
        double r4498303 = r4498295 + r4498302;
        double r4498304 = log(r4498303);
        double r4498305 = 0.008344283352146159;
        bool r4498306 = r4498289 <= r4498305;
        double r4498307 = -0.16666666666666666;
        double r4498308 = r4498289 * r4498307;
        double r4498309 = 0.075;
        double r4498310 = fma(r4498309, r4498294, r4498289);
        double r4498311 = fma(r4498308, r4498297, r4498310);
        double r4498312 = 1.0;
        double r4498313 = hypot(r4498312, r4498289);
        double r4498314 = r4498313 + r4498289;
        double r4498315 = log(r4498314);
        double r4498316 = r4498306 ? r4498311 : r4498315;
        double r4498317 = r4498291 ? r4498304 : r4498316;
        return r4498317;
}

Error

Bits error versus x

Target

Original52.0
Target44.3
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.0651328544879792

    1. Initial program 61.6

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

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

    if -1.0651328544879792 < x < 0.008344283352146159

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

    if 0.008344283352146159 < x

    1. Initial program 30.8

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

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

Reproduce

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