Average Error: 45.2 → 0.5
Time: 2.8s
Precision: binary64
Cost: 71880
\[\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 -10:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{elif}\;t_0 \leq 4 \cdot 10^{-12}:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, 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 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x)))
   (if (<= t_0 -10.0)
     (copysign (log (+ (fabs x) (hypot 1.0 x))) x)
     (if (<= t_0 4e-12)
       (copysign x x)
       (copysign (log (+ x (hypot 1.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 = copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
	double tmp;
	if (t_0 <= -10.0) {
		tmp = copysign(log((fabs(x) + hypot(1.0, x))), x);
	} else if (t_0 <= 4e-12) {
		tmp = copysign(x, x);
	} else {
		tmp = copysign(log((x + hypot(1.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 = Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
	double tmp;
	if (t_0 <= -10.0) {
		tmp = Math.copySign(Math.log((Math.abs(x) + Math.hypot(1.0, x))), x);
	} else if (t_0 <= 4e-12) {
		tmp = Math.copySign(x, x);
	} else {
		tmp = Math.copySign(Math.log((x + Math.hypot(1.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 = math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x)
	tmp = 0
	if t_0 <= -10.0:
		tmp = math.copysign(math.log((math.fabs(x) + math.hypot(1.0, x))), x)
	elif t_0 <= 4e-12:
		tmp = math.copysign(x, x)
	else:
		tmp = math.copysign(math.log((x + math.hypot(1.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 = copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x)
	tmp = 0.0
	if (t_0 <= -10.0)
		tmp = copysign(log(Float64(abs(x) + hypot(1.0, x))), x);
	elseif (t_0 <= 4e-12)
		tmp = copysign(x, x);
	else
		tmp = copysign(log(Float64(x + hypot(1.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 = sign(x) * abs(log((abs(x) + sqrt(((x * x) + 1.0)))));
	tmp = 0.0;
	if (t_0 <= -10.0)
		tmp = sign(x) * abs(log((abs(x) + hypot(1.0, x))));
	elseif (t_0 <= 4e-12)
		tmp = sign(x) * abs(x);
	else
		tmp = sign(x) * abs(log((x + hypot(1.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[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, -10.0], N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], If[LessEqual[t$95$0, 4e-12], N[With[{TMP1 = Abs[x], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], N[With[{TMP1 = Abs[N[Log[N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $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 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\
\mathbf{if}\;t_0 \leq -10:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\

\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{copysign}\left(x, x\right)\\

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


\end{array}

Error

Target

Original45.2
Target0.0
Herbie0.5
\[\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 31.6

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

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

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

    1. Initial program 59.2

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

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

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

      \[\leadsto \mathsf{copysign}\left(\log \color{blue}{\left(\frac{1}{\mathsf{hypot}\left(1, x\right) - x}\right)}, x\right) \]
      Proof
      (copysign.f64 (log.f64 (/.f64 1 (-.f64 (hypot.f64 1 x) x))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite=> sub-neg_binary64 (+.f64 (hypot.f64 1 x) (neg.f64 x))))) x): 12 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (+.f64 (hypot.f64 1 x) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 x))))) x): 0 points increase in error, 16 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite=> +-commutative_binary64 (+.f64 (*.f64 -1 x) (hypot.f64 1 x))))) x): 4 points increase in error, 12 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (+.f64 (Rewrite=> mul-1-neg_binary64 (neg.f64 x)) (hypot.f64 1 x)))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 x)) (hypot.f64 1 x)))) x): 12 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 x (hypot.f64 1 x)))))) x): 0 points increase in error, 16 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 x (hypot.f64 1 x)))))) x): 16 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 x (hypot.f64 1 x)))))) x): 0 points increase in error, 16 points decrease in error
      (copysign.f64 (log.f64 (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 1 -1) (-.f64 x (hypot.f64 1 x))))) x): 16 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (Rewrite=> metadata-eval -1) (-.f64 x (hypot.f64 1 x)))) x): 0 points increase in error, 16 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (Rewrite<= metadata-eval (-.f64 0 1)) (-.f64 x (hypot.f64 1 x)))) x): 4 points increase in error, 12 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (-.f64 (Rewrite<= +-inverses_binary64 (-.f64 (*.f64 x x) (*.f64 x x))) 1) (-.f64 x (hypot.f64 1 x)))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (Rewrite<= associate--r+_binary64 (-.f64 (*.f64 x x) (+.f64 (*.f64 x x) 1))) (-.f64 x (hypot.f64 1 x)))) x): 12 points increase in error, 4 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (-.f64 (*.f64 x x) (Rewrite<= +-commutative_binary64 (+.f64 1 (*.f64 x x)))) (-.f64 x (hypot.f64 1 x)))) x): 3 points increase in error, 13 points decrease in error
      (copysign.f64 (log.f64 (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (*.f64 x x) (-.f64 x (hypot.f64 1 x))) (/.f64 (+.f64 1 (*.f64 x x)) (-.f64 x (hypot.f64 1 x)))))) x): 13 points increase in error, 3 points decrease in error
    5. Taylor expanded in x around 0 0.6

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

    if 3.99999999999999992e-12 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x)

    1. Initial program 31.6

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

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

      \[\leadsto \mathsf{copysign}\left(\color{blue}{0 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
    4. Simplified0.7

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
      Proof
      (copysign.f64 (log.f64 (/.f64 1 (-.f64 (hypot.f64 1 x) x))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite=> sub-neg_binary64 (+.f64 (hypot.f64 1 x) (neg.f64 x))))) x): 12 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (+.f64 (hypot.f64 1 x) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 x))))) x): 0 points increase in error, 16 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite=> +-commutative_binary64 (+.f64 (*.f64 -1 x) (hypot.f64 1 x))))) x): 4 points increase in error, 12 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (+.f64 (Rewrite=> mul-1-neg_binary64 (neg.f64 x)) (hypot.f64 1 x)))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 x)) (hypot.f64 1 x)))) x): 12 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 x (hypot.f64 1 x)))))) x): 0 points increase in error, 16 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 x (hypot.f64 1 x)))))) x): 16 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 1 (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 x (hypot.f64 1 x)))))) x): 0 points increase in error, 16 points decrease in error
      (copysign.f64 (log.f64 (Rewrite=> associate-/r*_binary64 (/.f64 (/.f64 1 -1) (-.f64 x (hypot.f64 1 x))))) x): 16 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (Rewrite=> metadata-eval -1) (-.f64 x (hypot.f64 1 x)))) x): 0 points increase in error, 16 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (Rewrite<= metadata-eval (-.f64 0 1)) (-.f64 x (hypot.f64 1 x)))) x): 4 points increase in error, 12 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (-.f64 (Rewrite<= +-inverses_binary64 (-.f64 (*.f64 x x) (*.f64 x x))) 1) (-.f64 x (hypot.f64 1 x)))) x): 0 points increase in error, 0 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (Rewrite<= associate--r+_binary64 (-.f64 (*.f64 x x) (+.f64 (*.f64 x x) 1))) (-.f64 x (hypot.f64 1 x)))) x): 12 points increase in error, 4 points decrease in error
      (copysign.f64 (log.f64 (/.f64 (-.f64 (*.f64 x x) (Rewrite<= +-commutative_binary64 (+.f64 1 (*.f64 x x)))) (-.f64 x (hypot.f64 1 x)))) x): 3 points increase in error, 13 points decrease in error
      (copysign.f64 (log.f64 (Rewrite=> div-sub_binary64 (-.f64 (/.f64 (*.f64 x x) (-.f64 x (hypot.f64 1 x))) (/.f64 (+.f64 1 (*.f64 x x)) (-.f64 x (hypot.f64 1 x)))))) x): 13 points increase in error, 3 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

    \[\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|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{elif}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq 4 \cdot 10^{-12}:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.3
Cost19784
\[\begin{array}{l} \mathbf{if}\;x \leq -0.8:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 + \frac{-0.5}{x}}\right), x\right)\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error0.5
Cost13576
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot -2\right), x\right)\\ \mathbf{elif}\;x \leq 0.8:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error0.5
Cost13576
\[\begin{array}{l} \mathbf{if}\;x \leq -0.8:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{1}{x \cdot -2 + \frac{-0.5}{x}}\right), x\right)\\ \mathbf{elif}\;x \leq 0.8:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(x + x\right)\right), x\right)\\ \end{array} \]
Alternative 4
Error0.6
Cost13320
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot -2\right), x\right)\\ \mathbf{elif}\;x \leq 1.26:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x + x\right), x\right)\\ \end{array} \]
Alternative 5
Error12.0
Cost13188
\[\begin{array}{l} \mathbf{if}\;x \leq -0.7:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(x \cdot -2\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \]
Alternative 6
Error22.6
Cost13124
\[\begin{array}{l} \mathbf{if}\;x \leq -0.5:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(-x\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \]
Alternative 7
Error26.4
Cost13060
\[\begin{array}{l} \mathbf{if}\;x \leq 1.6:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \]
Alternative 8
Error30.6
Cost6528
\[\mathsf{copysign}\left(x, x\right) \]

Error

Reproduce

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