Average Error: 52.6 → 0.1
Time: 18.7s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0776022250282242:\\ \;\;\;\;\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.007700169734768205:\\ \;\;\;\;\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), 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.0776022250282242:\\
\;\;\;\;\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.007700169734768205:\\
\;\;\;\;\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), 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 r5676618 = x;
        double r5676619 = r5676618 * r5676618;
        double r5676620 = 1.0;
        double r5676621 = r5676619 + r5676620;
        double r5676622 = sqrt(r5676621);
        double r5676623 = r5676618 + r5676622;
        double r5676624 = log(r5676623);
        return r5676624;
}

double f(double x) {
        double r5676625 = x;
        double r5676626 = -1.0776022250282242;
        bool r5676627 = r5676625 <= r5676626;
        double r5676628 = -0.0625;
        double r5676629 = 5.0;
        double r5676630 = pow(r5676625, r5676629);
        double r5676631 = r5676628 / r5676630;
        double r5676632 = 0.5;
        double r5676633 = r5676632 / r5676625;
        double r5676634 = -0.125;
        double r5676635 = r5676625 * r5676625;
        double r5676636 = r5676625 * r5676635;
        double r5676637 = r5676634 / r5676636;
        double r5676638 = r5676633 + r5676637;
        double r5676639 = r5676631 - r5676638;
        double r5676640 = log(r5676639);
        double r5676641 = 0.007700169734768205;
        bool r5676642 = r5676625 <= r5676641;
        double r5676643 = 0.075;
        double r5676644 = -0.16666666666666666;
        double r5676645 = fma(r5676644, r5676636, r5676625);
        double r5676646 = fma(r5676643, r5676630, r5676645);
        double r5676647 = 1.0;
        double r5676648 = hypot(r5676647, r5676625);
        double r5676649 = r5676648 + r5676625;
        double r5676650 = sqrt(r5676649);
        double r5676651 = log(r5676650);
        double r5676652 = r5676651 + r5676651;
        double r5676653 = r5676642 ? r5676646 : r5676652;
        double r5676654 = r5676627 ? r5676640 : r5676653;
        return r5676654;
}

Error

Bits error versus x

Target

Original52.6
Target45.0
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.0776022250282242

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

    if -1.0776022250282242 < x < 0.007700169734768205

    1. Initial program 58.9

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

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

    if 0.007700169734768205 < x

    1. Initial program 30.2

      \[\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-sqr-sqrt0.1

      \[\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.1

      \[\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.0776022250282242:\\ \;\;\;\;\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.007700169734768205:\\ \;\;\;\;\mathsf{fma}\left(\frac{3}{40}, {x}^{5}, \mathsf{fma}\left(\frac{-1}{6}, x \cdot \left(x \cdot x\right), 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 2019149 +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)))))