Average Error: 52.8 → 0.2
Time: 16.4s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.9983730585657322187387308076722547411919:\\ \;\;\;\;\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.8840407169458701641673314952640794217587:\\ \;\;\;\;\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 -0.9983730585657322187387308076722547411919:\\
\;\;\;\;\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.8840407169458701641673314952640794217587:\\
\;\;\;\;\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 r5786795 = x;
        double r5786796 = r5786795 * r5786795;
        double r5786797 = 1.0;
        double r5786798 = r5786796 + r5786797;
        double r5786799 = sqrt(r5786798);
        double r5786800 = r5786795 + r5786799;
        double r5786801 = log(r5786800);
        return r5786801;
}

double f(double x) {
        double r5786802 = x;
        double r5786803 = -0.9983730585657322;
        bool r5786804 = r5786802 <= r5786803;
        double r5786805 = 0.125;
        double r5786806 = r5786802 * r5786802;
        double r5786807 = r5786806 * r5786802;
        double r5786808 = r5786805 / r5786807;
        double r5786809 = 0.5;
        double r5786810 = r5786809 / r5786802;
        double r5786811 = r5786808 - r5786810;
        double r5786812 = 0.0625;
        double r5786813 = 5.0;
        double r5786814 = pow(r5786802, r5786813);
        double r5786815 = r5786812 / r5786814;
        double r5786816 = r5786811 - r5786815;
        double r5786817 = log(r5786816);
        double r5786818 = 0.8840407169458702;
        bool r5786819 = r5786802 <= r5786818;
        double r5786820 = 1.0;
        double r5786821 = r5786807 / r5786820;
        double r5786822 = sqrt(r5786820);
        double r5786823 = r5786821 / r5786822;
        double r5786824 = -0.16666666666666666;
        double r5786825 = r5786802 / r5786822;
        double r5786826 = log(r5786822);
        double r5786827 = r5786825 + r5786826;
        double r5786828 = fma(r5786823, r5786824, r5786827);
        double r5786829 = 2.0;
        double r5786830 = fma(r5786802, r5786829, r5786810);
        double r5786831 = r5786830 - r5786808;
        double r5786832 = log(r5786831);
        double r5786833 = r5786819 ? r5786828 : r5786832;
        double r5786834 = r5786804 ? r5786817 : r5786833;
        return r5786834;
}

Error

Bits error versus x

Target

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

    if -0.9983730585657322 < x < 0.8840407169458702

    1. Initial program 58.7

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

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

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

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

    1. Initial program 30.3

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

      \[\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 -0.9983730585657322187387308076722547411919:\\ \;\;\;\;\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.8840407169458701641673314952640794217587:\\ \;\;\;\;\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 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)))))