Average Error: 52.8 → 0.2
Time: 8.9s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.0079740505275243:\\ \;\;\;\;\log \left(\mathsf{fma}\left(\frac{1}{8}, \frac{1}{\frac{{x}^{3}}{1}}, -\mathsf{fma}\left(\frac{1}{16}, \frac{{\left(\sqrt{1}\right)}^{6}}{{x}^{5}}, \frac{1}{2} \cdot \frac{1}{x}\right)\right)\right)\\ \mathbf{elif}\;x \le 0.0012348249841071897:\\ \;\;\;\;\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(\sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)} \cdot \sqrt{\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.0079740505275243:\\
\;\;\;\;\log \left(\mathsf{fma}\left(\frac{1}{8}, \frac{1}{\frac{{x}^{3}}{1}}, -\mathsf{fma}\left(\frac{1}{16}, \frac{{\left(\sqrt{1}\right)}^{6}}{{x}^{5}}, \frac{1}{2} \cdot \frac{1}{x}\right)\right)\right)\\

\mathbf{elif}\;x \le 0.0012348249841071897:\\
\;\;\;\;\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(\sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)} \cdot \sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)} + x\right)\\

\end{array}
double f(double x) {
        double r227796 = x;
        double r227797 = r227796 * r227796;
        double r227798 = 1.0;
        double r227799 = r227797 + r227798;
        double r227800 = sqrt(r227799);
        double r227801 = r227796 + r227800;
        double r227802 = log(r227801);
        return r227802;
}

double f(double x) {
        double r227803 = x;
        double r227804 = -1.0079740505275243;
        bool r227805 = r227803 <= r227804;
        double r227806 = 0.125;
        double r227807 = 1.0;
        double r227808 = 3.0;
        double r227809 = pow(r227803, r227808);
        double r227810 = r227809 / r227807;
        double r227811 = r227807 / r227810;
        double r227812 = 0.0625;
        double r227813 = sqrt(r227807);
        double r227814 = 6.0;
        double r227815 = pow(r227813, r227814);
        double r227816 = 5.0;
        double r227817 = pow(r227803, r227816);
        double r227818 = r227815 / r227817;
        double r227819 = 0.5;
        double r227820 = r227807 / r227803;
        double r227821 = r227819 * r227820;
        double r227822 = fma(r227812, r227818, r227821);
        double r227823 = -r227822;
        double r227824 = fma(r227806, r227811, r227823);
        double r227825 = log(r227824);
        double r227826 = 0.0012348249841071897;
        bool r227827 = r227803 <= r227826;
        double r227828 = pow(r227813, r227808);
        double r227829 = r227809 / r227828;
        double r227830 = -0.16666666666666666;
        double r227831 = log(r227813);
        double r227832 = r227803 / r227813;
        double r227833 = r227831 + r227832;
        double r227834 = fma(r227829, r227830, r227833);
        double r227835 = hypot(r227813, r227803);
        double r227836 = sqrt(r227835);
        double r227837 = r227836 * r227836;
        double r227838 = r227837 + r227803;
        double r227839 = log(r227838);
        double r227840 = r227827 ? r227834 : r227839;
        double r227841 = r227805 ? r227825 : r227840;
        return r227841;
}

Error

Bits error versus x

Target

Original52.8
Target44.6
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.0079740505275243

    1. Initial program 62.8

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

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

      \[\leadsto \log \left(\sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(x, x, 1\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, 1\right)}}} + x\right)\]
    5. Applied sqrt-prod62.6

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

      \[\leadsto \log \left(\color{blue}{\sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(x, x, 1\right)}} + x\right)\]
    7. Simplified62.5

      \[\leadsto \log \left(\sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)} \cdot \color{blue}{\sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)}} + x\right)\]
    8. Taylor expanded around -inf 0.2

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

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

    if -1.0079740505275243 < x < 0.0012348249841071897

    1. Initial program 58.7

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

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

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

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

    1. Initial program 30.9

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

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

      \[\leadsto \log \left(\sqrt{\color{blue}{\sqrt{\mathsf{fma}\left(x, x, 1\right)} \cdot \sqrt{\mathsf{fma}\left(x, x, 1\right)}}} + x\right)\]
    5. Applied sqrt-prod30.9

      \[\leadsto \log \left(\color{blue}{\sqrt{\sqrt{\mathsf{fma}\left(x, x, 1\right)}} \cdot \sqrt{\sqrt{\mathsf{fma}\left(x, x, 1\right)}}} + x\right)\]
    6. Simplified30.9

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

      \[\leadsto \log \left(\sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)} \cdot \color{blue}{\sqrt{\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.0079740505275243:\\ \;\;\;\;\log \left(\mathsf{fma}\left(\frac{1}{8}, \frac{1}{\frac{{x}^{3}}{1}}, -\mathsf{fma}\left(\frac{1}{16}, \frac{{\left(\sqrt{1}\right)}^{6}}{{x}^{5}}, \frac{1}{2} \cdot \frac{1}{x}\right)\right)\right)\\ \mathbf{elif}\;x \le 0.0012348249841071897:\\ \;\;\;\;\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(\sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)} \cdot \sqrt{\mathsf{hypot}\left(\sqrt{1}, x\right)} + x\right)\\ \end{array}\]

Reproduce

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