Average Error: 52.5 → 1.4
Time: 4.7s
Precision: binary64
\[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -8.787849164671579:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 2.0878989945823202 \cdot 10^{-20}:\\ \;\;\;\;\mathsf{fma}\left(-0.16666666666666666, {x}^{3}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\log 2 + \log x\\ \end{array} \]
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x -8.787849164671579)
   (log (/ -0.5 x))
   (if (<= x 2.0878989945823202e-20)
     (fma -0.16666666666666666 (pow x 3.0) x)
     (+ (log 2.0) (log x)))))
double code(double x) {
	return log((x + sqrt(((x * x) + 1.0))));
}
double code(double x) {
	double tmp;
	if (x <= -8.787849164671579) {
		tmp = log((-0.5 / x));
	} else if (x <= 2.0878989945823202e-20) {
		tmp = fma(-0.16666666666666666, pow(x, 3.0), x);
	} else {
		tmp = log(2.0) + log(x);
	}
	return tmp;
}
function code(x)
	return log(Float64(x + sqrt(Float64(Float64(x * x) + 1.0))))
end
function code(x)
	tmp = 0.0
	if (x <= -8.787849164671579)
		tmp = log(Float64(-0.5 / x));
	elseif (x <= 2.0878989945823202e-20)
		tmp = fma(-0.16666666666666666, (x ^ 3.0), x);
	else
		tmp = Float64(log(2.0) + log(x));
	end
	return tmp
end
code[x_] := N[Log[N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -8.787849164671579], N[Log[N[(-0.5 / x), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 2.0878989945823202e-20], N[(-0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision] + x), $MachinePrecision], N[(N[Log[2.0], $MachinePrecision] + N[Log[x], $MachinePrecision]), $MachinePrecision]]]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \leq -8.787849164671579:\\
\;\;\;\;\log \left(\frac{-0.5}{x}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\log 2 + \log x\\


\end{array}

Error

Bits error versus x

Target

Original52.5
Target45.2
Herbie1.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 3 regimes
  2. if x < -8.78784916467157906

    1. Initial program 63.1

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

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

      \[\leadsto \log \color{blue}{\left(\frac{-0.5}{x}\right)} \]

    if -8.78784916467157906 < x < 2.0878989945823202e-20

    1. Initial program 59.4

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

      \[\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}{-0.16666666666666666 \cdot {x}^{3} + x} \]
    4. Simplified0.2

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

    if 2.0878989945823202e-20 < x

    1. Initial program 31.1

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

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

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

      \[\leadsto \color{blue}{\log 2 + \log x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.787849164671579:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 2.0878989945823202 \cdot 10^{-20}:\\ \;\;\;\;\mathsf{fma}\left(-0.16666666666666666, {x}^{3}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\log 2 + \log x\\ \end{array} \]

Reproduce

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