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

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

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

\end{array}
double f(double x) {
        double r5218190 = x;
        double r5218191 = r5218190 * r5218190;
        double r5218192 = 1.0;
        double r5218193 = r5218191 + r5218192;
        double r5218194 = sqrt(r5218193);
        double r5218195 = r5218190 + r5218194;
        double r5218196 = log(r5218195);
        return r5218196;
}

double f(double x) {
        double r5218197 = x;
        double r5218198 = -1.0098163723001696;
        bool r5218199 = r5218197 <= r5218198;
        double r5218200 = 0.125;
        double r5218201 = r5218197 * r5218197;
        double r5218202 = r5218201 * r5218197;
        double r5218203 = r5218200 / r5218202;
        double r5218204 = 0.5;
        double r5218205 = r5218204 / r5218197;
        double r5218206 = r5218203 - r5218205;
        double r5218207 = 0.0625;
        double r5218208 = 5.0;
        double r5218209 = pow(r5218197, r5218208);
        double r5218210 = r5218207 / r5218209;
        double r5218211 = r5218206 - r5218210;
        double r5218212 = log(r5218211);
        double r5218213 = 0.8987700841367662;
        bool r5218214 = r5218197 <= r5218213;
        double r5218215 = 1.0;
        double r5218216 = r5218202 / r5218215;
        double r5218217 = sqrt(r5218215);
        double r5218218 = r5218216 / r5218217;
        double r5218219 = -0.16666666666666666;
        double r5218220 = r5218197 / r5218217;
        double r5218221 = log(r5218217);
        double r5218222 = r5218220 + r5218221;
        double r5218223 = fma(r5218218, r5218219, r5218222);
        double r5218224 = 2.0;
        double r5218225 = fma(r5218197, r5218224, r5218205);
        double r5218226 = r5218225 - r5218203;
        double r5218227 = log(r5218226);
        double r5218228 = r5218214 ? r5218223 : r5218227;
        double r5218229 = r5218199 ? r5218212 : r5218228;
        return r5218229;
}

Error

Bits error versus x

Target

Original53.3
Target45.5
Herbie0.2
\[\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(\left(\frac{0.125}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)}\]

    if -1.0098163723001696 < x < 0.8987700841367662

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

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

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

    if 0.8987700841367662 < x

    1. Initial program 32.7

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Simplified32.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(\left(2 \cdot x + 0.5 \cdot \frac{1}{x}\right) - 0.125 \cdot \frac{1}{{x}^{3}}\right)}\]
    4. Simplified0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.009816372300169629028232520795427262783:\\ \;\;\;\;\log \left(\left(\frac{0.125}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\\ \mathbf{elif}\;x \le 0.8987700841367661785952236641605850309134:\\ \;\;\;\;\mathsf{fma}\left(\frac{\frac{\left(x \cdot x\right) \cdot x}{1}}{\sqrt{1}}, \frac{-1}{6}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\mathsf{fma}\left(x, 2, \frac{0.5}{x}\right) - \frac{0.125}{\left(x \cdot x\right) \cdot 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)))))