
(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 8 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 (* x 2.0)) (/ x (/ 1.0 (* c s)))) (* x (* c s))))
double code(double x, double c, double s) {
return (cos((x * 2.0)) / (x / (1.0 / (c * s)))) / (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((x * 2.0d0)) / (x / (1.0d0 / (c * s)))) / (x * (c * s))
end function
public static double code(double x, double c, double s) {
return (Math.cos((x * 2.0)) / (x / (1.0 / (c * s)))) / (x * (c * s));
}
def code(x, c, s): return (math.cos((x * 2.0)) / (x / (1.0 / (c * s)))) / (x * (c * s))
function code(x, c, s) return Float64(Float64(cos(Float64(x * 2.0)) / Float64(x / Float64(1.0 / Float64(c * s)))) / Float64(x * Float64(c * s))) end
function tmp = code(x, c, s) tmp = (cos((x * 2.0)) / (x / (1.0 / (c * s)))) / (x * (c * s)); end
code[x_, c_, s_] := N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x / N[(1.0 / N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\cos \left(x \cdot 2\right)}{\frac{x}{\frac{1}{c \cdot s}}}}{x \cdot \left(c \cdot s\right)}
\end{array}
Initial program 65.2%
*-un-lft-identity65.2%
associate-*r*66.8%
times-frac67.0%
*-commutative67.0%
associate-*r*66.3%
pow-prod-down87.9%
Applied egg-rr87.9%
frac-times87.7%
*-un-lft-identity87.7%
add-sqr-sqrt43.8%
add-sqr-sqrt43.8%
unswap-sqr43.7%
sqrt-prod43.7%
sqrt-pow131.4%
metadata-eval31.4%
pow131.4%
associate-*r*31.4%
add-sqr-sqrt31.4%
associate-*r*30.8%
add-sqr-sqrt16.5%
fabs-sqr16.5%
add-sqr-sqrt32.1%
Applied egg-rr98.5%
*-commutative98.5%
*-commutative98.5%
/-rgt-identity98.5%
clear-num98.5%
div-inv98.5%
clear-num98.5%
div-inv98.5%
associate-/l/98.5%
*-commutative98.5%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (x c s) :precision binary64 (/ (/ (cos (* x 2.0)) (* x (* c s))) (/ x (/ 1.0 (* c s)))))
double code(double x, double c, double s) {
return (cos((x * 2.0)) / (x * (c * s))) / (x / (1.0 / (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((x * 2.0d0)) / (x * (c * s))) / (x / (1.0d0 / (c * s)))
end function
public static double code(double x, double c, double s) {
return (Math.cos((x * 2.0)) / (x * (c * s))) / (x / (1.0 / (c * s)));
}
def code(x, c, s): return (math.cos((x * 2.0)) / (x * (c * s))) / (x / (1.0 / (c * s)))
function code(x, c, s) return Float64(Float64(cos(Float64(x * 2.0)) / Float64(x * Float64(c * s))) / Float64(x / Float64(1.0 / Float64(c * s)))) end
function tmp = code(x, c, s) tmp = (cos((x * 2.0)) / (x * (c * s))) / (x / (1.0 / (c * s))); end
code[x_, c_, s_] := N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x / N[(1.0 / N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot \left(c \cdot s\right)}}{\frac{x}{\frac{1}{c \cdot s}}}
\end{array}
Initial program 65.2%
*-un-lft-identity65.2%
associate-*r*66.8%
times-frac67.0%
*-commutative67.0%
associate-*r*66.3%
pow-prod-down87.9%
Applied egg-rr87.9%
frac-times87.7%
*-un-lft-identity87.7%
add-sqr-sqrt43.8%
add-sqr-sqrt43.8%
unswap-sqr43.7%
sqrt-prod43.7%
sqrt-pow131.4%
metadata-eval31.4%
pow131.4%
associate-*r*31.4%
add-sqr-sqrt31.4%
associate-*r*30.8%
add-sqr-sqrt16.5%
fabs-sqr16.5%
add-sqr-sqrt32.1%
Applied egg-rr98.5%
*-commutative98.5%
*-commutative98.5%
/-rgt-identity98.5%
clear-num98.5%
div-inv98.5%
clear-num98.5%
div-inv98.5%
associate-/l/98.5%
*-commutative98.5%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (x c s) :precision binary64 (let* ((t_0 (* x (* c s)))) (/ (/ (cos (* x 2.0)) t_0) t_0)))
double code(double x, double c, double s) {
double t_0 = x * (c * s);
return (cos((x * 2.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 = x * (c * s)
code = (cos((x * 2.0d0)) / 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((x * 2.0)) / t_0) / t_0;
}
def code(x, c, s): t_0 = x * (c * s) return (math.cos((x * 2.0)) / t_0) / t_0
function code(x, c, s) t_0 = Float64(x * Float64(c * s)) return Float64(Float64(cos(Float64(x * 2.0)) / t_0) / t_0) end
function tmp = code(x, c, s) t_0 = x * (c * s); tmp = (cos((x * 2.0)) / 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[(x * 2.0), $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(x \cdot 2\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 65.2%
*-un-lft-identity65.2%
associate-*r*66.8%
times-frac67.0%
*-commutative67.0%
associate-*r*66.3%
pow-prod-down87.9%
Applied egg-rr87.9%
frac-times87.7%
*-un-lft-identity87.7%
add-sqr-sqrt43.8%
add-sqr-sqrt43.8%
unswap-sqr43.7%
sqrt-prod43.7%
sqrt-pow131.4%
metadata-eval31.4%
pow131.4%
associate-*r*31.4%
add-sqr-sqrt31.4%
associate-*r*30.8%
add-sqr-sqrt16.5%
fabs-sqr16.5%
add-sqr-sqrt32.1%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (x c s) :precision binary64 (let* ((t_0 (* c (* x s)))) (/ (/ (cos (* x 2.0)) t_0) t_0)))
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return (cos((x * 2.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 = (cos((x * 2.0d0)) / 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((x * 2.0)) / t_0) / t_0;
}
def code(x, c, s): t_0 = c * (x * s) return (math.cos((x * 2.0)) / t_0) / t_0
function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(Float64(cos(Float64(x * 2.0)) / t_0) / t_0) end
function tmp = code(x, c, s) t_0 = c * (x * s); tmp = (cos((x * 2.0)) / 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[(x * 2.0), $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(x \cdot 2\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 65.2%
*-un-lft-identity65.2%
associate-*r*66.8%
times-frac67.0%
*-commutative67.0%
associate-*r*66.3%
pow-prod-down87.9%
Applied egg-rr87.9%
unpow287.9%
*-commutative87.9%
associate-*r*84.8%
Applied egg-rr84.8%
frac-times84.6%
*-un-lft-identity84.6%
*-commutative84.6%
associate-*r*75.6%
associate-*l*77.5%
*-commutative77.5%
swap-sqr98.3%
associate-/l/98.5%
associate-*l*95.8%
associate-*l*96.7%
Applied egg-rr96.7%
Final simplification96.7%
(FPCore (x c s) :precision binary64 (pow (/ (/ (/ 1.0 s) x) c) 2.0))
double code(double x, double c, double s) {
return pow((((1.0 / s) / x) / c), 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 = (((1.0d0 / s) / x) / c) ** 2.0d0
end function
public static double code(double x, double c, double s) {
return Math.pow((((1.0 / s) / x) / c), 2.0);
}
def code(x, c, s): return math.pow((((1.0 / s) / x) / c), 2.0)
function code(x, c, s) return Float64(Float64(Float64(1.0 / s) / x) / c) ^ 2.0 end
function tmp = code(x, c, s) tmp = (((1.0 / s) / x) / c) ^ 2.0; end
code[x_, c_, s_] := N[Power[N[(N[(N[(1.0 / s), $MachinePrecision] / x), $MachinePrecision] / c), $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\frac{\frac{\frac{1}{s}}{x}}{c}\right)}^{2}
\end{array}
Initial program 65.2%
*-un-lft-identity65.2%
add-sqr-sqrt65.2%
times-frac65.2%
sqrt-prod65.2%
sqrt-pow145.0%
metadata-eval45.0%
pow145.0%
*-commutative45.0%
associate-*r*41.8%
unpow241.8%
pow-prod-down45.0%
sqrt-prod45.0%
Applied egg-rr85.8%
associate-*l/85.8%
*-lft-identity85.8%
unpow285.8%
rem-sqrt-square85.8%
unpow285.8%
rem-sqrt-square96.7%
Simplified96.7%
Taylor expanded in x around 0 65.2%
unpow265.2%
unpow265.2%
sqr-abs65.2%
swap-sqr78.8%
associate-*r*78.1%
associate-*r*79.9%
associate-/l/79.9%
*-rgt-identity79.9%
associate-*r/79.9%
unpow279.9%
associate-/r*79.9%
associate-/r*79.9%
Simplified79.9%
div-inv79.8%
associate-/l/79.8%
*-commutative79.8%
Applied egg-rr79.8%
associate-*l/79.9%
*-un-lft-identity79.9%
*-commutative79.9%
associate-/r*78.8%
associate-/r*78.8%
*-commutative78.8%
associate-/r*78.8%
Applied egg-rr78.8%
(FPCore (x c s) :precision binary64 (/ (/ (/ 1.0 c) (* x s)) (* c (* x s))))
double code(double x, double c, double s) {
return ((1.0 / c) / (x * s)) / (c * (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 * (x * s))
end function
public static double code(double x, double c, double s) {
return ((1.0 / c) / (x * s)) / (c * (x * s));
}
def code(x, c, s): return ((1.0 / c) / (x * s)) / (c * (x * s))
function code(x, c, s) return Float64(Float64(Float64(1.0 / c) / Float64(x * s)) / Float64(c * Float64(x * s))) end
function tmp = code(x, c, s) tmp = ((1.0 / c) / (x * s)) / (c * (x * s)); end
code[x_, c_, s_] := N[(N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision] / N[(c * N[(x * s), $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%
*-un-lft-identity65.2%
add-sqr-sqrt65.2%
times-frac65.2%
sqrt-prod65.2%
sqrt-pow145.0%
metadata-eval45.0%
pow145.0%
*-commutative45.0%
associate-*r*41.8%
unpow241.8%
pow-prod-down45.0%
sqrt-prod45.0%
Applied egg-rr85.8%
associate-*l/85.8%
*-lft-identity85.8%
unpow285.8%
rem-sqrt-square85.8%
unpow285.8%
rem-sqrt-square96.7%
Simplified96.7%
Taylor expanded in x around 0 65.2%
unpow265.2%
unpow265.2%
sqr-abs65.2%
swap-sqr78.8%
associate-*r*78.1%
associate-*r*79.9%
associate-/l/79.9%
*-rgt-identity79.9%
associate-*r/79.9%
unpow279.9%
associate-/r*79.9%
associate-/r*79.9%
Simplified79.9%
div-inv79.8%
associate-/l/79.8%
*-commutative79.8%
frac-times79.9%
metadata-eval79.9%
metadata-eval79.9%
pow-sqr79.9%
pow179.9%
pow179.9%
div-inv79.9%
metadata-eval79.9%
frac-times79.9%
*-commutative79.9%
associate-/l/79.9%
div-inv79.9%
associate-/l/78.1%
associate-*l*78.8%
Applied egg-rr78.8%
Final simplification78.8%
(FPCore (x c s) :precision binary64 (/ (/ 1.0 c) (* (* c (* x s)) (* x s))))
double code(double x, double c, double s) {
return (1.0 / c) / ((c * (x * s)) * (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) / ((c * (x * s)) * (x * s))
end function
public static double code(double x, double c, double s) {
return (1.0 / c) / ((c * (x * s)) * (x * s));
}
def code(x, c, s): return (1.0 / c) / ((c * (x * s)) * (x * s))
function code(x, c, s) return Float64(Float64(1.0 / c) / Float64(Float64(c * Float64(x * s)) * Float64(x * s))) end
function tmp = code(x, c, s) tmp = (1.0 / c) / ((c * (x * s)) * (x * s)); end
code[x_, c_, s_] := N[(N[(1.0 / c), $MachinePrecision] / N[(N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision] * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{c}}{\left(c \cdot \left(x \cdot s\right)\right) \cdot \left(x \cdot s\right)}
\end{array}
Initial program 65.2%
*-un-lft-identity65.2%
add-sqr-sqrt65.2%
times-frac65.2%
sqrt-prod65.2%
sqrt-pow145.0%
metadata-eval45.0%
pow145.0%
*-commutative45.0%
associate-*r*41.8%
unpow241.8%
pow-prod-down45.0%
sqrt-prod45.0%
Applied egg-rr85.8%
associate-*l/85.8%
*-lft-identity85.8%
unpow285.8%
rem-sqrt-square85.8%
unpow285.8%
rem-sqrt-square96.7%
Simplified96.7%
Taylor expanded in x around 0 65.2%
unpow265.2%
unpow265.2%
sqr-abs65.2%
swap-sqr78.8%
associate-*r*78.1%
associate-*r*79.9%
associate-/l/79.9%
*-rgt-identity79.9%
associate-*r/79.9%
unpow279.9%
associate-/r*79.9%
associate-/r*79.9%
Simplified79.9%
unpow279.9%
clear-num79.9%
associate-/l/78.1%
frac-times76.9%
*-un-lft-identity76.9%
div-inv76.9%
clear-num76.9%
div-inv76.9%
clear-num76.9%
/-rgt-identity76.9%
*-commutative76.9%
*-commutative76.9%
associate-*l*77.6%
Applied egg-rr77.6%
Final simplification77.6%
(FPCore (x c s) :precision binary64 (let* ((t_0 (* x (* c s)))) (/ 1.0 (* t_0 t_0))))
double code(double x, double c, double s) {
double t_0 = x * (c * 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 = x * (c * s)
code = 1.0d0 / (t_0 * t_0)
end function
public static double code(double x, double c, double s) {
double t_0 = x * (c * s);
return 1.0 / (t_0 * t_0);
}
def code(x, c, s): t_0 = x * (c * s) return 1.0 / (t_0 * t_0)
function code(x, c, s) t_0 = Float64(x * Float64(c * s)) return Float64(1.0 / Float64(t_0 * t_0)) end
function tmp = code(x, c, s) t_0 = x * (c * s); tmp = 1.0 / (t_0 * t_0); end
code[x_, c_, s_] := Block[{t$95$0 = N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(c \cdot s\right)\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 65.2%
Taylor expanded in x around 0 53.6%
associate-/r*53.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%
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%
associate-*r*57.2%
add-sqr-sqrt36.7%
fabs-sqr36.7%
add-sqr-sqrt78.1%
associate-*r*79.9%
Applied egg-rr79.9%
Final simplification79.9%
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))))