Average Error: 45.7 → 0.3
Time: 4.4s
Precision: binary64
Cost: 19784
\[\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 0.00085:\\ \;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, 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
 (if (<= x -1.25)
   (copysign (log (/ -0.5 x)) x)
   (if (<= x 0.00085)
     (copysign (+ x (* -0.16666666666666666 (pow x 3.0))) 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 tmp;
	if (x <= -1.25) {
		tmp = copysign(log((-0.5 / x)), x);
	} else if (x <= 0.00085) {
		tmp = copysign((x + (-0.16666666666666666 * pow(x, 3.0))), 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 tmp;
	if (x <= -1.25) {
		tmp = Math.copySign(Math.log((-0.5 / x)), x);
	} else if (x <= 0.00085) {
		tmp = Math.copySign((x + (-0.16666666666666666 * Math.pow(x, 3.0))), 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):
	tmp = 0
	if x <= -1.25:
		tmp = math.copysign(math.log((-0.5 / x)), x)
	elif x <= 0.00085:
		tmp = math.copysign((x + (-0.16666666666666666 * math.pow(x, 3.0))), 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)
	tmp = 0.0
	if (x <= -1.25)
		tmp = copysign(log(Float64(-0.5 / x)), x);
	elseif (x <= 0.00085)
		tmp = copysign(Float64(x + Float64(-0.16666666666666666 * (x ^ 3.0))), 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)
	tmp = 0.0;
	if (x <= -1.25)
		tmp = sign(x) * abs(log((-0.5 / x)));
	elseif (x <= 0.00085)
		tmp = sign(x) * abs((x + (-0.16666666666666666 * (x ^ 3.0))));
	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_] := If[LessEqual[x, -1.25], 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, 0.00085], N[With[{TMP1 = Abs[N[(x + N[(-0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], 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}
\mathbf{if}\;x \leq -1.25:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\

\mathbf{elif}\;x \leq 0.00085:\\
\;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\

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


\end{array}

Error

Target

Original45.7
Target0.0
Herbie0.3
\[\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 < -1.25

    1. Initial program 32.6

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

      \[\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): 69 points increase in error, 0 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-rr62.8

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(\left(x + \mathsf{hypot}\left(1, x\right)\right) - 1\right)}, x\right) \]
    4. Simplified61.0

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) - 1\right)\right)}, x\right) \]
      Proof
      (log1p.f64 (+.f64 x (-.f64 (hypot.f64 1 x) 1))): 0 points increase in error, 0 points decrease in error
      (log1p.f64 (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 x (hypot.f64 1 x)) 1))): 194 points increase in error, 2 points decrease in error
    5. Taylor expanded in x around -inf 62.4

      \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{-\left(1 + 0.5 \cdot \frac{1}{x}\right)}\right), x\right) \]
    6. Simplified62.4

      \[\leadsto \mathsf{copysign}\left(\mathsf{log1p}\left(\color{blue}{-1 + \frac{-0.5}{x}}\right), x\right) \]
      Proof
      (+.f64 -1 (/.f64 -1/2 x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= metadata-eval (neg.f64 1)) (/.f64 -1/2 x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 1) (/.f64 (Rewrite<= metadata-eval (neg.f64 1/2)) x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 1) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 1/2 x)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 1) (neg.f64 (/.f64 (Rewrite<= metadata-eval (*.f64 1/2 1)) x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 1) (neg.f64 (Rewrite<= associate-*r/_binary64 (*.f64 1/2 (/.f64 1 x))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 1 (*.f64 1/2 (/.f64 1 x))))): 0 points increase in error, 0 points decrease in error
    7. Taylor expanded in x around 0 64.0

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

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(\frac{-0.5}{x}\right)}, x\right) \]
      Proof
      (log.f64 (/.f64 -1/2 x)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> log-div_binary64 (-.f64 (log.f64 -1/2) (log.f64 x))): 132 points increase in error, 0 points decrease in error
      (Rewrite<= unsub-neg_binary64 (+.f64 (log.f64 -1/2) (neg.f64 (log.f64 x)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (log.f64 -1/2) (Rewrite<= mul-1-neg_binary64 (*.f64 -1 (log.f64 x)))): 0 points increase in error, 0 points decrease in error

    if -1.25 < x < 8.49999999999999953e-4

    1. Initial program 58.9

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

      \[\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): 69 points increase in error, 0 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-rr58.9

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(\left(x + \mathsf{hypot}\left(1, x\right)\right) - 1\right)}, x\right) \]
    4. Simplified0.6

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) - 1\right)\right)}, x\right) \]
      Proof
      (log1p.f64 (+.f64 x (-.f64 (hypot.f64 1 x) 1))): 0 points increase in error, 0 points decrease in error
      (log1p.f64 (Rewrite<= associate--l+_binary64 (-.f64 (+.f64 x (hypot.f64 1 x)) 1))): 194 points increase in error, 2 points decrease in error
    5. Taylor expanded in x around 0 0.2

      \[\leadsto \mathsf{copysign}\left(\color{blue}{-0.16666666666666666 \cdot {x}^{3} + x}, x\right) \]

    if 8.49999999999999953e-4 < x

    1. Initial program 31.7

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

      \[\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): 69 points increase in error, 0 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.0

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

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\log \left(x + \mathsf{hypot}\left(1, x\right)\right)}, x\right) \]
      Proof
      (log.f64 (+.f64 x (hypot.f64 1 x))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-lft-identity_binary64 (+.f64 0 (log.f64 (+.f64 x (hypot.f64 1 x))))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 0.00085:\\ \;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, 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.5
Cost45828
\[\begin{array}{l} \mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -20:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \left(\mathsf{hypot}\left(1, x\right) + -1\right)\right), x\right)\\ \end{array} \]
Alternative 2
Error0.3
Cost13960
\[\begin{array}{l} \mathbf{if}\;x \leq -1.32:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 1.28:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \frac{x \cdot x}{2 + \left(x \cdot x\right) \cdot 0.5}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \left(\frac{0.5}{x} + \left(x + -1\right)\right)\right), x\right)\\ \end{array} \]
Alternative 3
Error0.3
Cost13704
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 0.96:\\ \;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + \left(\frac{0.5}{x} + \left(x + -1\right)\right)\right), x\right)\\ \end{array} \]
Alternative 4
Error0.4
Cost13512
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 1.28:\\ \;\;\;\;\mathsf{copysign}\left(x + -0.16666666666666666 \cdot {x}^{3}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(-1 + x \cdot 2\right), x\right)\\ \end{array} \]
Alternative 5
Error0.6
Cost13448
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 1.25:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(-1 + x \cdot 2\right), x\right)\\ \end{array} \]
Alternative 6
Error0.7
Cost13320
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 1.25:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x + x\right), x\right)\\ \end{array} \]
Alternative 7
Error11.6
Cost13188
\[\begin{array}{l} \mathbf{if}\;x \leq -0.7:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \]
Alternative 8
Error25.1
Cost13060
\[\begin{array}{l} \mathbf{if}\;x \leq -0.64:\\ \;\;\;\;\mathsf{copysign}\left(\frac{-x}{x}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)\\ \end{array} \]
Alternative 9
Error27.4
Cost6984
\[\begin{array}{l} t_0 := \mathsf{copysign}\left(\frac{-x}{x}, x\right)\\ \mathbf{if}\;x \leq -6:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(x, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error30.2
Cost6528
\[\mathsf{copysign}\left(x, x\right) \]

Error

Reproduce

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