
(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 5 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}
s_m = (fabs.f64 s) c_m = (fabs.f64 c) x_m = (fabs.f64 x) 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 4e-43) (/ 1.0 (* (* (* (* s_m x_m) c_m) (* s_m x_m)) c_m)) (* (cos (* 2.0 x_m)) (pow (* (* c_m x_m) s_m) -2.0))))
s_m = fabs(s);
c_m = fabs(c);
x_m = fabs(x);
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 <= 4e-43) {
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
} else {
tmp = cos((2.0 * x_m)) * pow(((c_m * x_m) * s_m), -2.0);
}
return tmp;
}
s_m = abs(s)
c_m = abs(c)
x_m = abs(x)
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 <= 4d-43) then
tmp = 1.0d0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m)
else
tmp = cos((2.0d0 * x_m)) * (((c_m * x_m) * s_m) ** (-2.0d0))
end if
code = tmp
end function
s_m = Math.abs(s);
c_m = Math.abs(c);
x_m = Math.abs(x);
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 <= 4e-43) {
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
} else {
tmp = Math.cos((2.0 * x_m)) * Math.pow(((c_m * x_m) * s_m), -2.0);
}
return tmp;
}
s_m = math.fabs(s) c_m = math.fabs(c) x_m = math.fabs(x) [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 <= 4e-43: tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m) else: tmp = math.cos((2.0 * x_m)) * math.pow(((c_m * x_m) * s_m), -2.0) return tmp
s_m = abs(s) c_m = abs(c) x_m = abs(x) 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 <= 4e-43) tmp = Float64(1.0 / Float64(Float64(Float64(Float64(s_m * x_m) * c_m) * Float64(s_m * x_m)) * c_m)); else tmp = Float64(cos(Float64(2.0 * x_m)) * (Float64(Float64(c_m * x_m) * s_m) ^ -2.0)); end return tmp end
s_m = abs(s);
c_m = abs(c);
x_m = abs(x);
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 <= 4e-43)
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
else
tmp = cos((2.0 * x_m)) * (((c_m * x_m) * s_m) ^ -2.0);
end
tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision] c_m = N[Abs[c], $MachinePrecision] x_m = N[Abs[x], $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, 4e-43], N[(1.0 / N[(N[(N[(N[(s$95$m * x$95$m), $MachinePrecision] * c$95$m), $MachinePrecision] * N[(s$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] * N[Power[N[(N[(c$95$m * x$95$m), $MachinePrecision] * s$95$m), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
c_m = \left|c\right|
\\
x_m = \left|x\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 4 \cdot 10^{-43}:\\
\;\;\;\;\frac{1}{\left(\left(\left(s\_m \cdot x\_m\right) \cdot c\_m\right) \cdot \left(s\_m \cdot x\_m\right)\right) \cdot c\_m}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(2 \cdot x\_m\right) \cdot {\left(\left(c\_m \cdot x\_m\right) \cdot s\_m\right)}^{-2}\\
\end{array}
\end{array}
if x < 4.00000000000000031e-43Initial program 63.4%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6496.1
Applied rewrites96.1%
Taylor expanded in x around 0
Applied rewrites82.9%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6472.4
Applied rewrites72.4%
Applied rewrites80.0%
if 4.00000000000000031e-43 < x Initial program 68.8%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-/l*N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites84.1%
Applied rewrites99.0%
Final simplification84.5%
s_m = (fabs.f64 s)
c_m = (fabs.f64 c)
x_m = (fabs.f64 x)
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)))
(if (<=
(/ (cos (* 2.0 x_m)) (* (* (* (pow s_m 2.0) x_m) x_m) (pow c_m 2.0)))
-5e-142)
(/ (fma -2.0 (* x_m x_m) 1.0) (* t_0 t_0))
(/ 1.0 (* (* (* (* s_m x_m) c_m) (* s_m x_m)) c_m)))))s_m = fabs(s);
c_m = fabs(c);
x_m = fabs(x);
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;
double tmp;
if ((cos((2.0 * x_m)) / (((pow(s_m, 2.0) * x_m) * x_m) * pow(c_m, 2.0))) <= -5e-142) {
tmp = fma(-2.0, (x_m * x_m), 1.0) / (t_0 * t_0);
} else {
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
}
return tmp;
}
s_m = abs(s) c_m = abs(c) x_m = abs(x) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(Float64(c_m * x_m) * s_m) tmp = 0.0 if (Float64(cos(Float64(2.0 * x_m)) / Float64(Float64(Float64((s_m ^ 2.0) * x_m) * x_m) * (c_m ^ 2.0))) <= -5e-142) tmp = Float64(fma(-2.0, Float64(x_m * x_m), 1.0) / Float64(t_0 * t_0)); else tmp = Float64(1.0 / Float64(Float64(Float64(Float64(s_m * x_m) * c_m) * Float64(s_m * x_m)) * c_m)); end return tmp end
s_m = N[Abs[s], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
x_m = N[Abs[x], $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[(N[(c$95$m * x$95$m), $MachinePrecision] * s$95$m), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] / N[(N[(N[(N[Power[s$95$m, 2.0], $MachinePrecision] * x$95$m), $MachinePrecision] * x$95$m), $MachinePrecision] * N[Power[c$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -5e-142], N[(N[(-2.0 * N[(x$95$m * x$95$m), $MachinePrecision] + 1.0), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[(N[(s$95$m * x$95$m), $MachinePrecision] * c$95$m), $MachinePrecision] * N[(s$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
s_m = \left|s\right|
\\
c_m = \left|c\right|
\\
x_m = \left|x\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c\_m \cdot x\_m\right) \cdot s\_m\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\_m\right)}{\left(\left({s\_m}^{2} \cdot x\_m\right) \cdot x\_m\right) \cdot {c\_m}^{2}} \leq -5 \cdot 10^{-142}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-2, x\_m \cdot x\_m, 1\right)}{t\_0 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left(\left(\left(s\_m \cdot x\_m\right) \cdot c\_m\right) \cdot \left(s\_m \cdot x\_m\right)\right) \cdot c\_m}\\
\end{array}
\end{array}
if (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) < -5.0000000000000002e-142Initial program 48.7%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6487.4
Applied rewrites87.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6429.1
Applied rewrites29.1%
if -5.0000000000000002e-142 < (/.f64 (cos.f64 (*.f64 #s(literal 2 binary64) x)) (*.f64 (pow.f64 c #s(literal 2 binary64)) (*.f64 (*.f64 x (pow.f64 s #s(literal 2 binary64))) x))) Initial program 66.3%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6497.8
Applied rewrites97.8%
Taylor expanded in x around 0
Applied rewrites86.5%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6477.1
Applied rewrites77.1%
Applied rewrites83.8%
Final simplification78.7%
s_m = (fabs.f64 s)
c_m = (fabs.f64 c)
x_m = (fabs.f64 x)
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)))
(if (<= x_m 3e-10)
(/ 1.0 (* (* (* (* s_m x_m) c_m) (* s_m x_m)) c_m))
(/ (/ (cos (* 2.0 x_m)) t_0) t_0))))s_m = fabs(s);
c_m = fabs(c);
x_m = fabs(x);
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;
double tmp;
if (x_m <= 3e-10) {
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
} else {
tmp = (cos((2.0 * x_m)) / t_0) / t_0;
}
return tmp;
}
s_m = abs(s)
c_m = abs(c)
x_m = abs(x)
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 * x_m) * s_m
if (x_m <= 3d-10) then
tmp = 1.0d0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m)
else
tmp = (cos((2.0d0 * x_m)) / t_0) / t_0
end if
code = tmp
end function
s_m = Math.abs(s);
c_m = Math.abs(c);
x_m = Math.abs(x);
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;
double tmp;
if (x_m <= 3e-10) {
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
} else {
tmp = (Math.cos((2.0 * x_m)) / t_0) / t_0;
}
return tmp;
}
s_m = math.fabs(s) c_m = math.fabs(c) x_m = math.fabs(x) [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 tmp = 0 if x_m <= 3e-10: tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m) else: tmp = (math.cos((2.0 * x_m)) / t_0) / t_0 return tmp
s_m = abs(s) c_m = abs(c) x_m = abs(x) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(Float64(c_m * x_m) * s_m) tmp = 0.0 if (x_m <= 3e-10) tmp = Float64(1.0 / Float64(Float64(Float64(Float64(s_m * x_m) * c_m) * Float64(s_m * x_m)) * c_m)); else tmp = Float64(Float64(cos(Float64(2.0 * x_m)) / t_0) / t_0); end return tmp end
s_m = abs(s);
c_m = abs(c);
x_m = abs(x);
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 * x_m) * s_m;
tmp = 0.0;
if (x_m <= 3e-10)
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
else
tmp = (cos((2.0 * x_m)) / t_0) / t_0;
end
tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
x_m = N[Abs[x], $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[(N[(c$95$m * x$95$m), $MachinePrecision] * s$95$m), $MachinePrecision]}, If[LessEqual[x$95$m, 3e-10], N[(1.0 / N[(N[(N[(N[(s$95$m * x$95$m), $MachinePrecision] * c$95$m), $MachinePrecision] * N[(s$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[N[(2.0 * x$95$m), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\begin{array}{l}
s_m = \left|s\right|
\\
c_m = \left|c\right|
\\
x_m = \left|x\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c\_m \cdot x\_m\right) \cdot s\_m\\
\mathbf{if}\;x\_m \leq 3 \cdot 10^{-10}:\\
\;\;\;\;\frac{1}{\left(\left(\left(s\_m \cdot x\_m\right) \cdot c\_m\right) \cdot \left(s\_m \cdot x\_m\right)\right) \cdot c\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\cos \left(2 \cdot x\_m\right)}{t\_0}}{t\_0}\\
\end{array}
\end{array}
if x < 3e-10Initial program 63.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6496.1
Applied rewrites96.1%
Taylor expanded in x around 0
Applied rewrites83.0%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6472.5
Applied rewrites72.5%
Applied rewrites80.2%
if 3e-10 < x Initial program 68.3%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
associate-/l*N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites83.8%
Applied rewrites99.0%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-pow.f64N/A
sqr-powN/A
associate-*r*N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
metadata-evalN/A
unpow-1N/A
un-div-invN/A
lower-/.f64N/A
Applied rewrites99.0%
Final simplification84.5%
s_m = (fabs.f64 s)
c_m = (fabs.f64 c)
x_m = (fabs.f64 x)
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)))
(if (<= x_m 3e-10)
(/ 1.0 (* (* (* (* s_m x_m) c_m) (* s_m x_m)) c_m))
(/ (cos (+ x_m x_m)) (* t_0 t_0)))))s_m = fabs(s);
c_m = fabs(c);
x_m = fabs(x);
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;
double tmp;
if (x_m <= 3e-10) {
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
} else {
tmp = cos((x_m + x_m)) / (t_0 * t_0);
}
return tmp;
}
s_m = abs(s)
c_m = abs(c)
x_m = abs(x)
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 * x_m) * s_m
if (x_m <= 3d-10) then
tmp = 1.0d0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m)
else
tmp = cos((x_m + x_m)) / (t_0 * t_0)
end if
code = tmp
end function
s_m = Math.abs(s);
c_m = Math.abs(c);
x_m = Math.abs(x);
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;
double tmp;
if (x_m <= 3e-10) {
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
} else {
tmp = Math.cos((x_m + x_m)) / (t_0 * t_0);
}
return tmp;
}
s_m = math.fabs(s) c_m = math.fabs(c) x_m = math.fabs(x) [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 tmp = 0 if x_m <= 3e-10: tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m) else: tmp = math.cos((x_m + x_m)) / (t_0 * t_0) return tmp
s_m = abs(s) c_m = abs(c) x_m = abs(x) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) t_0 = Float64(Float64(c_m * x_m) * s_m) tmp = 0.0 if (x_m <= 3e-10) tmp = Float64(1.0 / Float64(Float64(Float64(Float64(s_m * x_m) * c_m) * Float64(s_m * x_m)) * c_m)); else tmp = Float64(cos(Float64(x_m + x_m)) / Float64(t_0 * t_0)); end return tmp end
s_m = abs(s);
c_m = abs(c);
x_m = abs(x);
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 * x_m) * s_m;
tmp = 0.0;
if (x_m <= 3e-10)
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
else
tmp = cos((x_m + x_m)) / (t_0 * t_0);
end
tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
c_m = N[Abs[c], $MachinePrecision]
x_m = N[Abs[x], $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[(N[(c$95$m * x$95$m), $MachinePrecision] * s$95$m), $MachinePrecision]}, If[LessEqual[x$95$m, 3e-10], N[(1.0 / N[(N[(N[(N[(s$95$m * x$95$m), $MachinePrecision] * c$95$m), $MachinePrecision] * N[(s$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(x$95$m + x$95$m), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
s_m = \left|s\right|
\\
c_m = \left|c\right|
\\
x_m = \left|x\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\begin{array}{l}
t_0 := \left(c\_m \cdot x\_m\right) \cdot s\_m\\
\mathbf{if}\;x\_m \leq 3 \cdot 10^{-10}:\\
\;\;\;\;\frac{1}{\left(\left(\left(s\_m \cdot x\_m\right) \cdot c\_m\right) \cdot \left(s\_m \cdot x\_m\right)\right) \cdot c\_m}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x\_m + x\_m\right)}{t\_0 \cdot t\_0}\\
\end{array}
\end{array}
if x < 3e-10Initial program 63.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6496.1
Applied rewrites96.1%
Taylor expanded in x around 0
Applied rewrites83.0%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6472.5
Applied rewrites72.5%
Applied rewrites80.2%
if 3e-10 < x Initial program 68.3%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6499.0
Applied rewrites99.0%
lift-*.f64N/A
count-2N/A
lower-+.f6499.0
Applied rewrites99.0%
Final simplification84.5%
s_m = (fabs.f64 s) c_m = (fabs.f64 c) x_m = (fabs.f64 x) 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 (/ 1.0 (* (* (* (* s_m x_m) c_m) (* s_m x_m)) c_m)))
s_m = fabs(s);
c_m = fabs(c);
x_m = fabs(x);
assert(x_m < c_m && c_m < s_m);
double code(double x_m, double c_m, double s_m) {
return 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
}
s_m = abs(s)
c_m = abs(c)
x_m = abs(x)
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 = 1.0d0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m)
end function
s_m = Math.abs(s);
c_m = Math.abs(c);
x_m = Math.abs(x);
assert x_m < c_m && c_m < s_m;
public static double code(double x_m, double c_m, double s_m) {
return 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
}
s_m = math.fabs(s) c_m = math.fabs(c) x_m = math.fabs(x) [x_m, c_m, s_m] = sort([x_m, c_m, s_m]) def code(x_m, c_m, s_m): return 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m)
s_m = abs(s) c_m = abs(c) x_m = abs(x) x_m, c_m, s_m = sort([x_m, c_m, s_m]) function code(x_m, c_m, s_m) return Float64(1.0 / Float64(Float64(Float64(Float64(s_m * x_m) * c_m) * Float64(s_m * x_m)) * c_m)) end
s_m = abs(s);
c_m = abs(c);
x_m = abs(x);
x_m, c_m, s_m = num2cell(sort([x_m, c_m, s_m])){:}
function tmp = code(x_m, c_m, s_m)
tmp = 1.0 / ((((s_m * x_m) * c_m) * (s_m * x_m)) * c_m);
end
s_m = N[Abs[s], $MachinePrecision] c_m = N[Abs[c], $MachinePrecision] x_m = N[Abs[x], $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[(1.0 / N[(N[(N[(N[(s$95$m * x$95$m), $MachinePrecision] * c$95$m), $MachinePrecision] * N[(s$95$m * x$95$m), $MachinePrecision]), $MachinePrecision] * c$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
s_m = \left|s\right|
\\
c_m = \left|c\right|
\\
x_m = \left|x\right|
\\
[x_m, c_m, s_m] = \mathsf{sort}([x_m, c_m, s_m])\\
\\
\frac{1}{\left(\left(\left(s\_m \cdot x\_m\right) \cdot c\_m\right) \cdot \left(s\_m \cdot x\_m\right)\right) \cdot c\_m}
\end{array}
Initial program 64.6%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unpow2N/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6496.8
Applied rewrites96.8%
Taylor expanded in x around 0
Applied rewrites78.9%
Taylor expanded in x around 0
associate-*r*N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6470.4
Applied rewrites70.4%
Applied rewrites76.5%
Final simplification76.5%
herbie shell --seed 2024296
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))