
(FPCore (x) :precision binary64 (let* ((t_0 (exp (- x)))) (/ (- (exp x) t_0) (+ (exp x) t_0))))
double code(double x) {
double t_0 = exp(-x);
return (exp(x) - t_0) / (exp(x) + t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = exp(-x)
code = (exp(x) - t_0) / (exp(x) + t_0)
end function
public static double code(double x) {
double t_0 = Math.exp(-x);
return (Math.exp(x) - t_0) / (Math.exp(x) + t_0);
}
def code(x): t_0 = math.exp(-x) return (math.exp(x) - t_0) / (math.exp(x) + t_0)
function code(x) t_0 = exp(Float64(-x)) return Float64(Float64(exp(x) - t_0) / Float64(exp(x) + t_0)) end
function tmp = code(x) t_0 = exp(-x); tmp = (exp(x) - t_0) / (exp(x) + t_0); end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, N[(N[(N[Exp[x], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\frac{e^{x} - t_0}{e^{x} + t_0}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (let* ((t_0 (exp (- x)))) (/ (- (exp x) t_0) (+ (exp x) t_0))))
double code(double x) {
double t_0 = exp(-x);
return (exp(x) - t_0) / (exp(x) + t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = exp(-x)
code = (exp(x) - t_0) / (exp(x) + t_0)
end function
public static double code(double x) {
double t_0 = Math.exp(-x);
return (Math.exp(x) - t_0) / (Math.exp(x) + t_0);
}
def code(x): t_0 = math.exp(-x) return (math.exp(x) - t_0) / (math.exp(x) + t_0)
function code(x) t_0 = exp(Float64(-x)) return Float64(Float64(exp(x) - t_0) / Float64(exp(x) + t_0)) end
function tmp = code(x) t_0 = exp(-x); tmp = (exp(x) - t_0) / (exp(x) + t_0); end
code[x_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, N[(N[(N[Exp[x], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\frac{e^{x} - t_0}{e^{x} + t_0}
\end{array}
\end{array}
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (exp (- x_m))))
(*
x_s
(if (<= (/ (- (exp x_m) t_0) (+ (exp x_m) t_0)) 2e-6)
(+ x_m (* -0.3333333333333333 (pow x_m 3.0)))
(+
(/ 1.0 (+ 1.0 (/ 1.0 (exp (* x_m 2.0)))))
(/ -1.0 (+ (pow (exp x_m) 2.0) 1.0)))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = exp(-x_m);
double tmp;
if (((exp(x_m) - t_0) / (exp(x_m) + t_0)) <= 2e-6) {
tmp = x_m + (-0.3333333333333333 * pow(x_m, 3.0));
} else {
tmp = (1.0 / (1.0 + (1.0 / exp((x_m * 2.0))))) + (-1.0 / (pow(exp(x_m), 2.0) + 1.0));
}
return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-x_m)
if (((exp(x_m) - t_0) / (exp(x_m) + t_0)) <= 2d-6) then
tmp = x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))
else
tmp = (1.0d0 / (1.0d0 + (1.0d0 / exp((x_m * 2.0d0))))) + ((-1.0d0) / ((exp(x_m) ** 2.0d0) + 1.0d0))
end if
code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double t_0 = Math.exp(-x_m);
double tmp;
if (((Math.exp(x_m) - t_0) / (Math.exp(x_m) + t_0)) <= 2e-6) {
tmp = x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0));
} else {
tmp = (1.0 / (1.0 + (1.0 / Math.exp((x_m * 2.0))))) + (-1.0 / (Math.pow(Math.exp(x_m), 2.0) + 1.0));
}
return x_s * tmp;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): t_0 = math.exp(-x_m) tmp = 0 if ((math.exp(x_m) - t_0) / (math.exp(x_m) + t_0)) <= 2e-6: tmp = x_m + (-0.3333333333333333 * math.pow(x_m, 3.0)) else: tmp = (1.0 / (1.0 + (1.0 / math.exp((x_m * 2.0))))) + (-1.0 / (math.pow(math.exp(x_m), 2.0) + 1.0)) return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) t_0 = exp(Float64(-x_m)) tmp = 0.0 if (Float64(Float64(exp(x_m) - t_0) / Float64(exp(x_m) + t_0)) <= 2e-6) tmp = Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0))); else tmp = Float64(Float64(1.0 / Float64(1.0 + Float64(1.0 / exp(Float64(x_m * 2.0))))) + Float64(-1.0 / Float64((exp(x_m) ^ 2.0) + 1.0))); end return Float64(x_s * tmp) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) t_0 = exp(-x_m); tmp = 0.0; if (((exp(x_m) - t_0) / (exp(x_m) + t_0)) <= 2e-6) tmp = x_m + (-0.3333333333333333 * (x_m ^ 3.0)); else tmp = (1.0 / (1.0 + (1.0 / exp((x_m * 2.0))))) + (-1.0 / ((exp(x_m) ^ 2.0) + 1.0)); end tmp_2 = x_s * tmp; end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[Exp[(-x$95$m)], $MachinePrecision]}, N[(x$95$s * If[LessEqual[N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x$95$m], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision], 2e-6], N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.0 + N[(1.0 / N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(N[Power[N[Exp[x$95$m], $MachinePrecision], 2.0], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := e^{-x_m}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{e^{x_m} - t_0}{e^{x_m} + t_0} \leq 2 \cdot 10^{-6}:\\
\;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{e^{x_m \cdot 2}}} + \frac{-1}{{\left(e^{x_m}\right)}^{2} + 1}\\
\end{array}
\end{array}
\end{array}
if (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 1.99999999999999991e-6Initial program 7.2%
remove-double-neg7.2%
+-commutative7.2%
div-sub7.2%
Simplified5.8%
Taylor expanded in x around 0 99.2%
if 1.99999999999999991e-6 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) Initial program 18.9%
remove-double-neg18.9%
+-commutative18.9%
div-sub19.3%
Simplified86.7%
Taylor expanded in x around inf 99.3%
pow-exp99.3%
Applied egg-rr99.3%
Final simplification99.2%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (/ (- (expm1 (* x_m 2.0)) (expm1 (* x_m -2.0))) (* (- -1.0 (pow (exp x_m) 2.0)) (- -1.0 (pow (exp x_m) -2.0))))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * ((expm1((x_m * 2.0)) - expm1((x_m * -2.0))) / ((-1.0 - pow(exp(x_m), 2.0)) * (-1.0 - pow(exp(x_m), -2.0))));
}
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * ((Math.expm1((x_m * 2.0)) - Math.expm1((x_m * -2.0))) / ((-1.0 - Math.pow(Math.exp(x_m), 2.0)) * (-1.0 - Math.pow(Math.exp(x_m), -2.0))));
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * ((math.expm1((x_m * 2.0)) - math.expm1((x_m * -2.0))) / ((-1.0 - math.pow(math.exp(x_m), 2.0)) * (-1.0 - math.pow(math.exp(x_m), -2.0))))
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(Float64(expm1(Float64(x_m * 2.0)) - expm1(Float64(x_m * -2.0))) / Float64(Float64(-1.0 - (exp(x_m) ^ 2.0)) * Float64(-1.0 - (exp(x_m) ^ -2.0))))) end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * N[(N[(N[(Exp[N[(x$95$m * 2.0), $MachinePrecision]] - 1), $MachinePrecision] - N[(Exp[N[(x$95$m * -2.0), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] / N[(N[(-1.0 - N[Power[N[Exp[x$95$m], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[(-1.0 - N[Power[N[Exp[x$95$m], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \frac{\mathsf{expm1}\left(x_m \cdot 2\right) - \mathsf{expm1}\left(x_m \cdot -2\right)}{\left(-1 - {\left(e^{x_m}\right)}^{2}\right) \cdot \left(-1 - {\left(e^{x_m}\right)}^{-2}\right)}
\end{array}
Initial program 7.5%
remove-double-neg7.5%
+-commutative7.5%
div-sub7.5%
Simplified7.4%
Taylor expanded in x around inf 9.0%
frac-2neg9.0%
metadata-eval9.0%
frac-2neg9.0%
metadata-eval9.0%
frac-sub7.5%
Applied egg-rr7.5%
Simplified98.4%
Final simplification98.4%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (exp (* x_m 2.0))))
(*
x_s
(if (<= x_m 0.00095)
(+ x_m (* -0.3333333333333333 (pow x_m 3.0)))
(+ (/ 1.0 (+ 1.0 (/ 1.0 t_0))) (/ -1.0 (+ 1.0 t_0)))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = exp((x_m * 2.0));
double tmp;
if (x_m <= 0.00095) {
tmp = x_m + (-0.3333333333333333 * pow(x_m, 3.0));
} else {
tmp = (1.0 / (1.0 + (1.0 / t_0))) + (-1.0 / (1.0 + t_0));
}
return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: t_0
real(8) :: tmp
t_0 = exp((x_m * 2.0d0))
if (x_m <= 0.00095d0) then
tmp = x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))
else
tmp = (1.0d0 / (1.0d0 + (1.0d0 / t_0))) + ((-1.0d0) / (1.0d0 + t_0))
end if
code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double t_0 = Math.exp((x_m * 2.0));
double tmp;
if (x_m <= 0.00095) {
tmp = x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0));
} else {
tmp = (1.0 / (1.0 + (1.0 / t_0))) + (-1.0 / (1.0 + t_0));
}
return x_s * tmp;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): t_0 = math.exp((x_m * 2.0)) tmp = 0 if x_m <= 0.00095: tmp = x_m + (-0.3333333333333333 * math.pow(x_m, 3.0)) else: tmp = (1.0 / (1.0 + (1.0 / t_0))) + (-1.0 / (1.0 + t_0)) return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) t_0 = exp(Float64(x_m * 2.0)) tmp = 0.0 if (x_m <= 0.00095) tmp = Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0))); else tmp = Float64(Float64(1.0 / Float64(1.0 + Float64(1.0 / t_0))) + Float64(-1.0 / Float64(1.0 + t_0))); end return Float64(x_s * tmp) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) t_0 = exp((x_m * 2.0)); tmp = 0.0; if (x_m <= 0.00095) tmp = x_m + (-0.3333333333333333 * (x_m ^ 3.0)); else tmp = (1.0 / (1.0 + (1.0 / t_0))) + (-1.0 / (1.0 + t_0)); end tmp_2 = x_s * tmp; end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := Block[{t$95$0 = N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]}, N[(x$95$s * If[LessEqual[x$95$m, 0.00095], N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(1.0 + N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
\begin{array}{l}
t_0 := e^{x_m \cdot 2}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;x_m \leq 0.00095:\\
\;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \frac{1}{t_0}} + \frac{-1}{1 + t_0}\\
\end{array}
\end{array}
\end{array}
if x < 9.49999999999999998e-4Initial program 7.2%
remove-double-neg7.2%
+-commutative7.2%
div-sub7.2%
Simplified6.2%
Taylor expanded in x around 0 98.8%
if 9.49999999999999998e-4 < x Initial program 23.6%
remove-double-neg23.6%
+-commutative23.6%
div-sub24.1%
Simplified83.3%
Taylor expanded in x around inf 99.1%
pow-exp99.1%
Applied egg-rr99.1%
pow-exp99.1%
Applied egg-rr98.6%
Final simplification98.8%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 1.15)
(+
x_m
(+
(* -0.3333333333333333 (pow x_m 3.0))
(* 0.13333333333333333 (pow x_m 5.0))))
(+ 1.0 (/ -1.0 (+ 1.0 (exp (* x_m 2.0))))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.15) {
tmp = x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + (0.13333333333333333 * pow(x_m, 5.0)));
} else {
tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
}
return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.15d0) then
tmp = x_m + (((-0.3333333333333333d0) * (x_m ** 3.0d0)) + (0.13333333333333333d0 * (x_m ** 5.0d0)))
else
tmp = 1.0d0 + ((-1.0d0) / (1.0d0 + exp((x_m * 2.0d0))))
end if
code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.15) {
tmp = x_m + ((-0.3333333333333333 * Math.pow(x_m, 3.0)) + (0.13333333333333333 * Math.pow(x_m, 5.0)));
} else {
tmp = 1.0 + (-1.0 / (1.0 + Math.exp((x_m * 2.0))));
}
return x_s * tmp;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): tmp = 0 if x_m <= 1.15: tmp = x_m + ((-0.3333333333333333 * math.pow(x_m, 3.0)) + (0.13333333333333333 * math.pow(x_m, 5.0))) else: tmp = 1.0 + (-1.0 / (1.0 + math.exp((x_m * 2.0)))) return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) tmp = 0.0 if (x_m <= 1.15) tmp = Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0)))); else tmp = Float64(1.0 + Float64(-1.0 / Float64(1.0 + exp(Float64(x_m * 2.0))))); end return Float64(x_s * tmp) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) tmp = 0.0; if (x_m <= 1.15) tmp = x_m + ((-0.3333333333333333 * (x_m ^ 3.0)) + (0.13333333333333333 * (x_m ^ 5.0))); else tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0)))); end tmp_2 = x_s * tmp; end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * If[LessEqual[x$95$m, 1.15], N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-1.0 / N[(1.0 + N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;x_m \leq 1.15:\\
\;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + 0.13333333333333333 \cdot {x_m}^{5}\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\
\end{array}
\end{array}
if x < 1.1499999999999999Initial program 7.6%
remove-double-neg7.6%
+-commutative7.6%
div-sub7.6%
Simplified6.3%
Taylor expanded in x around 0 98.8%
if 1.1499999999999999 < x Initial program 0.0%
remove-double-neg0.0%
+-commutative0.0%
div-sub0.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in x around 0 56.2%
*-commutative54.6%
Simplified56.2%
Taylor expanded in x around inf 100.0%
pow-exp100.0%
Applied egg-rr100.0%
Final simplification98.8%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 1.15)
(+
(+ x_m (* -0.3333333333333333 (pow x_m 3.0)))
(* 0.13333333333333333 (pow x_m 5.0)))
(+ 1.0 (/ -1.0 (+ 1.0 (exp (* x_m 2.0))))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.15) {
tmp = (x_m + (-0.3333333333333333 * pow(x_m, 3.0))) + (0.13333333333333333 * pow(x_m, 5.0));
} else {
tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
}
return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.15d0) then
tmp = (x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))) + (0.13333333333333333d0 * (x_m ** 5.0d0))
else
tmp = 1.0d0 + ((-1.0d0) / (1.0d0 + exp((x_m * 2.0d0))))
end if
code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.15) {
tmp = (x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0))) + (0.13333333333333333 * Math.pow(x_m, 5.0));
} else {
tmp = 1.0 + (-1.0 / (1.0 + Math.exp((x_m * 2.0))));
}
return x_s * tmp;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): tmp = 0 if x_m <= 1.15: tmp = (x_m + (-0.3333333333333333 * math.pow(x_m, 3.0))) + (0.13333333333333333 * math.pow(x_m, 5.0)) else: tmp = 1.0 + (-1.0 / (1.0 + math.exp((x_m * 2.0)))) return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) tmp = 0.0 if (x_m <= 1.15) tmp = Float64(Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0))) + Float64(0.13333333333333333 * (x_m ^ 5.0))); else tmp = Float64(1.0 + Float64(-1.0 / Float64(1.0 + exp(Float64(x_m * 2.0))))); end return Float64(x_s * tmp) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) tmp = 0.0; if (x_m <= 1.15) tmp = (x_m + (-0.3333333333333333 * (x_m ^ 3.0))) + (0.13333333333333333 * (x_m ^ 5.0)); else tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0)))); end tmp_2 = x_s * tmp; end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * If[LessEqual[x$95$m, 1.15], N[(N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-1.0 / N[(1.0 + N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;x_m \leq 1.15:\\
\;\;\;\;\left(x_m + -0.3333333333333333 \cdot {x_m}^{3}\right) + 0.13333333333333333 \cdot {x_m}^{5}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\
\end{array}
\end{array}
if x < 1.1499999999999999Initial program 7.6%
remove-double-neg7.6%
+-commutative7.6%
div-sub7.6%
Simplified6.3%
Taylor expanded in x around 0 98.8%
associate-+r+98.8%
+-commutative98.8%
fma-def98.8%
Simplified98.8%
fma-udef98.8%
Applied egg-rr98.8%
if 1.1499999999999999 < x Initial program 0.0%
remove-double-neg0.0%
+-commutative0.0%
div-sub0.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in x around 0 56.2%
*-commutative54.6%
Simplified56.2%
Taylor expanded in x around inf 100.0%
pow-exp100.0%
Applied egg-rr100.0%
Final simplification98.8%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 1.05)
(+ x_m (* -0.3333333333333333 (pow x_m 3.0)))
(+ 1.0 (/ -1.0 (+ 1.0 (exp (* x_m 2.0))))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.05) {
tmp = x_m + (-0.3333333333333333 * pow(x_m, 3.0));
} else {
tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0))));
}
return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.05d0) then
tmp = x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))
else
tmp = 1.0d0 + ((-1.0d0) / (1.0d0 + exp((x_m * 2.0d0))))
end if
code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.05) {
tmp = x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0));
} else {
tmp = 1.0 + (-1.0 / (1.0 + Math.exp((x_m * 2.0))));
}
return x_s * tmp;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): tmp = 0 if x_m <= 1.05: tmp = x_m + (-0.3333333333333333 * math.pow(x_m, 3.0)) else: tmp = 1.0 + (-1.0 / (1.0 + math.exp((x_m * 2.0)))) return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) tmp = 0.0 if (x_m <= 1.05) tmp = Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0))); else tmp = Float64(1.0 + Float64(-1.0 / Float64(1.0 + exp(Float64(x_m * 2.0))))); end return Float64(x_s * tmp) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) tmp = 0.0; if (x_m <= 1.05) tmp = x_m + (-0.3333333333333333 * (x_m ^ 3.0)); else tmp = 1.0 + (-1.0 / (1.0 + exp((x_m * 2.0)))); end tmp_2 = x_s * tmp; end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * If[LessEqual[x$95$m, 1.05], N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-1.0 / N[(1.0 + N[Exp[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;x_m \leq 1.05:\\
\;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{-1}{1 + e^{x_m \cdot 2}}\\
\end{array}
\end{array}
if x < 1.05000000000000004Initial program 7.6%
remove-double-neg7.6%
+-commutative7.6%
div-sub7.6%
Simplified6.3%
Taylor expanded in x around 0 98.6%
if 1.05000000000000004 < x Initial program 0.0%
remove-double-neg0.0%
+-commutative0.0%
div-sub0.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in x around 0 56.2%
*-commutative54.6%
Simplified56.2%
Taylor expanded in x around inf 100.0%
pow-exp100.0%
Applied egg-rr100.0%
Final simplification98.6%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (if (<= x_m 1.2) (+ x_m (* -0.3333333333333333 (pow x_m 3.0))) 1.0)))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.2) {
tmp = x_m + (-0.3333333333333333 * pow(x_m, 3.0));
} else {
tmp = 1.0;
}
return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.2d0) then
tmp = x_m + ((-0.3333333333333333d0) * (x_m ** 3.0d0))
else
tmp = 1.0d0
end if
code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.2) {
tmp = x_m + (-0.3333333333333333 * Math.pow(x_m, 3.0));
} else {
tmp = 1.0;
}
return x_s * tmp;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): tmp = 0 if x_m <= 1.2: tmp = x_m + (-0.3333333333333333 * math.pow(x_m, 3.0)) else: tmp = 1.0 return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) tmp = 0.0 if (x_m <= 1.2) tmp = Float64(x_m + Float64(-0.3333333333333333 * (x_m ^ 3.0))); else tmp = 1.0; end return Float64(x_s * tmp) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) tmp = 0.0; if (x_m <= 1.2) tmp = x_m + (-0.3333333333333333 * (x_m ^ 3.0)); else tmp = 1.0; end tmp_2 = x_s * tmp; end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * If[LessEqual[x$95$m, 1.2], N[(x$95$m + N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;x_m \leq 1.2:\\
\;\;\;\;x_m + -0.3333333333333333 \cdot {x_m}^{3}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.19999999999999996Initial program 7.6%
remove-double-neg7.6%
+-commutative7.6%
div-sub7.6%
Simplified6.3%
Taylor expanded in x around 0 98.6%
if 1.19999999999999996 < x Initial program 0.0%
remove-double-neg0.0%
+-commutative0.0%
div-sub0.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in x around 0 56.2%
*-commutative56.2%
Simplified56.2%
Taylor expanded in x around 0 54.6%
*-commutative54.6%
Simplified54.6%
Taylor expanded in x around inf 100.0%
Final simplification98.6%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (if (<= x_m 1.0) x_m 1.0)))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = x_m;
} else {
tmp = 1.0;
}
return x_s * tmp;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 1.0d0) then
tmp = x_m
else
tmp = 1.0d0
end if
code = x_s * tmp
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
double tmp;
if (x_m <= 1.0) {
tmp = x_m;
} else {
tmp = 1.0;
}
return x_s * tmp;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): tmp = 0 if x_m <= 1.0: tmp = x_m else: tmp = 1.0 return x_s * tmp
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) tmp = 0.0 if (x_m <= 1.0) tmp = x_m; else tmp = 1.0; end return Float64(x_s * tmp) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp_2 = code(x_s, x_m) tmp = 0.0; if (x_m <= 1.0) tmp = x_m; else tmp = 1.0; end tmp_2 = x_s * tmp; end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * If[LessEqual[x$95$m, 1.0], x$95$m, 1.0]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;x_m \leq 1:\\
\;\;\;\;x_m\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1Initial program 7.6%
remove-double-neg7.6%
+-commutative7.6%
div-sub7.6%
Simplified6.3%
Taylor expanded in x around 0 98.6%
if 1 < x Initial program 0.0%
remove-double-neg0.0%
+-commutative0.0%
div-sub0.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in x around 0 56.2%
*-commutative56.2%
Simplified56.2%
Taylor expanded in x around 0 54.6%
*-commutative54.6%
Simplified54.6%
Taylor expanded in x around inf 100.0%
Final simplification98.7%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s 1.0))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * 1.0;
}
x_m = abs(x)
x_s = copysign(1.0d0, x)
real(8) function code(x_s, x_m)
real(8), intent (in) :: x_s
real(8), intent (in) :: x_m
code = x_s * 1.0d0
end function
x_m = Math.abs(x);
x_s = Math.copySign(1.0, x);
public static double code(double x_s, double x_m) {
return x_s * 1.0;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * 1.0
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * 1.0) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * 1.0; end
x_m = N[Abs[x], $MachinePrecision]
x_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[x$95$s_, x$95$m_] := N[(x$95$s * 1.0), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot 1
\end{array}
Initial program 7.5%
remove-double-neg7.5%
+-commutative7.5%
div-sub7.5%
Simplified7.4%
Taylor expanded in x around inf 9.0%
Taylor expanded in x around 0 7.0%
*-commutative7.0%
Simplified7.0%
Taylor expanded in x around 0 6.9%
*-commutative6.9%
Simplified6.9%
Taylor expanded in x around inf 4.9%
Final simplification4.9%
herbie shell --seed 2024024
(FPCore (x)
:name "Hyperbolic tangent"
:precision binary64
(/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))