Average Error: 53.0 → 0.3
Time: 19.9s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.026683657222892120941537541511934250593:\\ \;\;\;\;\log \left(\left(\frac{0.125}{x \cdot \left(x \cdot x\right)} - \frac{0.0625}{{x}^{5}}\right) - \frac{0.5}{x}\right)\\ \mathbf{elif}\;x \le 0.8807071635272687437634431262267753481865:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \frac{x \cdot \left(x \cdot x\right)}{1 \cdot \sqrt{1}}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{fma}\left(2, x, \frac{0.5}{x}\right) - \frac{0.125}{x \cdot \left(x \cdot x\right)}\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \le -1.026683657222892120941537541511934250593:\\
\;\;\;\;\log \left(\left(\frac{0.125}{x \cdot \left(x \cdot x\right)} - \frac{0.0625}{{x}^{5}}\right) - \frac{0.5}{x}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(2, x, \frac{0.5}{x}\right) - \frac{0.125}{x \cdot \left(x \cdot x\right)}\right)\\

\end{array}
double f(double x) {
        double r11777020 = x;
        double r11777021 = r11777020 * r11777020;
        double r11777022 = 1.0;
        double r11777023 = r11777021 + r11777022;
        double r11777024 = sqrt(r11777023);
        double r11777025 = r11777020 + r11777024;
        double r11777026 = log(r11777025);
        return r11777026;
}

double f(double x) {
        double r11777027 = x;
        double r11777028 = -1.0266836572228921;
        bool r11777029 = r11777027 <= r11777028;
        double r11777030 = 0.125;
        double r11777031 = r11777027 * r11777027;
        double r11777032 = r11777027 * r11777031;
        double r11777033 = r11777030 / r11777032;
        double r11777034 = 0.0625;
        double r11777035 = 5.0;
        double r11777036 = pow(r11777027, r11777035);
        double r11777037 = r11777034 / r11777036;
        double r11777038 = r11777033 - r11777037;
        double r11777039 = 0.5;
        double r11777040 = r11777039 / r11777027;
        double r11777041 = r11777038 - r11777040;
        double r11777042 = log(r11777041);
        double r11777043 = 0.8807071635272687;
        bool r11777044 = r11777027 <= r11777043;
        double r11777045 = -0.16666666666666666;
        double r11777046 = 1.0;
        double r11777047 = sqrt(r11777046);
        double r11777048 = r11777046 * r11777047;
        double r11777049 = r11777032 / r11777048;
        double r11777050 = r11777027 / r11777047;
        double r11777051 = log(r11777047);
        double r11777052 = r11777050 + r11777051;
        double r11777053 = fma(r11777045, r11777049, r11777052);
        double r11777054 = 2.0;
        double r11777055 = fma(r11777054, r11777027, r11777040);
        double r11777056 = r11777055 - r11777033;
        double r11777057 = log(r11777056);
        double r11777058 = r11777044 ? r11777053 : r11777057;
        double r11777059 = r11777029 ? r11777042 : r11777058;
        return r11777059;
}

Error

Bits error versus x

Target

Original53.0
Target45.4
Herbie0.3
\[\begin{array}{l} \mathbf{if}\;x \lt 0.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.0266836572228921

    1. Initial program 62.8

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

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

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

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

    if -1.0266836572228921 < x < 0.8807071635272687

    1. Initial program 58.6

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

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

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

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

    if 0.8807071635272687 < x

    1. Initial program 32.2

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

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

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

      \[\leadsto \log \color{blue}{\left(\mathsf{fma}\left(2, x, \frac{0.5}{x}\right) - \frac{0.125}{x \cdot \left(x \cdot x\right)}\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

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

Reproduce

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