
(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 6 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 (pow (cbrt -0.05396825396825397) 4.0))
(t_1 (* -0.1111111111111111 (cbrt (/ 1.0 t_0))))
(t_2 (pow (cbrt -0.05396825396825397) 2.0))
(t_3 (/ 1.0 t_2))
(t_4 (fma -0.2222222222222222 t_3 (/ 0.037037037037037035 t_2)))
(t_5 (exp (- x_m)))
(t_6 (/ (- (exp x_m) t_5) (+ (exp x_m) t_5)))
(t_7 (cbrt (/ 1.0 (cbrt -0.05396825396825397)))))
(*
x_s
(if (<= t_6 0.005)
(+
x_m
(+
(* -0.3333333333333333 (pow x_m 3.0))
(+
(* -0.05396825396825397 (pow x_m 7.0))
(* 0.13333333333333333 (pow x_m 5.0)))))
(if (<= t_6 2.0)
t_6
(+
-0.05396825396825397
(fma
x_m
(cbrt t_0)
(fma
(pow x_m 2.0)
(fma
-0.1111111111111111
t_7
(fma 0.2222222222222222 t_7 (* (cbrt -0.05396825396825397) t_1)))
(*
(pow x_m 3.0)
(fma
-0.3333333333333333
t_4
(fma
-0.07407407407407407
t_3
(fma
0.3333333333333333
(* t_1 (cbrt t_3))
(*
(cbrt -0.05396825396825397)
(fma
-0.6666666666666666
(/ t_4 (cbrt -0.05396825396825397))
1.3725490196078431))))))))))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = pow(cbrt(-0.05396825396825397), 4.0);
double t_1 = -0.1111111111111111 * cbrt((1.0 / t_0));
double t_2 = pow(cbrt(-0.05396825396825397), 2.0);
double t_3 = 1.0 / t_2;
double t_4 = fma(-0.2222222222222222, t_3, (0.037037037037037035 / t_2));
double t_5 = exp(-x_m);
double t_6 = (exp(x_m) - t_5) / (exp(x_m) + t_5);
double t_7 = cbrt((1.0 / cbrt(-0.05396825396825397)));
double tmp;
if (t_6 <= 0.005) {
tmp = x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + ((-0.05396825396825397 * pow(x_m, 7.0)) + (0.13333333333333333 * pow(x_m, 5.0))));
} else if (t_6 <= 2.0) {
tmp = t_6;
} else {
tmp = -0.05396825396825397 + fma(x_m, cbrt(t_0), fma(pow(x_m, 2.0), fma(-0.1111111111111111, t_7, fma(0.2222222222222222, t_7, (cbrt(-0.05396825396825397) * t_1))), (pow(x_m, 3.0) * fma(-0.3333333333333333, t_4, fma(-0.07407407407407407, t_3, fma(0.3333333333333333, (t_1 * cbrt(t_3)), (cbrt(-0.05396825396825397) * fma(-0.6666666666666666, (t_4 / cbrt(-0.05396825396825397)), 1.3725490196078431))))))));
}
return x_s * tmp;
}
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) t_0 = cbrt(-0.05396825396825397) ^ 4.0 t_1 = Float64(-0.1111111111111111 * cbrt(Float64(1.0 / t_0))) t_2 = cbrt(-0.05396825396825397) ^ 2.0 t_3 = Float64(1.0 / t_2) t_4 = fma(-0.2222222222222222, t_3, Float64(0.037037037037037035 / t_2)) t_5 = exp(Float64(-x_m)) t_6 = Float64(Float64(exp(x_m) - t_5) / Float64(exp(x_m) + t_5)) t_7 = cbrt(Float64(1.0 / cbrt(-0.05396825396825397))) tmp = 0.0 if (t_6 <= 0.005) tmp = Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(Float64(-0.05396825396825397 * (x_m ^ 7.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0))))); elseif (t_6 <= 2.0) tmp = t_6; else tmp = Float64(-0.05396825396825397 + fma(x_m, cbrt(t_0), fma((x_m ^ 2.0), fma(-0.1111111111111111, t_7, fma(0.2222222222222222, t_7, Float64(cbrt(-0.05396825396825397) * t_1))), Float64((x_m ^ 3.0) * fma(-0.3333333333333333, t_4, fma(-0.07407407407407407, t_3, fma(0.3333333333333333, Float64(t_1 * cbrt(t_3)), Float64(cbrt(-0.05396825396825397) * fma(-0.6666666666666666, Float64(t_4 / cbrt(-0.05396825396825397)), 1.3725490196078431))))))))); end return Float64(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[Power[N[Power[-0.05396825396825397, 1/3], $MachinePrecision], 4.0], $MachinePrecision]}, Block[{t$95$1 = N[(-0.1111111111111111 * N[Power[N[(1.0 / t$95$0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Power[-0.05396825396825397, 1/3], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(1.0 / t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[(-0.2222222222222222 * t$95$3 + N[(0.037037037037037035 / t$95$2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Exp[(-x$95$m)], $MachinePrecision]}, Block[{t$95$6 = N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$5), $MachinePrecision] / N[(N[Exp[x$95$m], $MachinePrecision] + t$95$5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$7 = N[Power[N[(1.0 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$6, 0.005], N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.05396825396825397 * N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$6, 2.0], t$95$6, N[(-0.05396825396825397 + N[(x$95$m * N[Power[t$95$0, 1/3], $MachinePrecision] + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(-0.1111111111111111 * t$95$7 + N[(0.2222222222222222 * t$95$7 + N[(N[Power[-0.05396825396825397, 1/3], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Power[x$95$m, 3.0], $MachinePrecision] * N[(-0.3333333333333333 * t$95$4 + N[(-0.07407407407407407 * t$95$3 + N[(0.3333333333333333 * N[(t$95$1 * N[Power[t$95$3, 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[-0.05396825396825397, 1/3], $MachinePrecision] * N[(-0.6666666666666666 * N[(t$95$4 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision] + 1.3725490196078431), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{4}\\
t_1 := -0.1111111111111111 \cdot \sqrt[3]{\frac{1}{t_0}}\\
t_2 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}\\
t_3 := \frac{1}{t_2}\\
t_4 := \mathsf{fma}\left(-0.2222222222222222, t_3, \frac{0.037037037037037035}{t_2}\right)\\
t_5 := e^{-x_m}\\
t_6 := \frac{e^{x_m} - t_5}{e^{x_m} + t_5}\\
t_7 := \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;t_6 \leq 0.005:\\
\;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\
\mathbf{elif}\;t_6 \leq 2:\\
\;\;\;\;t_6\\
\mathbf{else}:\\
\;\;\;\;-0.05396825396825397 + \mathsf{fma}\left(x_m, \sqrt[3]{t_0}, \mathsf{fma}\left({x_m}^{2}, \mathsf{fma}\left(-0.1111111111111111, t_7, \mathsf{fma}\left(0.2222222222222222, t_7, \sqrt[3]{-0.05396825396825397} \cdot t_1\right)\right), {x_m}^{3} \cdot \mathsf{fma}\left(-0.3333333333333333, t_4, \mathsf{fma}\left(-0.07407407407407407, t_3, \mathsf{fma}\left(0.3333333333333333, t_1 \cdot \sqrt[3]{t_3}, \sqrt[3]{-0.05396825396825397} \cdot \mathsf{fma}\left(-0.6666666666666666, \frac{t_4}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right)\right)\right)\right)\right)\right)\\
\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)))) < 0.0050000000000000001Initial program 7.4%
Taylor expanded in x around 0 99.6%
if 0.0050000000000000001 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 2Initial program 99.6%
if 2 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) Initial program 0.0%
Taylor expanded in x around 0 1.5%
*-commutative1.5%
Simplified1.5%
Applied egg-rr12.4%
add-cube-cbrt12.4%
pow312.4%
Applied egg-rr12.4%
Taylor expanded in x around 0 0.0%
Simplified12.7%
Final simplification96.5%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (pow (cbrt -0.05396825396825397) 2.0))
(t_1 (exp (- x_m)))
(t_2 (/ (- (exp x_m) t_1) (+ (exp x_m) t_1)))
(t_3 (cbrt (/ -18.529411764705884 (cbrt -0.05396825396825397))))
(t_4 (/ -0.18518518518518517 t_0)))
(*
x_s
(if (<= t_2 0.005)
(+
x_m
(+
(* -0.3333333333333333 (pow x_m 3.0))
(+
(* -0.05396825396825397 (pow x_m 7.0))
(* 0.13333333333333333 (pow x_m 5.0)))))
(if (<= t_2 2.0)
t_2
(+
(fma
x_m
(cbrt (* -0.05396825396825397 (cbrt -0.05396825396825397)))
-0.05396825396825397)
(*
(pow x_m 2.0)
(+
(+
(* t_3 (* (cbrt -0.05396825396825397) -0.1111111111111111))
(* (cbrt (/ 1.0 (cbrt -0.05396825396825397))) 0.1111111111111111))
(*
x_m
(+
(fma
(cbrt -0.05396825396825397)
(fma
-0.6666666666666666
(/ t_4 (cbrt -0.05396825396825397))
1.3725490196078431)
(*
(* -0.1111111111111111 t_3)
(* 0.3333333333333333 (cbrt (/ 1.0 t_0)))))
(fma
-0.3333333333333333
t_4
(/ -0.07407407407407407 t_0))))))))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
double t_0 = pow(cbrt(-0.05396825396825397), 2.0);
double t_1 = exp(-x_m);
double t_2 = (exp(x_m) - t_1) / (exp(x_m) + t_1);
double t_3 = cbrt((-18.529411764705884 / cbrt(-0.05396825396825397)));
double t_4 = -0.18518518518518517 / t_0;
double tmp;
if (t_2 <= 0.005) {
tmp = x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + ((-0.05396825396825397 * pow(x_m, 7.0)) + (0.13333333333333333 * pow(x_m, 5.0))));
} else if (t_2 <= 2.0) {
tmp = t_2;
} else {
tmp = fma(x_m, cbrt((-0.05396825396825397 * cbrt(-0.05396825396825397))), -0.05396825396825397) + (pow(x_m, 2.0) * (((t_3 * (cbrt(-0.05396825396825397) * -0.1111111111111111)) + (cbrt((1.0 / cbrt(-0.05396825396825397))) * 0.1111111111111111)) + (x_m * (fma(cbrt(-0.05396825396825397), fma(-0.6666666666666666, (t_4 / cbrt(-0.05396825396825397)), 1.3725490196078431), ((-0.1111111111111111 * t_3) * (0.3333333333333333 * cbrt((1.0 / t_0))))) + fma(-0.3333333333333333, t_4, (-0.07407407407407407 / t_0))))));
}
return x_s * tmp;
}
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) t_0 = cbrt(-0.05396825396825397) ^ 2.0 t_1 = exp(Float64(-x_m)) t_2 = Float64(Float64(exp(x_m) - t_1) / Float64(exp(x_m) + t_1)) t_3 = cbrt(Float64(-18.529411764705884 / cbrt(-0.05396825396825397))) t_4 = Float64(-0.18518518518518517 / t_0) tmp = 0.0 if (t_2 <= 0.005) tmp = Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(Float64(-0.05396825396825397 * (x_m ^ 7.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0))))); elseif (t_2 <= 2.0) tmp = t_2; else tmp = Float64(fma(x_m, cbrt(Float64(-0.05396825396825397 * cbrt(-0.05396825396825397))), -0.05396825396825397) + Float64((x_m ^ 2.0) * Float64(Float64(Float64(t_3 * Float64(cbrt(-0.05396825396825397) * -0.1111111111111111)) + Float64(cbrt(Float64(1.0 / cbrt(-0.05396825396825397))) * 0.1111111111111111)) + Float64(x_m * Float64(fma(cbrt(-0.05396825396825397), fma(-0.6666666666666666, Float64(t_4 / cbrt(-0.05396825396825397)), 1.3725490196078431), Float64(Float64(-0.1111111111111111 * t_3) * Float64(0.3333333333333333 * cbrt(Float64(1.0 / t_0))))) + fma(-0.3333333333333333, t_4, Float64(-0.07407407407407407 / t_0))))))); end return Float64(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[Power[N[Power[-0.05396825396825397, 1/3], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x$95$m)], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$1), $MachinePrecision] / N[(N[Exp[x$95$m], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[(-18.529411764705884 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$4 = N[(-0.18518518518518517 / t$95$0), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$2, 0.005], N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.05396825396825397 * N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.0], t$95$2, N[(N[(x$95$m * N[Power[N[(-0.05396825396825397 * N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + -0.05396825396825397), $MachinePrecision] + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(N[(N[(t$95$3 * N[(N[Power[-0.05396825396825397, 1/3], $MachinePrecision] * -0.1111111111111111), $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(1.0 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * 0.1111111111111111), $MachinePrecision]), $MachinePrecision] + N[(x$95$m * N[(N[(N[Power[-0.05396825396825397, 1/3], $MachinePrecision] * N[(-0.6666666666666666 * N[(t$95$4 / N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision] + 1.3725490196078431), $MachinePrecision] + N[(N[(-0.1111111111111111 * t$95$3), $MachinePrecision] * N[(0.3333333333333333 * N[Power[N[(1.0 / t$95$0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 * t$95$4 + N[(-0.07407407407407407 / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 := {\left(\sqrt[3]{-0.05396825396825397}\right)}^{2}\\
t_1 := e^{-x_m}\\
t_2 := \frac{e^{x_m} - t_1}{e^{x_m} + t_1}\\
t_3 := \sqrt[3]{\frac{-18.529411764705884}{\sqrt[3]{-0.05396825396825397}}}\\
t_4 := \frac{-0.18518518518518517}{t_0}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;t_2 \leq 0.005:\\
\;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\
\mathbf{elif}\;t_2 \leq 2:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x_m, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right) + {x_m}^{2} \cdot \left(\left(t_3 \cdot \left(\sqrt[3]{-0.05396825396825397} \cdot -0.1111111111111111\right) + \sqrt[3]{\frac{1}{\sqrt[3]{-0.05396825396825397}}} \cdot 0.1111111111111111\right) + x_m \cdot \left(\mathsf{fma}\left(\sqrt[3]{-0.05396825396825397}, \mathsf{fma}\left(-0.6666666666666666, \frac{t_4}{\sqrt[3]{-0.05396825396825397}}, 1.3725490196078431\right), \left(-0.1111111111111111 \cdot t_3\right) \cdot \left(0.3333333333333333 \cdot \sqrt[3]{\frac{1}{t_0}}\right)\right) + \mathsf{fma}\left(-0.3333333333333333, t_4, \frac{-0.07407407407407407}{t_0}\right)\right)\right)\\
\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)))) < 0.0050000000000000001Initial program 7.4%
Taylor expanded in x around 0 99.6%
if 0.0050000000000000001 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 2Initial program 99.6%
if 2 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) Initial program 0.0%
Taylor expanded in x around 0 1.5%
*-commutative1.5%
Simplified1.5%
Applied egg-rr12.4%
add-cube-cbrt12.4%
pow312.4%
Applied egg-rr12.4%
Taylor expanded in x around 0 0.0%
Simplified12.7%
Final simplification96.5%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (exp (- x_m))) (t_1 (/ (- (exp x_m) t_0) (+ (exp x_m) t_0))))
(*
x_s
(if (<= t_1 0.005)
(+
x_m
(+
(* -0.3333333333333333 (pow x_m 3.0))
(+
(* -0.05396825396825397 (pow x_m 7.0))
(* 0.13333333333333333 (pow x_m 5.0)))))
(if (<= t_1 2.0)
t_1
(fma
x_m
(cbrt (* -0.05396825396825397 (cbrt -0.05396825396825397)))
-0.05396825396825397))))))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 t_1 = (exp(x_m) - t_0) / (exp(x_m) + t_0);
double tmp;
if (t_1 <= 0.005) {
tmp = x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + ((-0.05396825396825397 * pow(x_m, 7.0)) + (0.13333333333333333 * pow(x_m, 5.0))));
} else if (t_1 <= 2.0) {
tmp = t_1;
} else {
tmp = fma(x_m, cbrt((-0.05396825396825397 * cbrt(-0.05396825396825397))), -0.05396825396825397);
}
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)) t_1 = Float64(Float64(exp(x_m) - t_0) / Float64(exp(x_m) + t_0)) tmp = 0.0 if (t_1 <= 0.005) tmp = Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(Float64(-0.05396825396825397 * (x_m ^ 7.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0))))); elseif (t_1 <= 2.0) tmp = t_1; else tmp = fma(x_m, cbrt(Float64(-0.05396825396825397 * cbrt(-0.05396825396825397))), -0.05396825396825397); end return Float64(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]}, Block[{t$95$1 = N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$0), $MachinePrecision] / N[(N[Exp[x$95$m], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$1, 0.005], N[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.05396825396825397 * N[Power[x$95$m, 7.0], $MachinePrecision]), $MachinePrecision] + N[(0.13333333333333333 * N[Power[x$95$m, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], t$95$1, N[(x$95$m * N[Power[N[(-0.05396825396825397 * N[Power[-0.05396825396825397, 1/3], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + -0.05396825396825397), $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}\\
t_1 := \frac{e^{x_m} - t_0}{e^{x_m} + t_0}\\
x_s \cdot \begin{array}{l}
\mathbf{if}\;t_1 \leq 0.005:\\
\;\;\;\;x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + \left(-0.05396825396825397 \cdot {x_m}^{7} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)\\
\mathbf{elif}\;t_1 \leq 2:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x_m, \sqrt[3]{-0.05396825396825397 \cdot \sqrt[3]{-0.05396825396825397}}, -0.05396825396825397\right)\\
\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)))) < 0.0050000000000000001Initial program 7.4%
Taylor expanded in x around 0 99.6%
if 0.0050000000000000001 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) < 2Initial program 99.6%
if 2 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) Initial program 0.0%
Taylor expanded in x around 0 1.5%
*-commutative1.5%
Simplified1.5%
Applied egg-rr12.4%
add-cube-cbrt12.4%
pow312.4%
Applied egg-rr12.4%
Taylor expanded in x around 0 12.7%
fma-neg12.7%
distribute-rgt-out12.7%
metadata-eval12.7%
*-rgt-identity12.7%
unpow1/312.7%
*-lft-identity12.7%
metadata-eval12.7%
pow-sqr12.7%
unpow212.7%
associate-*r*12.7%
unpow212.7%
rem-3cbrt-lft12.7%
metadata-eval12.7%
Simplified12.7%
Final simplification96.5%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s (+ x_m (+ (* -0.3333333333333333 (pow x_m 3.0)) (* (pow x_m 5.0) 0.125)))))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + (pow(x_m, 5.0) * 0.125)));
}
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 * (x_m + (((-0.3333333333333333d0) * (x_m ** 3.0d0)) + ((x_m ** 5.0d0) * 0.125d0)))
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 * (x_m + ((-0.3333333333333333 * Math.pow(x_m, 3.0)) + (Math.pow(x_m, 5.0) * 0.125)));
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * (x_m + ((-0.3333333333333333 * math.pow(x_m, 3.0)) + (math.pow(x_m, 5.0) * 0.125)))
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64((x_m ^ 5.0) * 0.125)))) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * (x_m + ((-0.3333333333333333 * (x_m ^ 3.0)) + ((x_m ^ 5.0) * 0.125))); 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[(x$95$m + N[(N[(-0.3333333333333333 * N[Power[x$95$m, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[x$95$m, 5.0], $MachinePrecision] * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \left(x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + {x_m}^{5} \cdot 0.125\right)\right)
\end{array}
Initial program 8.5%
Taylor expanded in x around 0 94.9%
Taylor expanded in x around 0 95.1%
Final simplification95.1%
x_m = (fabs.f64 x)
x_s = (copysign.f64 1 x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(+
x_m
(+
(* -0.3333333333333333 (pow x_m 3.0))
(* 0.13333333333333333 (pow x_m 5.0))))))x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * (x_m + ((-0.3333333333333333 * pow(x_m, 3.0)) + (0.13333333333333333 * pow(x_m, 5.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 * (x_m + (((-0.3333333333333333d0) * (x_m ** 3.0d0)) + (0.13333333333333333d0 * (x_m ** 5.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 * (x_m + ((-0.3333333333333333 * Math.pow(x_m, 3.0)) + (0.13333333333333333 * Math.pow(x_m, 5.0))));
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * (x_m + ((-0.3333333333333333 * math.pow(x_m, 3.0)) + (0.13333333333333333 * math.pow(x_m, 5.0))))
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * Float64(x_m + Float64(Float64(-0.3333333333333333 * (x_m ^ 3.0)) + Float64(0.13333333333333333 * (x_m ^ 5.0))))) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * (x_m + ((-0.3333333333333333 * (x_m ^ 3.0)) + (0.13333333333333333 * (x_m ^ 5.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[(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]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot \left(x_m + \left(-0.3333333333333333 \cdot {x_m}^{3} + 0.13333333333333333 \cdot {x_m}^{5}\right)\right)
\end{array}
Initial program 8.5%
Taylor expanded in x around 0 95.1%
Final simplification95.1%
x_m = (fabs.f64 x) x_s = (copysign.f64 1 x) (FPCore (x_s x_m) :precision binary64 (* x_s x_m))
x_m = fabs(x);
x_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * x_m;
}
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 * x_m
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 * x_m;
}
x_m = math.fabs(x) x_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * x_m
x_m = abs(x) x_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * x_m) end
x_m = abs(x); x_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * x_m; 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 * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x_s = \mathsf{copysign}\left(1, x\right)
\\
x_s \cdot x_m
\end{array}
Initial program 8.5%
Taylor expanded in x around 0 94.9%
Final simplification94.9%
herbie shell --seed 2024019
(FPCore (x)
:name "Hyperbolic tangent"
:precision binary64
(/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))