
(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)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
(FPCore (x c s_m)
:precision binary64
(let* ((t_0 (* c (* x s_m))) (t_1 (cos (* 2.0 x))) (t_2 (* x (* c s_m))))
(if (<= (/ t_1 (* (pow c 2.0) (* x (* x (pow s_m 2.0))))) INFINITY)
(/ (/ t_1 t_0) t_0)
(/ (/ t_1 t_2) t_2))))s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = c * (x * s_m);
double t_1 = cos((2.0 * x));
double t_2 = x * (c * s_m);
double tmp;
if ((t_1 / (pow(c, 2.0) * (x * (x * pow(s_m, 2.0))))) <= ((double) INFINITY)) {
tmp = (t_1 / t_0) / t_0;
} else {
tmp = (t_1 / t_2) / t_2;
}
return tmp;
}
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = c * (x * s_m);
double t_1 = Math.cos((2.0 * x));
double t_2 = x * (c * s_m);
double tmp;
if ((t_1 / (Math.pow(c, 2.0) * (x * (x * Math.pow(s_m, 2.0))))) <= Double.POSITIVE_INFINITY) {
tmp = (t_1 / t_0) / t_0;
} else {
tmp = (t_1 / t_2) / t_2;
}
return tmp;
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = c * (x * s_m) t_1 = math.cos((2.0 * x)) t_2 = x * (c * s_m) tmp = 0 if (t_1 / (math.pow(c, 2.0) * (x * (x * math.pow(s_m, 2.0))))) <= math.inf: tmp = (t_1 / t_0) / t_0 else: tmp = (t_1 / t_2) / t_2 return tmp
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(c * Float64(x * s_m)) t_1 = cos(Float64(2.0 * x)) t_2 = Float64(x * Float64(c * s_m)) tmp = 0.0 if (Float64(t_1 / Float64((c ^ 2.0) * Float64(x * Float64(x * (s_m ^ 2.0))))) <= Inf) tmp = Float64(Float64(t_1 / t_0) / t_0); else tmp = Float64(Float64(t_1 / t_2) / t_2); end return tmp end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp_2 = code(x, c, s_m)
t_0 = c * (x * s_m);
t_1 = cos((2.0 * x));
t_2 = x * (c * s_m);
tmp = 0.0;
if ((t_1 / ((c ^ 2.0) * (x * (x * (s_m ^ 2.0))))) <= Inf)
tmp = (t_1 / t_0) / t_0;
else
tmp = (t_1 / t_2) / t_2;
end
tmp_2 = tmp;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(c * N[(x * s$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(x * N[(c * s$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$1 / N[(N[Power[c, 2.0], $MachinePrecision] * N[(x * N[(x * N[Power[s$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(t$95$1 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(t$95$1 / t$95$2), $MachinePrecision] / t$95$2), $MachinePrecision]]]]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\_m\right)\\
t_1 := \cos \left(2 \cdot x\right)\\
t_2 := x \cdot \left(c \cdot s\_m\right)\\
\mathbf{if}\;\frac{t\_1}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s\_m}^{2}\right)\right)} \leq \infty:\\
\;\;\;\;\frac{\frac{t\_1}{t\_0}}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t\_1}{t\_2}}{t\_2}\\
\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))) < +inf.0Initial program 79.8%
*-un-lft-identity79.8%
add-sqr-sqrt79.8%
times-frac79.7%
Applied egg-rr99.6%
Applied egg-rr99.7%
if +inf.0 < (/.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 0.0%
*-un-lft-identity0.0%
add-sqr-sqrt0.0%
times-frac0.0%
Applied egg-rr92.8%
Applied egg-rr92.9%
div-inv92.7%
associate-/l*92.8%
un-div-inv92.7%
pow292.7%
inv-pow92.7%
pow-pow92.7%
associate-*r*90.1%
*-commutative90.1%
associate-*l*99.3%
metadata-eval99.3%
Applied egg-rr99.3%
sqr-pow99.3%
metadata-eval99.3%
inv-pow99.3%
metadata-eval99.3%
inv-pow99.3%
associate-*r*99.3%
associate-*r*90.2%
*-commutative90.2%
associate-*r*92.8%
div-inv92.9%
associate-*r*83.5%
*-commutative83.5%
associate-*r*92.8%
div-inv92.9%
Applied egg-rr99.4%
Final simplification99.7%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (let* ((t_0 (* c (* x s_m)))) (/ (/ (cos (* 2.0 x)) t_0) t_0)))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = c * (x * s_m);
return (cos((2.0 * x)) / t_0) / t_0;
}
s_m = abs(s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x, c, s_m)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = c * (x * s_m)
code = (cos((2.0d0 * x)) / t_0) / t_0
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = c * (x * s_m);
return (Math.cos((2.0 * x)) / t_0) / t_0;
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = c * (x * s_m) return (math.cos((2.0 * x)) / t_0) / t_0
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(c * Float64(x * s_m)) return Float64(Float64(cos(Float64(2.0 * x)) / t_0) / t_0) end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
t_0 = c * (x * s_m);
tmp = (cos((2.0 * x)) / t_0) / t_0;
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(c * N[(x * s$95$m), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\_m\right)\\
\frac{\frac{\cos \left(2 \cdot x\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 67.0%
*-un-lft-identity67.0%
add-sqr-sqrt67.0%
times-frac67.0%
Applied egg-rr98.5%
Applied egg-rr98.6%
Final simplification98.6%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (/ (/ (/ 1.0 c) (* x s_m)) (* c (* x s_m))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
return ((1.0 / c) / (x * s_m)) / (c * (x * s_m));
}
s_m = abs(s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x, c, s_m)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
code = ((1.0d0 / c) / (x * s_m)) / (c * (x * s_m))
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
return ((1.0 / c) / (x * s_m)) / (c * (x * s_m));
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): return ((1.0 / c) / (x * s_m)) / (c * (x * s_m))
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) return Float64(Float64(Float64(1.0 / c) / Float64(x * s_m)) / Float64(c * Float64(x * s_m))) end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
tmp = ((1.0 / c) / (x * s_m)) / (c * (x * s_m));
end
s_m = N[Abs[s], $MachinePrecision] NOTE: x, c, and s_m should be sorted in increasing order before calling this function. code[x_, c_, s$95$m_] := N[(N[(N[(1.0 / c), $MachinePrecision] / N[(x * s$95$m), $MachinePrecision]), $MachinePrecision] / N[(c * N[(x * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\frac{\frac{\frac{1}{c}}{x \cdot s\_m}}{c \cdot \left(x \cdot s\_m\right)}
\end{array}
Initial program 67.0%
*-un-lft-identity67.0%
add-sqr-sqrt67.0%
times-frac67.0%
Applied egg-rr98.5%
Applied egg-rr98.6%
Taylor expanded in x around 0 81.5%
associate-/r*81.6%
Simplified81.6%
Final simplification81.6%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (let* ((t_0 (* c (* x s_m)))) (/ 1.0 (* t_0 t_0))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
double t_0 = c * (x * s_m);
return 1.0 / (t_0 * t_0);
}
s_m = abs(s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x, c, s_m)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
real(8) :: t_0
t_0 = c * (x * s_m)
code = 1.0d0 / (t_0 * t_0)
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
double t_0 = c * (x * s_m);
return 1.0 / (t_0 * t_0);
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): t_0 = c * (x * s_m) return 1.0 / (t_0 * t_0)
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) t_0 = Float64(c * Float64(x * s_m)) return Float64(1.0 / Float64(t_0 * t_0)) end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
t_0 = c * (x * s_m);
tmp = 1.0 / (t_0 * t_0);
end
s_m = N[Abs[s], $MachinePrecision]
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
code[x_, c_, s$95$m_] := Block[{t$95$0 = N[(c * N[(x * s$95$m), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\_m\right)\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 67.0%
Taylor expanded in x around 0 55.8%
associate-/r*55.8%
*-commutative55.8%
unpow255.8%
unpow255.8%
swap-sqr70.6%
unpow270.6%
associate-/r*70.8%
unpow270.8%
unpow270.8%
swap-sqr81.4%
unpow281.4%
*-commutative81.4%
Simplified81.4%
*-commutative81.4%
unpow281.4%
Applied egg-rr81.4%
s_m = (fabs.f64 s) NOTE: x, c, and s_m should be sorted in increasing order before calling this function. (FPCore (x c s_m) :precision binary64 (/ 1.0 (* c (* (* x s_m) (* c (* x s_m))))))
s_m = fabs(s);
assert(x < c && c < s_m);
double code(double x, double c, double s_m) {
return 1.0 / (c * ((x * s_m) * (c * (x * s_m))));
}
s_m = abs(s)
NOTE: x, c, and s_m should be sorted in increasing order before calling this function.
real(8) function code(x, c, s_m)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s_m
code = 1.0d0 / (c * ((x * s_m) * (c * (x * s_m))))
end function
s_m = Math.abs(s);
assert x < c && c < s_m;
public static double code(double x, double c, double s_m) {
return 1.0 / (c * ((x * s_m) * (c * (x * s_m))));
}
s_m = math.fabs(s) [x, c, s_m] = sort([x, c, s_m]) def code(x, c, s_m): return 1.0 / (c * ((x * s_m) * (c * (x * s_m))))
s_m = abs(s) x, c, s_m = sort([x, c, s_m]) function code(x, c, s_m) return Float64(1.0 / Float64(c * Float64(Float64(x * s_m) * Float64(c * Float64(x * s_m))))) end
s_m = abs(s);
x, c, s_m = num2cell(sort([x, c, s_m])){:}
function tmp = code(x, c, s_m)
tmp = 1.0 / (c * ((x * s_m) * (c * (x * s_m))));
end
s_m = N[Abs[s], $MachinePrecision] NOTE: x, c, and s_m should be sorted in increasing order before calling this function. code[x_, c_, s$95$m_] := N[(1.0 / N[(c * N[(N[(x * s$95$m), $MachinePrecision] * N[(c * N[(x * s$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
s_m = \left|s\right|
\\
[x, c, s_m] = \mathsf{sort}([x, c, s_m])\\
\\
\frac{1}{c \cdot \left(\left(x \cdot s\_m\right) \cdot \left(c \cdot \left(x \cdot s\_m\right)\right)\right)}
\end{array}
Initial program 67.0%
Taylor expanded in x around 0 55.8%
associate-/r*55.8%
*-commutative55.8%
unpow255.8%
unpow255.8%
swap-sqr70.6%
unpow270.6%
associate-/r*70.8%
unpow270.8%
unpow270.8%
swap-sqr81.4%
unpow281.4%
*-commutative81.4%
Simplified81.4%
*-commutative81.4%
unpow281.4%
associate-*l*79.7%
Applied egg-rr79.7%
herbie shell --seed 2024123
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))