Average Error: 53.1 → 0.2
Time: 21.3s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -1.019640201583560834563968455768190324306:\\ \;\;\;\;\log \left(\left(\mathsf{fma}\left(\frac{-\sqrt{0.5}}{x}, \sqrt{0.5}, \frac{\sqrt{0.5}}{x} \cdot \sqrt{0.5}\right) - \frac{0.0625}{{x}^{5}}\right) + \mathsf{fma}\left(0.125, \frac{1}{\left(x \cdot x\right) \cdot x}, \sqrt{0.5} \cdot \frac{-\sqrt{0.5}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.9010700472866574051167276593332644551992:\\ \;\;\;\;\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 -1.019640201583560834563968455768190324306:\\
\;\;\;\;\log \left(\left(\mathsf{fma}\left(\frac{-\sqrt{0.5}}{x}, \sqrt{0.5}, \frac{\sqrt{0.5}}{x} \cdot \sqrt{0.5}\right) - \frac{0.0625}{{x}^{5}}\right) + \mathsf{fma}\left(0.125, \frac{1}{\left(x \cdot x\right) \cdot x}, \sqrt{0.5} \cdot \frac{-\sqrt{0.5}}{x}\right)\right)\\

\mathbf{elif}\;x \le 0.9010700472866574051167276593332644551992:\\
\;\;\;\;\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 r4366770 = x;
        double r4366771 = r4366770 * r4366770;
        double r4366772 = 1.0;
        double r4366773 = r4366771 + r4366772;
        double r4366774 = sqrt(r4366773);
        double r4366775 = r4366770 + r4366774;
        double r4366776 = log(r4366775);
        return r4366776;
}

double f(double x) {
        double r4366777 = x;
        double r4366778 = -1.0196402015835608;
        bool r4366779 = r4366777 <= r4366778;
        double r4366780 = 0.5;
        double r4366781 = sqrt(r4366780);
        double r4366782 = -r4366781;
        double r4366783 = r4366782 / r4366777;
        double r4366784 = r4366781 / r4366777;
        double r4366785 = r4366784 * r4366781;
        double r4366786 = fma(r4366783, r4366781, r4366785);
        double r4366787 = 0.0625;
        double r4366788 = 5.0;
        double r4366789 = pow(r4366777, r4366788);
        double r4366790 = r4366787 / r4366789;
        double r4366791 = r4366786 - r4366790;
        double r4366792 = 0.125;
        double r4366793 = 1.0;
        double r4366794 = r4366777 * r4366777;
        double r4366795 = r4366794 * r4366777;
        double r4366796 = r4366793 / r4366795;
        double r4366797 = r4366781 * r4366783;
        double r4366798 = fma(r4366792, r4366796, r4366797);
        double r4366799 = r4366791 + r4366798;
        double r4366800 = log(r4366799);
        double r4366801 = 0.9010700472866574;
        bool r4366802 = r4366777 <= r4366801;
        double r4366803 = 1.0;
        double r4366804 = r4366795 / r4366803;
        double r4366805 = sqrt(r4366803);
        double r4366806 = r4366804 / r4366805;
        double r4366807 = -0.16666666666666666;
        double r4366808 = r4366777 / r4366805;
        double r4366809 = log(r4366805);
        double r4366810 = r4366808 + r4366809;
        double r4366811 = fma(r4366806, r4366807, r4366810);
        double r4366812 = 2.0;
        double r4366813 = r4366780 / r4366777;
        double r4366814 = fma(r4366777, r4366812, r4366813);
        double r4366815 = r4366792 / r4366795;
        double r4366816 = r4366814 - r4366815;
        double r4366817 = log(r4366816);
        double r4366818 = r4366802 ? r4366811 : r4366817;
        double r4366819 = r4366779 ? r4366800 : r4366818;
        return r4366819;
}

Error

Bits error versus x

Target

Original53.1
Target45.5
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.0196402015835608

    1. Initial program 62.8

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

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

      \[\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)}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity0.2

      \[\leadsto \log \left(\left(\frac{0.125}{\left(x \cdot x\right) \cdot x} - \frac{0.5}{\color{blue}{1 \cdot x}}\right) - \frac{0.0625}{{x}^{5}}\right)\]
    7. Applied add-sqr-sqrt0.2

      \[\leadsto \log \left(\left(\frac{0.125}{\left(x \cdot x\right) \cdot x} - \frac{\color{blue}{\sqrt{0.5} \cdot \sqrt{0.5}}}{1 \cdot x}\right) - \frac{0.0625}{{x}^{5}}\right)\]
    8. Applied times-frac0.2

      \[\leadsto \log \left(\left(\frac{0.125}{\left(x \cdot x\right) \cdot x} - \color{blue}{\frac{\sqrt{0.5}}{1} \cdot \frac{\sqrt{0.5}}{x}}\right) - \frac{0.0625}{{x}^{5}}\right)\]
    9. Applied div-inv0.2

      \[\leadsto \log \left(\left(\color{blue}{0.125 \cdot \frac{1}{\left(x \cdot x\right) \cdot x}} - \frac{\sqrt{0.5}}{1} \cdot \frac{\sqrt{0.5}}{x}\right) - \frac{0.0625}{{x}^{5}}\right)\]
    10. Applied prod-diff0.2

      \[\leadsto \log \left(\color{blue}{\left(\mathsf{fma}\left(0.125, \frac{1}{\left(x \cdot x\right) \cdot x}, -\frac{\sqrt{0.5}}{x} \cdot \frac{\sqrt{0.5}}{1}\right) + \mathsf{fma}\left(-\frac{\sqrt{0.5}}{x}, \frac{\sqrt{0.5}}{1}, \frac{\sqrt{0.5}}{x} \cdot \frac{\sqrt{0.5}}{1}\right)\right)} - \frac{0.0625}{{x}^{5}}\right)\]
    11. Applied associate--l+0.2

      \[\leadsto \log \color{blue}{\left(\mathsf{fma}\left(0.125, \frac{1}{\left(x \cdot x\right) \cdot x}, -\frac{\sqrt{0.5}}{x} \cdot \frac{\sqrt{0.5}}{1}\right) + \left(\mathsf{fma}\left(-\frac{\sqrt{0.5}}{x}, \frac{\sqrt{0.5}}{1}, \frac{\sqrt{0.5}}{x} \cdot \frac{\sqrt{0.5}}{1}\right) - \frac{0.0625}{{x}^{5}}\right)\right)}\]

    if -1.0196402015835608 < x < 0.9010700472866574

    1. Initial program 58.6

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

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

    1. Initial program 32.0

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

      \[\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 -1.019640201583560834563968455768190324306:\\ \;\;\;\;\log \left(\left(\mathsf{fma}\left(\frac{-\sqrt{0.5}}{x}, \sqrt{0.5}, \frac{\sqrt{0.5}}{x} \cdot \sqrt{0.5}\right) - \frac{0.0625}{{x}^{5}}\right) + \mathsf{fma}\left(0.125, \frac{1}{\left(x \cdot x\right) \cdot x}, \sqrt{0.5} \cdot \frac{-\sqrt{0.5}}{x}\right)\right)\\ \mathbf{elif}\;x \le 0.9010700472866574051167276593332644551992:\\ \;\;\;\;\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 2019192 +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)))))