
(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}
NOTE: x 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 (cos (* x 2.0))))
(if (<= x 1.5e+118)
(/ (/ (- (/ t_0 c)) (* x s)) (* c (* x (- s))))
(* (/ t_0 (* s (* x c))) (* (/ (/ 1.0 c) x) (/ 1.0 s))))))x = abs(x);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = cos((x * 2.0));
double tmp;
if (x <= 1.5e+118) {
tmp = (-(t_0 / c) / (x * s)) / (c * (x * -s));
} else {
tmp = (t_0 / (s * (x * c))) * (((1.0 / c) / x) * (1.0 / s));
}
return tmp;
}
NOTE: x 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 = cos((x * 2.0d0))
if (x <= 1.5d+118) then
tmp = (-(t_0 / c) / (x * s)) / (c * (x * -s))
else
tmp = (t_0 / (s * (x * c))) * (((1.0d0 / c) / x) * (1.0d0 / s))
end if
code = tmp
end function
x = Math.abs(x);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = Math.cos((x * 2.0));
double tmp;
if (x <= 1.5e+118) {
tmp = (-(t_0 / c) / (x * s)) / (c * (x * -s));
} else {
tmp = (t_0 / (s * (x * c))) * (((1.0 / c) / x) * (1.0 / s));
}
return tmp;
}
x = abs(x) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = math.cos((x * 2.0)) tmp = 0 if x <= 1.5e+118: tmp = (-(t_0 / c) / (x * s)) / (c * (x * -s)) else: tmp = (t_0 / (s * (x * c))) * (((1.0 / c) / x) * (1.0 / s)) return tmp
x = abs(x) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = cos(Float64(x * 2.0)) tmp = 0.0 if (x <= 1.5e+118) tmp = Float64(Float64(Float64(-Float64(t_0 / c)) / Float64(x * s)) / Float64(c * Float64(x * Float64(-s)))); else tmp = Float64(Float64(t_0 / Float64(s * Float64(x * c))) * Float64(Float64(Float64(1.0 / c) / x) * Float64(1.0 / s))); end return tmp end
x = abs(x)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
t_0 = cos((x * 2.0));
tmp = 0.0;
if (x <= 1.5e+118)
tmp = (-(t_0 / c) / (x * s)) / (c * (x * -s));
else
tmp = (t_0 / (s * (x * c))) * (((1.0 / c) / x) * (1.0 / s));
end
tmp_2 = tmp;
end
NOTE: x 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[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 1.5e+118], N[(N[((-N[(t$95$0 / c), $MachinePrecision]) / N[(x * s), $MachinePrecision]), $MachinePrecision] / N[(c * N[(x * (-s)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 / N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(1.0 / c), $MachinePrecision] / x), $MachinePrecision] * N[(1.0 / s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \cos \left(x \cdot 2\right)\\
\mathbf{if}\;x \leq 1.5 \cdot 10^{+118}:\\
\;\;\;\;\frac{\frac{-\frac{t_0}{c}}{x \cdot s}}{c \cdot \left(x \cdot \left(-s\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{s \cdot \left(x \cdot c\right)} \cdot \left(\frac{\frac{1}{c}}{x} \cdot \frac{1}{s}\right)\\
\end{array}
\end{array}
if x < 1.5e118Initial program 69.3%
*-un-lft-identity69.3%
times-frac68.9%
pow-flip68.9%
metadata-eval68.9%
*-commutative68.9%
associate-*r*64.4%
unpow264.4%
pow-prod-down75.9%
Applied egg-rr75.9%
*-commutative75.9%
div-inv75.9%
associate-*l*75.9%
*-commutative75.9%
pow-flip75.9%
add-sqr-sqrt43.7%
fabs-sqr43.7%
add-sqr-sqrt75.9%
metadata-eval75.9%
unpow-prod-down96.8%
*-commutative96.8%
metadata-eval96.8%
pow-flip96.8%
div-inv96.8%
unpow296.8%
associate-/l/96.8%
Applied egg-rr96.8%
if 1.5e118 < x Initial program 50.5%
*-un-lft-identity50.5%
times-frac50.5%
pow-flip50.4%
metadata-eval50.4%
*-commutative50.4%
associate-*r*38.9%
unpow238.9%
pow-prod-down67.1%
Applied egg-rr67.1%
*-commutative67.1%
div-inv67.1%
associate-*l*67.1%
*-commutative67.1%
pow-flip67.0%
add-sqr-sqrt39.6%
fabs-sqr39.6%
add-sqr-sqrt67.0%
metadata-eval67.0%
unpow-prod-down91.5%
*-commutative91.5%
metadata-eval91.5%
pow-flip89.7%
div-inv89.7%
unpow289.7%
associate-/l/91.5%
Applied egg-rr91.6%
associate-/r*86.2%
distribute-frac-neg86.2%
associate-/r*86.2%
distribute-frac-neg86.2%
distribute-rgt-neg-out86.2%
frac-2neg86.2%
associate-/r*91.5%
div-inv91.6%
*-commutative91.6%
associate-*r*89.1%
*-commutative89.1%
associate-*r*97.1%
Applied egg-rr97.1%
associate-/r*97.1%
div-inv97.1%
associate-/r*97.3%
Applied egg-rr97.3%
Final simplification96.9%
NOTE: x 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 (* s (* x c))))
(if (<= x 4e-26)
(/ (/ (/ 1.0 (* x s)) c) (* c (* x s)))
(* (/ (cos (* x 2.0)) t_0) (/ 1.0 t_0)))))x = abs(x);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = s * (x * c);
double tmp;
if (x <= 4e-26) {
tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
} else {
tmp = (cos((x * 2.0)) / t_0) * (1.0 / t_0);
}
return tmp;
}
NOTE: x 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 = s * (x * c)
if (x <= 4d-26) then
tmp = ((1.0d0 / (x * s)) / c) / (c * (x * s))
else
tmp = (cos((x * 2.0d0)) / t_0) * (1.0d0 / t_0)
end if
code = tmp
end function
x = Math.abs(x);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = s * (x * c);
double tmp;
if (x <= 4e-26) {
tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
} else {
tmp = (Math.cos((x * 2.0)) / t_0) * (1.0 / t_0);
}
return tmp;
}
x = abs(x) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = s * (x * c) tmp = 0 if x <= 4e-26: tmp = ((1.0 / (x * s)) / c) / (c * (x * s)) else: tmp = (math.cos((x * 2.0)) / t_0) * (1.0 / t_0) return tmp
x = abs(x) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(s * Float64(x * c)) tmp = 0.0 if (x <= 4e-26) tmp = Float64(Float64(Float64(1.0 / Float64(x * s)) / c) / Float64(c * Float64(x * s))); else tmp = Float64(Float64(cos(Float64(x * 2.0)) / t_0) * Float64(1.0 / t_0)); end return tmp end
x = abs(x)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
t_0 = s * (x * c);
tmp = 0.0;
if (x <= 4e-26)
tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
else
tmp = (cos((x * 2.0)) / t_0) * (1.0 / t_0);
end
tmp_2 = tmp;
end
NOTE: x 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[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 4e-26], N[(N[(N[(1.0 / N[(x * s), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / N[(c * N[(x * s), $MachinePrecision]), $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}
x = |x|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := s \cdot \left(x \cdot c\right)\\
\mathbf{if}\;x \leq 4 \cdot 10^{-26}:\\
\;\;\;\;\frac{\frac{\frac{1}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x \cdot 2\right)}{t_0} \cdot \frac{1}{t_0}\\
\end{array}
\end{array}
if x < 4.0000000000000002e-26Initial program 68.4%
Taylor expanded in x around 0 59.1%
associate-/r*58.5%
*-commutative58.5%
unpow258.5%
unpow258.5%
swap-sqr69.2%
unpow269.2%
associate-/r*69.7%
rem-square-sqrt69.7%
unpow269.7%
swap-sqr74.9%
unpow274.9%
unpow274.9%
rem-sqrt-square83.1%
*-commutative83.1%
Simplified83.1%
clear-num83.1%
add-sqr-sqrt83.1%
clear-num83.1%
sqrt-div83.1%
metadata-eval83.1%
unpow283.1%
sqrt-prod57.0%
add-sqr-sqrt55.9%
add-sqr-sqrt33.7%
fabs-sqr33.7%
add-sqr-sqrt54.5%
clear-num54.5%
sqrt-div54.5%
metadata-eval54.5%
unpow254.5%
Applied egg-rr83.2%
un-div-inv83.2%
*-commutative83.2%
*-commutative83.2%
associate-/r*82.8%
*-commutative82.8%
Applied egg-rr82.8%
if 4.0000000000000002e-26 < x Initial program 61.7%
*-un-lft-identity61.7%
times-frac61.6%
pow-flip61.6%
metadata-eval61.6%
*-commutative61.6%
associate-*r*55.1%
unpow255.1%
pow-prod-down72.8%
Applied egg-rr72.8%
*-commutative72.8%
div-inv72.8%
associate-*l*72.8%
*-commutative72.8%
pow-flip72.8%
add-sqr-sqrt37.4%
fabs-sqr37.4%
add-sqr-sqrt72.8%
metadata-eval72.8%
unpow-prod-down94.9%
*-commutative94.9%
metadata-eval94.9%
pow-flip93.9%
div-inv93.9%
unpow293.9%
associate-/l/94.9%
Applied egg-rr95.0%
associate-/r*91.9%
distribute-frac-neg91.9%
associate-/r*91.9%
distribute-frac-neg91.9%
distribute-rgt-neg-out91.9%
frac-2neg91.9%
associate-/r*94.9%
div-inv94.9%
*-commutative94.9%
associate-*r*93.5%
*-commutative93.5%
associate-*r*98.1%
Applied egg-rr98.1%
Final simplification86.5%
NOTE: x 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 (* s (* x c))) (t_1 (cos (* x 2.0))))
(if (<= x 3.1e+103)
(/ (/ (- (/ t_1 c)) (* x s)) (* c (* x (- s))))
(* (/ t_1 t_0) (/ 1.0 t_0)))))x = abs(x);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = s * (x * c);
double t_1 = cos((x * 2.0));
double tmp;
if (x <= 3.1e+103) {
tmp = (-(t_1 / c) / (x * s)) / (c * (x * -s));
} else {
tmp = (t_1 / t_0) * (1.0 / t_0);
}
return tmp;
}
NOTE: x 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) :: t_1
real(8) :: tmp
t_0 = s * (x * c)
t_1 = cos((x * 2.0d0))
if (x <= 3.1d+103) then
tmp = (-(t_1 / c) / (x * s)) / (c * (x * -s))
else
tmp = (t_1 / t_0) * (1.0d0 / t_0)
end if
code = tmp
end function
x = Math.abs(x);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = s * (x * c);
double t_1 = Math.cos((x * 2.0));
double tmp;
if (x <= 3.1e+103) {
tmp = (-(t_1 / c) / (x * s)) / (c * (x * -s));
} else {
tmp = (t_1 / t_0) * (1.0 / t_0);
}
return tmp;
}
x = abs(x) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = s * (x * c) t_1 = math.cos((x * 2.0)) tmp = 0 if x <= 3.1e+103: tmp = (-(t_1 / c) / (x * s)) / (c * (x * -s)) else: tmp = (t_1 / t_0) * (1.0 / t_0) return tmp
x = abs(x) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(s * Float64(x * c)) t_1 = cos(Float64(x * 2.0)) tmp = 0.0 if (x <= 3.1e+103) tmp = Float64(Float64(Float64(-Float64(t_1 / c)) / Float64(x * s)) / Float64(c * Float64(x * Float64(-s)))); else tmp = Float64(Float64(t_1 / t_0) * Float64(1.0 / t_0)); end return tmp end
x = abs(x)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
t_0 = s * (x * c);
t_1 = cos((x * 2.0));
tmp = 0.0;
if (x <= 3.1e+103)
tmp = (-(t_1 / c) / (x * s)) / (c * (x * -s));
else
tmp = (t_1 / t_0) * (1.0 / t_0);
end
tmp_2 = tmp;
end
NOTE: x 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[(s * N[(x * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 3.1e+103], N[(N[((-N[(t$95$1 / c), $MachinePrecision]) / N[(x * s), $MachinePrecision]), $MachinePrecision] / N[(c * N[(x * (-s)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / t$95$0), $MachinePrecision] * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
x = |x|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := s \cdot \left(x \cdot c\right)\\
t_1 := \cos \left(x \cdot 2\right)\\
\mathbf{if}\;x \leq 3.1 \cdot 10^{+103}:\\
\;\;\;\;\frac{\frac{-\frac{t_1}{c}}{x \cdot s}}{c \cdot \left(x \cdot \left(-s\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1}{t_0} \cdot \frac{1}{t_0}\\
\end{array}
\end{array}
if x < 3.1000000000000002e103Initial program 69.4%
*-un-lft-identity69.4%
times-frac68.9%
pow-flip68.9%
metadata-eval68.9%
*-commutative68.9%
associate-*r*64.3%
unpow264.3%
pow-prod-down76.0%
Applied egg-rr76.0%
*-commutative76.0%
div-inv76.0%
associate-*l*76.0%
*-commutative76.0%
pow-flip76.0%
add-sqr-sqrt43.4%
fabs-sqr43.4%
add-sqr-sqrt76.0%
metadata-eval76.0%
unpow-prod-down96.8%
*-commutative96.8%
metadata-eval96.8%
pow-flip96.7%
div-inv96.7%
unpow296.7%
associate-/l/96.8%
Applied egg-rr96.8%
if 3.1000000000000002e103 < x Initial program 51.7%
*-un-lft-identity51.7%
times-frac51.7%
pow-flip51.7%
metadata-eval51.7%
*-commutative51.7%
associate-*r*41.1%
unpow241.1%
pow-prod-down67.1%
Applied egg-rr67.1%
*-commutative67.1%
div-inv67.1%
associate-*l*67.1%
*-commutative67.1%
pow-flip67.1%
add-sqr-sqrt41.7%
fabs-sqr41.7%
add-sqr-sqrt67.1%
metadata-eval67.1%
unpow-prod-down92.1%
*-commutative92.1%
metadata-eval92.1%
pow-flip90.5%
div-inv90.5%
unpow290.5%
associate-/l/92.1%
Applied egg-rr92.3%
associate-/r*87.3%
distribute-frac-neg87.3%
associate-/r*87.3%
distribute-frac-neg87.3%
distribute-rgt-neg-out87.3%
frac-2neg87.3%
associate-/r*92.1%
div-inv92.2%
*-commutative92.2%
associate-*r*89.9%
*-commutative89.9%
associate-*r*97.3%
Applied egg-rr97.3%
Final simplification96.9%
NOTE: x 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 (<= x 4.5e-46)
(/ (/ (/ 1.0 (* x s)) c) t_0)
(/ (/ (cos (* x 2.0)) (* x c)) (* s t_0)))))x = abs(x);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
double tmp;
if (x <= 4.5e-46) {
tmp = ((1.0 / (x * s)) / c) / t_0;
} else {
tmp = (cos((x * 2.0)) / (x * c)) / (s * t_0);
}
return tmp;
}
NOTE: x 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 (x <= 4.5d-46) then
tmp = ((1.0d0 / (x * s)) / c) / t_0
else
tmp = (cos((x * 2.0d0)) / (x * c)) / (s * t_0)
end if
code = tmp
end function
x = Math.abs(x);
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 (x <= 4.5e-46) {
tmp = ((1.0 / (x * s)) / c) / t_0;
} else {
tmp = (Math.cos((x * 2.0)) / (x * c)) / (s * t_0);
}
return tmp;
}
x = abs(x) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) tmp = 0 if x <= 4.5e-46: tmp = ((1.0 / (x * s)) / c) / t_0 else: tmp = (math.cos((x * 2.0)) / (x * c)) / (s * t_0) return tmp
x = abs(x) s = abs(s) c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(c * Float64(x * s)) tmp = 0.0 if (x <= 4.5e-46) tmp = Float64(Float64(Float64(1.0 / Float64(x * s)) / c) / t_0); else tmp = Float64(Float64(cos(Float64(x * 2.0)) / Float64(x * c)) / Float64(s * t_0)); end return tmp end
x = abs(x)
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 (x <= 4.5e-46)
tmp = ((1.0 / (x * s)) / c) / t_0;
else
tmp = (cos((x * 2.0)) / (x * c)) / (s * t_0);
end
tmp_2 = tmp;
end
NOTE: x 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[x, 4.5e-46], N[(N[(N[(1.0 / N[(x * s), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(x * c), $MachinePrecision]), $MachinePrecision] / N[(s * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
x = |x|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := c \cdot \left(x \cdot s\right)\\
\mathbf{if}\;x \leq 4.5 \cdot 10^{-46}:\\
\;\;\;\;\frac{\frac{\frac{1}{x \cdot s}}{c}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\cos \left(x \cdot 2\right)}{x \cdot c}}{s \cdot t_0}\\
\end{array}
\end{array}
if x < 4.50000000000000001e-46Initial program 68.8%
Taylor expanded in x around 0 59.1%
associate-/r*58.6%
*-commutative58.6%
unpow258.6%
unpow258.6%
swap-sqr69.6%
unpow269.6%
associate-/r*70.2%
rem-square-sqrt70.2%
unpow270.2%
swap-sqr75.4%
unpow275.4%
unpow275.4%
rem-sqrt-square82.5%
*-commutative82.5%
Simplified82.5%
clear-num82.5%
add-sqr-sqrt82.5%
clear-num82.5%
sqrt-div82.5%
metadata-eval82.5%
unpow282.5%
sqrt-prod57.0%
add-sqr-sqrt56.4%
add-sqr-sqrt33.9%
fabs-sqr33.9%
add-sqr-sqrt54.4%
clear-num54.4%
sqrt-div54.4%
metadata-eval54.4%
unpow254.4%
Applied egg-rr82.6%
un-div-inv82.6%
*-commutative82.6%
*-commutative82.6%
associate-/r*82.2%
*-commutative82.2%
Applied egg-rr82.2%
if 4.50000000000000001e-46 < x Initial program 61.2%
*-un-lft-identity61.2%
times-frac61.1%
pow-flip61.1%
metadata-eval61.1%
*-commutative61.1%
associate-*r*55.3%
unpow255.3%
pow-prod-down71.2%
Applied egg-rr71.2%
*-commutative71.2%
div-inv71.2%
associate-*l*71.2%
*-commutative71.2%
pow-flip71.2%
add-sqr-sqrt36.5%
fabs-sqr36.5%
add-sqr-sqrt71.2%
metadata-eval71.2%
unpow-prod-down95.4%
*-commutative95.4%
metadata-eval95.4%
pow-flip94.5%
div-inv94.5%
unpow294.5%
associate-/l/95.4%
Applied egg-rr95.5%
associate-/r*92.7%
distribute-frac-neg92.7%
associate-/r*92.7%
distribute-frac-neg92.7%
distribute-rgt-neg-out92.7%
frac-2neg92.7%
associate-/r*95.4%
div-inv95.3%
*-commutative95.3%
associate-*r*94.1%
*-commutative94.1%
associate-*r*98.2%
Applied egg-rr98.2%
associate-/r*98.2%
frac-times90.7%
div-inv90.7%
associate-*l*86.6%
Applied egg-rr86.6%
Final simplification83.4%
NOTE: x 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 (* x 2.0)) t_0) t_0)))
x = abs(x);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
double t_0 = c * (x * s);
return (cos((x * 2.0)) / t_0) / t_0;
}
NOTE: x 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((x * 2.0d0)) / t_0) / t_0
end function
x = Math.abs(x);
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((x * 2.0)) / t_0) / t_0;
}
x = abs(x) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): t_0 = c * (x * s) return (math.cos((x * 2.0)) / t_0) / t_0
x = abs(x) 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(x * 2.0)) / t_0) / t_0) end
x = abs(x)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
t_0 = c * (x * s);
tmp = (cos((x * 2.0)) / t_0) / t_0;
end
NOTE: x 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[(x * 2.0), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\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 66.8%
*-un-lft-identity66.8%
times-frac66.3%
pow-flip66.4%
metadata-eval66.4%
*-commutative66.4%
associate-*r*60.9%
unpow260.9%
pow-prod-down74.7%
Applied egg-rr74.7%
*-commutative74.7%
div-inv74.7%
associate-*l*74.7%
*-commutative74.7%
pow-flip74.7%
add-sqr-sqrt43.1%
fabs-sqr43.1%
add-sqr-sqrt74.7%
metadata-eval74.7%
unpow-prod-down96.1%
*-commutative96.1%
metadata-eval96.1%
pow-flip95.8%
div-inv95.8%
unpow295.8%
associate-/l/96.1%
Applied egg-rr96.1%
Final simplification96.1%
NOTE: x 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))))
x = abs(x);
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: x 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
x = Math.abs(x);
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);
}
x = abs(x) 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)
x = abs(x) 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
x = abs(x)
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: x 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}
x = |x|\\
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 66.8%
Taylor expanded in x around 0 55.3%
associate-/r*54.9%
*-commutative54.9%
unpow254.9%
unpow254.9%
swap-sqr64.8%
unpow264.8%
associate-/r*65.2%
rem-square-sqrt65.2%
unpow265.2%
swap-sqr69.7%
unpow269.7%
unpow269.7%
rem-sqrt-square76.7%
*-commutative76.7%
Simplified76.7%
unpow-prod-down65.2%
pow265.2%
pow265.2%
sqr-abs65.2%
swap-sqr76.7%
Applied egg-rr76.7%
Final simplification76.7%
NOTE: x 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)))
x = abs(x);
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: x 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
x = Math.abs(x);
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;
}
x = abs(x) 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
x = abs(x) 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
x = abs(x)
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: x 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}
x = |x|\\
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 66.8%
*-un-lft-identity66.8%
times-frac66.3%
pow-flip66.4%
metadata-eval66.4%
*-commutative66.4%
associate-*r*60.9%
unpow260.9%
pow-prod-down74.7%
Applied egg-rr74.7%
*-commutative74.7%
div-inv74.7%
associate-*l*74.7%
*-commutative74.7%
pow-flip74.7%
add-sqr-sqrt43.1%
fabs-sqr43.1%
add-sqr-sqrt74.7%
metadata-eval74.7%
unpow-prod-down96.1%
*-commutative96.1%
metadata-eval96.1%
pow-flip95.8%
div-inv95.8%
unpow295.8%
associate-/l/96.1%
Applied egg-rr96.1%
Taylor expanded in x around 0 76.7%
Final simplification76.7%
NOTE: x 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 (/ (/ (/ 1.0 (* x s)) c) (* c (* x s))))
x = abs(x);
s = abs(s);
assert(c < s);
double code(double x, double c, double s) {
return ((1.0 / (x * s)) / c) / (c * (x * s));
}
NOTE: x 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 = ((1.0d0 / (x * s)) / c) / (c * (x * s))
end function
x = Math.abs(x);
s = Math.abs(s);
assert c < s;
public static double code(double x, double c, double s) {
return ((1.0 / (x * s)) / c) / (c * (x * s));
}
x = abs(x) s = abs(s) [c, s] = sort([c, s]) def code(x, c, s): return ((1.0 / (x * s)) / c) / (c * (x * s))
x = abs(x) s = abs(s) c, s = sort([c, s]) function code(x, c, s) return Float64(Float64(Float64(1.0 / Float64(x * s)) / c) / Float64(c * Float64(x * s))) end
x = abs(x)
s = abs(s)
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = ((1.0 / (x * s)) / c) / (c * (x * s));
end
NOTE: x 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[(1.0 / N[(x * s), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision] / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
s = |s|\\
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{\frac{1}{x \cdot s}}{c}}{c \cdot \left(x \cdot s\right)}
\end{array}
Initial program 66.8%
Taylor expanded in x around 0 55.3%
associate-/r*54.9%
*-commutative54.9%
unpow254.9%
unpow254.9%
swap-sqr64.8%
unpow264.8%
associate-/r*65.2%
rem-square-sqrt65.2%
unpow265.2%
swap-sqr69.7%
unpow269.7%
unpow269.7%
rem-sqrt-square76.7%
*-commutative76.7%
Simplified76.7%
clear-num76.7%
add-sqr-sqrt76.7%
clear-num76.7%
sqrt-div76.7%
metadata-eval76.7%
unpow276.7%
sqrt-prod51.2%
add-sqr-sqrt56.5%
add-sqr-sqrt32.6%
fabs-sqr32.6%
add-sqr-sqrt54.3%
clear-num54.3%
sqrt-div54.3%
metadata-eval54.3%
unpow254.3%
Applied egg-rr76.7%
un-div-inv76.7%
*-commutative76.7%
*-commutative76.7%
associate-/r*76.5%
*-commutative76.5%
Applied egg-rr76.5%
Final simplification76.5%
herbie shell --seed 2023306
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))