Average Error: 53.0 → 0.4
Time: 5.0s
Precision: binary64
\[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -8058.760018329849:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{fma}\left(1, x, \mathsf{hypot}\left(1, x\right) + -1\right)\right)\\ \end{array} \]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \leq -8058.760018329849:\\
\;\;\;\;\log \left(\frac{-0.5}{x}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{fma}\left(1, x, \mathsf{hypot}\left(1, x\right) + -1\right)\right)\\


\end{array}
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x -8058.760018329849)
   (log (/ -0.5 x))
   (log1p (fma 1.0 x (+ (hypot 1.0 x) -1.0)))))
double code(double x) {
	return log((x + sqrt(((x * x) + 1.0))));
}
double code(double x) {
	double tmp;
	if (x <= -8058.760018329849) {
		tmp = log((-0.5 / x));
	} else {
		tmp = log1p(fma(1.0, x, (hypot(1.0, x) + -1.0)));
	}
	return tmp;
}

Error

Bits error versus x

Target

Original53.0
Target44.9
Herbie0.4
\[\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 2 regimes
  2. if x < -8058.7600183298491

    1. Initial program 63.6

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

      \[\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(\frac{-0.5}{x}\right)} \]

    if -8058.7600183298491 < x

    1. Initial program 49.4

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)} \]
    3. Applied egg-rr38.9

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\left(x + \mathsf{hypot}\left(1, x\right)\right) - 1\right)} \]
    4. Applied egg-rr0.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8058.760018329849:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(\mathsf{fma}\left(1, x, \mathsf{hypot}\left(1, x\right) + -1\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(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)))))