
(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 7 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 (let* ((t_0 (* x (* c s)))) (* (/ (cos (* x 2.0)) t_0) (/ 1.0 t_0))))
double code(double x, double c, double s) {
double t_0 = x * (c * s);
return (cos((x * 2.0)) / t_0) * (1.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) * (1.0d0 / 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) * (1.0 / t_0);
}
def code(x, c, s): t_0 = x * (c * s) return (math.cos((x * 2.0)) / t_0) * (1.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) * Float64(1.0 / t_0)) end
function tmp = code(x, c, s) t_0 = x * (c * s); tmp = (cos((x * 2.0)) / t_0) * (1.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] * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(c \cdot s\right)\\
\frac{\cos \left(x \cdot 2\right)}{t\_0} \cdot \frac{1}{t\_0}
\end{array}
\end{array}
Initial program 69.7%
*-un-lft-identity69.7%
add-sqr-sqrt69.6%
times-frac69.6%
sqrt-prod69.6%
sqrt-pow150.5%
metadata-eval50.5%
pow150.5%
*-commutative50.5%
associate-*r*46.9%
unpow246.9%
pow-prod-down50.5%
sqrt-pow152.2%
metadata-eval52.2%
pow152.2%
*-commutative52.2%
Applied egg-rr97.6%
associate-*l/97.7%
*-un-lft-identity97.7%
*-commutative97.7%
Applied egg-rr97.7%
div-inv97.6%
*-commutative97.6%
associate-*r*96.9%
*-commutative96.9%
*-commutative96.9%
associate-*r*98.7%
*-commutative98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (x c s) :precision binary64 (/ (/ (cos (* x 2.0)) c) (* (* x s) (* c (* x s)))))
double code(double x, double c, double s) {
return (cos((x * 2.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 = (cos((x * 2.0d0)) / c) / ((x * s) * (c * (x * s)))
end function
public static double code(double x, double c, double s) {
return (Math.cos((x * 2.0)) / c) / ((x * s) * (c * (x * s)));
}
def code(x, c, s): return (math.cos((x * 2.0)) / c) / ((x * s) * (c * (x * s)))
function code(x, c, s) return Float64(Float64(cos(Float64(x * 2.0)) / c) / Float64(Float64(x * s) * Float64(c * Float64(x * s)))) end
function tmp = code(x, c, s) tmp = (cos((x * 2.0)) / c) / ((x * s) * (c * (x * s))); end
code[x_, c_, s_] := N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / c), $MachinePrecision] / N[(N[(x * s), $MachinePrecision] * N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\cos \left(x \cdot 2\right)}{c}}{\left(x \cdot s\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}
\end{array}
Initial program 69.7%
*-un-lft-identity69.7%
add-sqr-sqrt69.6%
times-frac69.6%
sqrt-prod69.6%
sqrt-pow150.5%
metadata-eval50.5%
pow150.5%
*-commutative50.5%
associate-*r*46.9%
unpow246.9%
pow-prod-down50.5%
sqrt-pow152.2%
metadata-eval52.2%
pow152.2%
*-commutative52.2%
Applied egg-rr97.6%
associate-/r*97.7%
frac-times92.8%
*-un-lft-identity92.8%
*-commutative92.8%
Applied egg-rr92.8%
Final simplification92.8%
(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 69.7%
*-un-lft-identity69.7%
add-sqr-sqrt69.6%
times-frac69.6%
sqrt-prod69.6%
sqrt-pow150.5%
metadata-eval50.5%
pow150.5%
*-commutative50.5%
associate-*r*46.9%
unpow246.9%
pow-prod-down50.5%
sqrt-pow152.2%
metadata-eval52.2%
pow152.2%
*-commutative52.2%
Applied egg-rr97.6%
associate-*l/97.7%
*-un-lft-identity97.7%
*-commutative97.7%
Applied egg-rr97.7%
Final simplification97.7%
(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 69.7%
Taylor expanded in x around 0 58.6%
associate-/r*58.2%
*-commutative58.2%
unpow258.2%
unpow258.2%
swap-sqr65.6%
unpow265.6%
associate-/r*66.0%
unpow266.0%
unpow266.0%
swap-sqr80.7%
unpow280.7%
*-commutative80.7%
Simplified80.7%
pow-flip80.8%
*-commutative80.8%
metadata-eval80.8%
Applied egg-rr80.8%
Final simplification80.8%
(FPCore (x c s) :precision binary64 (/ 1.0 (* (* c s) (* x (* c (* x s))))))
double code(double x, double c, double s) {
return 1.0 / ((c * s) * (x * (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 * s) * (x * (c * (x * s))))
end function
public static double code(double x, double c, double s) {
return 1.0 / ((c * s) * (x * (c * (x * s))));
}
def code(x, c, s): return 1.0 / ((c * s) * (x * (c * (x * s))))
function code(x, c, s) return Float64(1.0 / Float64(Float64(c * s) * Float64(x * Float64(c * Float64(x * s))))) end
function tmp = code(x, c, s) tmp = 1.0 / ((c * s) * (x * (c * (x * s)))); end
code[x_, c_, s_] := N[(1.0 / N[(N[(c * s), $MachinePrecision] * N[(x * N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(c \cdot s\right) \cdot \left(x \cdot \left(c \cdot \left(x \cdot s\right)\right)\right)}
\end{array}
Initial program 69.7%
Taylor expanded in x around 0 58.6%
associate-/r*58.2%
*-commutative58.2%
unpow258.2%
unpow258.2%
swap-sqr65.6%
unpow265.6%
associate-/r*66.0%
unpow266.0%
unpow266.0%
swap-sqr80.7%
unpow280.7%
*-commutative80.7%
Simplified80.7%
*-commutative80.7%
pow280.7%
Applied egg-rr80.7%
*-commutative80.7%
associate-*r*80.0%
associate-*r*79.6%
*-commutative79.6%
add-exp-log38.1%
add-exp-log41.9%
prod-exp41.9%
associate-*r*43.2%
Applied egg-rr43.2%
exp-sum43.2%
rem-exp-log38.1%
rem-exp-log80.5%
associate-*r*79.6%
Simplified79.6%
Final simplification79.6%
(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 69.7%
Taylor expanded in x around 0 58.6%
associate-/r*58.2%
*-commutative58.2%
unpow258.2%
unpow258.2%
swap-sqr65.6%
unpow265.6%
associate-/r*66.0%
unpow266.0%
unpow266.0%
swap-sqr80.7%
unpow280.7%
*-commutative80.7%
Simplified80.7%
*-commutative80.7%
pow280.7%
Applied egg-rr80.7%
Final simplification80.7%
(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(Float64(1.0 / 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[(N[(1.0 / 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{1}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 69.7%
*-un-lft-identity69.7%
add-sqr-sqrt69.6%
times-frac69.6%
sqrt-prod69.6%
sqrt-pow150.5%
metadata-eval50.5%
pow150.5%
*-commutative50.5%
associate-*r*46.9%
unpow246.9%
pow-prod-down50.5%
sqrt-pow152.2%
metadata-eval52.2%
pow152.2%
*-commutative52.2%
Applied egg-rr97.6%
associate-*l/97.7%
*-un-lft-identity97.7%
*-commutative97.7%
Applied egg-rr97.7%
Taylor expanded in x around 0 80.8%
Final simplification80.8%
herbie shell --seed 2024074
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))