Average Error: 52.4 → 0.1
Time: 21.2s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0611438585736817:\\ \;\;\;\;\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.008098797427502198:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \frac{-1}{6}, x \cdot x, \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.0611438585736817:\\
\;\;\;\;\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.008098797427502198:\\
\;\;\;\;\mathsf{fma}\left(x \cdot \frac{-1}{6}, x \cdot x, \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 r6987749 = x;
        double r6987750 = r6987749 * r6987749;
        double r6987751 = 1.0;
        double r6987752 = r6987750 + r6987751;
        double r6987753 = sqrt(r6987752);
        double r6987754 = r6987749 + r6987753;
        double r6987755 = log(r6987754);
        return r6987755;
}

double f(double x) {
        double r6987756 = x;
        double r6987757 = -1.0611438585736817;
        bool r6987758 = r6987756 <= r6987757;
        double r6987759 = -0.0625;
        double r6987760 = 5.0;
        double r6987761 = pow(r6987756, r6987760);
        double r6987762 = r6987759 / r6987761;
        double r6987763 = 0.125;
        double r6987764 = r6987756 * r6987756;
        double r6987765 = r6987763 / r6987764;
        double r6987766 = r6987765 / r6987756;
        double r6987767 = 0.5;
        double r6987768 = r6987767 / r6987756;
        double r6987769 = r6987766 - r6987768;
        double r6987770 = r6987762 + r6987769;
        double r6987771 = log(r6987770);
        double r6987772 = 0.008098797427502198;
        bool r6987773 = r6987756 <= r6987772;
        double r6987774 = -0.16666666666666666;
        double r6987775 = r6987756 * r6987774;
        double r6987776 = 0.075;
        double r6987777 = fma(r6987776, r6987761, r6987756);
        double r6987778 = fma(r6987775, r6987764, r6987777);
        double r6987779 = 1.0;
        double r6987780 = hypot(r6987779, r6987756);
        double r6987781 = r6987780 + r6987756;
        double r6987782 = sqrt(r6987781);
        double r6987783 = log(r6987782);
        double r6987784 = r6987783 + r6987783;
        double r6987785 = r6987773 ? r6987778 : r6987784;
        double r6987786 = r6987758 ? r6987771 : r6987785;
        return r6987786;
}

Error

Bits error versus x

Target

Original52.4
Target44.6
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.0611438585736817

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

    if -1.0611438585736817 < x < 0.008098797427502198

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

    if 0.008098797427502198 < 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. 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.0611438585736817:\\ \;\;\;\;\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.008098797427502198:\\ \;\;\;\;\mathsf{fma}\left(x \cdot \frac{-1}{6}, x \cdot x, \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 2019135 +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)))))