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

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

\mathbf{else}:\\
\;\;\;\;\log \left(\left(\sqrt[3]{\mathsf{hypot}\left(\sqrt{1}, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(\sqrt{1}, x\right)}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(\sqrt{1}, x\right)} + x\right)\\

\end{array}
double f(double x) {
        double r232681 = x;
        double r232682 = r232681 * r232681;
        double r232683 = 1.0;
        double r232684 = r232682 + r232683;
        double r232685 = sqrt(r232684);
        double r232686 = r232681 + r232685;
        double r232687 = log(r232686);
        return r232687;
}

double f(double x) {
        double r232688 = x;
        double r232689 = -1.03811431304858;
        bool r232690 = r232688 <= r232689;
        double r232691 = 0.125;
        double r232692 = 3.0;
        double r232693 = pow(r232688, r232692);
        double r232694 = r232691 / r232693;
        double r232695 = 0.5;
        double r232696 = r232695 / r232688;
        double r232697 = r232694 - r232696;
        double r232698 = 0.0625;
        double r232699 = 5.0;
        double r232700 = pow(r232688, r232699);
        double r232701 = r232698 / r232700;
        double r232702 = r232697 - r232701;
        double r232703 = log(r232702);
        double r232704 = 0.0013723653044277859;
        bool r232705 = r232688 <= r232704;
        double r232706 = 1.0;
        double r232707 = sqrt(r232706);
        double r232708 = pow(r232707, r232692);
        double r232709 = r232693 / r232708;
        double r232710 = -0.16666666666666666;
        double r232711 = log(r232707);
        double r232712 = r232688 / r232707;
        double r232713 = r232711 + r232712;
        double r232714 = fma(r232709, r232710, r232713);
        double r232715 = hypot(r232707, r232688);
        double r232716 = cbrt(r232715);
        double r232717 = r232716 * r232716;
        double r232718 = r232717 * r232716;
        double r232719 = r232718 + r232688;
        double r232720 = log(r232719);
        double r232721 = r232705 ? r232714 : r232720;
        double r232722 = r232690 ? r232703 : r232721;
        return r232722;
}

Error

Bits error versus x

Target

Original53.0
Target45.4
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.03811431304858

    1. Initial program 62.7

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

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

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

      \[\leadsto \log \color{blue}{\left(\left(\frac{0.125}{{x}^{3}} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)}\]

    if -1.03811431304858 < x < 0.0013723653044277859

    1. Initial program 59.0

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

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

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

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

    if 0.0013723653044277859 < x

    1. Initial program 32.3

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

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

      \[\leadsto \log \left(\color{blue}{\left(\sqrt[3]{\sqrt{\mathsf{fma}\left(x, x, 1\right)}} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(x, x, 1\right)}}\right) \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(x, x, 1\right)}}} + x\right)\]
    5. Simplified32.4

      \[\leadsto \log \left(\color{blue}{\left(\sqrt[3]{\mathsf{hypot}\left(\sqrt{1}, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(\sqrt{1}, x\right)}\right)} \cdot \sqrt[3]{\sqrt{\mathsf{fma}\left(x, x, 1\right)}} + x\right)\]
    6. Simplified0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.03811431304857993:\\ \;\;\;\;\log \left(\left(\frac{0.125}{{x}^{3}} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\\ \mathbf{elif}\;x \le 0.0013723653044277859:\\ \;\;\;\;\mathsf{fma}\left(\frac{{x}^{3}}{{\left(\sqrt{1}\right)}^{3}}, \frac{-1}{6}, \log \left(\sqrt{1}\right) + \frac{x}{\sqrt{1}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\left(\sqrt[3]{\mathsf{hypot}\left(\sqrt{1}, x\right)} \cdot \sqrt[3]{\mathsf{hypot}\left(\sqrt{1}, x\right)}\right) \cdot \sqrt[3]{\mathsf{hypot}\left(\sqrt{1}, x\right)} + x\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(FPCore (x)
  :name "Hyperbolic arcsine"
  :precision binary64

  :herbie-target
  (if (< x 0.0) (log (/ -1 (- x (sqrt (+ (* x x) 1))))) (log (+ x (sqrt (+ (* x x) 1)))))

  (log (+ x (sqrt (+ (* x x) 1)))))