Average Error: 52.7 → 0.1
Time: 2.2m
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.065310111108762:\\ \;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} - \left(\frac{\frac{1}{16}}{{x}^{5}} - \frac{\frac{1}{8}}{x \cdot \left(x \cdot x\right)}\right)\right)\\ \mathbf{elif}\;x \le 0.007474981908937188:\\ \;\;\;\;\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.065310111108762:\\
\;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} - \left(\frac{\frac{1}{16}}{{x}^{5}} - \frac{\frac{1}{8}}{x \cdot \left(x \cdot x\right)}\right)\right)\\

\mathbf{elif}\;x \le 0.007474981908937188:\\
\;\;\;\;\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 r45774458 = x;
        double r45774459 = r45774458 * r45774458;
        double r45774460 = 1.0;
        double r45774461 = r45774459 + r45774460;
        double r45774462 = sqrt(r45774461);
        double r45774463 = r45774458 + r45774462;
        double r45774464 = log(r45774463);
        return r45774464;
}

double f(double x) {
        double r45774465 = x;
        double r45774466 = -1.065310111108762;
        bool r45774467 = r45774465 <= r45774466;
        double r45774468 = -0.5;
        double r45774469 = r45774468 / r45774465;
        double r45774470 = 0.0625;
        double r45774471 = 5.0;
        double r45774472 = pow(r45774465, r45774471);
        double r45774473 = r45774470 / r45774472;
        double r45774474 = 0.125;
        double r45774475 = r45774465 * r45774465;
        double r45774476 = r45774465 * r45774475;
        double r45774477 = r45774474 / r45774476;
        double r45774478 = r45774473 - r45774477;
        double r45774479 = r45774469 - r45774478;
        double r45774480 = log(r45774479);
        double r45774481 = 0.007474981908937188;
        bool r45774482 = r45774465 <= r45774481;
        double r45774483 = -0.16666666666666666;
        double r45774484 = r45774465 * r45774483;
        double r45774485 = 0.075;
        double r45774486 = fma(r45774485, r45774472, r45774465);
        double r45774487 = fma(r45774484, r45774475, r45774486);
        double r45774488 = 1.0;
        double r45774489 = hypot(r45774488, r45774465);
        double r45774490 = r45774489 + r45774465;
        double r45774491 = log(r45774490);
        double r45774492 = r45774482 ? r45774487 : r45774491;
        double r45774493 = r45774467 ? r45774480 : r45774492;
        return r45774493;
}

Error

Bits error versus x

Target

Original52.7
Target44.8
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.065310111108762

    1. Initial program 62.0

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

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

    if -1.065310111108762 < x < 0.007474981908937188

    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(\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.007474981908937188 < x

    1. Initial program 29.9

      \[\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.065310111108762:\\ \;\;\;\;\log \left(\frac{\frac{-1}{2}}{x} - \left(\frac{\frac{1}{16}}{{x}^{5}} - \frac{\frac{1}{8}}{x \cdot \left(x \cdot x\right)}\right)\right)\\ \mathbf{elif}\;x \le 0.007474981908937188:\\ \;\;\;\;\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 2019125 +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)))))