
(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 5 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: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: 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 (<= (pow c 2.0) 4e-54)
(* (/ (/ 1.0 x) (* c s)) (/ (cos (* 2.0 x)) (* x (* c s))))
(/ (/ 1.0 t_0) t_0))))c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
double tmp;
if (pow(c, 2.0) <= 4e-54) {
tmp = ((1.0 / x) / (c * s)) * (cos((2.0 * x)) / (x * (c * s)));
} else {
tmp = (1.0 / t_0) / t_0;
}
return tmp;
}
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: 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
real(8) :: tmp
t_0 = c * (x * s)
if ((c ** 2.0d0) <= 4d-54) then
tmp = ((1.0d0 / x) / (c * s)) * (cos((2.0d0 * x)) / (x * (c * s)))
else
tmp = (1.0d0 / t_0) / t_0
end if
code = tmp
end function
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = c * (x * s);
double tmp;
if (Math.pow(c, 2.0) <= 4e-54) {
tmp = ((1.0 / x) / (c * s)) * (Math.cos((2.0 * x)) / (x * (c * s)));
} else {
tmp = (1.0 / t_0) / t_0;
}
return tmp;
}
c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) tmp = 0 if math.pow(c, 2.0) <= 4e-54: tmp = ((1.0 / x) / (c * s)) * (math.cos((2.0 * x)) / (x * (c * s))) else: tmp = (1.0 / t_0) / t_0 return tmp
c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(x * s)) tmp = 0.0 if ((c ^ 2.0) <= 4e-54) tmp = Float64(Float64(Float64(1.0 / x) / Float64(c * s)) * Float64(cos(Float64(2.0 * x)) / Float64(x * Float64(c * s)))); else tmp = Float64(Float64(1.0 / t_0) / t_0); end return tmp end
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
t_0 = c * (x * s);
tmp = 0.0;
if ((c ^ 2.0) <= 4e-54)
tmp = ((1.0 / x) / (c * s)) * (cos((2.0 * x)) / (x * (c * s)));
else
tmp = (1.0 / t_0) / t_0;
end
tmp_2 = tmp;
end
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Power[c, 2.0], $MachinePrecision], 4e-54], N[(N[(N[(1.0 / x), $MachinePrecision] / N[(c * s), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]]
\begin{array}{l}
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;{c}^{2} \leq 4 \cdot 10^{-54}:\\
\;\;\;\;\frac{\frac{1}{x}}{c \cdot s} \cdot \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(c \cdot s\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{t_0}}{t_0}\\
\end{array}
\end{array}
if (pow.f64 c 2) < 4.0000000000000001e-54Initial program 72.3%
*-un-lft-identity72.3%
associate-*r*75.1%
times-frac75.1%
*-commutative75.1%
associate-*r*72.0%
*-commutative72.0%
pow-prod-down88.2%
Applied egg-rr88.2%
frac-times88.3%
*-un-lft-identity88.3%
clear-num88.3%
associate-*l*81.5%
pow281.5%
unpow-prod-down98.5%
*-commutative98.5%
associate-*r*97.6%
*-commutative97.6%
*-commutative97.6%
associate-*l*98.5%
*-commutative98.5%
*-commutative98.5%
Applied egg-rr98.5%
clear-num98.5%
*-un-lft-identity98.5%
*-commutative98.5%
associate-*r*97.6%
pow297.6%
times-frac97.6%
*-commutative97.6%
*-commutative97.6%
associate-/l/97.7%
*-un-lft-identity97.7%
times-frac96.3%
associate-/r*96.3%
div-inv96.6%
associate-*r*98.6%
*-commutative98.6%
Applied egg-rr98.6%
if 4.0000000000000001e-54 < (pow.f64 c 2) Initial program 58.4%
add-cbrt-cube58.4%
add-cbrt-cube53.3%
cbrt-undiv53.3%
pow353.3%
pow353.3%
*-commutative53.3%
associate-*r*49.8%
unpow249.8%
pow-prod-down60.9%
Applied egg-rr60.9%
unpow260.9%
rem-square-sqrt60.9%
swap-sqr66.2%
unpow266.2%
unpow266.2%
rem-sqrt-square69.2%
*-commutative69.2%
Simplified69.2%
pow169.2%
metadata-eval69.2%
sqrt-pow169.2%
pow269.2%
add-sqr-sqrt69.2%
cbrt-div69.2%
rem-cbrt-cube69.2%
rem-cbrt-cube96.7%
unpow296.7%
associate-/l/97.4%
Applied egg-rr97.4%
Taylor expanded in x around 0 83.2%
Final simplification91.3%
NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: 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 (* 2.0 x)) t_0) t_0)))
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return (cos((2.0 * x)) / t_0) / t_0;
}
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: 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((2.0d0 * x)) / t_0) / t_0
end function
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = c * (x * s);
return (Math.cos((2.0 * x)) / t_0) / t_0;
}
c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) return (math.cos((2.0 * x)) / t_0) / t_0
c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(Float64(cos(Float64(2.0 * x)) / t_0) / t_0) end
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
t_0 = c * (x * s);
tmp = (cos((2.0 * x)) / t_0) / t_0;
end
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
code[x_, c_, s_] := Block[{t$95$0 = N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\frac{\frac{\cos \left(2 \cdot x\right)}{t_0}}{t_0}
\end{array}
\end{array}
Initial program 65.7%
add-cbrt-cube65.7%
add-cbrt-cube60.5%
cbrt-undiv60.5%
pow360.5%
pow360.5%
*-commutative60.5%
associate-*r*55.3%
unpow255.3%
pow-prod-down65.8%
Applied egg-rr65.8%
unpow265.8%
rem-square-sqrt65.8%
swap-sqr70.4%
unpow270.4%
unpow270.4%
rem-sqrt-square74.0%
*-commutative74.0%
Simplified74.0%
pow174.0%
metadata-eval74.0%
sqrt-pow174.0%
pow274.0%
add-sqr-sqrt74.0%
cbrt-div74.0%
rem-cbrt-cube74.0%
rem-cbrt-cube97.2%
unpow297.2%
associate-/l/97.5%
Applied egg-rr97.5%
Taylor expanded in x around inf 97.5%
*-commutative97.5%
Simplified97.5%
Final simplification97.5%
NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ (/ (/ (cos (* 2.0 x)) c) (* x s)) (* c (* x s))))
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
return ((cos((2.0 * x)) / c) / (x * s)) / (c * (x * s));
}
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: 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 = ((cos((2.0d0 * x)) / c) / (x * s)) / (c * (x * s))
end function
c = Math.abs(c);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
return ((Math.cos((2.0 * x)) / c) / (x * s)) / (c * (x * s));
}
c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): return ((math.cos((2.0 * x)) / c) / (x * s)) / (c * (x * s))
c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) return Float64(Float64(Float64(cos(Float64(2.0 * x)) / c) / Float64(x * s)) / Float64(c * Float64(x * s))) end
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = ((cos((2.0 * x)) / c) / (x * s)) / (c * (x * s));
end
NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(N[(N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision] / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{\frac{\cos \left(2 \cdot x\right)}{c}}{x \cdot s}}{c \cdot \left(x \cdot s\right)}
\end{array}
Initial program 65.7%
add-cbrt-cube65.7%
add-cbrt-cube60.5%
cbrt-undiv60.5%
pow360.5%
pow360.5%
*-commutative60.5%
associate-*r*55.3%
unpow255.3%
pow-prod-down65.8%
Applied egg-rr65.8%
unpow265.8%
rem-square-sqrt65.8%
swap-sqr70.4%
unpow270.4%
unpow270.4%
rem-sqrt-square74.0%
*-commutative74.0%
Simplified74.0%
pow174.0%
metadata-eval74.0%
sqrt-pow174.0%
pow274.0%
add-sqr-sqrt74.0%
cbrt-div74.0%
rem-cbrt-cube74.0%
rem-cbrt-cube97.2%
unpow297.2%
associate-/l/97.5%
Applied egg-rr97.5%
Final simplification97.5%
NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: 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))))
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return 1.0 / (t_0 * t_0);
}
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: 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
c = Math.abs(c);
s = Math.abs(s);
assert 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);
}
c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) return 1.0 / (t_0 * t_0)
c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(1.0 / Float64(t_0 * t_0)) end
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
t_0 = c * (x * s);
tmp = 1.0 / (t_0 * t_0);
end
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
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}
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\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 65.7%
Taylor expanded in x around 0 55.2%
*-commutative55.2%
unpow255.2%
unpow255.2%
swap-sqr67.9%
unpow267.9%
unpow267.9%
rem-square-sqrt67.9%
swap-sqr74.2%
unpow274.2%
unpow274.2%
rem-sqrt-square78.1%
*-commutative78.1%
Simplified78.1%
pow178.1%
metadata-eval78.1%
sqrt-pow178.1%
pow278.1%
add-sqr-sqrt78.1%
unpow278.1%
add-sqr-sqrt40.1%
fabs-sqr40.1%
add-sqr-sqrt54.4%
add-sqr-sqrt34.2%
fabs-sqr34.2%
add-sqr-sqrt78.1%
Applied egg-rr78.1%
Final simplification78.1%
NOTE: c should be positive before calling this function NOTE: s should be positive before calling this function NOTE: 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)))
c = abs(c);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return (1.0 / t_0) / t_0;
}
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: 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
c = Math.abs(c);
s = Math.abs(s);
assert 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;
}
c = abs(c) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) return (1.0 / t_0) / t_0
c = abs(c) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(x * s)) return Float64(Float64(1.0 / t_0) / t_0) end
c = abs(c)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
t_0 = c * (x * s);
tmp = (1.0 / t_0) / t_0;
end
NOTE: c should be positive before calling this function
NOTE: s should be positive before calling this function
NOTE: c and s should be sorted in increasing order before calling this function.
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}
c = |c|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\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 65.7%
add-cbrt-cube65.7%
add-cbrt-cube60.5%
cbrt-undiv60.5%
pow360.5%
pow360.5%
*-commutative60.5%
associate-*r*55.3%
unpow255.3%
pow-prod-down65.8%
Applied egg-rr65.8%
unpow265.8%
rem-square-sqrt65.8%
swap-sqr70.4%
unpow270.4%
unpow270.4%
rem-sqrt-square74.0%
*-commutative74.0%
Simplified74.0%
pow174.0%
metadata-eval74.0%
sqrt-pow174.0%
pow274.0%
add-sqr-sqrt74.0%
cbrt-div74.0%
rem-cbrt-cube74.0%
rem-cbrt-cube97.2%
unpow297.2%
associate-/l/97.5%
Applied egg-rr97.5%
Taylor expanded in x around 0 78.2%
Final simplification78.2%
herbie shell --seed 2023307
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))