Average Error: 52.5 → 0.1
Time: 11.2s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0715992056992538:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} + \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \frac{\frac{-1}{2}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.0077107299968686566:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \left(\left(x \cdot x\right) \cdot x\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\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.0715992056992538:\\
\;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} + \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \frac{\frac{-1}{2}}{x}\right)\right)\\

\mathbf{elif}\;x \le 0.0077107299968686566:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \left(\left(x \cdot x\right) \cdot x\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\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 r3290304 = x;
        double r3290305 = r3290304 * r3290304;
        double r3290306 = 1.0;
        double r3290307 = r3290305 + r3290306;
        double r3290308 = sqrt(r3290307);
        double r3290309 = r3290304 + r3290308;
        double r3290310 = log(r3290309);
        return r3290310;
}

double f(double x) {
        double r3290311 = x;
        double r3290312 = -1.0715992056992538;
        bool r3290313 = r3290311 <= r3290312;
        double r3290314 = -0.0625;
        double r3290315 = 5.0;
        double r3290316 = pow(r3290311, r3290315);
        double r3290317 = r3290314 / r3290316;
        double r3290318 = 0.125;
        double r3290319 = r3290318 / r3290311;
        double r3290320 = r3290311 * r3290311;
        double r3290321 = r3290319 / r3290320;
        double r3290322 = -0.5;
        double r3290323 = r3290322 / r3290311;
        double r3290324 = r3290321 + r3290323;
        double r3290325 = r3290317 + r3290324;
        double r3290326 = log(r3290325);
        double r3290327 = 0.0077107299968686566;
        bool r3290328 = r3290311 <= r3290327;
        double r3290329 = -0.16666666666666666;
        double r3290330 = r3290320 * r3290311;
        double r3290331 = 0.075;
        double r3290332 = fma(r3290331, r3290316, r3290311);
        double r3290333 = fma(r3290329, r3290330, r3290332);
        double r3290334 = 1.0;
        double r3290335 = hypot(r3290334, r3290311);
        double r3290336 = r3290335 + r3290311;
        double r3290337 = sqrt(r3290336);
        double r3290338 = log(r3290337);
        double r3290339 = r3290338 + r3290338;
        double r3290340 = r3290328 ? r3290333 : r3290339;
        double r3290341 = r3290313 ? r3290326 : r3290340;
        return r3290341;
}

Error

Bits error versus x

Target

Original52.5
Target44.8
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.0715992056992538

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

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

      \[\leadsto \log \color{blue}{\left(\frac{\frac{-1}{16}}{{x}^{5}} + \left(\frac{\frac{-1}{2}}{x} + \frac{\frac{\frac{1}{8}}{x}}{x \cdot x}\right)\right)}\]

    if -1.0715992056992538 < x < 0.0077107299968686566

    1. Initial program 58.9

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

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

    if 0.0077107299968686566 < x

    1. Initial program 30.6

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

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

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

      \[\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.0715992056992538:\\ \;\;\;\;\log \left(\frac{\frac{-1}{16}}{{x}^{5}} + \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} + \frac{\frac{-1}{2}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.0077107299968686566:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \left(\left(x \cdot x\right) \cdot x\right), \left(\mathsf{fma}\left(\frac{3}{40}, \left({x}^{5}\right), x\right)\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 2019128 +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)))))