Average Error: 52.4 → 0.2
Time: 19.8s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.043616525651111:\\ \;\;\;\;\log \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} - \left(\frac{\frac{1}{2}}{x} + \frac{\frac{1}{16}}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 1.028068851045838:\\ \;\;\;\;(\left(x \cdot \frac{-1}{6}\right) \cdot \left(x \cdot x\right) + \left((\frac{3}{40} \cdot \left({x}^{5}\right) + x)_*\right))_*\\ \mathbf{else}:\\ \;\;\;\;\log x + \left(\left(\frac{\frac{1}{4}}{x \cdot x} + \log 2\right) + \frac{\frac{-3}{32}}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \le -1.043616525651111:\\
\;\;\;\;\log \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} - \left(\frac{\frac{1}{2}}{x} + \frac{\frac{1}{16}}{{x}^{5}}\right)\right)\\

\mathbf{elif}\;x \le 1.028068851045838:\\
\;\;\;\;(\left(x \cdot \frac{-1}{6}\right) \cdot \left(x \cdot x\right) + \left((\frac{3}{40} \cdot \left({x}^{5}\right) + x)_*\right))_*\\

\mathbf{else}:\\
\;\;\;\;\log x + \left(\left(\frac{\frac{1}{4}}{x \cdot x} + \log 2\right) + \frac{\frac{-3}{32}}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}\right)\\

\end{array}
double f(double x) {
        double r5036643 = x;
        double r5036644 = r5036643 * r5036643;
        double r5036645 = 1.0;
        double r5036646 = r5036644 + r5036645;
        double r5036647 = sqrt(r5036646);
        double r5036648 = r5036643 + r5036647;
        double r5036649 = log(r5036648);
        return r5036649;
}

double f(double x) {
        double r5036650 = x;
        double r5036651 = -1.043616525651111;
        bool r5036652 = r5036650 <= r5036651;
        double r5036653 = 0.125;
        double r5036654 = r5036653 / r5036650;
        double r5036655 = r5036650 * r5036650;
        double r5036656 = r5036654 / r5036655;
        double r5036657 = 0.5;
        double r5036658 = r5036657 / r5036650;
        double r5036659 = 0.0625;
        double r5036660 = 5.0;
        double r5036661 = pow(r5036650, r5036660);
        double r5036662 = r5036659 / r5036661;
        double r5036663 = r5036658 + r5036662;
        double r5036664 = r5036656 - r5036663;
        double r5036665 = log(r5036664);
        double r5036666 = 1.028068851045838;
        bool r5036667 = r5036650 <= r5036666;
        double r5036668 = -0.16666666666666666;
        double r5036669 = r5036650 * r5036668;
        double r5036670 = 0.075;
        double r5036671 = fma(r5036670, r5036661, r5036650);
        double r5036672 = fma(r5036669, r5036655, r5036671);
        double r5036673 = log(r5036650);
        double r5036674 = 0.25;
        double r5036675 = r5036674 / r5036655;
        double r5036676 = 2.0;
        double r5036677 = log(r5036676);
        double r5036678 = r5036675 + r5036677;
        double r5036679 = -0.09375;
        double r5036680 = r5036655 * r5036655;
        double r5036681 = r5036679 / r5036680;
        double r5036682 = r5036678 + r5036681;
        double r5036683 = r5036673 + r5036682;
        double r5036684 = r5036667 ? r5036672 : r5036683;
        double r5036685 = r5036652 ? r5036665 : r5036684;
        return r5036685;
}

Error

Bits error versus x

Target

Original52.4
Target44.9
Herbie0.2
\[\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.043616525651111

    1. Initial program 61.8

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{1^2 + x^2}^*\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{\frac{1}{8}}{x}}{x \cdot x} - \left(\frac{\frac{1}{16}}{{x}^{5}} + \frac{\frac{1}{2}}{x}\right)\right)}\]

    if -1.043616525651111 < x < 1.028068851045838

    1. Initial program 58.7

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{1^2 + x^2}^*\right)}\]
    3. Taylor expanded around 0 0.2

      \[\leadsto \color{blue}{\left(x + \frac{3}{40} \cdot {x}^{5}\right) - \frac{1}{6} \cdot {x}^{3}}\]
    4. Simplified0.2

      \[\leadsto \color{blue}{(\left(x \cdot \frac{-1}{6}\right) \cdot \left(x \cdot x\right) + \left((\frac{3}{40} \cdot \left({x}^{5}\right) + x)_*\right))_*}\]

    if 1.028068851045838 < x

    1. Initial program 30.1

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

      \[\leadsto \color{blue}{\log \left(x + \sqrt{1^2 + x^2}^*\right)}\]
    3. Taylor expanded around inf 0.4

      \[\leadsto \color{blue}{\left(\log 2 + \frac{1}{4} \cdot \frac{1}{{x}^{2}}\right) - \left(\log \left(\frac{1}{x}\right) + \frac{3}{32} \cdot \frac{1}{{x}^{4}}\right)}\]
    4. Simplified0.4

      \[\leadsto \color{blue}{\left(\left(\frac{\frac{1}{4}}{x \cdot x} + \log 2\right) + \frac{\frac{-3}{32}}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}\right) + \log x}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.043616525651111:\\ \;\;\;\;\log \left(\frac{\frac{\frac{1}{8}}{x}}{x \cdot x} - \left(\frac{\frac{1}{2}}{x} + \frac{\frac{1}{16}}{{x}^{5}}\right)\right)\\ \mathbf{elif}\;x \le 1.028068851045838:\\ \;\;\;\;(\left(x \cdot \frac{-1}{6}\right) \cdot \left(x \cdot x\right) + \left((\frac{3}{40} \cdot \left({x}^{5}\right) + x)_*\right))_*\\ \mathbf{else}:\\ \;\;\;\;\log x + \left(\left(\frac{\frac{1}{4}}{x \cdot x} + \log 2\right) + \frac{\frac{-3}{32}}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019104 +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)))))