Average Error: 53.4 → 0.1
Time: 6.3s
Precision: binary64
\[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -0.9682457514610505:\\ \;\;\;\;\log \left(\left(\frac{0.125}{{x}^{3}} - \left(\frac{0.5}{x} + \frac{0.0625}{{x}^{5}}\right)\right) + \frac{0.0390625}{{x}^{7}}\right)\\ \mathbf{elif}\;x \leq 0.0011232502346767796:\\ \;\;\;\;\mathsf{fma}\left({x}^{3}, -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \log \left(\sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)\\ t_0 + t_0 \end{array}\\ \end{array} \]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \leq -0.9682457514610505:\\
\;\;\;\;\log \left(\left(\frac{0.125}{{x}^{3}} - \left(\frac{0.5}{x} + \frac{0.0625}{{x}^{5}}\right)\right) + \frac{0.0390625}{{x}^{7}}\right)\\

\mathbf{elif}\;x \leq 0.0011232502346767796:\\
\;\;\;\;\mathsf{fma}\left({x}^{3}, -0.16666666666666666, x\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \log \left(\sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)\\
t_0 + t_0
\end{array}\\


\end{array}
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x -0.9682457514610505)
   (log
    (+
     (- (/ 0.125 (pow x 3.0)) (+ (/ 0.5 x) (/ 0.0625 (pow x 5.0))))
     (/ 0.0390625 (pow x 7.0))))
   (if (<= x 0.0011232502346767796)
     (fma (pow x 3.0) -0.16666666666666666 x)
     (let* ((t_0 (log (sqrt (+ x (hypot 1.0 x)))))) (+ t_0 t_0)))))
double code(double x) {
	return log(x + sqrt((x * x) + 1.0));
}
double code(double x) {
	double tmp;
	if (x <= -0.9682457514610505) {
		tmp = log(((0.125 / pow(x, 3.0)) - ((0.5 / x) + (0.0625 / pow(x, 5.0)))) + (0.0390625 / pow(x, 7.0)));
	} else if (x <= 0.0011232502346767796) {
		tmp = fma(pow(x, 3.0), -0.16666666666666666, x);
	} else {
		double t_0 = log(sqrt(x + hypot(1.0, x)));
		tmp = t_0 + t_0;
	}
	return tmp;
}

Error

Bits error versus x

Target

Original53.4
Target46.0
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;x < 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.96824575146105052

    1. Initial program 62.8

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

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

      \[\leadsto \log \color{blue}{\left(\left(0.0390625 \cdot \frac{1}{{x}^{7}} + 0.125 \cdot \frac{1}{{x}^{3}}\right) - \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}^{3}} - \left(\frac{0.5}{x} + \frac{0.0625}{{x}^{5}}\right)\right) + \frac{0.0390625}{{x}^{7}}\right)} \]

    if -0.96824575146105052 < x < 0.00112325023467677964

    1. Initial program 58.9

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

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

      \[\leadsto \color{blue}{x - 0.16666666666666666 \cdot {x}^{3}} \]
    4. Simplified0.2

      \[\leadsto \color{blue}{\mathsf{fma}\left({x}^{3}, -0.16666666666666666, x\right)} \]

    if 0.00112325023467677964 < x

    1. Initial program 32.9

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)} \]
    3. Applied add-sqr-sqrt_binary640.1

      \[\leadsto \log \color{blue}{\left(\sqrt{x + \mathsf{hypot}\left(1, x\right)} \cdot \sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)} \]
    4. Applied log-prod_binary640.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -0.9682457514610505:\\ \;\;\;\;\log \left(\left(\frac{0.125}{{x}^{3}} - \left(\frac{0.5}{x} + \frac{0.0625}{{x}^{5}}\right)\right) + \frac{0.0390625}{{x}^{7}}\right)\\ \mathbf{elif}\;x \leq 0.0011232502346767796:\\ \;\;\;\;\mathsf{fma}\left({x}^{3}, -0.16666666666666666, x\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(\sqrt{x + \mathsf{hypot}\left(1, x\right)}\right) + \log \left(\sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022088 
(FPCore (x)
  :name "Hyperbolic arcsine"
  :precision binary64

  :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)))))