?

Average Error: 45.0 → 29.1
Time: 8.0s
Precision: binary64
Cost: 78472

?

\[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
\[\begin{array}{l} t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(-x\right) + \left|x\right|\right), x\right)\\ \mathbf{elif}\;t_0 \leq 10:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\ \end{array} \]
(FPCore (x)
 :precision binary64
 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)))
   (if (<= t_0 (- INFINITY))
     (copysign (log (+ (- x) (fabs x))) x)
     (if (<= t_0 10.0) t_0 (copysign (log (/ 0.5 x)) x)))))
double code(double x) {
	return copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
}
double code(double x) {
	double t_0 = copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = copysign(log((-x + fabs(x))), x);
	} else if (t_0 <= 10.0) {
		tmp = t_0;
	} else {
		tmp = copysign(log((0.5 / x)), x);
	}
	return tmp;
}
public static double code(double x) {
	return Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
}
public static double code(double x) {
	double t_0 = Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
	double tmp;
	if (t_0 <= -Double.POSITIVE_INFINITY) {
		tmp = Math.copySign(Math.log((-x + Math.abs(x))), x);
	} else if (t_0 <= 10.0) {
		tmp = t_0;
	} else {
		tmp = Math.copySign(Math.log((0.5 / x)), x);
	}
	return tmp;
}
def code(x):
	return math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x)
def code(x):
	t_0 = math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x)
	tmp = 0
	if t_0 <= -math.inf:
		tmp = math.copysign(math.log((-x + math.fabs(x))), x)
	elif t_0 <= 10.0:
		tmp = t_0
	else:
		tmp = math.copysign(math.log((0.5 / x)), x)
	return tmp
function code(x)
	return copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x)
end
function code(x)
	t_0 = copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x)
	tmp = 0.0
	if (t_0 <= Float64(-Inf))
		tmp = copysign(log(Float64(Float64(-x) + abs(x))), x);
	elseif (t_0 <= 10.0)
		tmp = t_0;
	else
		tmp = copysign(log(Float64(0.5 / x)), x);
	end
	return tmp
end
function tmp = code(x)
	tmp = sign(x) * abs(log((abs(x) + sqrt(((x * x) + 1.0)))));
end
function tmp_2 = code(x)
	t_0 = sign(x) * abs(log((abs(x) + sqrt(((x * x) + 1.0)))));
	tmp = 0.0;
	if (t_0 <= -Inf)
		tmp = sign(x) * abs(log((-x + abs(x))));
	elseif (t_0 <= 10.0)
		tmp = t_0;
	else
		tmp = sign(x) * abs(log((0.5 / x)));
	end
	tmp_2 = tmp;
end
code[x_] := N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x_] := Block[{t$95$0 = N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[With[{TMP1 = Abs[N[Log[N[((-x) + N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], If[LessEqual[t$95$0, 10.0], t$95$0, N[With[{TMP1 = Abs[N[Log[N[(0.5 / x), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]]]]
\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\begin{array}{l}
t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left(-x\right) + \left|x\right|\right), x\right)\\

\mathbf{elif}\;t_0 \leq 10:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\


\end{array}

Error?

Target

Original45.0
Target0.0
Herbie29.1
\[\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right| + \frac{\left|x\right|}{\mathsf{hypot}\left(1, \frac{1}{\left|x\right|}\right) + \frac{1}{\left|x\right|}}\right), x\right) \]

Derivation?

  1. Split input into 3 regimes
  2. if (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < -inf.0

    1. Initial program 64.0

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Taylor expanded in x around -inf 0.1

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left|x\right| + -1 \cdot x\right)}, x\right) \]
    3. Simplified0.1

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\left(-x\right) + \left|x\right|\right)}, x\right) \]
      Proof

      [Start]0.1

      \[ \mathsf{copysign}\left(\log \left(\left|x\right| + -1 \cdot x\right), x\right) \]

      rational.json-simplify-1 [=>]0.1

      \[ \mathsf{copysign}\left(\log \color{blue}{\left(-1 \cdot x + \left|x\right|\right)}, x\right) \]

      rational.json-simplify-2 [=>]0.1

      \[ \mathsf{copysign}\left(\log \left(\color{blue}{x \cdot -1} + \left|x\right|\right), x\right) \]

      rational.json-simplify-9 [=>]0.1

      \[ \mathsf{copysign}\left(\log \left(\color{blue}{\left(-x\right)} + \left|x\right|\right), x\right) \]

    if -inf.0 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < 10

    1. Initial program 46.2

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]

    if 10 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x)

    1. Initial program 32.3

      \[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
    2. Taylor expanded in x around inf 0.1

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right)}, x\right) \]
    3. Taylor expanded in x around 0 0.1

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\frac{0.5}{x}\right)}, x\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification29.1

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

Alternatives

Alternative 1
Error30.2
Cost20036
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left(-x\right) + \left|x\right|\right) - 0.5 \cdot \frac{1}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \left(\frac{0.5}{x} + \left|x\right|\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error30.3
Cost19844
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(-x\right) + \left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \left(\frac{0.5}{x} + \left|x\right|\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error30.4
Cost19652
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(-x\right) + \left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\ \end{array} \]
Alternative 4
Error40.7
Cost19588
\[\begin{array}{l} \mathbf{if}\;x \leq 2 \cdot 10^{-153}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + 1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\ \end{array} \]
Alternative 5
Error41.3
Cost13252
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{copysign}\left(-\log \left(\frac{-1}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\ \end{array} \]
Alternative 6
Error47.3
Cost13056
\[\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right) \]
Alternative 7
Error58.1
Cost12928
\[\mathsf{copysign}\left(\log x, x\right) \]

Error

Reproduce?

herbie shell --seed 2023074 
(FPCore (x)
  :name "Rust f64::asinh"
  :precision binary64

  :herbie-target
  (copysign (log1p (+ (fabs x) (/ (fabs x) (+ (hypot 1.0 (/ 1.0 (fabs x))) (/ 1.0 (fabs x)))))) x)

  (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))