
(FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
double code(double x, double c, double s) {
return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
def code(x, c, s): return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
function code(x, c, s) return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x)); end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
double code(double x, double c, double s) {
return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = cos((2.0d0 * x)) / ((c ** 2.0d0) * ((x * (s ** 2.0d0)) * x))
end function
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * ((x * Math.pow(s, 2.0)) * x));
}
def code(x, c, s): return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
function code(x, c, s) return Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x)); end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\end{array}
x_m = (fabs.f64 x)
c_m = (fabs.f64 c)
s_m = (fabs.f64 s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
(FPCore (x_m c_m s_m)
:precision binary64
(let* ((t_0 (cos (* x_m -2.0))) (t_1 (* s_m (* x_m c_m))))
(if (<= x_m 2e-25)
(pow (* c_m (* x_m s_m)) -2.0)
(if (<= x_m 2e+126)
(/ t_0 (* (* s_m c_m) (* x_m t_1)))
(/ t_0 (* (* x_m c_m) (* s_m t_1)))))))x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = cos((x_m * -2.0));
double t_1 = s_m * (x_m * c_m);
double tmp;
if (x_m <= 2e-25) {
tmp = pow((c_m * (x_m * s_m)), -2.0);
} else if (x_m <= 2e+126) {
tmp = t_0 / ((s_m * c_m) * (x_m * t_1));
} else {
tmp = t_0 / ((x_m * c_m) * (s_m * t_1));
}
return tmp;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((x_m * (-2.0d0)))
t_1 = s_m * (x_m * c_m)
if (x_m <= 2d-25) then
tmp = (c_m * (x_m * s_m)) ** (-2.0d0)
else if (x_m <= 2d+126) then
tmp = t_0 / ((s_m * c_m) * (x_m * t_1))
else
tmp = t_0 / ((x_m * c_m) * (s_m * t_1))
end if
code = tmp
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = Math.cos((x_m * -2.0));
double t_1 = s_m * (x_m * c_m);
double tmp;
if (x_m <= 2e-25) {
tmp = Math.pow((c_m * (x_m * s_m)), -2.0);
} else if (x_m <= 2e+126) {
tmp = t_0 / ((s_m * c_m) * (x_m * t_1));
} else {
tmp = t_0 / ((x_m * c_m) * (s_m * t_1));
}
return tmp;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = math.cos((x_m * -2.0)) t_1 = s_m * (x_m * c_m) tmp = 0 if x_m <= 2e-25: tmp = math.pow((c_m * (x_m * s_m)), -2.0) elif x_m <= 2e+126: tmp = t_0 / ((s_m * c_m) * (x_m * t_1)) else: tmp = t_0 / ((x_m * c_m) * (s_m * t_1)) return tmp
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = cos(Float64(x_m * -2.0)) t_1 = Float64(s_m * Float64(x_m * c_m)) tmp = 0.0 if (x_m <= 2e-25) tmp = Float64(c_m * Float64(x_m * s_m)) ^ -2.0; elseif (x_m <= 2e+126) tmp = Float64(t_0 / Float64(Float64(s_m * c_m) * Float64(x_m * t_1))); else tmp = Float64(t_0 / Float64(Float64(x_m * c_m) * Float64(s_m * t_1))); end return tmp end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp_2 = code(x_m, c_m, s_m)
t_0 = cos((x_m * -2.0));
t_1 = s_m * (x_m * c_m);
tmp = 0.0;
if (x_m <= 2e-25)
tmp = (c_m * (x_m * s_m)) ^ -2.0;
elseif (x_m <= 2e+126)
tmp = t_0 / ((s_m * c_m) * (x_m * t_1));
else
tmp = t_0 / ((x_m * c_m) * (s_m * t_1));
end
tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[Cos[N[(x$95$m * -2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 2e-25], N[Power[N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision], If[LessEqual[x$95$m, 2e+126], N[(t$95$0 / N[(N[(s$95$m * c$95$m), $MachinePrecision] * N[(x$95$m * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(N[(x$95$m * c$95$m), $MachinePrecision] * N[(s$95$m * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \cos \left(x\_m \cdot -2\right)\\
t_1 := s\_m \cdot \left(x\_m \cdot c\_m\right)\\
\mathbf{if}\;x\_m \leq 2 \cdot 10^{-25}:\\
\;\;\;\;{\left(c\_m \cdot \left(x\_m \cdot s\_m\right)\right)}^{-2}\\
\mathbf{elif}\;x\_m \leq 2 \cdot 10^{+126}:\\
\;\;\;\;\frac{t\_0}{\left(s\_m \cdot c\_m\right) \cdot \left(x\_m \cdot t\_1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\left(x\_m \cdot c\_m\right) \cdot \left(s\_m \cdot t\_1\right)}\\
\end{array}
\end{array}
if x < 2.00000000000000008e-25Initial program 70.6%
associate-/r*70.6%
associate-*l*70.6%
unpow270.6%
sqr-neg70.6%
unpow270.6%
*-commutative70.6%
*-commutative70.6%
associate-/r*70.6%
cos-neg70.6%
*-commutative70.6%
distribute-rgt-neg-in70.6%
metadata-eval70.6%
associate-*r*70.3%
*-commutative70.3%
unpow270.3%
sqr-neg70.3%
associate-*l*75.3%
associate-*r*76.6%
Simplified65.2%
Taylor expanded in x around inf 65.2%
associate-/r*65.2%
*-commutative65.2%
unpow265.2%
unpow265.2%
swap-sqr78.2%
unpow278.2%
associate-/r*78.2%
*-commutative78.2%
unpow278.2%
unpow278.2%
swap-sqr96.1%
unpow296.1%
associate-*r*96.6%
*-commutative96.6%
Simplified96.6%
Taylor expanded in x around 0 57.2%
associate-*r*56.1%
*-commutative56.1%
unpow256.1%
unpow256.1%
swap-sqr67.1%
unpow267.1%
swap-sqr80.2%
associate-*r*78.6%
associate-*r*79.2%
/-rgt-identity79.2%
associate-/r/79.2%
associate-/l*79.4%
associate-*l/79.4%
unpow-179.4%
unpow-179.4%
pow-sqr79.4%
metadata-eval79.4%
associate-*r*80.4%
*-commutative80.4%
associate-*r*80.8%
Simplified80.8%
if 2.00000000000000008e-25 < x < 1.99999999999999985e126Initial program 76.0%
associate-/r*76.0%
associate-*l*76.0%
unpow276.0%
sqr-neg76.0%
unpow276.0%
*-commutative76.0%
*-commutative76.0%
associate-/r*76.0%
cos-neg76.0%
*-commutative76.0%
distribute-rgt-neg-in76.0%
metadata-eval76.0%
associate-*r*79.1%
*-commutative79.1%
unpow279.1%
sqr-neg79.1%
associate-*l*79.0%
associate-*r*82.2%
Simplified76.0%
Taylor expanded in x around inf 76.0%
associate-/r*76.0%
*-commutative76.0%
unpow276.0%
unpow276.0%
swap-sqr75.8%
unpow275.8%
associate-/r*75.8%
*-commutative75.8%
unpow275.8%
unpow275.8%
swap-sqr99.6%
unpow299.6%
associate-*r*99.5%
*-commutative99.5%
Simplified99.5%
*-commutative99.5%
associate-*r*99.6%
unpow299.6%
*-commutative99.6%
associate-*r*99.7%
associate-*l*99.6%
*-commutative99.6%
associate-*r*99.5%
*-commutative99.5%
Applied egg-rr99.5%
if 1.99999999999999985e126 < x Initial program 66.9%
associate-/r*67.4%
associate-*l*67.4%
unpow267.4%
sqr-neg67.4%
unpow267.4%
*-commutative67.4%
*-commutative67.4%
associate-/r*66.9%
cos-neg66.9%
*-commutative66.9%
distribute-rgt-neg-in66.9%
metadata-eval66.9%
associate-*r*67.0%
*-commutative67.0%
unpow267.0%
sqr-neg67.0%
associate-*l*74.2%
associate-*r*75.0%
Simplified54.3%
Taylor expanded in x around inf 54.3%
associate-/r*54.1%
*-commutative54.1%
unpow254.1%
unpow254.1%
swap-sqr76.8%
unpow276.8%
associate-/r*77.4%
*-commutative77.4%
unpow277.4%
unpow277.4%
swap-sqr99.0%
unpow299.0%
associate-*r*96.9%
*-commutative96.9%
Simplified96.9%
unpow296.9%
*-commutative96.9%
associate-*r*96.9%
associate-*r*94.7%
associate-*r*94.7%
*-commutative94.7%
Applied egg-rr94.7%
Final simplification85.4%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (if (<= x_m 1.1e-25) (pow (* c_m (* x_m s_m)) -2.0) (/ (cos (* x_m -2.0)) (* (* s_m c_m) (* x_m (* s_m (* x_m c_m)))))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double tmp;
if (x_m <= 1.1e-25) {
tmp = pow((c_m * (x_m * s_m)), -2.0);
} else {
tmp = cos((x_m * -2.0)) / ((s_m * c_m) * (x_m * (s_m * (x_m * c_m))));
}
return tmp;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: tmp
if (x_m <= 1.1d-25) then
tmp = (c_m * (x_m * s_m)) ** (-2.0d0)
else
tmp = cos((x_m * (-2.0d0))) / ((s_m * c_m) * (x_m * (s_m * (x_m * c_m))))
end if
code = tmp
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double tmp;
if (x_m <= 1.1e-25) {
tmp = Math.pow((c_m * (x_m * s_m)), -2.0);
} else {
tmp = Math.cos((x_m * -2.0)) / ((s_m * c_m) * (x_m * (s_m * (x_m * c_m))));
}
return tmp;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): tmp = 0 if x_m <= 1.1e-25: tmp = math.pow((c_m * (x_m * s_m)), -2.0) else: tmp = math.cos((x_m * -2.0)) / ((s_m * c_m) * (x_m * (s_m * (x_m * c_m)))) return tmp
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) tmp = 0.0 if (x_m <= 1.1e-25) tmp = Float64(c_m * Float64(x_m * s_m)) ^ -2.0; else tmp = Float64(cos(Float64(x_m * -2.0)) / Float64(Float64(s_m * c_m) * Float64(x_m * Float64(s_m * Float64(x_m * c_m))))); end return tmp end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp_2 = code(x_m, c_m, s_m)
tmp = 0.0;
if (x_m <= 1.1e-25)
tmp = (c_m * (x_m * s_m)) ^ -2.0;
else
tmp = cos((x_m * -2.0)) / ((s_m * c_m) * (x_m * (s_m * (x_m * c_m))));
end
tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision] c_m = N[Abs[c], $MachinePrecision] s_m = N[Abs[s], $MachinePrecision] NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. code[x$95$m_, c$95$m_, s$95$m_] := If[LessEqual[x$95$m, 1.1e-25], N[Power[N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision], N[(N[Cos[N[(x$95$m * -2.0), $MachinePrecision]], $MachinePrecision] / N[(N[(s$95$m * c$95$m), $MachinePrecision] * N[(x$95$m * N[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1.1 \cdot 10^{-25}:\\
\;\;\;\;{\left(c\_m \cdot \left(x\_m \cdot s\_m\right)\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x\_m \cdot -2\right)}{\left(s\_m \cdot c\_m\right) \cdot \left(x\_m \cdot \left(s\_m \cdot \left(x\_m \cdot c\_m\right)\right)\right)}\\
\end{array}
\end{array}
if x < 1.1000000000000001e-25Initial program 70.6%
associate-/r*70.6%
associate-*l*70.6%
unpow270.6%
sqr-neg70.6%
unpow270.6%
*-commutative70.6%
*-commutative70.6%
associate-/r*70.6%
cos-neg70.6%
*-commutative70.6%
distribute-rgt-neg-in70.6%
metadata-eval70.6%
associate-*r*70.3%
*-commutative70.3%
unpow270.3%
sqr-neg70.3%
associate-*l*75.3%
associate-*r*76.6%
Simplified65.2%
Taylor expanded in x around inf 65.2%
associate-/r*65.2%
*-commutative65.2%
unpow265.2%
unpow265.2%
swap-sqr78.2%
unpow278.2%
associate-/r*78.2%
*-commutative78.2%
unpow278.2%
unpow278.2%
swap-sqr96.1%
unpow296.1%
associate-*r*96.6%
*-commutative96.6%
Simplified96.6%
Taylor expanded in x around 0 57.2%
associate-*r*56.1%
*-commutative56.1%
unpow256.1%
unpow256.1%
swap-sqr67.1%
unpow267.1%
swap-sqr80.2%
associate-*r*78.6%
associate-*r*79.2%
/-rgt-identity79.2%
associate-/r/79.2%
associate-/l*79.4%
associate-*l/79.4%
unpow-179.4%
unpow-179.4%
pow-sqr79.4%
metadata-eval79.4%
associate-*r*80.4%
*-commutative80.4%
associate-*r*80.8%
Simplified80.8%
if 1.1000000000000001e-25 < x Initial program 70.8%
associate-/r*71.1%
associate-*l*71.1%
unpow271.1%
sqr-neg71.1%
unpow271.1%
*-commutative71.1%
*-commutative71.1%
associate-/r*70.8%
cos-neg70.8%
*-commutative70.8%
distribute-rgt-neg-in70.8%
metadata-eval70.8%
associate-*r*72.2%
*-commutative72.2%
unpow272.2%
sqr-neg72.2%
associate-*l*76.3%
associate-*r*78.1%
Simplified63.7%
Taylor expanded in x around inf 63.7%
associate-/r*63.6%
*-commutative63.6%
unpow263.6%
unpow263.6%
swap-sqr76.4%
unpow276.4%
associate-/r*76.7%
*-commutative76.7%
unpow276.7%
unpow276.7%
swap-sqr99.3%
unpow299.3%
associate-*r*98.0%
*-commutative98.0%
Simplified98.0%
*-commutative98.0%
associate-*r*99.3%
unpow299.3%
*-commutative99.3%
associate-*r*95.7%
associate-*l*95.6%
*-commutative95.6%
associate-*r*94.3%
*-commutative94.3%
Applied egg-rr94.3%
Final simplification84.7%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (if (<= x_m 2.9e-25) (pow (* c_m (* x_m s_m)) -2.0) (/ (cos (* x_m -2.0)) (* s_m (* (* x_m c_m) (* s_m (* x_m c_m)))))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double tmp;
if (x_m <= 2.9e-25) {
tmp = pow((c_m * (x_m * s_m)), -2.0);
} else {
tmp = cos((x_m * -2.0)) / (s_m * ((x_m * c_m) * (s_m * (x_m * c_m))));
}
return tmp;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: tmp
if (x_m <= 2.9d-25) then
tmp = (c_m * (x_m * s_m)) ** (-2.0d0)
else
tmp = cos((x_m * (-2.0d0))) / (s_m * ((x_m * c_m) * (s_m * (x_m * c_m))))
end if
code = tmp
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double tmp;
if (x_m <= 2.9e-25) {
tmp = Math.pow((c_m * (x_m * s_m)), -2.0);
} else {
tmp = Math.cos((x_m * -2.0)) / (s_m * ((x_m * c_m) * (s_m * (x_m * c_m))));
}
return tmp;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): tmp = 0 if x_m <= 2.9e-25: tmp = math.pow((c_m * (x_m * s_m)), -2.0) else: tmp = math.cos((x_m * -2.0)) / (s_m * ((x_m * c_m) * (s_m * (x_m * c_m)))) return tmp
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) tmp = 0.0 if (x_m <= 2.9e-25) tmp = Float64(c_m * Float64(x_m * s_m)) ^ -2.0; else tmp = Float64(cos(Float64(x_m * -2.0)) / Float64(s_m * Float64(Float64(x_m * c_m) * Float64(s_m * Float64(x_m * c_m))))); end return tmp end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp_2 = code(x_m, c_m, s_m)
tmp = 0.0;
if (x_m <= 2.9e-25)
tmp = (c_m * (x_m * s_m)) ^ -2.0;
else
tmp = cos((x_m * -2.0)) / (s_m * ((x_m * c_m) * (s_m * (x_m * c_m))));
end
tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision] c_m = N[Abs[c], $MachinePrecision] s_m = N[Abs[s], $MachinePrecision] NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. code[x$95$m_, c$95$m_, s$95$m_] := If[LessEqual[x$95$m, 2.9e-25], N[Power[N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision], N[(N[Cos[N[(x$95$m * -2.0), $MachinePrecision]], $MachinePrecision] / N[(s$95$m * N[(N[(x$95$m * c$95$m), $MachinePrecision] * N[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.9 \cdot 10^{-25}:\\
\;\;\;\;{\left(c\_m \cdot \left(x\_m \cdot s\_m\right)\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x\_m \cdot -2\right)}{s\_m \cdot \left(\left(x\_m \cdot c\_m\right) \cdot \left(s\_m \cdot \left(x\_m \cdot c\_m\right)\right)\right)}\\
\end{array}
\end{array}
if x < 2.9000000000000001e-25Initial program 70.6%
associate-/r*70.6%
associate-*l*70.6%
unpow270.6%
sqr-neg70.6%
unpow270.6%
*-commutative70.6%
*-commutative70.6%
associate-/r*70.6%
cos-neg70.6%
*-commutative70.6%
distribute-rgt-neg-in70.6%
metadata-eval70.6%
associate-*r*70.3%
*-commutative70.3%
unpow270.3%
sqr-neg70.3%
associate-*l*75.3%
associate-*r*76.6%
Simplified65.2%
Taylor expanded in x around inf 65.2%
associate-/r*65.2%
*-commutative65.2%
unpow265.2%
unpow265.2%
swap-sqr78.2%
unpow278.2%
associate-/r*78.2%
*-commutative78.2%
unpow278.2%
unpow278.2%
swap-sqr96.1%
unpow296.1%
associate-*r*96.6%
*-commutative96.6%
Simplified96.6%
Taylor expanded in x around 0 57.2%
associate-*r*56.1%
*-commutative56.1%
unpow256.1%
unpow256.1%
swap-sqr67.1%
unpow267.1%
swap-sqr80.2%
associate-*r*78.6%
associate-*r*79.2%
/-rgt-identity79.2%
associate-/r/79.2%
associate-/l*79.4%
associate-*l/79.4%
unpow-179.4%
unpow-179.4%
pow-sqr79.4%
metadata-eval79.4%
associate-*r*80.4%
*-commutative80.4%
associate-*r*80.8%
Simplified80.8%
if 2.9000000000000001e-25 < x Initial program 70.8%
associate-/r*71.1%
associate-*l*71.1%
unpow271.1%
sqr-neg71.1%
unpow271.1%
*-commutative71.1%
*-commutative71.1%
associate-/r*70.8%
cos-neg70.8%
*-commutative70.8%
distribute-rgt-neg-in70.8%
metadata-eval70.8%
associate-*r*72.2%
*-commutative72.2%
unpow272.2%
sqr-neg72.2%
associate-*l*76.3%
associate-*r*78.1%
Simplified63.7%
Taylor expanded in x around inf 63.7%
associate-/r*63.6%
*-commutative63.6%
unpow263.6%
unpow263.6%
swap-sqr76.4%
unpow276.4%
associate-/r*76.7%
*-commutative76.7%
unpow276.7%
unpow276.7%
swap-sqr99.3%
unpow299.3%
associate-*r*98.0%
*-commutative98.0%
Simplified98.0%
unpow298.0%
*-commutative98.0%
associate-*r*98.1%
*-commutative98.1%
associate-*r*94.5%
associate-*r*94.4%
*-commutative94.4%
Applied egg-rr94.4%
Final simplification84.7%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (let* ((t_0 (* s_m (* x_m c_m)))) (/ (/ (cos (* x_m -2.0)) t_0) t_0)))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = s_m * (x_m * c_m);
return (cos((x_m * -2.0)) / t_0) / t_0;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = s_m * (x_m * c_m)
code = (cos((x_m * (-2.0d0))) / t_0) / t_0
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = s_m * (x_m * c_m);
return (Math.cos((x_m * -2.0)) / t_0) / t_0;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = s_m * (x_m * c_m) return (math.cos((x_m * -2.0)) / t_0) / t_0
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(s_m * Float64(x_m * c_m)) return Float64(Float64(cos(Float64(x_m * -2.0)) / t_0) / t_0) end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
t_0 = s_m * (x_m * c_m);
tmp = (cos((x_m * -2.0)) / t_0) / t_0;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(x$95$m * -2.0), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := s\_m \cdot \left(x\_m \cdot c\_m\right)\\
\frac{\frac{\cos \left(x\_m \cdot -2\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 70.7%
*-un-lft-identity70.7%
associate-*r*70.9%
times-frac71.0%
*-commutative71.0%
associate-*r*68.8%
pow-prod-down86.5%
Applied egg-rr86.5%
frac-times85.9%
*-un-lft-identity85.9%
add-sqr-sqrt63.0%
add-sqr-sqrt85.9%
add-sqr-sqrt39.6%
sqrt-unprod67.3%
*-commutative67.3%
*-commutative67.3%
swap-sqr67.3%
metadata-eval67.3%
metadata-eval67.3%
swap-sqr67.3%
sqrt-unprod38.2%
add-sqr-sqrt85.9%
associate-*l*79.4%
unpow279.4%
swap-sqr97.1%
associate-*r*95.3%
associate-*r*97.0%
Applied egg-rr97.8%
Final simplification97.8%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (pow (* c_m (* x_m s_m)) -2.0))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
return pow((c_m * (x_m * s_m)), -2.0);
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
code = (c_m * (x_m * s_m)) ** (-2.0d0)
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
return Math.pow((c_m * (x_m * s_m)), -2.0);
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): return math.pow((c_m * (x_m * s_m)), -2.0)
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) return Float64(c_m * Float64(x_m * s_m)) ^ -2.0 end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
tmp = (c_m * (x_m * s_m)) ^ -2.0;
end
x_m = N[Abs[x], $MachinePrecision] c_m = N[Abs[c], $MachinePrecision] s_m = N[Abs[s], $MachinePrecision] NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. code[x$95$m_, c$95$m_, s$95$m_] := N[Power[N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
{\left(c\_m \cdot \left(x\_m \cdot s\_m\right)\right)}^{-2}
\end{array}
Initial program 70.7%
associate-/r*70.8%
associate-*l*70.8%
unpow270.8%
sqr-neg70.8%
unpow270.8%
*-commutative70.8%
*-commutative70.8%
associate-/r*70.7%
cos-neg70.7%
*-commutative70.7%
distribute-rgt-neg-in70.7%
metadata-eval70.7%
associate-*r*70.9%
*-commutative70.9%
unpow270.9%
sqr-neg70.9%
associate-*l*75.6%
associate-*r*77.0%
Simplified64.7%
Taylor expanded in x around inf 64.7%
associate-/r*64.7%
*-commutative64.7%
unpow264.7%
unpow264.7%
swap-sqr77.7%
unpow277.7%
associate-/r*77.8%
*-commutative77.8%
unpow277.8%
unpow277.8%
swap-sqr97.0%
unpow297.0%
associate-*r*97.0%
*-commutative97.0%
Simplified97.0%
Taylor expanded in x around 0 55.8%
associate-*r*55.0%
*-commutative55.0%
unpow255.0%
unpow255.0%
swap-sqr65.3%
unpow265.3%
swap-sqr75.6%
associate-*r*74.5%
associate-*r*74.9%
/-rgt-identity74.9%
associate-/r/74.9%
associate-/l*75.1%
associate-*l/75.1%
unpow-175.1%
unpow-175.1%
pow-sqr75.1%
metadata-eval75.1%
associate-*r*75.7%
*-commutative75.7%
associate-*r*76.1%
Simplified76.1%
Final simplification76.1%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (let* ((t_0 (/ 1.0 (* c_m (* x_m s_m))))) (* t_0 t_0)))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = 1.0 / (c_m * (x_m * s_m));
return t_0 * t_0;
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = 1.0d0 / (c_m * (x_m * s_m))
code = t_0 * t_0
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = 1.0 / (c_m * (x_m * s_m));
return t_0 * t_0;
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = 1.0 / (c_m * (x_m * s_m)) return t_0 * t_0
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(1.0 / Float64(c_m * Float64(x_m * s_m))) return Float64(t_0 * t_0) end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
t_0 = 1.0 / (c_m * (x_m * s_m));
tmp = t_0 * t_0;
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(1.0 / N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \frac{1}{c\_m \cdot \left(x\_m \cdot s\_m\right)}\\
t\_0 \cdot t\_0
\end{array}
\end{array}
Initial program 70.7%
Taylor expanded in x around 0 55.8%
associate-/r*55.7%
*-commutative55.7%
unpow255.7%
unpow255.7%
swap-sqr65.5%
unpow265.5%
associate-/r*65.6%
unpow265.6%
unpow265.6%
swap-sqr75.9%
unpow275.9%
*-commutative75.9%
Simplified75.9%
unpow-prod-down65.6%
*-commutative65.6%
unpow-prod-down75.9%
add-sqr-sqrt75.8%
sqrt-div75.9%
metadata-eval75.9%
sqrt-pow153.0%
metadata-eval53.0%
associate-*r*53.0%
*-commutative53.0%
pow153.0%
sqrt-div53.0%
metadata-eval53.0%
sqrt-pow174.9%
metadata-eval74.9%
associate-*r*75.1%
*-commutative75.1%
pow175.1%
Applied egg-rr75.1%
associate-/r*75.1%
frac-times74.0%
*-un-lft-identity74.0%
*-commutative74.0%
*-commutative74.0%
Applied egg-rr74.0%
*-un-lft-identity74.0%
frac-times75.1%
associate-*r*74.9%
*-commutative74.9%
*-commutative74.9%
associate-/l/74.9%
*-commutative74.9%
associate-*r*76.0%
Applied egg-rr76.0%
Final simplification76.0%
x_m = (fabs.f64 x) c_m = (fabs.f64 c) s_m = (fabs.f64 s) NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function. (FPCore (x_m c_m s_m) :precision binary64 (let* ((t_0 (* c_m (* x_m s_m)))) (/ 1.0 (* t_0 t_0))))
x_m = fabs(x);
c_m = fabs(c);
s_m = fabs(s);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
double t_0 = c_m * (x_m * s_m);
return 1.0 / (t_0 * t_0);
}
x_m = abs(x)
c_m = abs(c)
s_m = abs(s)
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x_m, c_m, s_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: c_m
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = c_m * (x_m * s_m)
code = 1.0d0 / (t_0 * t_0)
end function
x_m = Math.abs(x);
c_m = Math.abs(c);
s_m = Math.abs(s);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
double t_0 = c_m * (x_m * s_m);
return 1.0 / (t_0 * t_0);
}
x_m = math.fabs(x) c_m = math.fabs(c) s_m = math.fabs(s) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): t_0 = c_m * (x_m * s_m) return 1.0 / (t_0 * t_0)
x_m = abs(x) c_m = abs(c) s_m = abs(s) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(c_m * Float64(x_m * s_m)) return Float64(1.0 / Float64(t_0 * t_0)) end
x_m = abs(x);
c_m = abs(c);
s_m = abs(s);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
t_0 = c_m * (x_m * s_m);
tmp = 1.0 / (t_0 * t_0);
end
x_m = N[Abs[x], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
s_m = N[Abs[s], $MachinePrecision]
NOTE: x_m, c_m, and s_m should be sorted in increasing order before calling this function.
code[x$95$m_, c$95$m_, s$95$m_] := Block[{t$95$0 = N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
c_m = \left|c\right|
\\
s_m = \left|s\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 70.7%
Taylor expanded in x around 0 55.8%
associate-/r*55.7%
*-commutative55.7%
unpow255.7%
unpow255.7%
swap-sqr65.5%
unpow265.5%
associate-/r*65.6%
unpow265.6%
unpow265.6%
swap-sqr75.9%
unpow275.9%
*-commutative75.9%
Simplified75.9%
unpow-prod-down65.6%
*-commutative65.6%
unpow-prod-down75.9%
add-sqr-sqrt75.8%
sqrt-div75.9%
metadata-eval75.9%
sqrt-pow153.0%
metadata-eval53.0%
associate-*r*53.0%
*-commutative53.0%
pow153.0%
sqrt-div53.0%
metadata-eval53.0%
sqrt-pow174.9%
metadata-eval74.9%
associate-*r*75.1%
*-commutative75.1%
pow175.1%
Applied egg-rr75.1%
un-div-inv75.1%
clear-num74.9%
*-commutative74.9%
associate-/r*74.9%
*-commutative74.9%
Applied egg-rr74.9%
div-inv74.9%
associate-*r*74.8%
*-commutative74.8%
*-commutative74.8%
associate-/l/74.8%
*-commutative74.8%
inv-pow74.8%
pow-flip74.8%
associate-*r*75.9%
*-commutative75.9%
*-commutative75.9%
metadata-eval75.9%
pow175.9%
Applied egg-rr75.9%
Final simplification75.9%
herbie shell --seed 2024026
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))