?

Average Error: 45.4 → 29.8
Time: 6.2s
Precision: binary64
Cost: 85576

?

\[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{1}{x}\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_2 := 1 + \left|x\right|\\ \mathbf{if}\;t_1 \leq -10:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| - t_0\right) - x\right), x\right)\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\mathsf{copysign}\left(0.5 \cdot \frac{{x}^{2}}{t_2} + \left(\left(0 - \left(-1 - \log t_2\right)\right) - 1\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(t_0 + x\right)\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 (* 0.5 (/ 1.0 x)))
        (t_1 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
        (t_2 (+ 1.0 (fabs x))))
   (if (<= t_1 -10.0)
     (copysign (log (- (- (fabs x) t_0) x)) x)
     (if (<= t_1 0.0)
       (copysign
        (+ (* 0.5 (/ (pow x 2.0) t_2)) (- (- 0.0 (- -1.0 (log t_2))) 1.0))
        x)
       (copysign (log (+ (fabs x) (+ t_0 x))) x)))))
double code(double x) {
	return copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
}
double code(double x) {
	double t_0 = 0.5 * (1.0 / x);
	double t_1 = copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
	double t_2 = 1.0 + fabs(x);
	double tmp;
	if (t_1 <= -10.0) {
		tmp = copysign(log(((fabs(x) - t_0) - x)), x);
	} else if (t_1 <= 0.0) {
		tmp = copysign(((0.5 * (pow(x, 2.0) / t_2)) + ((0.0 - (-1.0 - log(t_2))) - 1.0)), x);
	} else {
		tmp = copysign(log((fabs(x) + (t_0 + 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 = 0.5 * (1.0 / x);
	double t_1 = Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
	double t_2 = 1.0 + Math.abs(x);
	double tmp;
	if (t_1 <= -10.0) {
		tmp = Math.copySign(Math.log(((Math.abs(x) - t_0) - x)), x);
	} else if (t_1 <= 0.0) {
		tmp = Math.copySign(((0.5 * (Math.pow(x, 2.0) / t_2)) + ((0.0 - (-1.0 - Math.log(t_2))) - 1.0)), x);
	} else {
		tmp = Math.copySign(Math.log((Math.abs(x) + (t_0 + 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 = 0.5 * (1.0 / x)
	t_1 = math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x)
	t_2 = 1.0 + math.fabs(x)
	tmp = 0
	if t_1 <= -10.0:
		tmp = math.copysign(math.log(((math.fabs(x) - t_0) - x)), x)
	elif t_1 <= 0.0:
		tmp = math.copysign(((0.5 * (math.pow(x, 2.0) / t_2)) + ((0.0 - (-1.0 - math.log(t_2))) - 1.0)), x)
	else:
		tmp = math.copysign(math.log((math.fabs(x) + (t_0 + 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 = Float64(0.5 * Float64(1.0 / x))
	t_1 = copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x)
	t_2 = Float64(1.0 + abs(x))
	tmp = 0.0
	if (t_1 <= -10.0)
		tmp = copysign(log(Float64(Float64(abs(x) - t_0) - x)), x);
	elseif (t_1 <= 0.0)
		tmp = copysign(Float64(Float64(0.5 * Float64((x ^ 2.0) / t_2)) + Float64(Float64(0.0 - Float64(-1.0 - log(t_2))) - 1.0)), x);
	else
		tmp = copysign(log(Float64(abs(x) + Float64(t_0 + 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 = 0.5 * (1.0 / x);
	t_1 = sign(x) * abs(log((abs(x) + sqrt(((x * x) + 1.0)))));
	t_2 = 1.0 + abs(x);
	tmp = 0.0;
	if (t_1 <= -10.0)
		tmp = sign(x) * abs(log(((abs(x) - t_0) - x)));
	elseif (t_1 <= 0.0)
		tmp = sign(x) * abs(((0.5 * ((x ^ 2.0) / t_2)) + ((0.0 - (-1.0 - log(t_2))) - 1.0)));
	else
		tmp = sign(x) * abs(log((abs(x) + (t_0 + 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[(0.5 * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = 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]}, Block[{t$95$2 = N[(1.0 + N[Abs[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -10.0], N[With[{TMP1 = Abs[N[Log[N[(N[(N[Abs[x], $MachinePrecision] - t$95$0), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[With[{TMP1 = Abs[N[(N[(0.5 * N[(N[Power[x, 2.0], $MachinePrecision] / t$95$2), $MachinePrecision]), $MachinePrecision] + N[(N[(0.0 - N[(-1.0 - N[Log[t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[(t$95$0 + x), $MachinePrecision]), $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 := 0.5 \cdot \frac{1}{x}\\
t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\
t_2 := 1 + \left|x\right|\\
\mathbf{if}\;t_1 \leq -10:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| - t_0\right) - x\right), x\right)\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;\mathsf{copysign}\left(0.5 \cdot \frac{{x}^{2}}{t_2} + \left(\left(0 - \left(-1 - \log t_2\right)\right) - 1\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(t_0 + x\right)\right), x\right)\\


\end{array}

Error?

Target

Original45.4
Target0.0
Herbie29.8
\[\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) < -10

    1. Initial program 32.2

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

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

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

      [Start]0.0

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

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

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

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

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

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

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

    1. Initial program 59.2

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

      \[\leadsto \mathsf{copysign}\left(\color{blue}{0.5 \cdot \frac{{x}^{2}}{1 + \left|x\right|} + \log \left(1 + \left|x\right|\right)}, x\right) \]
    3. Applied egg-rr59.0

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

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

    1. Initial program 31.9

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

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

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

Alternatives

Alternative 1
Error29.8
Cost85192
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{1}{x}\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_2 := 1 + \left|x\right|\\ \mathbf{if}\;t_1 \leq -10:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| - t_0\right) - x\right), x\right)\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\mathsf{copysign}\left(0.5 \cdot \frac{{x}^{2}}{t_2} + \log t_2, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(t_0 + x\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error30.2
Cost72200
\[\begin{array}{l} t_0 := 0.5 \cdot \frac{1}{x}\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ \mathbf{if}\;t_1 \leq -10:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| - t_0\right) - x\right), x\right)\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;\mathsf{copysign}\left(0.5 \cdot \frac{{x}^{2}}{\left|x\right| - -1}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \left(t_0 + x\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error30.6
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(\left|x\right| + \left(0.5 \cdot \frac{1}{x} + x\right)\right), x\right)\\ \end{array} \]
Alternative 4
Error41.3
Cost13188
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \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 5
Error30.7
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 6
Error52.3
Cost13124
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-311}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log x, x\right)\\ \end{array} \]
Alternative 7
Error58.2
Cost12928
\[\mathsf{copysign}\left(\log x, x\right) \]

Error

Reproduce?

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