Average Error: 52.9 → 0.1
Time: 32.4s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.002637632358202246507516974816098809242:\\ \;\;\;\;\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 8.996474414043170155994011416566991101718 \cdot 10^{-4}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \frac{x \cdot x}{\sqrt{1}} \cdot \frac{x}{1}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(\sqrt{1}, x\right)\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \le -1.002637632358202246507516974816098809242:\\
\;\;\;\;\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 8.996474414043170155994011416566991101718 \cdot 10^{-4}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \frac{x \cdot x}{\sqrt{1}} \cdot \frac{x}{1}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)\\

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

\end{array}
double f(double x) {
        double r4405776 = x;
        double r4405777 = r4405776 * r4405776;
        double r4405778 = 1.0;
        double r4405779 = r4405777 + r4405778;
        double r4405780 = sqrt(r4405779);
        double r4405781 = r4405776 + r4405780;
        double r4405782 = log(r4405781);
        return r4405782;
}

double f(double x) {
        double r4405783 = x;
        double r4405784 = -1.0026376323582022;
        bool r4405785 = r4405783 <= r4405784;
        double r4405786 = 0.125;
        double r4405787 = r4405783 * r4405783;
        double r4405788 = r4405787 * r4405783;
        double r4405789 = r4405786 / r4405788;
        double r4405790 = 0.5;
        double r4405791 = r4405790 / r4405783;
        double r4405792 = r4405789 - r4405791;
        double r4405793 = 0.0625;
        double r4405794 = 5.0;
        double r4405795 = pow(r4405783, r4405794);
        double r4405796 = r4405793 / r4405795;
        double r4405797 = r4405792 - r4405796;
        double r4405798 = log(r4405797);
        double r4405799 = 0.000899647441404317;
        bool r4405800 = r4405783 <= r4405799;
        double r4405801 = -0.16666666666666666;
        double r4405802 = 1.0;
        double r4405803 = sqrt(r4405802);
        double r4405804 = r4405787 / r4405803;
        double r4405805 = r4405783 / r4405802;
        double r4405806 = r4405804 * r4405805;
        double r4405807 = r4405783 / r4405803;
        double r4405808 = log(r4405803);
        double r4405809 = r4405807 + r4405808;
        double r4405810 = fma(r4405801, r4405806, r4405809);
        double r4405811 = hypot(r4405803, r4405783);
        double r4405812 = r4405783 + r4405811;
        double r4405813 = log(r4405812);
        double r4405814 = r4405800 ? r4405810 : r4405813;
        double r4405815 = r4405785 ? r4405798 : r4405814;
        return r4405815;
}

Error

Bits error versus x

Target

Original52.9
Target45.2
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 < -1.0026376323582022

    1. Initial program 63.0

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

      \[\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}{x \cdot \left(x \cdot x\right)} - \frac{0.5}{x}\right) - \frac{0.0625}{{x}^{5}}\right)}\]

    if -1.0026376323582022 < x < 0.000899647441404317

    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}{1} \cdot \frac{x \cdot x}{\sqrt{1}}, \log \left(\sqrt{1}\right) + \frac{x}{\sqrt{1}}\right)}\]

    if 0.000899647441404317 < x

    1. Initial program 31.4

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

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

      \[\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(x + \mathsf{hypot}\left(\sqrt{1}, x\right)\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.002637632358202246507516974816098809242:\\ \;\;\;\;\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 8.996474414043170155994011416566991101718 \cdot 10^{-4}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{6}, \frac{x \cdot x}{\sqrt{1}} \cdot \frac{x}{1}, \frac{x}{\sqrt{1}} + \log \left(\sqrt{1}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(\sqrt{1}, x\right)\right)\\ \end{array}\]

Reproduce

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