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

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

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

\end{array}
double f(double x) {
        double r4596664 = x;
        double r4596665 = r4596664 * r4596664;
        double r4596666 = 1.0;
        double r4596667 = r4596665 + r4596666;
        double r4596668 = sqrt(r4596667);
        double r4596669 = r4596664 + r4596668;
        double r4596670 = log(r4596669);
        return r4596670;
}

double f(double x) {
        double r4596671 = x;
        double r4596672 = -1.0788943454777058;
        bool r4596673 = r4596671 <= r4596672;
        double r4596674 = -0.0625;
        double r4596675 = 5.0;
        double r4596676 = pow(r4596671, r4596675);
        double r4596677 = r4596674 / r4596676;
        double r4596678 = 0.5;
        double r4596679 = r4596678 / r4596671;
        double r4596680 = -0.125;
        double r4596681 = r4596671 * r4596671;
        double r4596682 = r4596671 * r4596681;
        double r4596683 = r4596680 / r4596682;
        double r4596684 = r4596679 + r4596683;
        double r4596685 = r4596677 - r4596684;
        double r4596686 = log(r4596685);
        double r4596687 = 0.007378209414887432;
        bool r4596688 = r4596671 <= r4596687;
        double r4596689 = -0.16666666666666666;
        double r4596690 = 0.075;
        double r4596691 = fma(r4596690, r4596676, r4596671);
        double r4596692 = fma(r4596689, r4596682, r4596691);
        double r4596693 = 1.0;
        double r4596694 = hypot(r4596693, r4596671);
        double r4596695 = r4596694 + r4596671;
        double r4596696 = sqrt(r4596695);
        double r4596697 = log(r4596696);
        double r4596698 = r4596697 + r4596697;
        double r4596699 = r4596688 ? r4596692 : r4596698;
        double r4596700 = r4596673 ? r4596686 : r4596699;
        return r4596700;
}

Error

Bits error versus x

Target

Original52.6
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.0788943454777058

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

    if -1.0788943454777058 < x < 0.007378209414887432

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

    if 0.007378209414887432 < x

    1. Initial program 30.7

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}\]
    3. Using strategy rm
    4. Applied add-sqr-sqrt0.0

      \[\leadsto \log \color{blue}{\left(\sqrt{x + \mathsf{hypot}\left(1, x\right)} \cdot \sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)}\]
    5. Applied log-prod0.0

      \[\leadsto \color{blue}{\log \left(\sqrt{x + \mathsf{hypot}\left(1, x\right)}\right) + \log \left(\sqrt{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.0788943454777058:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} - \left(\frac{\frac{1}{2}}{x} + \frac{\frac{-1}{8}}{x \cdot \left(x \cdot x\right)}\right)\right)\\ \mathbf{elif}\;x \le 0.007378209414887432:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), \mathsf{fma}\left(\frac{3}{40}, {x}^{5}, x\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{\mathsf{hypot}\left(1, x\right) + x}\right) + \log \left(\sqrt{\mathsf{hypot}\left(1, x\right) + x}\right)\\ \end{array}\]

Reproduce

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