Average Error: 53.4 → 0.4
Time: 7.7s
Precision: binary64
Cost: 39240
\[\log \left(x + \sqrt{x \cdot x + 1}\right) \]
\[\begin{array}{l} t_0 := \log \left(\sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)\\ \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;-\log \left(\left(\frac{-0.5}{x} - x\right) - x\right)\\ \mathbf{elif}\;x \leq 9.821702311257485 \cdot 10^{-8}:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;t_0 + t_0\\ \end{array} \]
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (log (sqrt (+ x (hypot 1.0 x))))))
   (if (<= x -48450.84557538221)
     (- (log (- (- (/ -0.5 x) x) x)))
     (if (<= x 9.821702311257485e-8)
       (+ x (* -0.16666666666666666 (pow x 3.0)))
       (+ t_0 t_0)))))
double code(double x) {
	return log((x + sqrt(((x * x) + 1.0))));
}
double code(double x) {
	double t_0 = log(sqrt((x + hypot(1.0, x))));
	double tmp;
	if (x <= -48450.84557538221) {
		tmp = -log((((-0.5 / x) - x) - x));
	} else if (x <= 9.821702311257485e-8) {
		tmp = x + (-0.16666666666666666 * pow(x, 3.0));
	} else {
		tmp = t_0 + 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 = Math.log(Math.sqrt((x + Math.hypot(1.0, x))));
	double tmp;
	if (x <= -48450.84557538221) {
		tmp = -Math.log((((-0.5 / x) - x) - x));
	} else if (x <= 9.821702311257485e-8) {
		tmp = x + (-0.16666666666666666 * Math.pow(x, 3.0));
	} else {
		tmp = t_0 + t_0;
	}
	return tmp;
}
def code(x):
	return math.log((x + math.sqrt(((x * x) + 1.0))))
def code(x):
	t_0 = math.log(math.sqrt((x + math.hypot(1.0, x))))
	tmp = 0
	if x <= -48450.84557538221:
		tmp = -math.log((((-0.5 / x) - x) - x))
	elif x <= 9.821702311257485e-8:
		tmp = x + (-0.16666666666666666 * math.pow(x, 3.0))
	else:
		tmp = t_0 + t_0
	return tmp
function code(x)
	return log(Float64(x + sqrt(Float64(Float64(x * x) + 1.0))))
end
function code(x)
	t_0 = log(sqrt(Float64(x + hypot(1.0, x))))
	tmp = 0.0
	if (x <= -48450.84557538221)
		tmp = Float64(-log(Float64(Float64(Float64(-0.5 / x) - x) - x)));
	elseif (x <= 9.821702311257485e-8)
		tmp = Float64(x + Float64(-0.16666666666666666 * (x ^ 3.0)));
	else
		tmp = Float64(t_0 + 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 = log(sqrt((x + hypot(1.0, x))));
	tmp = 0.0;
	if (x <= -48450.84557538221)
		tmp = -log((((-0.5 / x) - x) - x));
	elseif (x <= 9.821702311257485e-8)
		tmp = x + (-0.16666666666666666 * (x ^ 3.0));
	else
		tmp = t_0 + 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[Log[N[Sqrt[N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -48450.84557538221], (-N[Log[N[(N[(N[(-0.5 / x), $MachinePrecision] - x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), If[LessEqual[x, 9.821702311257485e-8], N[(x + N[(-0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + t$95$0), $MachinePrecision]]]]
\log \left(x + \sqrt{x \cdot x + 1}\right)
\begin{array}{l}
t_0 := \log \left(\sqrt{x + \mathsf{hypot}\left(1, x\right)}\right)\\
\mathbf{if}\;x \leq -48450.84557538221:\\
\;\;\;\;-\log \left(\left(\frac{-0.5}{x} - x\right) - x\right)\\

\mathbf{elif}\;x \leq 9.821702311257485 \cdot 10^{-8}:\\
\;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\

\mathbf{else}:\\
\;\;\;\;t_0 + t_0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original53.4
Target45.7
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 3 regimes
  2. if x < -48450.8455753822127

    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)} \]
      Proof
      (log.f64 (+.f64 x (hypot.f64 1 x))): 0 points increase in error, 0 points decrease in error
      (log.f64 (+.f64 x (Rewrite<= hypot-1-def_binary64 (sqrt.f64 (+.f64 1 (*.f64 x x)))))): 32 points increase in error, 0 points decrease in error
      (log.f64 (+.f64 x (sqrt.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x x) 1))))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr63.1

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

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

      \[\leadsto -\log \left(\color{blue}{\left(-1 \cdot x - 0.5 \cdot \frac{1}{x}\right)} - x\right) \]
    6. Simplified0.1

      \[\leadsto -\log \left(\color{blue}{\left(\frac{-0.5}{x} - x\right)} - x\right) \]
      Proof
      (-.f64 (/.f64 -1/2 x) x): 0 points increase in error, 0 points decrease in error
      (-.f64 (/.f64 (Rewrite<= metadata-eval (neg.f64 1/2)) x) x): 0 points increase in error, 0 points decrease in error
      (-.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 1/2 x))) x): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 1/2 1)) x)) x): 0 points increase in error, 0 points decrease in error
      (-.f64 (neg.f64 (Rewrite<= associate-*r/_binary64 (*.f64 1/2 (/.f64 1 x)))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (*.f64 1/2 (/.f64 1 x))) (neg.f64 x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (*.f64 1/2 (/.f64 1 x))) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 -1 x) (neg.f64 (*.f64 1/2 (/.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= sub-neg_binary64 (-.f64 (*.f64 -1 x) (*.f64 1/2 (/.f64 1 x)))): 0 points increase in error, 0 points decrease in error

    if -48450.8455753822127 < x < 9.821702311257485e-8

    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
      (log.f64 (+.f64 x (hypot.f64 1 x))): 0 points increase in error, 0 points decrease in error
      (log.f64 (+.f64 x (Rewrite<= hypot-1-def_binary64 (sqrt.f64 (+.f64 1 (*.f64 x x)))))): 32 points increase in error, 0 points decrease in error
      (log.f64 (+.f64 x (sqrt.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x x) 1))))): 0 points increase in error, 0 points decrease in error
    3. Taylor expanded in x around 0 0.7

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot {x}^{3} + x} \]

    if 9.821702311257485e-8 < x

    1. Initial program 32.6

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

      \[\leadsto \color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)} \]
      Proof
      (log.f64 (+.f64 x (hypot.f64 1 x))): 0 points increase in error, 0 points decrease in error
      (log.f64 (+.f64 x (Rewrite<= hypot-1-def_binary64 (sqrt.f64 (+.f64 1 (*.f64 x x)))))): 32 points increase in error, 0 points decrease in error
      (log.f64 (+.f64 x (sqrt.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x x) 1))))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr0.2

      \[\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.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;-\log \left(\left(\frac{-0.5}{x} - x\right) - x\right)\\ \mathbf{elif}\;x \leq 9.821702311257485 \cdot 10^{-8}:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \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} \]

