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.02122159882250018725358131632674485445:\\ \;\;\;\;\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 9.875399030201360492386974954115430591628 \cdot 10^{-4}:\\ \;\;\;\;\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.02122159882250018725358131632674485445:\\
\;\;\;\;\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 9.875399030201360492386974954115430591628 \cdot 10^{-4}:\\
\;\;\;\;\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 r4650357 = x;
        double r4650358 = r4650357 * r4650357;
        double r4650359 = 1.0;
        double r4650360 = r4650358 + r4650359;
        double r4650361 = sqrt(r4650360);
        double r4650362 = r4650357 + r4650361;
        double r4650363 = log(r4650362);
        return r4650363;
}

double f(double x) {
        double r4650364 = x;
        double r4650365 = -1.0212215988225002;
        bool r4650366 = r4650364 <= r4650365;
        double r4650367 = 0.125;
        double r4650368 = r4650364 * r4650364;
        double r4650369 = r4650368 * r4650364;
        double r4650370 = r4650367 / r4650369;
        double r4650371 = 0.5;
        double r4650372 = r4650371 / r4650364;
        double r4650373 = 0.0625;
        double r4650374 = 5.0;
        double r4650375 = pow(r4650364, r4650374);
        double r4650376 = r4650373 / r4650375;
        double r4650377 = r4650372 + r4650376;
        double r4650378 = r4650370 - r4650377;
        double r4650379 = log(r4650378);
        double r4650380 = 0.000987539903020136;
        bool r4650381 = r4650364 <= r4650380;
        double r4650382 = -0.16666666666666666;
        double r4650383 = 1.0;
        double r4650384 = sqrt(r4650383);
        double r4650385 = r4650383 * r4650384;
        double r4650386 = r4650369 / r4650385;
        double r4650387 = r4650364 / r4650384;
        double r4650388 = log(r4650384);
        double r4650389 = r4650387 + r4650388;
        double r4650390 = fma(r4650382, r4650386, r4650389);
        double r4650391 = hypot(r4650364, r4650384);
        double r4650392 = r4650391 + r4650364;
        double r4650393 = log(r4650392);
        double r4650394 = r4650381 ? r4650390 : r4650393;
        double r4650395 = r4650366 ? r4650379 : r4650394;
        return r4650395;
}

Error

Bits error versus x

Target

Original53.0
Target45.3
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.0212215988225002

    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(\frac{0.125}{x \cdot \left(x \cdot x\right)} - \left(\frac{0.0625}{{x}^{5}} + \frac{0.5}{x}\right)\right)}\]

    if -1.0212215988225002 < x < 0.000987539903020136

    1. Initial program 58.9

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

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

    1. Initial program 31.8

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

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

      \[\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.02122159882250018725358131632674485445:\\ \;\;\;\;\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 9.875399030201360492386974954115430591628 \cdot 10^{-4}:\\ \;\;\;\;\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 2019169 +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)))))