Average Error: 52.2 → 0.1
Time: 1.8m
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.009171061219366458:\\ \;\;\;\;\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(\left(\sqrt[3]{\mathsf{hypot}\left(1, x\right) + x} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right) + x}\right) \cdot \sqrt[3]{\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.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.009171061219366458:\\
\;\;\;\;\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(\left(\sqrt[3]{\mathsf{hypot}\left(1, x\right) + x} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right) + x}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right) + x}\right)\\

\end{array}
double f(double x) {
        double r15947523 = x;
        double r15947524 = r15947523 * r15947523;
        double r15947525 = 1.0;
        double r15947526 = r15947524 + r15947525;
        double r15947527 = sqrt(r15947526);
        double r15947528 = r15947523 + r15947527;
        double r15947529 = log(r15947528);
        return r15947529;
}

double f(double x) {
        double r15947530 = x;
        double r15947531 = -1.0682549790295666;
        bool r15947532 = r15947530 <= r15947531;
        double r15947533 = -0.5;
        double r15947534 = r15947533 / r15947530;
        double r15947535 = 0.125;
        double r15947536 = r15947530 * r15947530;
        double r15947537 = r15947535 / r15947536;
        double r15947538 = r15947537 / r15947530;
        double r15947539 = 0.0625;
        double r15947540 = 5.0;
        double r15947541 = pow(r15947530, r15947540);
        double r15947542 = r15947539 / r15947541;
        double r15947543 = r15947538 - r15947542;
        double r15947544 = r15947534 + r15947543;
        double r15947545 = log(r15947544);
        double r15947546 = 0.009171061219366458;
        bool r15947547 = r15947530 <= r15947546;
        double r15947548 = 0.075;
        double r15947549 = r15947530 * r15947536;
        double r15947550 = -0.16666666666666666;
        double r15947551 = fma(r15947549, r15947550, r15947530);
        double r15947552 = fma(r15947541, r15947548, r15947551);
        double r15947553 = 1.0;
        double r15947554 = hypot(r15947553, r15947530);
        double r15947555 = r15947554 + r15947530;
        double r15947556 = cbrt(r15947555);
        double r15947557 = r15947556 * r15947556;
        double r15947558 = r15947557 * r15947556;
        double r15947559 = log(r15947558);
        double r15947560 = r15947547 ? r15947552 : r15947559;
        double r15947561 = r15947532 ? r15947545 : r15947560;
        return r15947561;
}

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

    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.009171061219366458 < 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 \color{blue}{\left(\left(\sqrt[3]{x + \mathsf{hypot}\left(1, x\right)} \cdot \sqrt[3]{x + \mathsf{hypot}\left(1, x\right)}\right) \cdot \sqrt[3]{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.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.009171061219366458:\\ \;\;\;\;\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(\left(\sqrt[3]{\mathsf{hypot}\left(1, x\right) + x} \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\right) + x}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(1, x\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)))))