
(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}
c_m = (fabs.f64 c) (FPCore (x c_m s) :precision binary64 (let* ((t_0 (/ (/ (pow c_m -0.5) x) s))) (* t_0 (* t_0 (/ (cos (* x 2.0)) c_m)))))
c_m = fabs(c);
double code(double x, double c_m, double s) {
double t_0 = (pow(c_m, -0.5) / x) / s;
return t_0 * (t_0 * (cos((x * 2.0)) / c_m));
}
c_m = abs(c)
real(8) function code(x, c_m, s)
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s
real(8) :: t_0
t_0 = ((c_m ** (-0.5d0)) / x) / s
code = t_0 * (t_0 * (cos((x * 2.0d0)) / c_m))
end function
c_m = Math.abs(c);
public static double code(double x, double c_m, double s) {
double t_0 = (Math.pow(c_m, -0.5) / x) / s;
return t_0 * (t_0 * (Math.cos((x * 2.0)) / c_m));
}
c_m = math.fabs(c) def code(x, c_m, s): t_0 = (math.pow(c_m, -0.5) / x) / s return t_0 * (t_0 * (math.cos((x * 2.0)) / c_m))
c_m = abs(c) function code(x, c_m, s) t_0 = Float64(Float64((c_m ^ -0.5) / x) / s) return Float64(t_0 * Float64(t_0 * Float64(cos(Float64(x * 2.0)) / c_m))) end
c_m = abs(c); function tmp = code(x, c_m, s) t_0 = ((c_m ^ -0.5) / x) / s; tmp = t_0 * (t_0 * (cos((x * 2.0)) / c_m)); end
c_m = N[Abs[c], $MachinePrecision]
code[x_, c$95$m_, s_] := Block[{t$95$0 = N[(N[(N[Power[c$95$m, -0.5], $MachinePrecision] / x), $MachinePrecision] / s), $MachinePrecision]}, N[(t$95$0 * N[(t$95$0 * N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / c$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
c_m = \left|c\right|
\\
\begin{array}{l}
t_0 := \frac{\frac{{c\_m}^{-0.5}}{x}}{s}\\
t\_0 \cdot \left(t\_0 \cdot \frac{\cos \left(x \cdot 2\right)}{c\_m}\right)
\end{array}
\end{array}
Initial program 65.5%
*-un-lft-identity65.5%
add-sqr-sqrt65.5%
times-frac65.5%
Applied egg-rr97.4%
clear-num97.4%
un-div-inv97.4%
associate-/r*97.5%
*-commutative97.5%
*-un-lft-identity97.5%
times-frac97.5%
/-rgt-identity97.5%
*-commutative97.5%
Applied egg-rr97.5%
associate-/l/94.2%
add-sqr-sqrt43.2%
times-frac45.1%
inv-pow45.1%
sqrt-pow145.2%
metadata-eval45.2%
clear-num45.1%
un-div-inv45.1%
inv-pow45.1%
sqrt-pow145.1%
metadata-eval45.1%
Applied egg-rr45.1%
*-commutative45.1%
associate-/r*45.2%
associate-/r/45.2%
associate-/r*46.2%
Simplified46.2%
Final simplification46.2%
c_m = (fabs.f64 c) (FPCore (x c_m s) :precision binary64 (* (/ 1.0 (* c_m (* x s))) (/ (/ (/ (cos (* x 2.0)) s) x) c_m)))
c_m = fabs(c);
double code(double x, double c_m, double s) {
return (1.0 / (c_m * (x * s))) * (((cos((x * 2.0)) / s) / x) / c_m);
}
c_m = abs(c)
real(8) function code(x, c_m, s)
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s
code = (1.0d0 / (c_m * (x * s))) * (((cos((x * 2.0d0)) / s) / x) / c_m)
end function
c_m = Math.abs(c);
public static double code(double x, double c_m, double s) {
return (1.0 / (c_m * (x * s))) * (((Math.cos((x * 2.0)) / s) / x) / c_m);
}
c_m = math.fabs(c) def code(x, c_m, s): return (1.0 / (c_m * (x * s))) * (((math.cos((x * 2.0)) / s) / x) / c_m)
c_m = abs(c) function code(x, c_m, s) return Float64(Float64(1.0 / Float64(c_m * Float64(x * s))) * Float64(Float64(Float64(cos(Float64(x * 2.0)) / s) / x) / c_m)) end
c_m = abs(c); function tmp = code(x, c_m, s) tmp = (1.0 / (c_m * (x * s))) * (((cos((x * 2.0)) / s) / x) / c_m); end
c_m = N[Abs[c], $MachinePrecision] code[x_, c$95$m_, s_] := N[(N[(1.0 / N[(c$95$m * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / s), $MachinePrecision] / x), $MachinePrecision] / c$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
\frac{1}{c\_m \cdot \left(x \cdot s\right)} \cdot \frac{\frac{\frac{\cos \left(x \cdot 2\right)}{s}}{x}}{c\_m}
\end{array}
Initial program 65.5%
*-un-lft-identity65.5%
add-sqr-sqrt65.5%
times-frac65.5%
Applied egg-rr97.4%
Taylor expanded in x around inf 97.4%
*-commutative97.4%
associate-*r*94.8%
associate-/l/94.8%
associate-/l/97.5%
associate-/r*97.4%
associate-/l/97.6%
Simplified97.6%
Final simplification97.6%
c_m = (fabs.f64 c) (FPCore (x c_m s) :precision binary64 (/ (/ (/ 1.0 c_m) (* x s)) (* (* x s) (/ c_m (cos (* x 2.0))))))
c_m = fabs(c);
double code(double x, double c_m, double s) {
return ((1.0 / c_m) / (x * s)) / ((x * s) * (c_m / cos((x * 2.0))));
}
c_m = abs(c)
real(8) function code(x, c_m, s)
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s
code = ((1.0d0 / c_m) / (x * s)) / ((x * s) * (c_m / cos((x * 2.0d0))))
end function
c_m = Math.abs(c);
public static double code(double x, double c_m, double s) {
return ((1.0 / c_m) / (x * s)) / ((x * s) * (c_m / Math.cos((x * 2.0))));
}
c_m = math.fabs(c) def code(x, c_m, s): return ((1.0 / c_m) / (x * s)) / ((x * s) * (c_m / math.cos((x * 2.0))))
c_m = abs(c) function code(x, c_m, s) return Float64(Float64(Float64(1.0 / c_m) / Float64(x * s)) / Float64(Float64(x * s) * Float64(c_m / cos(Float64(x * 2.0))))) end
c_m = abs(c); function tmp = code(x, c_m, s) tmp = ((1.0 / c_m) / (x * s)) / ((x * s) * (c_m / cos((x * 2.0)))); end
c_m = N[Abs[c], $MachinePrecision] code[x_, c$95$m_, s_] := N[(N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision] / N[(N[(x * s), $MachinePrecision] * N[(c$95$m / N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
\frac{\frac{\frac{1}{c\_m}}{x \cdot s}}{\left(x \cdot s\right) \cdot \frac{c\_m}{\cos \left(x \cdot 2\right)}}
\end{array}
Initial program 65.5%
*-un-lft-identity65.5%
add-sqr-sqrt65.5%
times-frac65.5%
Applied egg-rr97.4%
clear-num97.4%
un-div-inv97.4%
associate-/r*97.5%
*-commutative97.5%
*-un-lft-identity97.5%
times-frac97.5%
/-rgt-identity97.5%
*-commutative97.5%
Applied egg-rr97.5%
Final simplification97.5%
c_m = (fabs.f64 c) (FPCore (x c_m s) :precision binary64 (/ (/ (cos (* x 2.0)) c_m) (* (* x s) (* c_m (* x s)))))
c_m = fabs(c);
double code(double x, double c_m, double s) {
return (cos((x * 2.0)) / c_m) / ((x * s) * (c_m * (x * s)));
}
c_m = abs(c)
real(8) function code(x, c_m, s)
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s
code = (cos((x * 2.0d0)) / c_m) / ((x * s) * (c_m * (x * s)))
end function
c_m = Math.abs(c);
public static double code(double x, double c_m, double s) {
return (Math.cos((x * 2.0)) / c_m) / ((x * s) * (c_m * (x * s)));
}
c_m = math.fabs(c) def code(x, c_m, s): return (math.cos((x * 2.0)) / c_m) / ((x * s) * (c_m * (x * s)))
c_m = abs(c) function code(x, c_m, s) return Float64(Float64(cos(Float64(x * 2.0)) / c_m) / Float64(Float64(x * s) * Float64(c_m * Float64(x * s)))) end
c_m = abs(c); function tmp = code(x, c_m, s) tmp = (cos((x * 2.0)) / c_m) / ((x * s) * (c_m * (x * s))); end
c_m = N[Abs[c], $MachinePrecision] code[x_, c$95$m_, s_] := N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / c$95$m), $MachinePrecision] / N[(N[(x * s), $MachinePrecision] * N[(c$95$m * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
\frac{\frac{\cos \left(x \cdot 2\right)}{c\_m}}{\left(x \cdot s\right) \cdot \left(c\_m \cdot \left(x \cdot s\right)\right)}
\end{array}
Initial program 65.5%
*-un-lft-identity65.5%
add-sqr-sqrt65.5%
times-frac65.5%
Applied egg-rr97.4%
*-commutative97.4%
associate-/r*97.5%
frac-times94.3%
div-inv94.2%
*-commutative94.2%
Applied egg-rr94.2%
Final simplification94.2%
c_m = (fabs.f64 c) (FPCore (x c_m s) :precision binary64 (let* ((t_0 (* c_m (* x s)))) (/ (/ (cos (* x 2.0)) t_0) t_0)))
c_m = fabs(c);
double code(double x, double c_m, double s) {
double t_0 = c_m * (x * s);
return (cos((x * 2.0)) / t_0) / t_0;
}
c_m = abs(c)
real(8) function code(x, c_m, s)
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s
real(8) :: t_0
t_0 = c_m * (x * s)
code = (cos((x * 2.0d0)) / t_0) / t_0
end function
c_m = Math.abs(c);
public static double code(double x, double c_m, double s) {
double t_0 = c_m * (x * s);
return (Math.cos((x * 2.0)) / t_0) / t_0;
}
c_m = math.fabs(c) def code(x, c_m, s): t_0 = c_m * (x * s) return (math.cos((x * 2.0)) / t_0) / t_0
c_m = abs(c) function code(x, c_m, s) t_0 = Float64(c_m * Float64(x * s)) return Float64(Float64(cos(Float64(x * 2.0)) / t_0) / t_0) end
c_m = abs(c); function tmp = code(x, c_m, s) t_0 = c_m * (x * s); tmp = (cos((x * 2.0)) / t_0) / t_0; end
c_m = N[Abs[c], $MachinePrecision]
code[x_, c$95$m_, s_] := Block[{t$95$0 = N[(c$95$m * 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}
c_m = \left|c\right|
\\
\begin{array}{l}
t_0 := c\_m \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.5%
*-un-lft-identity65.5%
add-sqr-sqrt65.5%
times-frac65.5%
Applied egg-rr97.4%
associate-*l/97.4%
*-un-lft-identity97.4%
div-inv97.4%
div-inv97.4%
*-commutative97.4%
Applied egg-rr97.4%
Final simplification97.4%
c_m = (fabs.f64 c) (FPCore (x c_m s) :precision binary64 (let* ((t_0 (* c_m (* x s)))) (/ 1.0 (* t_0 t_0))))
c_m = fabs(c);
double code(double x, double c_m, double s) {
double t_0 = c_m * (x * s);
return 1.0 / (t_0 * t_0);
}
c_m = abs(c)
real(8) function code(x, c_m, s)
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s
real(8) :: t_0
t_0 = c_m * (x * s)
code = 1.0d0 / (t_0 * t_0)
end function
c_m = Math.abs(c);
public static double code(double x, double c_m, double s) {
double t_0 = c_m * (x * s);
return 1.0 / (t_0 * t_0);
}
c_m = math.fabs(c) def code(x, c_m, s): t_0 = c_m * (x * s) return 1.0 / (t_0 * t_0)
c_m = abs(c) function code(x, c_m, s) t_0 = Float64(c_m * Float64(x * s)) return Float64(1.0 / Float64(t_0 * t_0)) end
c_m = abs(c); function tmp = code(x, c_m, s) t_0 = c_m * (x * s); tmp = 1.0 / (t_0 * t_0); end
c_m = N[Abs[c], $MachinePrecision]
code[x_, c$95$m_, s_] := Block[{t$95$0 = N[(c$95$m * N[(x * s), $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
c_m = \left|c\right|
\\
\begin{array}{l}
t_0 := c\_m \cdot \left(x \cdot s\right)\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 65.5%
Taylor expanded in x around 0 56.5%
associate-/r*56.5%
*-commutative56.5%
unpow256.5%
unpow256.5%
swap-sqr68.0%
unpow268.0%
associate-/r*68.0%
unpow268.0%
unpow268.0%
swap-sqr82.9%
unpow282.9%
*-commutative82.9%
Simplified82.9%
*-commutative82.9%
pow282.9%
Applied egg-rr82.9%
Final simplification82.9%
c_m = (fabs.f64 c) (FPCore (x c_m s) :precision binary64 (/ (/ (/ 1.0 c_m) (* x s)) (* c_m (* x s))))
c_m = fabs(c);
double code(double x, double c_m, double s) {
return ((1.0 / c_m) / (x * s)) / (c_m * (x * s));
}
c_m = abs(c)
real(8) function code(x, c_m, s)
real(8), intent (in) :: x
real(8), intent (in) :: c_m
real(8), intent (in) :: s
code = ((1.0d0 / c_m) / (x * s)) / (c_m * (x * s))
end function
c_m = Math.abs(c);
public static double code(double x, double c_m, double s) {
return ((1.0 / c_m) / (x * s)) / (c_m * (x * s));
}
c_m = math.fabs(c) def code(x, c_m, s): return ((1.0 / c_m) / (x * s)) / (c_m * (x * s))
c_m = abs(c) function code(x, c_m, s) return Float64(Float64(Float64(1.0 / c_m) / Float64(x * s)) / Float64(c_m * Float64(x * s))) end
c_m = abs(c); function tmp = code(x, c_m, s) tmp = ((1.0 / c_m) / (x * s)) / (c_m * (x * s)); end
c_m = N[Abs[c], $MachinePrecision] code[x_, c$95$m_, s_] := N[(N[(N[(1.0 / c$95$m), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision] / N[(c$95$m * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c_m = \left|c\right|
\\
\frac{\frac{\frac{1}{c\_m}}{x \cdot s}}{c\_m \cdot \left(x \cdot s\right)}
\end{array}
Initial program 65.5%
*-un-lft-identity65.5%
add-sqr-sqrt65.5%
times-frac65.5%
Applied egg-rr97.4%
clear-num97.4%
un-div-inv97.4%
associate-/r*97.5%
*-commutative97.5%
*-un-lft-identity97.5%
times-frac97.5%
/-rgt-identity97.5%
*-commutative97.5%
Applied egg-rr97.5%
Taylor expanded in x around 0 82.9%
Final simplification82.9%
herbie shell --seed 2024055
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))