
(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 10 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 and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (let* ((t_0 (* s (* x c)))) (/ (cos (* 2.0 x)) (* t_0 t_0))))
assert(c < s);
double code(double x, double c, double s) {
double t_0 = s * (x * c);
return cos((2.0 * x)) / (t_0 * t_0);
}
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 = s * (x * c)
code = cos((2.0d0 * x)) / (t_0 * t_0)
end function
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = s * (x * c);
return Math.cos((2.0 * x)) / (t_0 * t_0);
}
[c, s] = sort([c, s]) def code(x, c, s): t_0 = s * (x * c) return math.cos((2.0 * x)) / (t_0 * t_0)
c, s = sort([c, s]) function code(x, c, s) t_0 = Float64(s * Float64(x * c)) return Float64(cos(Float64(2.0 * x)) / Float64(t_0 * t_0)) end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
t_0 = s * (x * c);
tmp = cos((2.0 * x)) / (t_0 * t_0);
end
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]}, N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := s \cdot \left(x \cdot c\right)\\
\frac{\cos \left(2 \cdot x\right)}{t_0 \cdot t_0}
\end{array}
\end{array}
Initial program 66.0%
associate-/r*65.5%
remove-double-neg65.5%
distribute-lft-neg-out65.5%
distribute-lft-neg-out65.5%
distribute-rgt-neg-out65.5%
associate-/l/66.0%
distribute-rgt-neg-out66.0%
distribute-lft-neg-out66.0%
associate-*l*68.7%
distribute-lft-neg-in68.7%
distribute-lft-neg-out68.7%
remove-double-neg68.7%
associate-*r*68.4%
*-commutative68.4%
associate-*r*68.8%
Simplified76.6%
Taylor expanded in x around 0 59.6%
unpow259.6%
unpow259.6%
unpow259.6%
swap-sqr77.2%
swap-sqr97.1%
unpow297.1%
associate-*r*97.1%
*-commutative97.1%
associate-*l*97.8%
Simplified97.8%
unpow297.8%
Applied egg-rr97.8%
Final simplification97.8%
NOTE: c and s should be sorted in increasing order before calling this function.
(FPCore (x c s)
:precision binary64
(let* ((t_0 (cos (* 2.0 x))))
(if (<= x 1.08e-19)
(* (/ 1.0 (* c (* x s))) (/ (/ 1.0 c) (* x s)))
(if (<= x 1.6e+166)
(/ t_0 (* x (* x (* c (* s (* s c))))))
(/ t_0 (* (* c (* x c)) (* s (* x s))))))))assert(c < s);
double code(double x, double c, double s) {
double t_0 = cos((2.0 * x));
double tmp;
if (x <= 1.08e-19) {
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
} else if (x <= 1.6e+166) {
tmp = t_0 / (x * (x * (c * (s * (s * c)))));
} else {
tmp = t_0 / ((c * (x * c)) * (s * (x * s)));
}
return tmp;
}
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((2.0d0 * x))
if (x <= 1.08d-19) then
tmp = (1.0d0 / (c * (x * s))) * ((1.0d0 / c) / (x * s))
else if (x <= 1.6d+166) then
tmp = t_0 / (x * (x * (c * (s * (s * c)))))
else
tmp = t_0 / ((c * (x * c)) * (s * (x * s)))
end if
code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
double t_0 = Math.cos((2.0 * x));
double tmp;
if (x <= 1.08e-19) {
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
} else if (x <= 1.6e+166) {
tmp = t_0 / (x * (x * (c * (s * (s * c)))));
} else {
tmp = t_0 / ((c * (x * c)) * (s * (x * s)));
}
return tmp;
}
[c, s] = sort([c, s]) def code(x, c, s): t_0 = math.cos((2.0 * x)) tmp = 0 if x <= 1.08e-19: tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s)) elif x <= 1.6e+166: tmp = t_0 / (x * (x * (c * (s * (s * c))))) else: tmp = t_0 / ((c * (x * c)) * (s * (x * s))) return tmp
c, s = sort([c, s]) function code(x, c, s) t_0 = cos(Float64(2.0 * x)) tmp = 0.0 if (x <= 1.08e-19) tmp = Float64(Float64(1.0 / Float64(c * Float64(x * s))) * Float64(Float64(1.0 / c) / Float64(x * s))); elseif (x <= 1.6e+166) tmp = Float64(t_0 / Float64(x * Float64(x * Float64(c * Float64(s * Float64(s * c)))))); else tmp = Float64(t_0 / Float64(Float64(c * Float64(x * c)) * Float64(s * Float64(x * s)))); end return tmp end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
t_0 = cos((2.0 * x));
tmp = 0.0;
if (x <= 1.08e-19)
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
elseif (x <= 1.6e+166)
tmp = t_0 / (x * (x * (c * (s * (s * c)))));
else
tmp = t_0 / ((c * (x * c)) * (s * (x * s)));
end
tmp_2 = tmp;
end
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[(2.0 * x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 1.08e-19], N[(N[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.6e+166], N[(t$95$0 / N[(x * N[(x * N[(c * N[(s * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[(N[(c * N[(x * c), $MachinePrecision]), $MachinePrecision] * N[(s * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
t_0 := \cos \left(2 \cdot x\right)\\
\mathbf{if}\;x \leq 1.08 \cdot 10^{-19}:\\
\;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{+166}:\\
\;\;\;\;\frac{t_0}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(s \cdot c\right)\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0}{\left(c \cdot \left(x \cdot c\right)\right) \cdot \left(s \cdot \left(x \cdot s\right)\right)}\\
\end{array}
\end{array}
if x < 1.08e-19Initial program 61.5%
associate-/r*61.9%
remove-double-neg61.9%
distribute-lft-neg-out61.9%
distribute-lft-neg-out61.9%
distribute-rgt-neg-out61.9%
associate-/l/61.5%
distribute-rgt-neg-out61.5%
distribute-lft-neg-out61.5%
associate-*l*64.7%
distribute-lft-neg-in64.7%
distribute-lft-neg-out64.7%
remove-double-neg64.7%
associate-*r*64.8%
*-commutative64.8%
associate-*r*64.8%
Simplified64.8%
associate-/r*64.8%
swap-sqr86.6%
associate-/r*72.7%
associate-/r*72.6%
associate-/r*73.7%
*-un-lft-identity73.7%
add-sqr-sqrt73.7%
times-frac73.7%
Applied egg-rr97.1%
Taylor expanded in x around 0 81.7%
associate-/r*81.8%
Simplified81.8%
if 1.08e-19 < x < 1.59999999999999984e166Initial program 85.3%
associate-/r*85.4%
remove-double-neg85.4%
distribute-lft-neg-out85.4%
distribute-lft-neg-out85.4%
distribute-rgt-neg-out85.4%
associate-/l/85.3%
distribute-rgt-neg-out85.3%
distribute-lft-neg-out85.3%
associate-*l*85.4%
distribute-lft-neg-in85.4%
distribute-lft-neg-out85.4%
remove-double-neg85.4%
associate-*r*85.4%
*-commutative85.4%
associate-*r*85.4%
Simplified87.9%
Taylor expanded in c around 0 87.9%
unpow287.9%
associate-*r*97.3%
*-commutative97.3%
Simplified97.3%
if 1.59999999999999984e166 < x Initial program 68.0%
associate-/r*59.7%
remove-double-neg59.7%
distribute-lft-neg-out59.7%
distribute-lft-neg-out59.7%
distribute-rgt-neg-out59.7%
associate-/l/68.0%
distribute-rgt-neg-out68.0%
distribute-lft-neg-out68.0%
associate-*l*72.0%
distribute-lft-neg-in72.0%
distribute-lft-neg-out72.0%
remove-double-neg72.0%
associate-*r*68.3%
*-commutative68.3%
associate-*r*72.1%
Simplified72.0%
Taylor expanded in x around 0 50.8%
unpow250.8%
unpow250.8%
unpow250.8%
swap-sqr79.5%
swap-sqr95.5%
unpow295.5%
associate-*r*91.8%
*-commutative91.8%
associate-*l*99.3%
Simplified99.3%
associate-*r*91.8%
*-commutative91.8%
associate-*r*95.5%
unpow-prod-down79.5%
pow279.5%
pow279.5%
unswap-sqr50.8%
associate-*r*68.0%
associate-*r*75.9%
*-commutative75.9%
associate-*r*79.9%
Applied egg-rr79.9%
associate-*l*88.1%
Simplified88.1%
Final simplification84.9%
NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (if (<= x 0.0125) (* (/ 1.0 (* c (* x s))) (/ (/ 1.0 c) (* x s))) (/ (cos (* 2.0 x)) (* x (* x (* c (* c (* s s))))))))
assert(c < s);
double code(double x, double c, double s) {
double tmp;
if (x <= 0.0125) {
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
} else {
tmp = cos((2.0 * x)) / (x * (x * (c * (c * (s * s)))));
}
return tmp;
}
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) :: tmp
if (x <= 0.0125d0) then
tmp = (1.0d0 / (c * (x * s))) * ((1.0d0 / c) / (x * s))
else
tmp = cos((2.0d0 * x)) / (x * (x * (c * (c * (s * s)))))
end if
code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
double tmp;
if (x <= 0.0125) {
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
} else {
tmp = Math.cos((2.0 * x)) / (x * (x * (c * (c * (s * s)))));
}
return tmp;
}
[c, s] = sort([c, s]) def code(x, c, s): tmp = 0 if x <= 0.0125: tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s)) else: tmp = math.cos((2.0 * x)) / (x * (x * (c * (c * (s * s))))) return tmp
c, s = sort([c, s]) function code(x, c, s) tmp = 0.0 if (x <= 0.0125) tmp = Float64(Float64(1.0 / Float64(c * Float64(x * s))) * Float64(Float64(1.0 / c) / Float64(x * s))); else tmp = Float64(cos(Float64(2.0 * x)) / Float64(x * Float64(x * Float64(c * Float64(c * Float64(s * s)))))); end return tmp end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
tmp = 0.0;
if (x <= 0.0125)
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
else
tmp = cos((2.0 * x)) / (x * (x * (c * (c * (s * s)))));
end
tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := If[LessEqual[x, 0.0125], N[(N[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(x * N[(x * N[(c * N[(c * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0125:\\
\;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(2 \cdot x\right)}{x \cdot \left(x \cdot \left(c \cdot \left(c \cdot \left(s \cdot s\right)\right)\right)\right)}\\
\end{array}
\end{array}
if x < 0.012500000000000001Initial program 62.4%
associate-/r*62.8%
remove-double-neg62.8%
distribute-lft-neg-out62.8%
distribute-lft-neg-out62.8%
distribute-rgt-neg-out62.8%
associate-/l/62.4%
distribute-rgt-neg-out62.4%
distribute-lft-neg-out62.4%
associate-*l*65.4%
distribute-lft-neg-in65.4%
distribute-lft-neg-out65.4%
remove-double-neg65.4%
associate-*r*65.5%
*-commutative65.5%
associate-*r*65.6%
Simplified65.6%
associate-/r*65.6%
swap-sqr87.1%
associate-/r*73.7%
associate-/r*73.6%
associate-/r*74.6%
*-un-lft-identity74.6%
add-sqr-sqrt74.6%
times-frac74.6%
Applied egg-rr97.2%
Taylor expanded in x around 0 82.1%
associate-/r*82.1%
Simplified82.1%
if 0.012500000000000001 < x Initial program 78.1%
associate-/r*74.7%
remove-double-neg74.7%
distribute-lft-neg-out74.7%
distribute-lft-neg-out74.7%
distribute-rgt-neg-out74.7%
associate-/l/78.1%
distribute-rgt-neg-out78.1%
distribute-lft-neg-out78.1%
associate-*l*79.8%
distribute-lft-neg-in79.8%
distribute-lft-neg-out79.8%
remove-double-neg79.8%
associate-*r*78.3%
*-commutative78.3%
associate-*r*79.9%
Simplified81.6%
Final simplification82.0%
NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (if (<= x 1e-19) (* (/ 1.0 (* c (* x s))) (/ (/ 1.0 c) (* x s))) (/ (cos (* 2.0 x)) (* x (* x (* c (* s (* s c))))))))
assert(c < s);
double code(double x, double c, double s) {
double tmp;
if (x <= 1e-19) {
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
} else {
tmp = cos((2.0 * x)) / (x * (x * (c * (s * (s * c)))));
}
return tmp;
}
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) :: tmp
if (x <= 1d-19) then
tmp = (1.0d0 / (c * (x * s))) * ((1.0d0 / c) / (x * s))
else
tmp = cos((2.0d0 * x)) / (x * (x * (c * (s * (s * c)))))
end if
code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
double tmp;
if (x <= 1e-19) {
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
} else {
tmp = Math.cos((2.0 * x)) / (x * (x * (c * (s * (s * c)))));
}
return tmp;
}
[c, s] = sort([c, s]) def code(x, c, s): tmp = 0 if x <= 1e-19: tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s)) else: tmp = math.cos((2.0 * x)) / (x * (x * (c * (s * (s * c))))) return tmp
c, s = sort([c, s]) function code(x, c, s) tmp = 0.0 if (x <= 1e-19) tmp = Float64(Float64(1.0 / Float64(c * Float64(x * s))) * Float64(Float64(1.0 / c) / Float64(x * s))); else tmp = Float64(cos(Float64(2.0 * x)) / Float64(x * Float64(x * Float64(c * Float64(s * Float64(s * c)))))); end return tmp end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
tmp = 0.0;
if (x <= 1e-19)
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
else
tmp = cos((2.0 * x)) / (x * (x * (c * (s * (s * c)))));
end
tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := If[LessEqual[x, 1e-19], N[(N[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(x * N[(x * N[(c * N[(s * N[(s * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{-19}:\\
\;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{1}{c}}{x \cdot s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(2 \cdot x\right)}{x \cdot \left(x \cdot \left(c \cdot \left(s \cdot \left(s \cdot c\right)\right)\right)\right)}\\
\end{array}
\end{array}
if x < 9.9999999999999998e-20Initial program 61.5%
associate-/r*61.9%
remove-double-neg61.9%
distribute-lft-neg-out61.9%
distribute-lft-neg-out61.9%
distribute-rgt-neg-out61.9%
associate-/l/61.5%
distribute-rgt-neg-out61.5%
distribute-lft-neg-out61.5%
associate-*l*64.7%
distribute-lft-neg-in64.7%
distribute-lft-neg-out64.7%
remove-double-neg64.7%
associate-*r*64.8%
*-commutative64.8%
associate-*r*64.8%
Simplified64.8%
associate-/r*64.8%
swap-sqr86.6%
associate-/r*72.7%
associate-/r*72.6%
associate-/r*73.7%
*-un-lft-identity73.7%
add-sqr-sqrt73.7%
times-frac73.7%
Applied egg-rr97.1%
Taylor expanded in x around 0 81.7%
associate-/r*81.8%
Simplified81.8%
if 9.9999999999999998e-20 < x Initial program 78.9%
associate-/r*75.9%
remove-double-neg75.9%
distribute-lft-neg-out75.9%
distribute-lft-neg-out75.9%
distribute-rgt-neg-out75.9%
associate-/l/78.9%
distribute-rgt-neg-out78.9%
distribute-lft-neg-out78.9%
associate-*l*80.5%
distribute-lft-neg-in80.5%
distribute-lft-neg-out80.5%
remove-double-neg80.5%
associate-*r*79.1%
*-commutative79.1%
associate-*r*80.5%
Simplified82.0%
Taylor expanded in c around 0 82.0%
unpow282.0%
associate-*r*88.0%
*-commutative88.0%
Simplified88.0%
Final simplification83.4%
NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (* s (* x c)) (* c (* x s)))))
assert(c < s);
double code(double x, double c, double s) {
return cos((2.0 * x)) / ((s * (x * c)) * (c * (x * s)));
}
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)) / ((s * (x * c)) * (c * (x * s)))
end function
assert c < s;
public static double code(double x, double c, double s) {
return Math.cos((2.0 * x)) / ((s * (x * c)) * (c * (x * s)));
}
[c, s] = sort([c, s]) def code(x, c, s): return math.cos((2.0 * x)) / ((s * (x * c)) * (c * (x * s)))
c, s = sort([c, s]) function code(x, c, s) return Float64(cos(Float64(2.0 * x)) / Float64(Float64(s * Float64(x * c)) * Float64(c * Float64(x * s)))) end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = cos((2.0 * x)) / ((s * (x * c)) * (c * (x * s)));
end
NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision] * N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\cos \left(2 \cdot x\right)}{\left(s \cdot \left(x \cdot c\right)\right) \cdot \left(c \cdot \left(x \cdot s\right)\right)}
\end{array}
Initial program 66.0%
associate-/r*65.5%
remove-double-neg65.5%
distribute-lft-neg-out65.5%
distribute-lft-neg-out65.5%
distribute-rgt-neg-out65.5%
associate-/l/66.0%
distribute-rgt-neg-out66.0%
distribute-lft-neg-out66.0%
associate-*l*68.7%
distribute-lft-neg-in68.7%
distribute-lft-neg-out68.7%
remove-double-neg68.7%
associate-*r*68.4%
*-commutative68.4%
associate-*r*68.8%
Simplified76.6%
Taylor expanded in x around 0 59.6%
unpow259.6%
unpow259.6%
unpow259.6%
swap-sqr77.2%
swap-sqr97.1%
unpow297.1%
associate-*r*97.1%
*-commutative97.1%
associate-*l*97.8%
Simplified97.8%
unpow297.8%
Applied egg-rr97.8%
Taylor expanded in s around 0 95.7%
Final simplification95.7%
NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (if (<= s 7.8e-64) (/ (/ (+ (* x -2.0) (/ 1.0 x)) (* s s)) (* c (* x c))) (* (/ 1.0 (* c (* x s))) (/ (/ 1.0 c) (* x s)))))
assert(c < s);
double code(double x, double c, double s) {
double tmp;
if (s <= 7.8e-64) {
tmp = (((x * -2.0) + (1.0 / x)) / (s * s)) / (c * (x * c));
} else {
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
}
return tmp;
}
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) :: tmp
if (s <= 7.8d-64) then
tmp = (((x * (-2.0d0)) + (1.0d0 / x)) / (s * s)) / (c * (x * c))
else
tmp = (1.0d0 / (c * (x * s))) * ((1.0d0 / c) / (x * s))
end if
code = tmp
end function
assert c < s;
public static double code(double x, double c, double s) {
double tmp;
if (s <= 7.8e-64) {
tmp = (((x * -2.0) + (1.0 / x)) / (s * s)) / (c * (x * c));
} else {
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
}
return tmp;
}
[c, s] = sort([c, s]) def code(x, c, s): tmp = 0 if s <= 7.8e-64: tmp = (((x * -2.0) + (1.0 / x)) / (s * s)) / (c * (x * c)) else: tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s)) return tmp
c, s = sort([c, s]) function code(x, c, s) tmp = 0.0 if (s <= 7.8e-64) tmp = Float64(Float64(Float64(Float64(x * -2.0) + Float64(1.0 / x)) / Float64(s * s)) / Float64(c * Float64(x * c))); else tmp = Float64(Float64(1.0 / Float64(c * Float64(x * s))) * Float64(Float64(1.0 / c) / Float64(x * s))); end return tmp end
c, s = num2cell(sort([c, s])){:}
function tmp_2 = code(x, c, s)
tmp = 0.0;
if (s <= 7.8e-64)
tmp = (((x * -2.0) + (1.0 / x)) / (s * s)) / (c * (x * c));
else
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
end
tmp_2 = tmp;
end
NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := If[LessEqual[s, 7.8e-64], N[(N[(N[(N[(x * -2.0), $MachinePrecision] + N[(1.0 / x), $MachinePrecision]), $MachinePrecision] / N[(s * s), $MachinePrecision]), $MachinePrecision] / N[(c * N[(x * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\begin{array}{l}
\mathbf{if}\;s \leq 7.8 \cdot 10^{-64}:\\
\;\;\;\;\frac{\frac{x \cdot -2 + \frac{1}{x}}{s \cdot s}}{c \cdot \left(x \cdot c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{1}{c}}{x \cdot s}\\
\end{array}
\end{array}
if s < 7.7999999999999994e-64Initial program 65.3%
associate-/r*65.7%
remove-double-neg65.7%
distribute-lft-neg-out65.7%
distribute-lft-neg-out65.7%
distribute-rgt-neg-out65.7%
associate-/l/65.3%
distribute-rgt-neg-out65.3%
distribute-lft-neg-out65.3%
associate-*l*68.1%
distribute-lft-neg-in68.1%
distribute-lft-neg-out68.1%
remove-double-neg68.1%
associate-*r*67.7%
*-commutative67.7%
associate-*r*68.3%
Simplified68.3%
associate-/r*68.2%
swap-sqr87.5%
associate-/r*75.4%
associate-/r*74.7%
associate-/r*75.8%
*-un-lft-identity75.8%
swap-sqr59.8%
*-commutative59.8%
associate-*r*59.0%
associate-*r*65.3%
*-commutative65.3%
associate-*r*68.1%
times-frac68.5%
associate-*l*78.8%
*-commutative78.8%
*-commutative78.8%
associate-*l*85.9%
Applied egg-rr85.9%
associate-*l/85.9%
*-lft-identity85.9%
associate-*r*78.8%
*-commutative78.8%
associate-/r*78.8%
*-commutative78.8%
Simplified78.8%
Taylor expanded in x around 0 59.3%
if 7.7999999999999994e-64 < s Initial program 67.5%
associate-/r*64.9%
remove-double-neg64.9%
distribute-lft-neg-out64.9%
distribute-lft-neg-out64.9%
distribute-rgt-neg-out64.9%
associate-/l/67.5%
distribute-rgt-neg-out67.5%
distribute-lft-neg-out67.5%
associate-*l*70.0%
distribute-lft-neg-in70.0%
distribute-lft-neg-out70.0%
remove-double-neg70.0%
associate-*r*70.1%
*-commutative70.1%
associate-*r*70.1%
Simplified70.1%
associate-/r*70.1%
swap-sqr85.7%
associate-/r*72.8%
associate-/r*72.9%
associate-/r*72.8%
*-un-lft-identity72.8%
add-sqr-sqrt72.8%
times-frac72.8%
Applied egg-rr95.7%
Taylor expanded in x around 0 84.5%
associate-/r*84.5%
Simplified84.5%
Final simplification66.7%
NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (* (/ 1.0 (* c (* x s))) (/ (/ 1.0 c) (* x s))))
assert(c < s);
double code(double x, double c, double s) {
return (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
}
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 / (c * (x * s))) * ((1.0d0 / c) / (x * s))
end function
assert c < s;
public static double code(double x, double c, double s) {
return (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
}
[c, s] = sort([c, s]) def code(x, c, s): return (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s))
c, s = sort([c, s]) function code(x, c, s) return Float64(Float64(1.0 / Float64(c * Float64(x * s))) * Float64(Float64(1.0 / c) / Float64(x * s))) end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = (1.0 / (c * (x * s))) * ((1.0 / c) / (x * s));
end
NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(N[(1.0 / N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / c), $MachinePrecision] / N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{c \cdot \left(x \cdot s\right)} \cdot \frac{\frac{1}{c}}{x \cdot s}
\end{array}
Initial program 66.0%
associate-/r*65.5%
remove-double-neg65.5%
distribute-lft-neg-out65.5%
distribute-lft-neg-out65.5%
distribute-rgt-neg-out65.5%
associate-/l/66.0%
distribute-rgt-neg-out66.0%
distribute-lft-neg-out66.0%
associate-*l*68.7%
distribute-lft-neg-in68.7%
distribute-lft-neg-out68.7%
remove-double-neg68.7%
associate-*r*68.4%
*-commutative68.4%
associate-*r*68.8%
Simplified68.8%
associate-/r*68.8%
swap-sqr87.0%
associate-/r*74.6%
associate-/r*74.2%
associate-/r*74.9%
*-un-lft-identity74.9%
add-sqr-sqrt74.9%
times-frac74.9%
Applied egg-rr97.3%
Taylor expanded in x around 0 74.3%
associate-/r*74.4%
Simplified74.4%
Final simplification74.4%
NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ 1.0 (* (* s c) (* (* x c) (* x s)))))
assert(c < s);
double code(double x, double c, double s) {
return 1.0 / ((s * c) * ((x * c) * (x * s)));
}
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 / ((s * c) * ((x * c) * (x * s)))
end function
assert c < s;
public static double code(double x, double c, double s) {
return 1.0 / ((s * c) * ((x * c) * (x * s)));
}
[c, s] = sort([c, s]) def code(x, c, s): return 1.0 / ((s * c) * ((x * c) * (x * s)))
c, s = sort([c, s]) function code(x, c, s) return Float64(1.0 / Float64(Float64(s * c) * Float64(Float64(x * c) * Float64(x * s)))) end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = 1.0 / ((s * c) * ((x * c) * (x * s)));
end
NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(1.0 / N[(N[(s * c), $MachinePrecision] * N[(N[(x * c), $MachinePrecision] * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{1}{\left(s \cdot c\right) \cdot \left(\left(x \cdot c\right) \cdot \left(x \cdot s\right)\right)}
\end{array}
Initial program 66.0%
associate-/r*65.5%
remove-double-neg65.5%
distribute-lft-neg-out65.5%
distribute-lft-neg-out65.5%
distribute-rgt-neg-out65.5%
associate-/l/66.0%
distribute-rgt-neg-out66.0%
distribute-lft-neg-out66.0%
associate-*l*68.7%
distribute-lft-neg-in68.7%
distribute-lft-neg-out68.7%
remove-double-neg68.7%
associate-*r*68.4%
*-commutative68.4%
associate-*r*68.8%
Simplified68.8%
Applied egg-rr90.2%
Taylor expanded in x around 0 71.1%
frac-times71.5%
metadata-eval71.5%
associate-*r*71.2%
*-commutative71.2%
Applied egg-rr71.2%
Final simplification71.2%
NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ (/ 1.0 (* s c)) (* (* x c) (* x s))))
assert(c < s);
double code(double x, double c, double s) {
return (1.0 / (s * c)) / ((x * c) * (x * s));
}
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 / (s * c)) / ((x * c) * (x * s))
end function
assert c < s;
public static double code(double x, double c, double s) {
return (1.0 / (s * c)) / ((x * c) * (x * s));
}
[c, s] = sort([c, s]) def code(x, c, s): return (1.0 / (s * c)) / ((x * c) * (x * s))
c, s = sort([c, s]) function code(x, c, s) return Float64(Float64(1.0 / Float64(s * c)) / Float64(Float64(x * c) * Float64(x * s))) end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = (1.0 / (s * c)) / ((x * c) * (x * s));
end
NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(N[(1.0 / N[(s * c), $MachinePrecision]), $MachinePrecision] / N[(N[(x * c), $MachinePrecision] * N[(x * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{\frac{1}{s \cdot c}}{\left(x \cdot c\right) \cdot \left(x \cdot s\right)}
\end{array}
Initial program 66.0%
associate-/r*65.5%
remove-double-neg65.5%
distribute-lft-neg-out65.5%
distribute-lft-neg-out65.5%
distribute-rgt-neg-out65.5%
associate-/l/66.0%
distribute-rgt-neg-out66.0%
distribute-lft-neg-out66.0%
associate-*l*68.7%
distribute-lft-neg-in68.7%
distribute-lft-neg-out68.7%
remove-double-neg68.7%
associate-*r*68.4%
*-commutative68.4%
associate-*r*68.8%
Simplified68.8%
Applied egg-rr90.2%
Taylor expanded in x around 0 71.1%
associate-*l/71.8%
*-un-lft-identity71.8%
associate-*r*71.5%
*-commutative71.5%
Applied egg-rr71.5%
Final simplification71.5%
NOTE: c and s should be sorted in increasing order before calling this function. (FPCore (x c s) :precision binary64 (/ -2.0 (* c (* c (* s s)))))
assert(c < s);
double code(double x, double c, double s) {
return -2.0 / (c * (c * (s * s)));
}
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 = (-2.0d0) / (c * (c * (s * s)))
end function
assert c < s;
public static double code(double x, double c, double s) {
return -2.0 / (c * (c * (s * s)));
}
[c, s] = sort([c, s]) def code(x, c, s): return -2.0 / (c * (c * (s * s)))
c, s = sort([c, s]) function code(x, c, s) return Float64(-2.0 / Float64(c * Float64(c * Float64(s * s)))) end
c, s = num2cell(sort([c, s])){:}
function tmp = code(x, c, s)
tmp = -2.0 / (c * (c * (s * s)));
end
NOTE: c and s should be sorted in increasing order before calling this function. code[x_, c_, s_] := N[(-2.0 / N[(c * N[(c * N[(s * s), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[c, s] = \mathsf{sort}([c, s])\\
\\
\frac{-2}{c \cdot \left(c \cdot \left(s \cdot s\right)\right)}
\end{array}
Initial program 66.0%
associate-/r*65.5%
remove-double-neg65.5%
distribute-lft-neg-out65.5%
distribute-lft-neg-out65.5%
distribute-rgt-neg-out65.5%
associate-/l/66.0%
distribute-rgt-neg-out66.0%
distribute-lft-neg-out66.0%
associate-*l*68.7%
distribute-lft-neg-in68.7%
distribute-lft-neg-out68.7%
remove-double-neg68.7%
associate-*r*68.4%
*-commutative68.4%
associate-*r*68.8%
Simplified68.8%
Taylor expanded in x around 0 32.2%
unpow232.2%
unpow232.2%
unpow232.2%
swap-sqr38.4%
unpow238.4%
associate-/r*37.9%
unpow237.9%
swap-sqr31.7%
associate-*r/31.7%
metadata-eval31.7%
unpow231.7%
unpow231.7%
*-commutative31.7%
Simplified31.7%
Taylor expanded in x around inf 30.9%
unpow230.9%
associate-*r*31.1%
unpow231.1%
Simplified31.1%
Final simplification31.1%
herbie shell --seed 2023285
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))