
(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}
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (let* ((t_0 (* (* c x) s))) (/ (cos (+ x x)) (* t_0 t_0))))
assert(x < c && c < s);
double code(double x, double c, double s) {
double t_0 = (c * x) * s;
return cos((x + x)) / (t_0 * t_0);
}
NOTE: x, c, and s should be sorted in increasing order before calling this function.
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
assert x < c && c < s;
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);
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): t_0 = (c * x) * s return math.cos((x + x)) / (t_0 * t_0)
x, c, s = sort([x, c, s]) function code(x, c, s) t_0 = Float64(Float64(c * x) * s) return Float64(cos(Float64(x + x)) / Float64(t_0 * t_0)) end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
t_0 = (c * x) * s;
tmp = cos((x + x)) / (t_0 * t_0);
end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(c * x), $MachinePrecision] * s), $MachinePrecision]}, N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot x\right) \cdot s\\
\frac{\cos \left(x + x\right)}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 66.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
unpow2N/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
lift-*.f64N/A
count-2N/A
lower-+.f6498.1
Applied rewrites98.1%
NOTE: x, c, and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
:precision binary64
(let* ((t_0 (* (* c x) s)))
(if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))) -2e-102)
(/ (fma -2.0 (* x x) 1.0) (* t_0 t_0))
(pow (* s (* x c)) -2.0))))assert(x < c && c < s);
double code(double x, double c, double s) {
double t_0 = (c * x) * s;
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x))) <= -2e-102) {
tmp = fma(-2.0, (x * x), 1.0) / (t_0 * t_0);
} else {
tmp = pow((s * (x * c)), -2.0);
}
return tmp;
}
x, c, s = sort([x, c, s]) function code(x, c, s) t_0 = Float64(Float64(c * x) * s) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) <= -2e-102) tmp = Float64(fma(-2.0, Float64(x * x), 1.0) / Float64(t_0 * t_0)); else tmp = Float64(s * Float64(x * c)) ^ -2.0; end return tmp end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(c * x), $MachinePrecision] * s), $MachinePrecision]}, If[LessEqual[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], -2e-102], N[(N[(-2.0 * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot x\right) \cdot s\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -2 \cdot 10^{-102}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{t\_0 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\
\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))) < -1.99999999999999987e-102Initial program 53.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
unpow2N/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6499.5
Applied rewrites99.5%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6442.6
Applied rewrites42.6%
if -1.99999999999999987e-102 < (/.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.9%
Taylor expanded in x around 0
associate-*r*N/A
associate-/l/N/A
unpow2N/A
associate-*l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6469.3
Applied rewrites69.3%
Applied rewrites87.0%
NOTE: x, c, and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
:precision binary64
(let* ((t_0 (* (* c x) s)) (t_1 (* t_0 t_0)))
(if (<= (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))) -2e-102)
(/ (fma -2.0 (* x x) 1.0) t_1)
(/ 1.0 t_1))))assert(x < c && c < s);
double code(double x, double c, double s) {
double t_0 = (c * x) * s;
double t_1 = t_0 * t_0;
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x))) <= -2e-102) {
tmp = fma(-2.0, (x * x), 1.0) / t_1;
} else {
tmp = 1.0 / t_1;
}
return tmp;
}
x, c, s = sort([x, c, s]) function code(x, c, s) t_0 = Float64(Float64(c * x) * s) t_1 = Float64(t_0 * t_0) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(Float64(x * (s ^ 2.0)) * x))) <= -2e-102) tmp = Float64(fma(-2.0, Float64(x * x), 1.0) / t_1); else tmp = Float64(1.0 / t_1); end return tmp end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(c * x), $MachinePrecision] * s), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * t$95$0), $MachinePrecision]}, If[LessEqual[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], -2e-102], N[(N[(-2.0 * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] / t$95$1), $MachinePrecision], N[(1.0 / t$95$1), $MachinePrecision]]]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot x\right) \cdot s\\
t_1 := t\_0 \cdot t\_0\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)} \leq -2 \cdot 10^{-102}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-2, x \cdot x, 1\right)}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t\_1}\\
\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))) < -1.99999999999999987e-102Initial program 53.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
unpow2N/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6499.5
Applied rewrites99.5%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6442.6
Applied rewrites42.6%
if -1.99999999999999987e-102 < (/.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.9%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
unpow2N/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6498.0
Applied rewrites98.0%
Taylor expanded in x around 0
Applied rewrites86.9%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (let* ((t_0 (* (* c x) s))) (/ 1.0 (* t_0 t_0))))
assert(x < c && c < s);
double code(double x, double c, double s) {
double t_0 = (c * x) * s;
return 1.0 / (t_0 * t_0);
}
NOTE: x, c, and s should be sorted in increasing order before calling this function.
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
assert x < c && c < s;
public static double code(double x, double c, double s) {
double t_0 = (c * x) * s;
return 1.0 / (t_0 * t_0);
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): t_0 = (c * x) * s return 1.0 / (t_0 * t_0)
x, c, s = sort([x, c, s]) function code(x, c, s) t_0 = Float64(Float64(c * x) * s) return Float64(1.0 / Float64(t_0 * t_0)) end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
t_0 = (c * x) * s;
tmp = 1.0 / (t_0 * t_0);
end
NOTE: x, c, and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(N[(c * x), $MachinePrecision] * s), $MachinePrecision]}, N[(1.0 / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\begin{array}{l}
t_0 := \left(c \cdot x\right) \cdot s\\
\frac{1}{t\_0 \cdot t\_0}
\end{array}
\end{array}
Initial program 66.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
unpow2N/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites80.8%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ 1.0 (* c (* (* s x) (* (* c x) s)))))
assert(x < c && c < s);
double code(double x, double c, double s) {
return 1.0 / (c * ((s * x) * ((c * x) * s)));
}
NOTE: x, c, and s should be sorted in increasing order before calling this function.
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
assert x < c && c < s;
public static double code(double x, double c, double s) {
return 1.0 / (c * ((s * x) * ((c * x) * s)));
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): return 1.0 / (c * ((s * x) * ((c * x) * s)))
x, c, s = sort([x, c, s]) function code(x, c, s) return Float64(1.0 / Float64(c * Float64(Float64(s * x) * Float64(Float64(c * x) * s)))) end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
tmp = 1.0 / (c * ((s * x) * ((c * x) * s)));
end
NOTE: x, c, and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(1.0 / N[(c * N[(N[(s * x), $MachinePrecision] * N[(N[(c * x), $MachinePrecision] * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\frac{1}{c \cdot \left(\left(s \cdot x\right) \cdot \left(\left(c \cdot x\right) \cdot s\right)\right)}
\end{array}
Initial program 66.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
unpow2N/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites80.8%
Applied rewrites78.2%
NOTE: x, c, and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ 1.0 (* c (* (* s c) (* (* x x) s)))))
assert(x < c && c < s);
double code(double x, double c, double s) {
return 1.0 / (c * ((s * c) * ((x * x) * s)));
}
NOTE: x, c, and s should be sorted in increasing order before calling this function.
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 * c) * ((x * x) * s)))
end function
assert x < c && c < s;
public static double code(double x, double c, double s) {
return 1.0 / (c * ((s * c) * ((x * x) * s)));
}
[x, c, s] = sort([x, c, s]) def code(x, c, s): return 1.0 / (c * ((s * c) * ((x * x) * s)))
x, c, s = sort([x, c, s]) function code(x, c, s) return Float64(1.0 / Float64(c * Float64(Float64(s * c) * Float64(Float64(x * x) * s)))) end
x, c, s = num2cell(sort([x, c, s])){:}
function tmp = code(x, c, s)
tmp = 1.0 / (c * ((s * c) * ((x * x) * s)));
end
NOTE: x, c, and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(1.0 / N[(c * N[(N[(s * c), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, c, s] = \mathsf{sort}([x, c, s])\\
\\
\frac{1}{c \cdot \left(\left(s \cdot c\right) \cdot \left(\left(x \cdot x\right) \cdot s\right)\right)}
\end{array}
Initial program 66.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
unpow2N/A
unpow2N/A
unpow2N/A
unswap-sqrN/A
unswap-sqrN/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites80.8%
Applied rewrites78.2%
Applied rewrites68.0%
herbie shell --seed 2024318
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))