
(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 (let* ((t_0 (* c (* x s)))) (/ (/ (cos (+ x x)) t_0) t_0)))
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return (cos((x + 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((x + 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((x + x)) / t_0) / t_0;
}
def code(x, c, s): t_0 = c * (x * s) return (math.cos((x + x)) / t_0) / t_0
function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(Float64(cos(Float64(x + x)) / t_0) / t_0) end
function tmp = code(x, c, s) t_0 = c * (x * s); tmp = (cos((x + 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[(x + 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(x + x\right)}{t\_0}}{t\_0}
\end{array}
\end{array}
Initial program 68.4%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
lift-pow.f64N/A
lift-pow.f64N/A
pow-prod-downN/A
pow2N/A
pow-prod-downN/A
lower-pow.f64N/A
lower-*.f64N/A
lower-*.f6497.2
Applied rewrites97.2%
lift-/.f64N/A
lift-pow.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f6497.5
lift-*.f64N/A
count-2N/A
lift-+.f6497.5
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6496.5
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6498.6
Applied rewrites98.6%
Final simplification98.6%
(FPCore (x c s)
:precision binary64
(let* ((t_0 (* c (* x s))))
(if (<= (/ (cos (* x 2.0)) (* (pow c 2.0) (* x (* x (pow s 2.0))))) -2e+21)
(/ -2.0 (* c (* c (* s s))))
(/ (/ 1.0 t_0) t_0))))
double code(double x, double c, double s) {
double t_0 = c * (x * s);
double tmp;
if ((cos((x * 2.0)) / (pow(c, 2.0) * (x * (x * pow(s, 2.0))))) <= -2e+21) {
tmp = -2.0 / (c * (c * (s * s)));
} else {
tmp = (1.0 / t_0) / t_0;
}
return tmp;
}
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
real(8) :: tmp
t_0 = c * (x * s)
if ((cos((x * 2.0d0)) / ((c ** 2.0d0) * (x * (x * (s ** 2.0d0))))) <= (-2d+21)) then
tmp = (-2.0d0) / (c * (c * (s * s)))
else
tmp = (1.0d0 / t_0) / t_0
end if
code = tmp
end function
public static double code(double x, double c, double s) {
double t_0 = c * (x * s);
double tmp;
if ((Math.cos((x * 2.0)) / (Math.pow(c, 2.0) * (x * (x * Math.pow(s, 2.0))))) <= -2e+21) {
tmp = -2.0 / (c * (c * (s * s)));
} else {
tmp = (1.0 / t_0) / t_0;
}
return tmp;
}
def code(x, c, s): t_0 = c * (x * s) tmp = 0 if (math.cos((x * 2.0)) / (math.pow(c, 2.0) * (x * (x * math.pow(s, 2.0))))) <= -2e+21: tmp = -2.0 / (c * (c * (s * s))) else: tmp = (1.0 / t_0) / t_0 return tmp
function code(x, c, s) t_0 = Float64(c * Float64(x * s)) tmp = 0.0 if (Float64(cos(Float64(x * 2.0)) / Float64((c ^ 2.0) * Float64(x * Float64(x * (s ^ 2.0))))) <= -2e+21) tmp = Float64(-2.0 / Float64(c * Float64(c * Float64(s * s)))); else tmp = Float64(Float64(1.0 / t_0) / t_0); end return tmp end
function tmp_2 = code(x, c, s) t_0 = c * (x * s); tmp = 0.0; if ((cos((x * 2.0)) / ((c ^ 2.0) * (x * (x * (s ^ 2.0))))) <= -2e+21) tmp = -2.0 / (c * (c * (s * s))); else tmp = (1.0 / t_0) / t_0; end tmp_2 = tmp; end
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(x * N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -2e+21], N[(-2.0 / N[(c * N[(c * N[(s * s), $MachinePrecision]), $MachinePrecision]), $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)\\
\mathbf{if}\;\frac{\cos \left(x \cdot 2\right)}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s}^{2}\right)\right)} \leq -2 \cdot 10^{+21}:\\
\;\;\;\;\frac{-2}{c \cdot \left(c \cdot \left(s \cdot s\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{t\_0}}{t\_0}\\
\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))) < -2e21Initial program 64.4%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-pow.f64N/A
unpow2N/A
associate-*r*N/A
associate-/r*N/A
lower-/.f64N/A
Applied rewrites54.3%
Taylor expanded in x around 0
lower-/.f64N/A
Applied rewrites37.8%
Taylor expanded in x around inf
Applied rewrites52.2%
if -2e21 < (/.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 67.2%
Taylor expanded in x around 0
lower-/.f64N/A
associate-*r*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.6
Applied rewrites75.6%
Applied rewrites84.6%
Final simplification82.3%
herbie shell --seed 2024222
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))