
(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 (* c_m (* x_m s_m))))
(if (<= x_m 5e-26)
(/ (/ t_0 t_1) t_1)
(/ t_0 (/ 1.0 (pow (* s_m (* x_m c_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) {
double t_0 = cos((x_m * 2.0));
double t_1 = c_m * (x_m * s_m);
double tmp;
if (x_m <= 5e-26) {
tmp = (t_0 / t_1) / t_1;
} else {
tmp = t_0 / (1.0 / pow((s_m * (x_m * c_m)), -2.0));
}
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 = c_m * (x_m * s_m)
if (x_m <= 5d-26) then
tmp = (t_0 / t_1) / t_1
else
tmp = t_0 / (1.0d0 / ((s_m * (x_m * c_m)) ** (-2.0d0)))
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 = c_m * (x_m * s_m);
double tmp;
if (x_m <= 5e-26) {
tmp = (t_0 / t_1) / t_1;
} else {
tmp = t_0 / (1.0 / Math.pow((s_m * (x_m * c_m)), -2.0));
}
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 = c_m * (x_m * s_m) tmp = 0 if x_m <= 5e-26: tmp = (t_0 / t_1) / t_1 else: tmp = t_0 / (1.0 / math.pow((s_m * (x_m * c_m)), -2.0)) 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(c_m * Float64(x_m * s_m)) tmp = 0.0 if (x_m <= 5e-26) tmp = Float64(Float64(t_0 / t_1) / t_1); else tmp = Float64(t_0 / Float64(1.0 / (Float64(s_m * Float64(x_m * c_m)) ^ -2.0))); 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 = c_m * (x_m * s_m);
tmp = 0.0;
if (x_m <= 5e-26)
tmp = (t_0 / t_1) / t_1;
else
tmp = t_0 / (1.0 / ((s_m * (x_m * c_m)) ^ -2.0));
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[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 5e-26], N[(N[(t$95$0 / t$95$1), $MachinePrecision] / t$95$1), $MachinePrecision], N[(t$95$0 / N[(1.0 / N[Power[N[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $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 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\
\mathbf{if}\;x\_m \leq 5 \cdot 10^{-26}:\\
\;\;\;\;\frac{\frac{t\_0}{t\_1}}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{\frac{1}{{\left(s\_m \cdot \left(x\_m \cdot c\_m\right)\right)}^{-2}}}\\
\end{array}
\end{array}
if x < 5.00000000000000019e-26Initial program 66.7%
Taylor expanded in x around inf 61.5%
associate-/r*61.5%
*-commutative61.5%
unpow261.5%
unpow261.5%
swap-sqr76.6%
unpow276.6%
associate-/r*76.7%
unpow276.7%
unpow276.7%
swap-sqr97.1%
unpow297.1%
*-commutative97.1%
Simplified97.1%
*-commutative97.1%
*-un-lft-identity97.1%
unpow297.1%
times-frac97.1%
*-commutative97.1%
*-commutative97.1%
associate-*l*95.3%
*-commutative95.3%
*-commutative95.3%
*-commutative95.3%
associate-*l*97.7%
Applied egg-rr97.7%
frac-times97.6%
*-un-lft-identity97.6%
*-commutative97.6%
associate-/r*97.7%
associate-*r*95.3%
*-commutative95.3%
*-commutative95.3%
associate-*r*97.1%
*-commutative97.1%
Applied egg-rr97.1%
if 5.00000000000000019e-26 < x Initial program 65.8%
Taylor expanded in x around inf 62.6%
associate-/r*62.6%
*-commutative62.6%
unpow262.6%
unpow262.6%
swap-sqr75.2%
unpow275.2%
associate-/r*75.2%
unpow275.2%
unpow275.2%
swap-sqr96.7%
unpow296.7%
*-commutative96.7%
Simplified96.7%
/-rgt-identity96.7%
clear-num96.6%
pow-flip96.6%
*-commutative96.6%
*-commutative96.6%
associate-*l*96.5%
metadata-eval96.5%
Applied egg-rr96.5%
Final simplification97.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 (* s_m (* x_m c_m)))
(t_1 (cos (* x_m 2.0)))
(t_2 (* c_m (* x_m s_m))))
(if (<= x_m 1e+17) (/ (/ t_1 t_2) t_2) (/ (/ t_1 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);
double t_1 = cos((x_m * 2.0));
double t_2 = c_m * (x_m * s_m);
double tmp;
if (x_m <= 1e+17) {
tmp = (t_1 / t_2) / t_2;
} else {
tmp = (t_1 / t_0) / t_0;
}
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) :: t_2
real(8) :: tmp
t_0 = s_m * (x_m * c_m)
t_1 = cos((x_m * 2.0d0))
t_2 = c_m * (x_m * s_m)
if (x_m <= 1d+17) then
tmp = (t_1 / t_2) / t_2
else
tmp = (t_1 / t_0) / t_0
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 = s_m * (x_m * c_m);
double t_1 = Math.cos((x_m * 2.0));
double t_2 = c_m * (x_m * s_m);
double tmp;
if (x_m <= 1e+17) {
tmp = (t_1 / t_2) / t_2;
} else {
tmp = (t_1 / t_0) / t_0;
}
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 = s_m * (x_m * c_m) t_1 = math.cos((x_m * 2.0)) t_2 = c_m * (x_m * s_m) tmp = 0 if x_m <= 1e+17: tmp = (t_1 / t_2) / t_2 else: tmp = (t_1 / t_0) / t_0 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 = Float64(s_m * Float64(x_m * c_m)) t_1 = cos(Float64(x_m * 2.0)) t_2 = Float64(c_m * Float64(x_m * s_m)) tmp = 0.0 if (x_m <= 1e+17) tmp = Float64(Float64(t_1 / t_2) / t_2); else tmp = Float64(Float64(t_1 / t_0) / t_0); 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 = s_m * (x_m * c_m);
t_1 = cos((x_m * 2.0));
t_2 = c_m * (x_m * s_m);
tmp = 0.0;
if (x_m <= 1e+17)
tmp = (t_1 / t_2) / t_2;
else
tmp = (t_1 / t_0) / t_0;
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[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 1e+17], N[(N[(t$95$1 / t$95$2), $MachinePrecision] / t$95$2), $MachinePrecision], N[(N[(t$95$1 / 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)\\
t_1 := \cos \left(x\_m \cdot 2\right)\\
t_2 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\
\mathbf{if}\;x\_m \leq 10^{+17}:\\
\;\;\;\;\frac{\frac{t\_1}{t\_2}}{t\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_1}{t\_0}}{t\_0}\\
\end{array}
\end{array}
if x < 1e17Initial program 66.6%
Taylor expanded in x around inf 61.7%
associate-/r*61.6%
*-commutative61.6%
unpow261.6%
unpow261.6%
swap-sqr76.1%
unpow276.1%
associate-/r*76.2%
unpow276.2%
unpow276.2%
swap-sqr97.2%
unpow297.2%
*-commutative97.2%
Simplified97.2%
*-commutative97.2%
*-un-lft-identity97.2%
unpow297.2%
times-frac97.2%
*-commutative97.2%
*-commutative97.2%
associate-*l*95.5%
*-commutative95.5%
*-commutative95.5%
*-commutative95.5%
associate-*l*97.7%
Applied egg-rr97.7%
frac-times97.7%
*-un-lft-identity97.7%
*-commutative97.7%
associate-/r*97.8%
associate-*r*95.5%
*-commutative95.5%
*-commutative95.5%
associate-*r*97.2%
*-commutative97.2%
Applied egg-rr97.2%
if 1e17 < x Initial program 66.1%
associate-/r*66.1%
cos-neg66.1%
distribute-rgt-neg-out66.1%
distribute-rgt-neg-out66.1%
*-commutative66.1%
distribute-rgt-neg-in66.1%
metadata-eval66.1%
*-commutative66.1%
associate-*l*62.4%
unpow262.4%
Simplified62.4%
Applied egg-rr96.2%
associate-*l/96.2%
*-un-lft-identity96.2%
unpow296.2%
associate-/r*96.2%
*-commutative96.2%
*-commutative96.2%
*-commutative96.2%
associate-*l*92.8%
*-commutative92.8%
*-commutative92.8%
associate-*l*96.1%
Applied egg-rr96.1%
Final simplification97.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 (cos (* x_m 2.0))) (t_1 (* c_m (* x_m s_m))))
(if (<= x_m 1.4e+36)
(/ (/ t_0 t_1) t_1)
(/ t_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 t_0 = cos((x_m * 2.0));
double t_1 = c_m * (x_m * s_m);
double tmp;
if (x_m <= 1.4e+36) {
tmp = (t_0 / t_1) / t_1;
} else {
tmp = t_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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos((x_m * 2.0d0))
t_1 = c_m * (x_m * s_m)
if (x_m <= 1.4d+36) then
tmp = (t_0 / t_1) / t_1
else
tmp = t_0 / (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 t_0 = Math.cos((x_m * 2.0));
double t_1 = c_m * (x_m * s_m);
double tmp;
if (x_m <= 1.4e+36) {
tmp = (t_0 / t_1) / t_1;
} else {
tmp = t_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): t_0 = math.cos((x_m * 2.0)) t_1 = c_m * (x_m * s_m) tmp = 0 if x_m <= 1.4e+36: tmp = (t_0 / t_1) / t_1 else: tmp = t_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) t_0 = cos(Float64(x_m * 2.0)) t_1 = Float64(c_m * Float64(x_m * s_m)) tmp = 0.0 if (x_m <= 1.4e+36) tmp = Float64(Float64(t_0 / t_1) / t_1); else tmp = Float64(t_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)
t_0 = cos((x_m * 2.0));
t_1 = c_m * (x_m * s_m);
tmp = 0.0;
if (x_m <= 1.4e+36)
tmp = (t_0 / t_1) / t_1;
else
tmp = t_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_] := Block[{t$95$0 = N[Cos[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(c$95$m * N[(x$95$m * s$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 1.4e+36], N[(N[(t$95$0 / t$95$1), $MachinePrecision] / t$95$1), $MachinePrecision], N[(t$95$0 / 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}
t_0 := \cos \left(x\_m \cdot 2\right)\\
t_1 := c\_m \cdot \left(x\_m \cdot s\_m\right)\\
\mathbf{if}\;x\_m \leq 1.4 \cdot 10^{+36}:\\
\;\;\;\;\frac{\frac{t\_0}{t\_1}}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{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 < 1.4e36Initial program 66.3%
Taylor expanded in x around inf 61.4%
associate-/r*61.3%
*-commutative61.3%
unpow261.3%
unpow261.3%
swap-sqr75.8%
unpow275.8%
associate-/r*75.8%
unpow275.8%
unpow275.8%
swap-sqr97.2%
unpow297.2%
*-commutative97.2%
Simplified97.2%
*-commutative97.2%
*-un-lft-identity97.2%
unpow297.2%
times-frac97.2%
*-commutative97.2%
*-commutative97.2%
associate-*l*95.5%
*-commutative95.5%
*-commutative95.5%
*-commutative95.5%
associate-*l*97.7%
Applied egg-rr97.7%
frac-times97.7%
*-un-lft-identity97.7%
*-commutative97.7%
associate-/r*97.8%
associate-*r*95.5%
*-commutative95.5%
*-commutative95.5%
associate-*r*97.2%
*-commutative97.2%
Applied egg-rr97.2%
if 1.4e36 < x Initial program 67.1%
Taylor expanded in x around inf 63.3%
associate-/r*63.3%
*-commutative63.3%
unpow263.3%
unpow263.3%
swap-sqr78.0%
unpow278.0%
associate-/r*78.0%
unpow278.0%
unpow278.0%
swap-sqr96.2%
unpow296.2%
*-commutative96.2%
Simplified96.2%
unpow296.2%
associate-*r*92.7%
associate-*r*89.3%
*-commutative89.3%
*-commutative89.3%
associate-*l*92.8%
*-commutative92.8%
Applied egg-rr92.8%
Final simplification96.3%
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 4.1e-8) (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 <= 4.1e-8) {
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 <= 4.1d-8) 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 <= 4.1e-8) {
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 <= 4.1e-8: 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 <= 4.1e-8) 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 <= 4.1e-8)
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, 4.1e-8], 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 4.1 \cdot 10^{-8}:\\
\;\;\;\;{\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 < 4.10000000000000032e-8Initial program 66.2%
associate-/r*66.2%
cos-neg66.2%
distribute-rgt-neg-out66.2%
distribute-rgt-neg-out66.2%
*-commutative66.2%
distribute-rgt-neg-in66.2%
metadata-eval66.2%
*-commutative66.2%
associate-*l*61.1%
unpow261.1%
Simplified61.1%
Taylor expanded in x around 0 59.6%
associate-/r*59.5%
*-commutative59.5%
unpow259.5%
unpow259.5%
swap-sqr70.5%
unpow270.5%
associate-/r*70.6%
unpow270.6%
unpow270.6%
swap-sqr87.6%
unpow287.6%
Simplified87.6%
*-un-lft-identity87.6%
pow-flip87.6%
*-commutative87.6%
*-commutative87.6%
associate-*l*87.8%
metadata-eval87.8%
Applied egg-rr87.8%
*-lft-identity87.8%
associate-*r*87.6%
*-commutative87.6%
*-commutative87.6%
*-commutative87.6%
Simplified87.6%
if 4.10000000000000032e-8 < x Initial program 67.4%
Taylor expanded in x around inf 64.0%
associate-/r*64.0%
*-commutative64.0%
unpow264.0%
unpow264.0%
swap-sqr77.2%
unpow277.2%
associate-/r*77.2%
unpow277.2%
unpow277.2%
swap-sqr96.5%
unpow296.5%
*-commutative96.5%
Simplified96.5%
unpow296.5%
associate-*r*93.4%
associate-*r*90.4%
*-commutative90.4%
*-commutative90.4%
associate-*l*93.5%
*-commutative93.5%
Applied egg-rr93.5%
Final simplification89.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 (if (<= x_m 1.4e-7) (pow (* c_m (* x_m s_m)) -2.0) (/ (cos (* x_m 2.0)) (* (* c_m (* s_m (* x_m c_m))) (* x_m s_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.4e-7) {
tmp = pow((c_m * (x_m * s_m)), -2.0);
} else {
tmp = cos((x_m * 2.0)) / ((c_m * (s_m * (x_m * c_m))) * (x_m * s_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.4d-7) then
tmp = (c_m * (x_m * s_m)) ** (-2.0d0)
else
tmp = cos((x_m * 2.0d0)) / ((c_m * (s_m * (x_m * c_m))) * (x_m * s_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.4e-7) {
tmp = Math.pow((c_m * (x_m * s_m)), -2.0);
} else {
tmp = Math.cos((x_m * 2.0)) / ((c_m * (s_m * (x_m * c_m))) * (x_m * s_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.4e-7: tmp = math.pow((c_m * (x_m * s_m)), -2.0) else: tmp = math.cos((x_m * 2.0)) / ((c_m * (s_m * (x_m * c_m))) * (x_m * s_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.4e-7) tmp = Float64(c_m * Float64(x_m * s_m)) ^ -2.0; else tmp = Float64(cos(Float64(x_m * 2.0)) / Float64(Float64(c_m * Float64(s_m * Float64(x_m * c_m))) * Float64(x_m * s_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.4e-7)
tmp = (c_m * (x_m * s_m)) ^ -2.0;
else
tmp = cos((x_m * 2.0)) / ((c_m * (s_m * (x_m * c_m))) * (x_m * s_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.4e-7], 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[(c$95$m * N[(s$95$m * N[(x$95$m * c$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(x$95$m * s$95$m), $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.4 \cdot 10^{-7}:\\
\;\;\;\;{\left(c\_m \cdot \left(x\_m \cdot s\_m\right)\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x\_m \cdot 2\right)}{\left(c\_m \cdot \left(s\_m \cdot \left(x\_m \cdot c\_m\right)\right)\right) \cdot \left(x\_m \cdot s\_m\right)}\\
\end{array}
\end{array}
if x < 1.4000000000000001e-7Initial program 66.2%
associate-/r*66.2%
cos-neg66.2%
distribute-rgt-neg-out66.2%
distribute-rgt-neg-out66.2%
*-commutative66.2%
distribute-rgt-neg-in66.2%
metadata-eval66.2%
*-commutative66.2%
associate-*l*61.1%
unpow261.1%
Simplified61.1%
Taylor expanded in x around 0 59.6%
associate-/r*59.5%
*-commutative59.5%
unpow259.5%
unpow259.5%
swap-sqr70.5%
unpow270.5%
associate-/r*70.6%
unpow270.6%
unpow270.6%
swap-sqr87.6%
unpow287.6%
Simplified87.6%
*-un-lft-identity87.6%
pow-flip87.6%
*-commutative87.6%
*-commutative87.6%
associate-*l*87.8%
metadata-eval87.8%
Applied egg-rr87.8%
*-lft-identity87.8%
associate-*r*87.6%
*-commutative87.6%
*-commutative87.6%
*-commutative87.6%
Simplified87.6%
if 1.4000000000000001e-7 < x Initial program 67.4%
Taylor expanded in x around inf 64.0%
associate-/r*64.0%
*-commutative64.0%
unpow264.0%
unpow264.0%
swap-sqr77.2%
unpow277.2%
associate-/r*77.2%
unpow277.2%
unpow277.2%
swap-sqr96.5%
unpow296.5%
*-commutative96.5%
Simplified96.5%
unpow296.5%
associate-*r*91.5%
*-commutative91.5%
*-commutative91.5%
associate-*l*89.9%
Applied egg-rr89.9%
Final simplification88.2%
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 66.5%
associate-/r*66.5%
cos-neg66.5%
distribute-rgt-neg-out66.5%
distribute-rgt-neg-out66.5%
*-commutative66.5%
distribute-rgt-neg-in66.5%
metadata-eval66.5%
*-commutative66.5%
associate-*l*61.8%
unpow261.8%
Simplified61.8%
Taylor expanded in x around 0 57.8%
associate-/r*57.8%
*-commutative57.8%
unpow257.8%
unpow257.8%
swap-sqr67.6%
unpow267.6%
associate-/r*67.6%
unpow267.6%
unpow267.6%
swap-sqr81.9%
unpow281.9%
Simplified81.9%
*-un-lft-identity81.9%
pow-flip81.9%
*-commutative81.9%
*-commutative81.9%
associate-*l*82.0%
metadata-eval82.0%
Applied egg-rr82.0%
*-lft-identity82.0%
associate-*r*81.9%
*-commutative81.9%
*-commutative81.9%
*-commutative81.9%
Simplified81.9%
Final simplification81.9%
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 66.5%
associate-/r*66.5%
cos-neg66.5%
distribute-rgt-neg-out66.5%
distribute-rgt-neg-out66.5%
*-commutative66.5%
distribute-rgt-neg-in66.5%
metadata-eval66.5%
*-commutative66.5%
associate-*l*61.8%
unpow261.8%
Simplified61.8%
Taylor expanded in x around 0 57.8%
associate-/r*57.8%
*-commutative57.8%
unpow257.8%
unpow257.8%
swap-sqr67.6%
unpow267.6%
associate-/r*67.6%
unpow267.6%
unpow267.6%
swap-sqr81.9%
unpow281.9%
Simplified81.9%
add-sqr-sqrt81.9%
sqrt-unprod74.4%
pow-prod-up74.4%
*-commutative74.4%
*-commutative74.4%
associate-*l*74.4%
metadata-eval74.4%
Applied egg-rr74.4%
associate-*r*74.4%
*-commutative74.4%
*-commutative74.4%
*-commutative74.4%
Simplified74.4%
sqrt-pow181.9%
metadata-eval81.9%
unpow-prod-down67.6%
pow267.6%
pow267.6%
swap-sqr81.9%
Applied egg-rr81.9%
Final simplification81.9%
herbie shell --seed 2024145
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))