?

Average Error: 45.2 → 29.2
Time: 2.4s
Precision: binary64
Cost: 26376

?

\[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+154}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 5000000:\\ \;\;\;\;\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} \]
(FPCore (x)
 :precision binary64
 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
(FPCore (x)
 :precision binary64
 (if (<= x -4e+154)
   (copysign (log (/ -0.5 x)) x)
   (if (<= x 5000000.0)
     (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)
     (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 tmp;
	if (x <= -4e+154) {
		tmp = copysign(log((-0.5 / x)), x);
	} else if (x <= 5000000.0) {
		tmp = copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
	} 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 tmp;
	if (x <= -4e+154) {
		tmp = Math.copySign(Math.log((-0.5 / x)), x);
	} else if (x <= 5000000.0) {
		tmp = Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
	} 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):
	tmp = 0
	if x <= -4e+154:
		tmp = math.copysign(math.log((-0.5 / x)), x)
	elif x <= 5000000.0:
		tmp = math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x)
	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)
	tmp = 0.0
	if (x <= -4e+154)
		tmp = copysign(log(Float64(-0.5 / x)), x);
	elseif (x <= 5000000.0)
		tmp = copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x);
	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)
	tmp = 0.0;
	if (x <= -4e+154)
		tmp = sign(x) * abs(log((-0.5 / x)));
	elseif (x <= 5000000.0)
		tmp = sign(x) * abs(log((abs(x) + sqrt(((x * x) + 1.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_] := If[LessEqual[x, -4e+154], N[With[{TMP1 = Abs[N[Log[N[(-0.5 / x), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], If[LessEqual[x, 5000000.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], 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}
\mathbf{if}\;x \leq -4 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\

\mathbf{elif}\;x \leq 5000000:\\
\;\;\;\;\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}

Error?

Target

Original45.2
Target0.1
Herbie29.2
\[\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 x < -4.00000000000000015e154

    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(\left|x\right| + -1 \cdot x\right) - 0.5 \cdot \frac{1}{x}\right)}, x\right) \]
    3. Simplified0.1

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

      [Start]0.1

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

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

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

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

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

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

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

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

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

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

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

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

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

      rational.json-simplify-41 [<=]0.1

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

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

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

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

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

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

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

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

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

      metadata-eval [=>]0.1

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

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

    if -4.00000000000000015e154 < x < 5e6

    1. Initial program 46.3

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

    if 5e6 < x

    1. Initial program 33.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.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -4 \cdot 10^{+154}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 5000000:\\ \;\;\;\;\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.3
Cost19972
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error30.3
Cost19972
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-308}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\frac{1}{x} \cdot -0.5 - x\right) + \left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(0.5 \cdot \frac{1}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error41.4
Cost13188
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log x, x\right)\\ \end{array} \]
Alternative 4
Error30.4
Cost13188
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x}\right), x\right)\\ \end{array} \]
Alternative 5
Error52.2
Cost13124
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{-309}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log x, x\right)\\ \end{array} \]
Alternative 6
Error58.1
Cost12928
\[\mathsf{copysign}\left(\log x, x\right) \]

Error

Reproduce?

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