
(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 #s(literal 1 binary64) x)
(FPCore (x_s x_m)
:precision binary64
(let* ((t_0 (exp (- x_m))) (t_1 (+ (exp x_m) t_0)))
(*
x_s
(if (<= (/ (- (exp x_m) t_0) t_1) 0.9)
(/
(*
x_m
(+
2.0
(*
(pow x_m 2.0)
(+
0.3333333333333333
(*
(pow x_m 2.0)
(+
0.016666666666666666
(* (pow x_m 2.0) 0.0003968253968253968)))))))
t_1)
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 t_1 = exp(x_m) + t_0;
double tmp;
if (((exp(x_m) - t_0) / t_1) <= 0.9) {
tmp = (x_m * (2.0 + (pow(x_m, 2.0) * (0.3333333333333333 + (pow(x_m, 2.0) * (0.016666666666666666 + (pow(x_m, 2.0) * 0.0003968253968253968))))))) / t_1;
} 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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = exp(-x_m)
t_1 = exp(x_m) + t_0
if (((exp(x_m) - t_0) / t_1) <= 0.9d0) then
tmp = (x_m * (2.0d0 + ((x_m ** 2.0d0) * (0.3333333333333333d0 + ((x_m ** 2.0d0) * (0.016666666666666666d0 + ((x_m ** 2.0d0) * 0.0003968253968253968d0))))))) / t_1
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 t_0 = Math.exp(-x_m);
double t_1 = Math.exp(x_m) + t_0;
double tmp;
if (((Math.exp(x_m) - t_0) / t_1) <= 0.9) {
tmp = (x_m * (2.0 + (Math.pow(x_m, 2.0) * (0.3333333333333333 + (Math.pow(x_m, 2.0) * (0.016666666666666666 + (Math.pow(x_m, 2.0) * 0.0003968253968253968))))))) / t_1;
} 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): t_0 = math.exp(-x_m) t_1 = math.exp(x_m) + t_0 tmp = 0 if ((math.exp(x_m) - t_0) / t_1) <= 0.9: tmp = (x_m * (2.0 + (math.pow(x_m, 2.0) * (0.3333333333333333 + (math.pow(x_m, 2.0) * (0.016666666666666666 + (math.pow(x_m, 2.0) * 0.0003968253968253968))))))) / t_1 else: tmp = 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)) t_1 = Float64(exp(x_m) + t_0) tmp = 0.0 if (Float64(Float64(exp(x_m) - t_0) / t_1) <= 0.9) tmp = Float64(Float64(x_m * Float64(2.0 + Float64((x_m ^ 2.0) * Float64(0.3333333333333333 + Float64((x_m ^ 2.0) * Float64(0.016666666666666666 + Float64((x_m ^ 2.0) * 0.0003968253968253968))))))) / t_1); 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) t_0 = exp(-x_m); t_1 = exp(x_m) + t_0; tmp = 0.0; if (((exp(x_m) - t_0) / t_1) <= 0.9) tmp = (x_m * (2.0 + ((x_m ^ 2.0) * (0.3333333333333333 + ((x_m ^ 2.0) * (0.016666666666666666 + ((x_m ^ 2.0) * 0.0003968253968253968))))))) / t_1; 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_] := Block[{t$95$0 = N[Exp[(-x$95$m)], $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[x$95$m], $MachinePrecision] + t$95$0), $MachinePrecision]}, N[(x$95$s * If[LessEqual[N[(N[(N[Exp[x$95$m], $MachinePrecision] - t$95$0), $MachinePrecision] / t$95$1), $MachinePrecision], 0.9], N[(N[(x$95$m * N[(2.0 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(0.3333333333333333 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(0.016666666666666666 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 0.0003968253968253968), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], 1.0]), $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 := e^{x\_m} + t\_0\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{e^{x\_m} - t\_0}{t\_1} \leq 0.9:\\
\;\;\;\;\frac{x\_m \cdot \left(2 + {x\_m}^{2} \cdot \left(0.3333333333333333 + {x\_m}^{2} \cdot \left(0.016666666666666666 + {x\_m}^{2} \cdot 0.0003968253968253968\right)\right)\right)}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;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)))) < 0.900000000000000022Initial program 11.1%
Taylor expanded in x around 0 98.3%
*-commutative98.3%
Simplified98.3%
if 0.900000000000000022 < (/.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%
+-commutative1.5%
distribute-lft1-in1.5%
associate-*l*1.5%
fma-define1.5%
pow-plus1.5%
metadata-eval1.5%
Simplified1.5%
Applied egg-rr78.1%
Final simplification97.6%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) 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)) 0.1)
(*
x_m
(+
1.0
(*
(pow x_m 2.0)
(-
(*
(pow x_m 2.0)
(+ 0.13333333333333333 (* (pow x_m 2.0) -0.05396825396825397)))
0.3333333333333333))))
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)) <= 0.1) {
tmp = x_m * (1.0 + (pow(x_m, 2.0) * ((pow(x_m, 2.0) * (0.13333333333333333 + (pow(x_m, 2.0) * -0.05396825396825397))) - 0.3333333333333333)));
} 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) :: t_0
real(8) :: tmp
t_0 = exp(-x_m)
if (((exp(x_m) - t_0) / (exp(x_m) + t_0)) <= 0.1d0) then
tmp = x_m * (1.0d0 + ((x_m ** 2.0d0) * (((x_m ** 2.0d0) * (0.13333333333333333d0 + ((x_m ** 2.0d0) * (-0.05396825396825397d0)))) - 0.3333333333333333d0)))
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 t_0 = Math.exp(-x_m);
double tmp;
if (((Math.exp(x_m) - t_0) / (Math.exp(x_m) + t_0)) <= 0.1) {
tmp = x_m * (1.0 + (Math.pow(x_m, 2.0) * ((Math.pow(x_m, 2.0) * (0.13333333333333333 + (Math.pow(x_m, 2.0) * -0.05396825396825397))) - 0.3333333333333333)));
} 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): t_0 = math.exp(-x_m) tmp = 0 if ((math.exp(x_m) - t_0) / (math.exp(x_m) + t_0)) <= 0.1: tmp = x_m * (1.0 + (math.pow(x_m, 2.0) * ((math.pow(x_m, 2.0) * (0.13333333333333333 + (math.pow(x_m, 2.0) * -0.05396825396825397))) - 0.3333333333333333))) else: tmp = 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)) <= 0.1) tmp = Float64(x_m * Float64(1.0 + Float64((x_m ^ 2.0) * Float64(Float64((x_m ^ 2.0) * Float64(0.13333333333333333 + Float64((x_m ^ 2.0) * -0.05396825396825397))) - 0.3333333333333333)))); 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) t_0 = exp(-x_m); tmp = 0.0; if (((exp(x_m) - t_0) / (exp(x_m) + t_0)) <= 0.1) tmp = x_m * (1.0 + ((x_m ^ 2.0) * (((x_m ^ 2.0) * (0.13333333333333333 + ((x_m ^ 2.0) * -0.05396825396825397))) - 0.3333333333333333))); 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_] := 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], 0.1], N[(x$95$m * N[(1.0 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(0.13333333333333333 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * -0.05396825396825397), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]), $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 0.1:\\
\;\;\;\;x\_m \cdot \left(1 + {x\_m}^{2} \cdot \left({x\_m}^{2} \cdot \left(0.13333333333333333 + {x\_m}^{2} \cdot -0.05396825396825397\right) - 0.3333333333333333\right)\right)\\
\mathbf{else}:\\
\;\;\;\;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)))) < 0.10000000000000001Initial program 10.8%
Taylor expanded in x around 0 98.3%
if 0.10000000000000001 < (/.f64 (-.f64 (exp.f64 x) (exp.f64 (neg.f64 x))) (+.f64 (exp.f64 x) (exp.f64 (neg.f64 x)))) Initial program 10.0%
Taylor expanded in x around 0 3.3%
*-commutative3.3%
+-commutative3.3%
distribute-lft1-in3.3%
associate-*l*3.3%
fma-define3.3%
pow-plus3.3%
metadata-eval3.3%
Simplified3.3%
Applied egg-rr72.5%
Final simplification97.2%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 1.25)
(+
x_m
(*
(pow x_m 3.0)
(fma (pow x_m 2.0) 0.13333333333333333 -0.3333333333333333)))
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.25) {
tmp = x_m + (pow(x_m, 3.0) * fma(pow(x_m, 2.0), 0.13333333333333333, -0.3333333333333333));
} 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.25) tmp = Float64(x_m + Float64((x_m ^ 3.0) * fma((x_m ^ 2.0), 0.13333333333333333, -0.3333333333333333))); else tmp = 1.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_] := N[(x$95$s * If[LessEqual[x$95$m, 1.25], N[(x$95$m + N[(N[Power[x$95$m, 3.0], $MachinePrecision] * N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 0.13333333333333333 + -0.3333333333333333), $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.25:\\
\;\;\;\;x\_m + {x\_m}^{3} \cdot \mathsf{fma}\left({x\_m}^{2}, 0.13333333333333333, -0.3333333333333333\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.25Initial program 10.7%
Taylor expanded in x around 0 97.5%
Taylor expanded in x around inf 21.7%
associate-*r/21.7%
metadata-eval21.7%
Simplified21.7%
Taylor expanded in x around 0 97.5%
distribute-lft-in97.5%
*-rgt-identity97.5%
associate-*r*97.5%
unpow297.5%
cube-mult97.5%
*-commutative97.5%
fma-neg97.5%
metadata-eval97.5%
Simplified97.5%
if 1.25 < x Initial program 12.5%
Taylor expanded in x around 0 3.8%
*-commutative3.8%
+-commutative3.8%
distribute-lft1-in3.8%
associate-*l*3.8%
fma-define3.8%
pow-plus3.8%
metadata-eval3.8%
Simplified3.8%
Applied egg-rr90.2%
Final simplification97.3%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 1.25)
(*
x_m
(+
1.0
(*
(pow x_m 2.0)
(- (* (pow x_m 2.0) 0.13333333333333333) 0.3333333333333333))))
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.25) {
tmp = x_m * (1.0 + (pow(x_m, 2.0) * ((pow(x_m, 2.0) * 0.13333333333333333) - 0.3333333333333333)));
} 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.25d0) then
tmp = x_m * (1.0d0 + ((x_m ** 2.0d0) * (((x_m ** 2.0d0) * 0.13333333333333333d0) - 0.3333333333333333d0)))
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.25) {
tmp = x_m * (1.0 + (Math.pow(x_m, 2.0) * ((Math.pow(x_m, 2.0) * 0.13333333333333333) - 0.3333333333333333)));
} 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.25: tmp = x_m * (1.0 + (math.pow(x_m, 2.0) * ((math.pow(x_m, 2.0) * 0.13333333333333333) - 0.3333333333333333))) 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.25) tmp = Float64(x_m * Float64(1.0 + Float64((x_m ^ 2.0) * Float64(Float64((x_m ^ 2.0) * 0.13333333333333333) - 0.3333333333333333)))); 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.25) tmp = x_m * (1.0 + ((x_m ^ 2.0) * (((x_m ^ 2.0) * 0.13333333333333333) - 0.3333333333333333))); 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.25], N[(x$95$m * N[(1.0 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 0.13333333333333333), $MachinePrecision] - 0.3333333333333333), $MachinePrecision]), $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.25:\\
\;\;\;\;x\_m \cdot \left(1 + {x\_m}^{2} \cdot \left({x\_m}^{2} \cdot 0.13333333333333333 - 0.3333333333333333\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.25Initial program 10.7%
Taylor expanded in x around 0 97.5%
if 1.25 < x Initial program 12.5%
Taylor expanded in x around 0 3.8%
*-commutative3.8%
+-commutative3.8%
distribute-lft1-in3.8%
associate-*l*3.8%
fma-define3.8%
pow-plus3.8%
metadata-eval3.8%
Simplified3.8%
Applied egg-rr90.2%
Final simplification97.3%
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
(FPCore (x_s x_m)
:precision binary64
(*
x_s
(if (<= x_m 1.6)
(/ (* x_m (+ 2.0 (* (pow x_m 2.0) 0.3333333333333333))) (fma x_m 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 tmp;
if (x_m <= 1.6) {
tmp = (x_m * (2.0 + (pow(x_m, 2.0) * 0.3333333333333333))) / fma(x_m, x_m, 2.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.6) tmp = Float64(Float64(x_m * Float64(2.0 + Float64((x_m ^ 2.0) * 0.3333333333333333))) / fma(x_m, x_m, 2.0)); else tmp = 1.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_] := N[(x$95$s * If[LessEqual[x$95$m, 1.6], N[(N[(x$95$m * N[(2.0 + N[(N[Power[x$95$m, 2.0], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x$95$m * x$95$m + 2.0), $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.6:\\
\;\;\;\;\frac{x\_m \cdot \left(2 + {x\_m}^{2} \cdot 0.3333333333333333\right)}{\mathsf{fma}\left(x\_m, x\_m, 2\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.6000000000000001Initial program 11.0%
Taylor expanded in x around 0 96.9%
Taylor expanded in x around 0 97.0%
+-commutative97.0%
unpow297.0%
fma-define97.0%
Simplified97.0%
if 1.6000000000000001 < x Initial program 0.0%
Taylor expanded in x around 0 1.5%
*-commutative1.5%
+-commutative1.5%
distribute-lft1-in1.5%
associate-*l*1.5%
fma-define1.5%
pow-plus1.5%
metadata-eval1.5%
Simplified1.5%
Applied egg-rr100.0%
Final simplification97.1%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m) :precision binary64 (* x_s (if (<= x_m 1.16) (+ x_m (* (pow x_m 3.0) -0.3333333333333333)) 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.16) {
tmp = x_m + (pow(x_m, 3.0) * -0.3333333333333333);
} 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.16d0) then
tmp = x_m + ((x_m ** 3.0d0) * (-0.3333333333333333d0))
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.16) {
tmp = x_m + (Math.pow(x_m, 3.0) * -0.3333333333333333);
} 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.16: tmp = x_m + (math.pow(x_m, 3.0) * -0.3333333333333333) 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.16) tmp = Float64(x_m + Float64((x_m ^ 3.0) * -0.3333333333333333)); 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.16) tmp = x_m + ((x_m ^ 3.0) * -0.3333333333333333); 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.16], N[(x$95$m + N[(N[Power[x$95$m, 3.0], $MachinePrecision] * -0.3333333333333333), $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.16:\\
\;\;\;\;x\_m + {x\_m}^{3} \cdot -0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < 1.15999999999999992Initial program 10.7%
Taylor expanded in x around 0 96.9%
*-commutative96.9%
+-commutative96.9%
distribute-lft1-in97.0%
associate-*l*97.0%
fma-define97.0%
pow-plus97.0%
metadata-eval97.0%
Simplified97.0%
Taylor expanded in x around 0 96.9%
distribute-rgt-in97.0%
*-lft-identity97.0%
associate-*r*97.0%
unpow297.0%
unpow397.0%
Simplified97.0%
if 1.15999999999999992 < x Initial program 12.5%
Taylor expanded in x around 0 3.8%
*-commutative3.8%
+-commutative3.8%
distribute-lft1-in3.8%
associate-*l*3.8%
fma-define3.8%
pow-plus3.8%
metadata-eval3.8%
Simplified3.8%
Applied egg-rr90.2%
Final simplification96.7%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) 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 10.7%
Taylor expanded in x around 0 96.5%
if 1 < x Initial program 12.5%
Taylor expanded in x around 0 3.8%
*-commutative3.8%
+-commutative3.8%
distribute-lft1-in3.8%
associate-*l*3.8%
fma-define3.8%
pow-plus3.8%
metadata-eval3.8%
Simplified3.8%
Applied egg-rr90.2%
Final simplification96.3%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) x) (FPCore (x_s x_m) :precision binary64 (* x_s 0.8666666666666667))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
double code(double x_s, double x_m) {
return x_s * 0.8666666666666667;
}
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 * 0.8666666666666667d0
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 * 0.8666666666666667;
}
x\_m = math.fabs(x) x\_s = math.copysign(1.0, x) def code(x_s, x_m): return x_s * 0.8666666666666667
x\_m = abs(x) x\_s = copysign(1.0, x) function code(x_s, x_m) return Float64(x_s * 0.8666666666666667) end
x\_m = abs(x); x\_s = sign(x) * abs(1.0); function tmp = code(x_s, x_m) tmp = x_s * 0.8666666666666667; 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 * 0.8666666666666667), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
x\_s \cdot 0.8666666666666667
\end{array}
Initial program 10.7%
Taylor expanded in x around 0 94.0%
*-commutative94.0%
+-commutative94.0%
distribute-lft1-in94.0%
associate-*l*94.0%
fma-define94.0%
pow-plus94.0%
metadata-eval94.0%
Simplified94.0%
Applied egg-rr4.4%
Final simplification4.4%
x\_m = (fabs.f64 x) x\_s = (copysign.f64 #s(literal 1 binary64) 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 10.7%
Taylor expanded in x around 0 94.0%
*-commutative94.0%
+-commutative94.0%
distribute-lft1-in94.0%
associate-*l*94.0%
fma-define94.0%
pow-plus94.0%
metadata-eval94.0%
Simplified94.0%
Applied egg-rr6.5%
Final simplification6.5%
herbie shell --seed 2024078
(FPCore (x)
:name "Hyperbolic tangent"
:precision binary64
(/ (- (exp x) (exp (- x))) (+ (exp x) (exp (- x)))))