Alternatives

Alternative 1
Error0.4
Cost13576
\[\begin{array}{l} \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;-\log \left(\left(\frac{-0.5}{x} - x\right) - x\right)\\ \mathbf{elif}\;x \leq 9.821702311257485 \cdot 10^{-8}:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right) + -1\right)\\ \end{array} \]
Alternative 2
Error0.4
Cost13320
\[\begin{array}{l} \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;-\log \left(\left(\frac{-0.5}{x} - x\right) - x\right)\\ \mathbf{elif}\;x \leq 9.821702311257485 \cdot 10^{-8}:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\ \end{array} \]
Alternative 3
Error0.5
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.028846596609468356:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \left(x + \frac{0.5}{x}\right)\right)\\ \end{array} \]
Alternative 4
Error0.5
Cost7112
\[\begin{array}{l} \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;-\log \left(\left(\frac{-0.5}{x} - x\right) - x\right)\\ \mathbf{elif}\;x \leq 0.028846596609468356:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x + \left(x + \frac{0.5}{x}\right)\right)\\ \end{array} \]
Alternative 5
Error0.6
Cost7048
\[\begin{array}{l} \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.028846596609468356:\\ \;\;\;\;x + -0.16666666666666666 \cdot {x}^{3}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x \cdot 2\right)\\ \end{array} \]
Alternative 6
Error0.7
Cost6856
\[\begin{array}{l} \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{elif}\;x \leq 0.028846596609468356:\\ \;\;\;\;\left(x \cdot \left(x + -2\right)\right) \cdot \frac{1}{x + -2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(x \cdot 2\right)\\ \end{array} \]
Alternative 7
Error15.6
Cost6724
\[\begin{array}{l} \mathbf{if}\;x \leq -48450.84557538221:\\ \;\;\;\;\log \left(\frac{-0.5}{x}\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error30.4
Cost64
\[x \]

Error

Reproduce

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