Average Error: 53.0 → 0.1
Time: 16.0s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.013083326107210080380127692478708922863:\\ \;\;\;\;\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.001178095637719532009710099451638143364107:\\ \;\;\;\;\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.013083326107210080380127692478708922863:\\
\;\;\;\;\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.001178095637719532009710099451638143364107:\\
\;\;\;\;\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 r7575214 = x;
        double r7575215 = r7575214 * r7575214;
        double r7575216 = 1.0;
        double r7575217 = r7575215 + r7575216;
        double r7575218 = sqrt(r7575217);
        double r7575219 = r7575214 + r7575218;
        double r7575220 = log(r7575219);
        return r7575220;
}

double f(double x) {
        double r7575221 = x;
        double r7575222 = -1.01308332610721;
        bool r7575223 = r7575221 <= r7575222;
        double r7575224 = 0.125;
        double r7575225 = r7575221 * r7575221;
        double r7575226 = r7575225 * r7575221;
        double r7575227 = r7575224 / r7575226;
        double r7575228 = 0.5;
        double r7575229 = r7575228 / r7575221;
        double r7575230 = 0.0625;
        double r7575231 = 5.0;
        double r7575232 = pow(r7575221, r7575231);
        double r7575233 = r7575230 / r7575232;
        double r7575234 = r7575229 + r7575233;
        double r7575235 = r7575227 - r7575234;
        double r7575236 = log(r7575235);
        double r7575237 = 0.001178095637719532;
        bool r7575238 = r7575221 <= r7575237;
        double r7575239 = -0.16666666666666666;
        double r7575240 = 1.0;
        double r7575241 = sqrt(r7575240);
        double r7575242 = r7575240 * r7575241;
        double r7575243 = r7575226 / r7575242;
        double r7575244 = r7575221 / r7575241;
        double r7575245 = log(r7575241);
        double r7575246 = r7575244 + r7575245;
        double r7575247 = fma(r7575239, r7575243, r7575246);
        double r7575248 = hypot(r7575221, r7575241);
        double r7575249 = r7575248 + r7575221;
        double r7575250 = log(r7575249);
        double r7575251 = r7575238 ? r7575247 : r7575250;
        double r7575252 = r7575223 ? r7575236 : r7575251;
        return r7575252;
}

Error

Bits error versus x

Target

Original53.0
Target45.4
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.01308332610721

    1. Initial program 62.7

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

      \[\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.01308332610721 < x < 0.001178095637719532

    1. Initial program 58.8

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

      \[\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.001178095637719532 < x

    1. Initial program 31.5

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{\mathsf{fma}\left(x, x, 1\right)}\right)}\]
    3. Using strategy rm
    4. Applied add-log-exp31.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.013083326107210080380127692478708922863:\\ \;\;\;\;\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.001178095637719532009710099451638143364107:\\ \;\;\;\;\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 2019170 +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)))))