
(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}
(FPCore (x c s) :precision binary64 (* (cos (* 2.0 x)) (* (/ (/ 1.0 (* c s)) x) (/ (/ 1.0 x) (* c s)))))
double code(double x, double c, double s) {
return cos((2.0 * x)) * (((1.0 / (c * s)) / x) * ((1.0 / x) / (c * s)));
}
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)) * (((1.0d0 / (c * s)) / x) * ((1.0d0 / x) / (c * s)))
end function
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) * (((1.0 / (c * s)) / x) * ((1.0 / x) / (c * s)));
}
def code(x, c, s): return math.cos((2.0 * x)) * (((1.0 / (c * s)) / x) * ((1.0 / x) / (c * s)))
function code(x, c, s) return Float64(cos(Float64(2.0 * x)) * Float64(Float64(Float64(1.0 / Float64(c * s)) / x) * Float64(Float64(1.0 / x) / Float64(c * s)))) end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) * (((1.0 / (c * s)) / x) * ((1.0 / x) / (c * s))); end
code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] * N[(N[(N[(1.0 / N[(c * s), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * N[(N[(1.0 / x), $MachinePrecision] / N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(2 \cdot x\right) \cdot \left(\frac{\frac{1}{c \cdot s}}{x} \cdot \frac{\frac{1}{x}}{c \cdot s}\right)
\end{array}
Initial program 65.2%
associate-/l/65.2%
remove-double-neg65.2%
distribute-frac-neg65.2%
distribute-neg-frac65.2%
remove-double-neg65.2%
*-commutative65.2%
associate-*r*58.9%
unpow258.9%
associate-/r*58.2%
cos-neg58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
associate-/l/59.7%
div-inv59.7%
associate-/l*59.6%
add-sqr-sqrt26.6%
sqrt-unprod48.0%
*-commutative48.0%
*-commutative48.0%
swap-sqr48.0%
metadata-eval48.0%
metadata-eval48.0%
swap-sqr48.0%
sqrt-unprod30.5%
add-sqr-sqrt59.6%
pow-flip59.7%
metadata-eval59.7%
pow-prod-down76.7%
Applied egg-rr76.7%
add-sqr-sqrt76.7%
sqrt-div76.7%
sqrt-pow153.3%
metadata-eval53.3%
inv-pow53.3%
sqrt-pow154.2%
metadata-eval54.2%
pow154.2%
sqrt-div54.1%
sqrt-pow161.7%
metadata-eval61.7%
inv-pow61.7%
sqrt-pow198.5%
metadata-eval98.5%
pow198.5%
Applied egg-rr98.5%
Taylor expanded in x around 0 95.7%
associate-*r*98.6%
associate-/r*98.5%
Simplified98.5%
(FPCore (x c s) :precision binary64 (let* ((t_0 (* x (* c s)))) (/ (/ (cos (* 2.0 x)) t_0) t_0)))
double code(double x, double c, double s) {
double t_0 = x * (c * s);
return (cos((2.0 * x)) / t_0) / t_0;
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
t_0 = x * (c * s)
code = (cos((2.0d0 * x)) / t_0) / t_0
end function
public static double code(double x, double c, double s) {
double t_0 = x * (c * s);
return (Math.cos((2.0 * x)) / t_0) / t_0;
}
def code(x, c, s): t_0 = x * (c * s) return (math.cos((2.0 * x)) / t_0) / t_0
function code(x, c, s) t_0 = Float64(x * Float64(c * s)) return Float64(Float64(cos(Float64(2.0 * x)) / t_0) / t_0) end
function tmp = code(x, c, s) t_0 = x * (c * s); tmp = (cos((2.0 * x)) / t_0) / t_0; end
code[x_, c_, s_] := Block[{t$95$0 = N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(c \cdot s\right)\\
\frac{\frac{\cos \left(2 \cdot x\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 65.2%
associate-/l/65.2%
remove-double-neg65.2%
distribute-frac-neg65.2%
distribute-neg-frac65.2%
remove-double-neg65.2%
*-commutative65.2%
associate-*r*58.9%
unpow258.9%
associate-/r*58.2%
cos-neg58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
associate-/l/59.7%
div-inv59.7%
associate-/l*59.6%
add-sqr-sqrt26.6%
sqrt-unprod48.0%
*-commutative48.0%
*-commutative48.0%
swap-sqr48.0%
metadata-eval48.0%
metadata-eval48.0%
swap-sqr48.0%
sqrt-unprod30.5%
add-sqr-sqrt59.6%
pow-flip59.7%
metadata-eval59.7%
pow-prod-down76.7%
Applied egg-rr76.7%
add-sqr-sqrt76.7%
sqrt-div76.7%
sqrt-pow153.3%
metadata-eval53.3%
inv-pow53.3%
sqrt-pow154.2%
metadata-eval54.2%
pow154.2%
sqrt-div54.1%
sqrt-pow161.7%
metadata-eval61.7%
inv-pow61.7%
sqrt-pow198.5%
metadata-eval98.5%
pow198.5%
Applied egg-rr98.5%
associate-*r*98.5%
associate-/l/98.5%
un-div-inv98.6%
associate-/l/98.5%
un-div-inv98.5%
*-commutative98.5%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (x c s) :precision binary64 (let* ((t_0 (* c (* x s)))) (/ (/ (cos (* 2.0 x)) t_0) t_0)))
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return (cos((2.0 * x)) / t_0) / t_0;
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
t_0 = c * (x * s)
code = (cos((2.0d0 * x)) / t_0) / t_0
end function
public static double code(double x, double c, double s) {
double t_0 = c * (x * s);
return (Math.cos((2.0 * x)) / t_0) / t_0;
}
def code(x, c, s): t_0 = c * (x * s) return (math.cos((2.0 * x)) / t_0) / t_0
function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(Float64(cos(Float64(2.0 * x)) / t_0) / t_0) end
function tmp = code(x, c, s) t_0 = c * (x * s); tmp = (cos((2.0 * x)) / t_0) / t_0; end
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\frac{\frac{\cos \left(2 \cdot x\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 65.2%
associate-/l/65.2%
remove-double-neg65.2%
distribute-frac-neg65.2%
distribute-neg-frac65.2%
remove-double-neg65.2%
*-commutative65.2%
associate-*r*58.9%
unpow258.9%
associate-/r*58.2%
cos-neg58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
associate-/l/59.7%
div-inv59.7%
associate-/l*59.6%
add-sqr-sqrt26.6%
sqrt-unprod48.0%
*-commutative48.0%
*-commutative48.0%
swap-sqr48.0%
metadata-eval48.0%
metadata-eval48.0%
swap-sqr48.0%
sqrt-unprod30.5%
add-sqr-sqrt59.6%
pow-flip59.7%
metadata-eval59.7%
pow-prod-down76.7%
Applied egg-rr76.7%
add-sqr-sqrt76.7%
sqrt-div76.7%
sqrt-pow153.3%
metadata-eval53.3%
inv-pow53.3%
sqrt-pow154.2%
metadata-eval54.2%
pow154.2%
sqrt-div54.1%
sqrt-pow161.7%
metadata-eval61.7%
inv-pow61.7%
sqrt-pow198.5%
metadata-eval98.5%
pow198.5%
Applied egg-rr98.5%
unpow298.5%
associate-/l/98.5%
Simplified98.5%
*-commutative98.5%
associate-*l*96.7%
*-commutative96.7%
pow296.7%
associate-*r*96.7%
div-inv96.7%
un-div-inv96.7%
*-commutative96.7%
*-commutative96.7%
Applied egg-rr96.7%
Final simplification96.7%
(FPCore (x c s) :precision binary64 (/ (/ (/ 1.0 c) (* x s)) (* c (fabs (* x s)))))
double code(double x, double c, double s) {
return ((1.0 / c) / (x * s)) / (c * fabs((x * s)));
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = ((1.0d0 / c) / (x * s)) / (c * abs((x * s)))
end function
public static double code(double x, double c, double s) {
return ((1.0 / c) / (x * s)) / (c * Math.abs((x * s)));
}
def code(x, c, s): return ((1.0 / c) / (x * s)) / (c * math.fabs((x * s)))
function code(x, c, s) return Float64(Float64(Float64(1.0 / c) / Float64(x * s)) / Float64(c * abs(Float64(x * s)))) end
function tmp = code(x, c, s) tmp = ((1.0 / c) / (x * s)) / (c * abs((x * s))); end
code[x_, c_, s_] := N[(N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision] / N[(c * N[Abs[N[(x * s), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\frac{1}{c}}{x \cdot s}}{c \cdot \left|x \cdot s\right|}
\end{array}
Initial program 65.2%
associate-/l/65.2%
remove-double-neg65.2%
distribute-frac-neg65.2%
distribute-neg-frac65.2%
remove-double-neg65.2%
*-commutative65.2%
associate-*r*58.9%
unpow258.9%
associate-/r*58.2%
cos-neg58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
associate-/l/58.9%
add-sqr-sqrt26.6%
sqrt-unprod47.2%
*-commutative47.2%
*-commutative47.2%
swap-sqr47.2%
metadata-eval47.2%
metadata-eval47.2%
swap-sqr47.2%
sqrt-unprod29.8%
add-sqr-sqrt58.9%
unpow258.9%
associate-*r*65.2%
*-commutative65.2%
associate-/r*65.2%
*-commutative65.2%
Applied egg-rr85.8%
associate-*l/85.8%
*-lft-identity85.8%
*-commutative85.8%
unpow285.8%
rem-sqrt-square85.8%
*-commutative85.8%
unpow285.8%
rem-sqrt-square96.7%
*-commutative96.7%
Simplified96.7%
Taylor expanded in x around 0 78.8%
associate-/r*78.8%
*-commutative78.8%
rem-square-sqrt43.0%
fabs-sqr43.0%
rem-square-sqrt57.6%
*-commutative57.6%
Simplified57.6%
Final simplification57.6%
(FPCore (x c s) :precision binary64 (pow (* c (* x s)) -2.0))
double code(double x, double c, double s) {
return pow((c * (x * s)), -2.0);
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
code = (c * (x * s)) ** (-2.0d0)
end function
public static double code(double x, double c, double s) {
return Math.pow((c * (x * s)), -2.0);
}
def code(x, c, s): return math.pow((c * (x * s)), -2.0)
function code(x, c, s) return Float64(c * Float64(x * s)) ^ -2.0 end
function tmp = code(x, c, s) tmp = (c * (x * s)) ^ -2.0; end
code[x_, c_, s_] := N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(c \cdot \left(x \cdot s\right)\right)}^{-2}
\end{array}
Initial program 65.2%
associate-/l/65.2%
remove-double-neg65.2%
distribute-frac-neg65.2%
distribute-neg-frac65.2%
remove-double-neg65.2%
*-commutative65.2%
associate-*r*58.9%
unpow258.9%
associate-/r*58.2%
cos-neg58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
Taylor expanded in x around 0 53.6%
associate-/r*53.5%
*-commutative53.5%
*-commutative53.5%
unpow253.5%
unpow253.5%
swap-sqr65.2%
unpow265.2%
associate-/r*65.2%
unpow265.2%
rem-square-sqrt65.2%
swap-sqr72.1%
unpow272.1%
unpow272.1%
rem-sqrt-square78.8%
*-commutative78.8%
Simplified78.8%
pow178.8%
metadata-eval78.8%
sqrt-pow178.8%
pow278.8%
add-sqr-sqrt78.8%
pow-flip78.8%
add-sqr-sqrt43.0%
fabs-sqr43.0%
add-sqr-sqrt78.8%
metadata-eval78.8%
Applied egg-rr78.8%
(FPCore (x c s) :precision binary64 (let* ((t_0 (* c (* x s)))) (/ 1.0 (* t_0 t_0))))
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return 1.0 / (t_0 * t_0);
}
real(8) function code(x, c, s)
real(8), intent (in) :: x
real(8), intent (in) :: c
real(8), intent (in) :: s
real(8) :: t_0
t_0 = c * (x * s)
code = 1.0d0 / (t_0 * t_0)
end function
public static double code(double x, double c, double s) {
double t_0 = c * (x * s);
return 1.0 / (t_0 * t_0);
}
def code(x, c, s): t_0 = c * (x * s) return 1.0 / (t_0 * t_0)
function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(1.0 / Float64(t_0 * t_0)) end
function tmp = code(x, c, s) t_0 = c * (x * s); tmp = 1.0 / (t_0 * t_0); end
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 65.2%
associate-/l/65.2%
remove-double-neg65.2%
distribute-frac-neg65.2%
distribute-neg-frac65.2%
remove-double-neg65.2%
*-commutative65.2%
associate-*r*58.9%
unpow258.9%
associate-/r*58.2%
cos-neg58.2%
*-commutative58.2%
distribute-rgt-neg-in58.2%
metadata-eval58.2%
Simplified58.2%
Taylor expanded in x around 0 53.6%
associate-/r*53.5%
*-commutative53.5%
*-commutative53.5%
unpow253.5%
unpow253.5%
swap-sqr65.2%
unpow265.2%
associate-/r*65.2%
unpow265.2%
rem-square-sqrt65.2%
swap-sqr72.1%
unpow272.1%
unpow272.1%
rem-sqrt-square78.8%
*-commutative78.8%
Simplified78.8%
pow178.8%
metadata-eval78.8%
sqrt-pow178.8%
pow278.8%
add-sqr-sqrt78.8%
unpow278.8%
add-sqr-sqrt43.0%
fabs-sqr43.0%
add-sqr-sqrt57.6%
add-sqr-sqrt37.0%
fabs-sqr37.0%
add-sqr-sqrt78.8%
Applied egg-rr78.8%
herbie shell --seed 2024137
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))