Average Error: 53.1 → 0.2
Time: 8.8s
Precision: binary64
Cost: 32968
\[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
\[\begin{array}{l} t_0 := x + \mathsf{hypot}\left(1, x\right)\\ \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.00115:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \log t_0 + \log \left(\sqrt{t_0}\right)\\ \end{array} \]
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ x (hypot 1.0 x))))
   (if (<= x -1.25)
     (log (/ -0.5 x))
     (if (<= x 0.00115)
       (+ x (* (* x x) (* x -0.16666666666666666)))
       (+ (* 0.5 (log t_0)) (log (sqrt t_0)))))))
double code(double x) {
	return log((x + sqrt(((x * x) + 1.0))));
}
double code(double x) {
	double t_0 = x + hypot(1.0, x);
	double tmp;
	if (x <= -1.25) {
		tmp = log((-0.5 / x));
	} else if (x <= 0.00115) {
		tmp = x + ((x * x) * (x * -0.16666666666666666));
	} else {
		tmp = (0.5 * log(t_0)) + log(sqrt(t_0));
	}
	return tmp;
}
public static double code(double x) {
	return Math.log((x + Math.sqrt(((x * x) + 1.0))));
}
public static double code(double x) {
	double t_0 = x + Math.hypot(1.0, x);
	double tmp;
	if (x <= -1.25) {
		tmp = Math.log((-0.5 / x));
	} else if (x <= 0.00115) {
		tmp = x + ((x * x) * (x * -0.16666666666666666));
	} else {
		tmp = (0.5 * Math.log(t_0)) + Math.log(Math.sqrt(t_0));
	}
	return tmp;
}
def code(x):
	return math.log((x + math.sqrt(((x * x) + 1.0))))
def code(x):
	t_0 = x + math.hypot(1.0, x)
	tmp = 0
	if x <= -1.25:
		tmp = math.log((-0.5 / x))
	elif x <= 0.00115:
		tmp = x + ((x * x) * (x * -0.16666666666666666))
	else:
		tmp = (0.5 * math.log(t_0)) + math.log(math.sqrt(t_0))
	return tmp
function code(x)
	return log(Float64(x + sqrt(Float64(Float64(x * x) + 1.0))))
end
function code(x)
	t_0 = Float64(x + hypot(1.0, x))
	tmp = 0.0
	if (x <= -1.25)
		tmp = log(Float64(-0.5 / x));
	elseif (x <= 0.00115)
		tmp = Float64(x + Float64(Float64(x * x) * Float64(x * -0.16666666666666666)));
	else
		tmp = Float64(Float64(0.5 * log(t_0)) + log(sqrt(t_0)));
	end
	return tmp
end
function tmp = code(x)
	tmp = log((x + sqrt(((x * x) + 1.0))));
end
function tmp_2 = code(x)
	t_0 = x + hypot(1.0, x);
	tmp = 0.0;
	if (x <= -1.25)
		tmp = log((-0.5 / x));
	elseif (x <= 0.00115)
		tmp = x + ((x * x) * (x * -0.16666666666666666));
	else
		tmp = (0.5 * log(t_0)) + log(sqrt(t_0));
	end
	tmp_2 = tmp;
end
code[x_] := N[Log[N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.25], N[Log[N[(-0.5 / x), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, 0.00115], N[(x + N[(N[(x * x), $MachinePrecision] * N[(x * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Log[t$95$0], $MachinePrecision]), $MachinePrecision] + N[Log[N[Sqrt[t$95$0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
t_0 := x + \mathsf{hypot}\left(1, x\right)\\
\mathbf{if}\;x \leq -1.25:\\
\;\;\;\;\log \left(\frac{-0.5}{x}\right)\\

\mathbf{elif}\;x \leq 0.00115:\\
\;\;\;\;x + \left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \log t_0 + \log \left(\sqrt{t_0}\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original53.1
Target45.2
Herbie0.2
\[\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 < -1.25

    1. Initial program 62.7

      \[\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)} \]
      Proof

      [Start]62.7

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

      +-commutative [=>]62.7

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

      hypot-1-def [=>]62.8

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

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

    if -1.25 < x < 0.00115

    1. Initial program 59.0

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)} \]
      Proof

      [Start]59.0

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

      +-commutative [=>]59.0

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

      hypot-1-def [=>]59.0

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

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + x} \]
    4. Applied egg-rr0.2

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

      \[\leadsto \color{blue}{\left(1 + \left(-0.16666666666666666 \cdot {x}^{3} - 1\right)\right)} + x \]
      Proof

      [Start]0.2

      \[ \left(\left(1 + -0.16666666666666666 \cdot {x}^{3}\right) - 1\right) + x \]

      associate--l+ [=>]0.2

      \[ \color{blue}{\left(1 + \left(-0.16666666666666666 \cdot {x}^{3} - 1\right)\right)} + x \]
    6. Applied egg-rr0.1

      \[\leadsto \color{blue}{\left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)} + x \]

    if 0.00115 < x

    1. Initial program 31.2

      \[\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)} \]
      Proof

      [Start]31.2

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

      +-commutative [=>]31.2

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

      hypot-1-def [=>]0.0

      \[ \log \left(x + \color{blue}{\mathsf{hypot}\left(1, x\right)}\right) \]
    3. Applied egg-rr0.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)} \]
    4. Applied egg-rr0.1

      \[\leadsto \color{blue}{0.5 \cdot \log \left(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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.00115:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \log \left(x + \mathsf{hypot}\left(1, x\right)\right) + \log \left(\sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.2
Cost13320
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.00094:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\ \end{array} \]
Alternative 2
Error0.5
Cost6856
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 1.26:\\ \;\;\;\;x + \left(x \cdot x\right) \cdot \left(x \cdot -0.16666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 3
Error16.2
Cost6724
\[\begin{array}{l} \mathbf{if}\;x \leq 1.26:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + x\right)\\ \end{array} \]
Alternative 4
Error30.9
Cost64
\[x \]

Error

Reproduce

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