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

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

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

\end{array}
double f(double x) {
        double r5005038 = x;
        double r5005039 = r5005038 * r5005038;
        double r5005040 = 1.0;
        double r5005041 = r5005039 + r5005040;
        double r5005042 = sqrt(r5005041);
        double r5005043 = r5005038 + r5005042;
        double r5005044 = log(r5005043);
        return r5005044;
}

double f(double x) {
        double r5005045 = x;
        double r5005046 = -1.0098163723001696;
        bool r5005047 = r5005045 <= r5005046;
        double r5005048 = 0.125;
        double r5005049 = r5005045 * r5005045;
        double r5005050 = r5005049 * r5005045;
        double r5005051 = r5005048 / r5005050;
        double r5005052 = 0.5;
        double r5005053 = r5005052 / r5005045;
        double r5005054 = 0.0625;
        double r5005055 = 5.0;
        double r5005056 = pow(r5005045, r5005055);
        double r5005057 = r5005054 / r5005056;
        double r5005058 = r5005053 + r5005057;
        double r5005059 = r5005051 - r5005058;
        double r5005060 = log(r5005059);
        double r5005061 = 0.0010835521119949194;
        bool r5005062 = r5005045 <= r5005061;
        double r5005063 = -0.16666666666666666;
        double r5005064 = 1.0;
        double r5005065 = sqrt(r5005064);
        double r5005066 = r5005064 * r5005065;
        double r5005067 = r5005050 / r5005066;
        double r5005068 = r5005045 / r5005065;
        double r5005069 = log(r5005065);
        double r5005070 = r5005068 + r5005069;
        double r5005071 = fma(r5005063, r5005067, r5005070);
        double r5005072 = hypot(r5005045, r5005065);
        double r5005073 = r5005072 + r5005045;
        double r5005074 = log(r5005073);
        double r5005075 = r5005062 ? r5005071 : r5005074;
        double r5005076 = r5005047 ? r5005060 : r5005075;
        return r5005076;
}

Error

Bits error versus x

Target

Original53.3
Target45.5
Herbie0.1
\[\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.0098163723001696

    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.2

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

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

    if -1.0098163723001696 < x < 0.0010835521119949194

    1. Initial program 59.0

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

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

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

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

    if 0.0010835521119949194 < x

    1. Initial program 32.5

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

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

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

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

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

Reproduce

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