Average Error: 52.8 → 0.1
Time: 15.6s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.9983730585657322187387308076722547411919:\\ \;\;\;\;\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 5.269995288876961172033763780575554847019 \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 -0.9983730585657322187387308076722547411919:\\
\;\;\;\;\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 5.269995288876961172033763780575554847019 \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 r5351161 = x;
        double r5351162 = r5351161 * r5351161;
        double r5351163 = 1.0;
        double r5351164 = r5351162 + r5351163;
        double r5351165 = sqrt(r5351164);
        double r5351166 = r5351161 + r5351165;
        double r5351167 = log(r5351166);
        return r5351167;
}

double f(double x) {
        double r5351168 = x;
        double r5351169 = -0.9983730585657322;
        bool r5351170 = r5351168 <= r5351169;
        double r5351171 = 0.125;
        double r5351172 = r5351168 * r5351168;
        double r5351173 = r5351172 * r5351168;
        double r5351174 = r5351171 / r5351173;
        double r5351175 = 0.5;
        double r5351176 = r5351175 / r5351168;
        double r5351177 = 0.0625;
        double r5351178 = 5.0;
        double r5351179 = pow(r5351168, r5351178);
        double r5351180 = r5351177 / r5351179;
        double r5351181 = r5351176 + r5351180;
        double r5351182 = r5351174 - r5351181;
        double r5351183 = log(r5351182);
        double r5351184 = 0.0005269995288876961;
        bool r5351185 = r5351168 <= r5351184;
        double r5351186 = -0.16666666666666666;
        double r5351187 = 1.0;
        double r5351188 = sqrt(r5351187);
        double r5351189 = r5351187 * r5351188;
        double r5351190 = r5351173 / r5351189;
        double r5351191 = r5351168 / r5351188;
        double r5351192 = log(r5351188);
        double r5351193 = r5351191 + r5351192;
        double r5351194 = fma(r5351186, r5351190, r5351193);
        double r5351195 = hypot(r5351168, r5351188);
        double r5351196 = r5351195 + r5351168;
        double r5351197 = log(r5351196);
        double r5351198 = r5351185 ? r5351194 : r5351197;
        double r5351199 = r5351170 ? r5351183 : r5351198;
        return r5351199;
}

Error

Bits error versus x

Target

Original52.8
Target45.1
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 < -0.9983730585657322

    1. Initial program 63.0

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

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

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

      \[\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 -0.9983730585657322 < x < 0.0005269995288876961

    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.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{-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.0005269995288876961 < x

    1. Initial program 30.0

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

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

      \[\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 -0.9983730585657322187387308076722547411919:\\ \;\;\;\;\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 5.269995288876961172033763780575554847019 \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 2019172 +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)))))