Average Error: 53.0 → 0.0
Time: 9.9s
Precision: 64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \le -7.0657300333594919 \cdot 10^{-4}:\\ \;\;\;\;\log \left(\frac{-1}{x - \mathsf{hypot}\left(\sqrt{1}, x\right)}\right)\\ \mathbf{elif}\;x \le 9.19903403515578391 \cdot 10^{-4}:\\ \;\;\;\;\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(\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 -7.0657300333594919 \cdot 10^{-4}:\\
\;\;\;\;\log \left(\frac{-1}{x - \mathsf{hypot}\left(\sqrt{1}, x\right)}\right)\\

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

\end{array}
double f(double x) {
        double r191642 = x;
        double r191643 = r191642 * r191642;
        double r191644 = 1.0;
        double r191645 = r191643 + r191644;
        double r191646 = sqrt(r191645);
        double r191647 = r191642 + r191646;
        double r191648 = log(r191647);
        return r191648;
}

double f(double x) {
        double r191649 = x;
        double r191650 = -0.0007065730033359492;
        bool r191651 = r191649 <= r191650;
        double r191652 = 1.0;
        double r191653 = -r191652;
        double r191654 = sqrt(r191652);
        double r191655 = hypot(r191654, r191649);
        double r191656 = r191649 - r191655;
        double r191657 = r191653 / r191656;
        double r191658 = log(r191657);
        double r191659 = 0.0009199034035155784;
        bool r191660 = r191649 <= r191659;
        double r191661 = 3.0;
        double r191662 = pow(r191649, r191661);
        double r191663 = pow(r191654, r191661);
        double r191664 = r191662 / r191663;
        double r191665 = -0.16666666666666666;
        double r191666 = log(r191654);
        double r191667 = r191649 / r191654;
        double r191668 = r191666 + r191667;
        double r191669 = fma(r191664, r191665, r191668);
        double r191670 = r191655 + r191649;
        double r191671 = log(r191670);
        double r191672 = r191660 ? r191669 : r191671;
        double r191673 = r191651 ? r191658 : r191672;
        return r191673;
}

Error

Bits error versus x

Target

Original53.0
Target45.4
Herbie0.0
\[\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 < -0.0007065730033359492

    1. Initial program 62.1

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Using strategy rm
    3. Applied flip-+61.8

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

      \[\leadsto \log \left(\frac{\color{blue}{0 - 1}}{x - \sqrt{x \cdot x + 1}}\right)\]
    5. Simplified0.1

      \[\leadsto \log \left(\frac{0 - 1}{\color{blue}{x - \mathsf{hypot}\left(\sqrt{1}, x\right)}}\right)\]

    if -0.0007065730033359492 < x < 0.0009199034035155784

    1. Initial program 59.3

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Taylor expanded around 0 0.0

      \[\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}}}\]
    3. Simplified0.0

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

    1. Initial program 32.3

      \[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
    2. Using strategy rm
    3. Applied *-un-lft-identity32.3

      \[\leadsto \log \left(x + \color{blue}{1 \cdot \sqrt{x \cdot x + 1}}\right)\]
    4. Applied *-un-lft-identity32.3

      \[\leadsto \log \left(\color{blue}{1 \cdot x} + 1 \cdot \sqrt{x \cdot x + 1}\right)\]
    5. Applied distribute-lft-out32.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.0657300333594919 \cdot 10^{-4}:\\ \;\;\;\;\log \left(\frac{-1}{x - \mathsf{hypot}\left(\sqrt{1}, x\right)}\right)\\ \mathbf{elif}\;x \le 9.19903403515578391 \cdot 10^{-4}:\\ \;\;\;\;\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(\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)))))