?

Average Error: 45.3 → 0.2
Time: 1.0min
Precision: binary64
Cost: 105352

?

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

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{copysign}\left(\left(-0.041666666666666664 \cdot \left({x}^{4} \cdot \frac{\frac{3}{t_0} + 3}{t_0}\right) + \frac{0.5 \cdot {x}^{2}}{t_0}\right) + \mathsf{log1p}\left(\left|x\right|\right), x\right)\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error?

Target

Original45.3
Target0.1
Herbie0.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 2 regimes
  2. if (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < -2 or 2.00000000000000016e-5 < (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. Simplified0.1

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

    if -2 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) 1)))) x) < 2.00000000000000016e-5

    1. Initial program 58.8

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

      \[\leadsto \color{blue}{\mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)} \]
      Proof
    3. Taylor expanded in x around 0 58.3

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

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\mathsf{fma}\left(-0.041666666666666664, {x}^{4} \cdot \left(\frac{3}{\left|x\right| - -1} + \frac{3}{{\left(\left|x\right| - -1\right)}^{2}}\right), \mathsf{fma}\left(0.5, \frac{x \cdot x}{\left|x\right| - -1}, \mathsf{log1p}\left(\left|x\right|\right)\right)\right)}, x\right) \]
      Proof
    5. Applied egg-rr0.2

      \[\leadsto \mathsf{copysign}\left(\color{blue}{\left(-0.041666666666666664 \cdot \left({x}^{4} \cdot \frac{\frac{3}{\left|x\right| - -1} + 3}{\left|x\right| - -1}\right) + \frac{0.5 \cdot {x}^{2}}{\left|x\right| - -1}\right) + \mathsf{log1p}\left(\left|x\right|\right)}, x\right) \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error0.1
Cost78728
\[\begin{array}{l} t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{if}\;t_0 \leq -0.0002:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{-5}:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right) - \frac{x \cdot x}{\frac{\left|x\right| - -1}{-0.5}}, x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.6
Cost78280
\[\begin{array}{l} t_0 := \mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)\\ t_1 := \mathsf{copysign}\left(\log \left(\left|x\right| + \mathsf{hypot}\left(1, x\right)\right), x\right)\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{-8}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error1.0
Cost19976
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| - x\right), x\right)\\ \mathbf{elif}\;x \leq 0.65:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
Alternative 4
Error0.9
Cost19976
\[\begin{array}{l} \mathbf{if}\;x \leq -0.65:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left(\left|x\right| - x\right) - \frac{0.5}{x}\right), x\right)\\ \mathbf{elif}\;x \leq 0.65:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\frac{0.5}{x} + \left(\left|x\right| + x\right)\right), x\right)\\ \end{array} \]
Alternative 5
Error1.0
Cost19720
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| - x\right), x\right)\\ \mathbf{elif}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + x\right), x\right)\\ \end{array} \]
Alternative 6
Error12.2
Cost19588
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{copysign}\left(\log \left(\left|x\right| + x\right), x\right)\\ \end{array} \]
Alternative 7
Error22.5
Cost19328
\[\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right) \]
Alternative 8
Error52.3
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 9
Error58.3
Cost12928
\[\mathsf{copysign}\left(\log x, x\right) \]

Error

Reproduce?

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