Average Error: 52.9 → 11.1
Time: 7.1s
Precision: binary64
\[\log \left(x + \sqrt{x \cdot x + 1}\right)\]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3307054299543536 \cdot 10^{+154}:\\ \;\;\;\;\log \left(\frac{-1}{x - \left(-4 + \frac{-4 + \frac{-4}{x}}{x}\right)}\right)\\ \mathbf{elif}\;x \leq -8.98759362711225 \cdot 10^{-06}:\\ \;\;\;\;\log \left(\frac{-1}{x - \sqrt{x \cdot x + 1}}\right)\\ \mathbf{elif}\;x \leq 5.3198639586972195 \cdot 10^{-06}:\\ \;\;\;\;x + \log 1\\ \mathbf{elif}\;x \leq 1.3309234847747417 \cdot 10^{+154}:\\ \;\;\;\;\log \left(\sqrt{x + \sqrt{x \cdot x + 1}}\right) + \log \left(\sqrt{x + \sqrt{x \cdot x + 1}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \left(-4 + \frac{-4 + \frac{-4}{x}}{x}\right)\right)\\ \end{array}\]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
\mathbf{if}\;x \leq -1.3307054299543536 \cdot 10^{+154}:\\
\;\;\;\;\log \left(\frac{-1}{x - \left(-4 + \frac{-4 + \frac{-4}{x}}{x}\right)}\right)\\

\mathbf{elif}\;x \leq -8.98759362711225 \cdot 10^{-06}:\\
\;\;\;\;\log \left(\frac{-1}{x - \sqrt{x \cdot x + 1}}\right)\\

\mathbf{elif}\;x \leq 5.3198639586972195 \cdot 10^{-06}:\\
\;\;\;\;x + \log 1\\

\mathbf{elif}\;x \leq 1.3309234847747417 \cdot 10^{+154}:\\
\;\;\;\;\log \left(\sqrt{x + \sqrt{x \cdot x + 1}}\right) + \log \left(\sqrt{x + \sqrt{x \cdot x + 1}}\right)\\

\mathbf{else}:\\
\;\;\;\;\log \left(x + \left(-4 + \frac{-4 + \frac{-4}{x}}{x}\right)\right)\\

\end{array}
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
(FPCore (x)
 :precision binary64
 (if (<= x -1.3307054299543536e+154)
   (log (/ -1.0 (- x (+ -4.0 (/ (+ -4.0 (/ -4.0 x)) x)))))
   (if (<= x -8.98759362711225e-06)
     (log (/ -1.0 (- x (sqrt (+ (* x x) 1.0)))))
     (if (<= x 5.3198639586972195e-06)
       (+ x (log 1.0))
       (if (<= x 1.3309234847747417e+154)
         (+
          (log (sqrt (+ x (sqrt (+ (* x x) 1.0)))))
          (log (sqrt (+ x (sqrt (+ (* x x) 1.0))))))
         (log (+ x (+ -4.0 (/ (+ -4.0 (/ -4.0 x)) x)))))))))
double code(double x) {
	return log(x + sqrt((x * x) + 1.0));
}
double code(double x) {
	double tmp;
	if (x <= -1.3307054299543536e+154) {
		tmp = log(-1.0 / (x - (-4.0 + ((-4.0 + (-4.0 / x)) / x))));
	} else if (x <= -8.98759362711225e-06) {
		tmp = log(-1.0 / (x - sqrt((x * x) + 1.0)));
	} else if (x <= 5.3198639586972195e-06) {
		tmp = x + log(1.0);
	} else if (x <= 1.3309234847747417e+154) {
		tmp = log(sqrt(x + sqrt((x * x) + 1.0))) + log(sqrt(x + sqrt((x * x) + 1.0)));
	} else {
		tmp = log(x + (-4.0 + ((-4.0 + (-4.0 / x)) / x)));
	}
	return tmp;
}

Error

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original52.9
Target44.9
Herbie11.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 5 regimes
  2. if x < -1.3307054299543536e154

    1. Initial program 64.0

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

      \[\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. Simplified64.0

      \[\leadsto \log \left(\frac{\color{blue}{-1}}{x - \sqrt{x \cdot x + 1}}\right)\]
    5. Taylor expanded around inf 42.9

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

    if -1.3307054299543536e154 < x < -8.9875936271122497e-6

    1. Initial program 60.0

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

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

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

    if -8.9875936271122497e-6 < x < 5.3198639586972195e-6

    1. Initial program 59.5

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

      \[\leadsto \color{blue}{x + \log 1 \cdot \left(1 + {x}^{3}\right)}\]
    3. Using strategy rm
    4. Applied add-log-exp_binary640.1

      \[\leadsto x + \color{blue}{\log \left(e^{\log 1 \cdot \left(1 + {x}^{3}\right)}\right)}\]
    5. Simplified0.1

      \[\leadsto x + \log \color{blue}{1}\]

    if 5.3198639586972195e-6 < x < 1.33092348477474166e154

    1. Initial program 0.3

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

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

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

    if 1.33092348477474166e154 < x

    1. Initial program 64.0

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

      \[\leadsto \log \left(x + \color{blue}{\left(-4 + \frac{-4 + \frac{-4}{x}}{x}\right)}\right)\]
  3. Recombined 5 regimes into one program.
  4. Final simplification11.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.3307054299543536 \cdot 10^{+154}:\\ \;\;\;\;\log \left(\frac{-1}{x - \left(-4 + \frac{-4 + \frac{-4}{x}}{x}\right)}\right)\\ \mathbf{elif}\;x \leq -8.98759362711225 \cdot 10^{-06}:\\ \;\;\;\;\log \left(\frac{-1}{x - \sqrt{x \cdot x + 1}}\right)\\ \mathbf{elif}\;x \leq 5.3198639586972195 \cdot 10^{-06}:\\ \;\;\;\;x + \log 1\\ \mathbf{elif}\;x \leq 1.3309234847747417 \cdot 10^{+154}:\\ \;\;\;\;\log \left(\sqrt{x + \sqrt{x \cdot x + 1}}\right) + \log \left(\sqrt{x + \sqrt{x \cdot x + 1}}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \left(-4 + \frac{-4 + \frac{-4}{x}}{x}\right)\right)\\ \end{array}\]

Reproduce

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