Average Error: 52.9 → 0.1
Time: 39.3s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1.0}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.994661063828435:\\ \;\;\;\;\log \left(\left(\frac{0.125}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\\ \mathbf{elif}\;x \le 0.0009799194081595412:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \frac{x \cdot x}{\sqrt{1.0}} \cdot \frac{x}{1.0}, \frac{x}{\sqrt{1.0}} + \log \left(\sqrt{1.0}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{x + \mathsf{hypot}\left(\sqrt{1.0}, x\right)} \cdot \sqrt{x + \mathsf{hypot}\left(\sqrt{1.0}, x\right)}\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1.0}\right)
\begin{array}{l}
\mathbf{if}\;x \le -0.994661063828435:\\
\;\;\;\;\log \left(\left(\frac{0.125}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\\

\mathbf{elif}\;x \le 0.0009799194081595412:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \frac{x \cdot x}{\sqrt{1.0}} \cdot \frac{x}{1.0}, \frac{x}{\sqrt{1.0}} + \log \left(\sqrt{1.0}\right)\right)\\

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

\end{array}
double f(double x) {
        double r5335094 = x;
        double r5335095 = r5335094 * r5335094;
        double r5335096 = 1.0;
        double r5335097 = r5335095 + r5335096;
        double r5335098 = sqrt(r5335097);
        double r5335099 = r5335094 + r5335098;
        double r5335100 = log(r5335099);
        return r5335100;
}

double f(double x) {
        double r5335101 = x;
        double r5335102 = -0.994661063828435;
        bool r5335103 = r5335101 <= r5335102;
        double r5335104 = 0.125;
        double r5335105 = r5335101 * r5335101;
        double r5335106 = r5335105 * r5335101;
        double r5335107 = r5335104 / r5335106;
        double r5335108 = 0.5;
        double r5335109 = r5335108 / r5335101;
        double r5335110 = r5335107 - r5335109;
        double r5335111 = 0.0625;
        double r5335112 = 5.0;
        double r5335113 = pow(r5335101, r5335112);
        double r5335114 = r5335111 / r5335113;
        double r5335115 = r5335110 - r5335114;
        double r5335116 = log(r5335115);
        double r5335117 = 0.0009799194081595412;
        bool r5335118 = r5335101 <= r5335117;
        double r5335119 = -0.16666666666666666;
        double r5335120 = 1.0;
        double r5335121 = sqrt(r5335120);
        double r5335122 = r5335105 / r5335121;
        double r5335123 = r5335101 / r5335120;
        double r5335124 = r5335122 * r5335123;
        double r5335125 = r5335101 / r5335121;
        double r5335126 = log(r5335121);
        double r5335127 = r5335125 + r5335126;
        double r5335128 = fma(r5335119, r5335124, r5335127);
        double r5335129 = hypot(r5335121, r5335101);
        double r5335130 = r5335101 + r5335129;
        double r5335131 = sqrt(r5335130);
        double r5335132 = r5335131 * r5335131;
        double r5335133 = log(r5335132);
        double r5335134 = r5335118 ? r5335128 : r5335133;
        double r5335135 = r5335103 ? r5335116 : r5335134;
        return r5335135;
}

Error

Bits error versus x

Target

Original52.9
Target44.8
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x \lt 0.0:\\ \;\;\;\;\log \left(\frac{-1.0}{x - \sqrt{x \cdot x + 1.0}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \sqrt{x \cdot x + 1.0}\right)\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -0.994661063828435

    1. Initial program 62.9

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{\mathsf{fma}\left(x, x, 1.0\right)}\right)}\]
    3. Taylor expanded around -inf 0.1

      \[\leadsto \log \color{blue}{\left(0.125 \cdot \frac{1}{{x}^{3}} - \left(0.0625 \cdot \frac{1}{{x}^{5}} + 0.5 \cdot \frac{1}{x}\right)\right)}\]
    4. Simplified0.1

      \[\leadsto \log \color{blue}{\left(\left(\frac{0.125}{x \cdot \left(x \cdot x\right)} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)}\]

    if -0.994661063828435 < x < 0.0009799194081595412

    1. Initial program 58.7

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{\mathsf{fma}\left(x, x, 1.0\right)}\right)}\]
    3. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{\left(\frac{x}{\sqrt{1.0}} + \log \left(\sqrt{1.0}\right)\right) - \frac{1}{6} \cdot \frac{{x}^{3}}{{\left(\sqrt{1.0}\right)}^{3}}}\]
    4. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, \frac{x}{1.0} \cdot \frac{x \cdot x}{\sqrt{1.0}}, \log \left(\sqrt{1.0}\right) + \frac{x}{\sqrt{1.0}}\right)}\]

    if 0.0009799194081595412 < x

    1. Initial program 31.4

      \[\log \left(x + \sqrt{x \cdot x + 1.0}\right)\]
    2. Simplified31.4

      \[\leadsto \color{blue}{\log \left(x + \sqrt{\mathsf{fma}\left(x, x, 1.0\right)}\right)}\]
    3. Using strategy rm
    4. Applied add-log-exp31.4

      \[\leadsto \color{blue}{\log \left(e^{\log \left(x + \sqrt{\mathsf{fma}\left(x, x, 1.0\right)}\right)}\right)}\]
    5. Simplified0.0

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

      \[\leadsto \log \color{blue}{\left(\sqrt{x + \mathsf{hypot}\left(\sqrt{1.0}, x\right)} \cdot \sqrt{x + \mathsf{hypot}\left(\sqrt{1.0}, x\right)}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -0.994661063828435:\\ \;\;\;\;\log \left(\left(\frac{0.125}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\\ \mathbf{elif}\;x \le 0.0009799194081595412:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \frac{x \cdot x}{\sqrt{1.0}} \cdot \frac{x}{1.0}, \frac{x}{\sqrt{1.0}} + \log \left(\sqrt{1.0}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{x + \mathsf{hypot}\left(\sqrt{1.0}, x\right)} \cdot \sqrt{x + \mathsf{hypot}\left(\sqrt{1.0}, x\right)}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019165 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic arcsine"

  :herbie-target
  (if (< x 0.0) (log (/ -1.0 (- x (sqrt (+ (* x x) 1.0))))) (log (+ x (sqrt (+ (* x x) 1.0)))))

  (log (+ x (sqrt (+ (* x x) 1.0)))))