
(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 6 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 (* c_m (* s_m x_m))))
(if (<= x_m 2.7e-14)
(/ (/ 1.0 t_0) t_0)
(*
(/ 1.0 s_m)
(/ (/ (cos (* x_m 2.0)) (* s_m (* c_m x_m))) (* c_m x_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 = c_m * (s_m * x_m);
double tmp;
if (x_m <= 2.7e-14) {
tmp = (1.0 / t_0) / t_0;
} else {
tmp = (1.0 / s_m) * ((cos((x_m * 2.0)) / (s_m * (c_m * x_m))) / (c_m * x_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) :: tmp
t_0 = c_m * (s_m * x_m)
if (x_m <= 2.7d-14) then
tmp = (1.0d0 / t_0) / t_0
else
tmp = (1.0d0 / s_m) * ((cos((x_m * 2.0d0)) / (s_m * (c_m * x_m))) / (c_m * x_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 = c_m * (s_m * x_m);
double tmp;
if (x_m <= 2.7e-14) {
tmp = (1.0 / t_0) / t_0;
} else {
tmp = (1.0 / s_m) * ((Math.cos((x_m * 2.0)) / (s_m * (c_m * x_m))) / (c_m * x_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 = c_m * (s_m * x_m) tmp = 0 if x_m <= 2.7e-14: tmp = (1.0 / t_0) / t_0 else: tmp = (1.0 / s_m) * ((math.cos((x_m * 2.0)) / (s_m * (c_m * x_m))) / (c_m * x_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 = Float64(c_m * Float64(s_m * x_m)) tmp = 0.0 if (x_m <= 2.7e-14) tmp = Float64(Float64(1.0 / t_0) / t_0); else tmp = Float64(Float64(1.0 / s_m) * Float64(Float64(cos(Float64(x_m * 2.0)) / Float64(s_m * Float64(c_m * x_m))) / Float64(c_m * x_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 = c_m * (s_m * x_m);
tmp = 0.0;
if (x_m <= 2.7e-14)
tmp = (1.0 / t_0) / t_0;
else
tmp = (1.0 / s_m) * ((cos((x_m * 2.0)) / (s_m * (c_m * x_m))) / (c_m * x_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[(c$95$m * N[(s$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x$95$m, 2.7e-14], N[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(1.0 / s$95$m), $MachinePrecision] * N[(N[(N[Cos[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision] / N[(s$95$m * N[(c$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c$95$m * x$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}
t_0 := c\_m \cdot \left(s\_m \cdot x\_m\right)\\
\mathbf{if}\;x\_m \leq 2.7 \cdot 10^{-14}:\\
\;\;\;\;\frac{\frac{1}{t\_0}}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s\_m} \cdot \frac{\frac{\cos \left(x\_m \cdot 2\right)}{s\_m \cdot \left(c\_m \cdot x\_m\right)}}{c\_m \cdot x\_m}\\
\end{array}
\end{array}
if x < 2.6999999999999999e-14Initial program 63.7%
associate-/r*63.7%
cos-neg63.7%
distribute-rgt-neg-out63.7%
distribute-rgt-neg-out63.7%
*-commutative63.7%
distribute-rgt-neg-in63.7%
metadata-eval63.7%
*-commutative63.7%
associate-*l*57.9%
unpow257.9%
Simplified57.9%
Applied egg-rr97.0%
associate-*l/97.1%
*-un-lft-identity97.1%
*-commutative97.1%
Applied egg-rr97.1%
Taylor expanded in x around 0 89.6%
if 2.6999999999999999e-14 < x Initial program 67.4%
associate-/r*68.3%
cos-neg68.3%
distribute-rgt-neg-out68.3%
distribute-rgt-neg-out68.3%
*-commutative68.3%
distribute-rgt-neg-in68.3%
metadata-eval68.3%
*-commutative68.3%
associate-*l*64.5%
unpow264.5%
Simplified64.5%
associate-/l/64.4%
add-sqr-sqrt39.5%
add-sqr-sqrt64.4%
add-sqr-sqrt0.0%
sqrt-unprod36.6%
swap-sqr36.6%
metadata-eval36.6%
metadata-eval36.6%
swap-sqr36.6%
*-commutative36.6%
*-commutative36.6%
sqrt-unprod61.7%
add-sqr-sqrt64.4%
*-un-lft-identity64.4%
*-commutative64.4%
unpow264.4%
associate-*r*67.4%
associate-*l*70.9%
*-commutative70.9%
*-commutative70.9%
Applied egg-rr90.4%
Taylor expanded in c around 0 64.4%
associate-/r*64.5%
*-commutative64.5%
*-commutative64.5%
unpow264.5%
unpow264.5%
swap-sqr79.8%
unpow279.8%
associate-/l/78.8%
*-commutative78.8%
unpow278.8%
unpow278.8%
swap-sqr92.5%
associate-/r*94.2%
*-lft-identity94.2%
associate-*r/94.2%
associate-*l/94.2%
associate-/r/94.2%
associate-/l/92.4%
Simplified94.9%
*-commutative94.9%
*-commutative94.9%
associate-*r*98.3%
*-commutative98.3%
unpow-prod-down84.1%
metadata-eval84.1%
pow-flip83.4%
pow283.4%
metadata-eval83.4%
pow-prod-up83.4%
inv-pow83.4%
inv-pow83.4%
un-div-inv83.4%
times-frac90.4%
*-un-lft-identity90.4%
associate-/l/88.5%
div-inv88.6%
*-commutative88.6%
Applied egg-rr94.0%
unpow294.0%
*-commutative94.0%
associate-*r*88.6%
associate-*r*87.4%
associate-/r*88.3%
*-commutative88.3%
associate-*r*90.9%
*-commutative90.9%
associate-/l/91.6%
associate-/r*94.2%
*-un-lft-identity94.2%
associate-*r*89.5%
*-commutative89.5%
times-frac86.0%
Applied egg-rr91.4%
Final simplification90.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 (* (pow (* s_m (* c_m x_m)) -2.0) (cos (* x_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((s_m * (c_m * x_m)), -2.0) * cos((x_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 = ((s_m * (c_m * x_m)) ** (-2.0d0)) * cos((x_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((s_m * (c_m * x_m)), -2.0) * Math.cos((x_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((s_m * (c_m * x_m)), -2.0) * math.cos((x_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((Float64(s_m * Float64(c_m * x_m)) ^ -2.0) * cos(Float64(x_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 = ((s_m * (c_m * x_m)) ^ -2.0) * cos((x_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[(N[Power[N[(s$95$m * N[(c$95$m * x$95$m), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision] * N[Cos[N[(x$95$m * 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])\\
\\
{\left(s\_m \cdot \left(c\_m \cdot x\_m\right)\right)}^{-2} \cdot \cos \left(x\_m \cdot 2\right)
\end{array}
Initial program 64.7%
associate-/r*65.0%
cos-neg65.0%
distribute-rgt-neg-out65.0%
distribute-rgt-neg-out65.0%
*-commutative65.0%
distribute-rgt-neg-in65.0%
metadata-eval65.0%
*-commutative65.0%
associate-*l*59.7%
unpow259.7%
Simplified59.7%
associate-/l/59.7%
add-sqr-sqrt44.6%
add-sqr-sqrt59.7%
add-sqr-sqrt24.7%
sqrt-unprod43.8%
swap-sqr43.8%
metadata-eval43.8%
metadata-eval43.8%
swap-sqr43.8%
*-commutative43.8%
*-commutative43.8%
sqrt-unprod33.7%
add-sqr-sqrt59.7%
*-un-lft-identity59.7%
*-commutative59.7%
unpow259.7%
associate-*r*64.7%
associate-*l*67.7%
*-commutative67.7%
*-commutative67.7%
Applied egg-rr87.6%
Taylor expanded in c around 0 59.7%
associate-/r*59.7%
*-commutative59.7%
*-commutative59.7%
unpow259.7%
unpow259.7%
swap-sqr78.1%
unpow278.1%
associate-/l/77.8%
*-commutative77.8%
unpow277.8%
unpow277.8%
swap-sqr95.6%
associate-/r*96.3%
*-lft-identity96.3%
associate-*r/96.3%
associate-*l/96.3%
associate-/r/96.3%
associate-/l/95.6%
Simplified98.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
(let* ((t_0 (* s_m (* c_m x_m))) (t_1 (cos (* x_m 2.0))))
(if (<= x_m 2.7e-34)
(/ (/ t_1 c_m) (* (* s_m x_m) (* c_m (* s_m x_m))))
(/ 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 * (c_m * x_m);
double t_1 = cos((x_m * 2.0));
double tmp;
if (x_m <= 2.7e-34) {
tmp = (t_1 / c_m) / ((s_m * x_m) * (c_m * (s_m * x_m)));
} 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) :: tmp
t_0 = s_m * (c_m * x_m)
t_1 = cos((x_m * 2.0d0))
if (x_m <= 2.7d-34) then
tmp = (t_1 / c_m) / ((s_m * x_m) * (c_m * (s_m * x_m)))
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 * (c_m * x_m);
double t_1 = Math.cos((x_m * 2.0));
double tmp;
if (x_m <= 2.7e-34) {
tmp = (t_1 / c_m) / ((s_m * x_m) * (c_m * (s_m * x_m)));
} 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 * (c_m * x_m) t_1 = math.cos((x_m * 2.0)) tmp = 0 if x_m <= 2.7e-34: tmp = (t_1 / c_m) / ((s_m * x_m) * (c_m * (s_m * x_m))) 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(c_m * x_m)) t_1 = cos(Float64(x_m * 2.0)) tmp = 0.0 if (x_m <= 2.7e-34) tmp = Float64(Float64(t_1 / c_m) / Float64(Float64(s_m * x_m) * Float64(c_m * Float64(s_m * x_m)))); else tmp = Float64(t_1 / Float64(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 * (c_m * x_m);
t_1 = cos((x_m * 2.0));
tmp = 0.0;
if (x_m <= 2.7e-34)
tmp = (t_1 / c_m) / ((s_m * x_m) * (c_m * (s_m * x_m)));
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[(c$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x$95$m, 2.7e-34], N[(N[(t$95$1 / c$95$m), $MachinePrecision] / N[(N[(s$95$m * x$95$m), $MachinePrecision] * N[(c$95$m * N[(s$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 / 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 := s\_m \cdot \left(c\_m \cdot x\_m\right)\\
t_1 := \cos \left(x\_m \cdot 2\right)\\
\mathbf{if}\;x\_m \leq 2.7 \cdot 10^{-34}:\\
\;\;\;\;\frac{\frac{t\_1}{c\_m}}{\left(s\_m \cdot x\_m\right) \cdot \left(c\_m \cdot \left(s\_m \cdot x\_m\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{t\_0 \cdot t\_0}\\
\end{array}
\end{array}
if x < 2.70000000000000017e-34Initial program 63.7%
associate-/r*63.7%
cos-neg63.7%
distribute-rgt-neg-out63.7%
distribute-rgt-neg-out63.7%
*-commutative63.7%
distribute-rgt-neg-in63.7%
metadata-eval63.7%
*-commutative63.7%
associate-*l*57.8%
unpow257.8%
Simplified57.8%
Applied egg-rr97.0%
associate-/r*97.1%
frac-times93.3%
metadata-eval93.3%
times-frac93.3%
*-un-lft-identity93.3%
*-un-lft-identity93.3%
*-commutative93.3%
Applied egg-rr93.3%
if 2.70000000000000017e-34 < x Initial program 67.3%
associate-/r*68.3%
cos-neg68.3%
distribute-rgt-neg-out68.3%
distribute-rgt-neg-out68.3%
*-commutative68.3%
distribute-rgt-neg-in68.3%
metadata-eval68.3%
*-commutative68.3%
associate-*l*64.5%
unpow264.5%
Simplified64.5%
associate-/l/64.5%
add-sqr-sqrt40.7%
add-sqr-sqrt64.5%
add-sqr-sqrt0.0%
sqrt-unprod37.8%
swap-sqr37.8%
metadata-eval37.8%
metadata-eval37.8%
swap-sqr37.8%
*-commutative37.8%
*-commutative37.8%
sqrt-unprod61.9%
add-sqr-sqrt64.5%
*-un-lft-identity64.5%
*-commutative64.5%
unpow264.5%
associate-*r*67.3%
associate-*l*70.7%
*-commutative70.7%
*-commutative70.7%
Applied egg-rr90.8%
Taylor expanded in c around 0 64.5%
associate-/r*64.5%
*-commutative64.5%
*-commutative64.5%
unpow264.5%
unpow264.5%
swap-sqr79.2%
unpow279.2%
associate-/l/78.3%
*-commutative78.3%
unpow278.3%
unpow278.3%
swap-sqr92.8%
associate-/r*94.4%
*-lft-identity94.4%
associate-*r/94.4%
associate-*l/94.4%
associate-/r/94.4%
associate-/l/92.7%
Simplified95.1%
*-commutative95.1%
*-commutative95.1%
associate-*r*98.4%
*-commutative98.4%
unpow-prod-down84.7%
metadata-eval84.7%
pow-flip84.1%
pow284.1%
metadata-eval84.1%
pow-prod-up84.0%
inv-pow84.0%
inv-pow84.0%
un-div-inv84.1%
times-frac90.8%
*-un-lft-identity90.8%
associate-/l/89.0%
div-inv89.1%
*-commutative89.1%
Applied egg-rr94.2%
unpow294.2%
*-commutative94.2%
*-commutative94.2%
Applied egg-rr94.2%
Final simplification93.6%
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 (* c_m x_m))) (t_1 (/ (/ (/ 1.0 x_m) s_m) c_m))) (if (<= x_m 3.6e-13) (* t_1 t_1) (/ (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 * (c_m * x_m);
double t_1 = ((1.0 / x_m) / s_m) / c_m;
double tmp;
if (x_m <= 3.6e-13) {
tmp = t_1 * t_1;
} else {
tmp = cos((x_m * 2.0)) / (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) :: tmp
t_0 = s_m * (c_m * x_m)
t_1 = ((1.0d0 / x_m) / s_m) / c_m
if (x_m <= 3.6d-13) then
tmp = t_1 * t_1
else
tmp = cos((x_m * 2.0d0)) / (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 * (c_m * x_m);
double t_1 = ((1.0 / x_m) / s_m) / c_m;
double tmp;
if (x_m <= 3.6e-13) {
tmp = t_1 * t_1;
} else {
tmp = Math.cos((x_m * 2.0)) / (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 * (c_m * x_m) t_1 = ((1.0 / x_m) / s_m) / c_m tmp = 0 if x_m <= 3.6e-13: tmp = t_1 * t_1 else: tmp = math.cos((x_m * 2.0)) / (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(c_m * x_m)) t_1 = Float64(Float64(Float64(1.0 / x_m) / s_m) / c_m) tmp = 0.0 if (x_m <= 3.6e-13) tmp = Float64(t_1 * t_1); else tmp = Float64(cos(Float64(x_m * 2.0)) / Float64(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 * (c_m * x_m);
t_1 = ((1.0 / x_m) / s_m) / c_m;
tmp = 0.0;
if (x_m <= 3.6e-13)
tmp = t_1 * t_1;
else
tmp = cos((x_m * 2.0)) / (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[(c$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 / x$95$m), $MachinePrecision] / s$95$m), $MachinePrecision] / c$95$m), $MachinePrecision]}, If[LessEqual[x$95$m, 3.6e-13], N[(t$95$1 * t$95$1), $MachinePrecision], N[(N[Cos[N[(x$95$m * 2.0), $MachinePrecision]], $MachinePrecision] / 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 := s\_m \cdot \left(c\_m \cdot x\_m\right)\\
t_1 := \frac{\frac{\frac{1}{x\_m}}{s\_m}}{c\_m}\\
\mathbf{if}\;x\_m \leq 3.6 \cdot 10^{-13}:\\
\;\;\;\;t\_1 \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x\_m \cdot 2\right)}{t\_0 \cdot t\_0}\\
\end{array}
\end{array}
if x < 3.5999999999999998e-13Initial program 63.9%
associate-/r*63.9%
cos-neg63.9%
distribute-rgt-neg-out63.9%
distribute-rgt-neg-out63.9%
*-commutative63.9%
distribute-rgt-neg-in63.9%
metadata-eval63.9%
*-commutative63.9%
associate-*l*58.1%
unpow258.1%
Simplified58.1%
associate-/l/58.1%
add-sqr-sqrt46.7%
add-sqr-sqrt58.1%
add-sqr-sqrt33.8%
sqrt-unprod46.8%
swap-sqr46.8%
metadata-eval46.8%
metadata-eval46.8%
swap-sqr46.8%
*-commutative46.8%
*-commutative46.8%
sqrt-unprod23.5%
add-sqr-sqrt58.1%
*-un-lft-identity58.1%
*-commutative58.1%
unpow258.1%
associate-*r*63.9%
associate-*l*66.6%
*-commutative66.6%
*-commutative66.6%
Applied egg-rr86.7%
Taylor expanded in c around 0 58.1%
associate-/r*58.1%
*-commutative58.1%
*-commutative58.1%
unpow258.1%
unpow258.1%
swap-sqr77.5%
unpow277.5%
associate-/l/77.5%
*-commutative77.5%
unpow277.5%
unpow277.5%
swap-sqr96.8%
associate-/r*97.1%
*-lft-identity97.1%
associate-*r/97.1%
associate-*l/97.1%
associate-/r/97.0%
associate-/l/96.7%
Simplified99.6%
Taylor expanded in x around 0 55.7%
associate-*r*55.6%
*-commutative55.6%
associate-*l*55.7%
unpow255.7%
unpow255.7%
unpow255.7%
swap-sqr67.8%
swap-sqr91.4%
unpow291.4%
exp-to-pow54.6%
exp-to-pow91.4%
*-commutative91.4%
*-commutative91.4%
associate-*r*88.3%
Simplified88.3%
pow-flip88.6%
*-commutative88.6%
*-commutative88.6%
associate-*r*91.7%
*-commutative91.7%
associate-*r*89.6%
sqr-pow89.6%
metadata-eval89.6%
metadata-eval89.6%
metadata-eval89.6%
metadata-eval89.6%
inv-pow89.6%
inv-pow89.6%
*-commutative89.6%
associate-/r*89.6%
associate-/r*89.7%
*-commutative89.7%
associate-/r*89.7%
associate-/r*89.6%
Applied egg-rr89.6%
if 3.5999999999999998e-13 < x Initial program 66.9%
associate-/r*67.9%
cos-neg67.9%
distribute-rgt-neg-out67.9%
distribute-rgt-neg-out67.9%
*-commutative67.9%
distribute-rgt-neg-in67.9%
metadata-eval67.9%
*-commutative67.9%
associate-*l*64.0%
unpow264.0%
Simplified64.0%
associate-/l/63.9%
add-sqr-sqrt38.7%
add-sqr-sqrt63.9%
add-sqr-sqrt0.0%
sqrt-unprod35.7%
swap-sqr35.7%
metadata-eval35.7%
metadata-eval35.7%
swap-sqr35.7%
*-commutative35.7%
*-commutative35.7%
sqrt-unprod61.2%
add-sqr-sqrt63.9%
*-un-lft-identity63.9%
*-commutative63.9%
unpow263.9%
associate-*r*66.9%
associate-*l*70.5%
*-commutative70.5%
*-commutative70.5%
Applied egg-rr90.2%
Taylor expanded in c around 0 63.9%
associate-/r*64.0%
*-commutative64.0%
*-commutative64.0%
unpow264.0%
unpow264.0%
swap-sqr79.5%
unpow279.5%
associate-/l/78.5%
*-commutative78.5%
unpow278.5%
unpow278.5%
swap-sqr92.4%
associate-/r*94.1%
*-lft-identity94.1%
associate-*r/94.1%
associate-*l/94.2%
associate-/r/94.2%
associate-/l/92.4%
Simplified94.8%
*-commutative94.8%
*-commutative94.8%
associate-*r*98.3%
*-commutative98.3%
unpow-prod-down83.8%
metadata-eval83.8%
pow-flip83.2%
pow283.2%
metadata-eval83.2%
pow-prod-up83.2%
inv-pow83.2%
inv-pow83.2%
un-div-inv83.2%
times-frac90.2%
*-un-lft-identity90.2%
associate-/l/88.4%
div-inv88.4%
*-commutative88.4%
Applied egg-rr93.9%
unpow293.9%
*-commutative93.9%
*-commutative93.9%
Applied egg-rr93.9%
Final simplification90.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 (let* ((t_0 (* c_m (* s_m x_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 * (s_m * x_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 * (s_m * x_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 * (s_m * x_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 * (s_m * x_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(s_m * x_m)) return Float64(Float64(1.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 = c_m * (s_m * x_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[(s$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]}, N[(N[(1.0 / 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 := c\_m \cdot \left(s\_m \cdot x\_m\right)\\
\frac{\frac{1}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 64.7%
associate-/r*65.0%
cos-neg65.0%
distribute-rgt-neg-out65.0%
distribute-rgt-neg-out65.0%
*-commutative65.0%
distribute-rgt-neg-in65.0%
metadata-eval65.0%
*-commutative65.0%
associate-*l*59.7%
unpow259.7%
Simplified59.7%
Applied egg-rr96.3%
associate-*l/96.3%
*-un-lft-identity96.3%
*-commutative96.3%
Applied egg-rr96.3%
Taylor expanded in x around 0 83.1%
Final simplification83.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 (* c_m (* s_m x_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 * (s_m * x_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 * (s_m * x_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 * (s_m * x_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 * (s_m * x_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(s_m * x_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 * (s_m * x_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[(s$95$m * x$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(s\_m \cdot x\_m\right)\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 64.7%
associate-/r*65.0%
cos-neg65.0%
distribute-rgt-neg-out65.0%
distribute-rgt-neg-out65.0%
*-commutative65.0%
distribute-rgt-neg-in65.0%
metadata-eval65.0%
*-commutative65.0%
associate-*l*59.7%
unpow259.7%
Simplified59.7%
Taylor expanded in x around 0 55.9%
associate-/r*55.9%
*-commutative55.9%
unpow255.9%
unpow255.9%
swap-sqr70.6%
unpow270.6%
associate-/r*70.6%
unpow270.6%
unpow270.6%
swap-sqr82.9%
unpow282.9%
Simplified82.9%
unpow282.9%
Applied egg-rr82.9%
Final simplification82.9%
herbie shell --seed 2024135
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))