| Alternative 1 | |
|---|---|
| Error | 2.1 |
| Cost | 7752 |
(FPCore (x c s) :precision binary64 (/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))
(FPCore (x c s)
:precision binary64
(let* ((t_0 (* s (* c x))) (t_1 (cos (+ x x))))
(if (<= c -6.6e-207)
(* (/ (/ 1.0 c) (* s x)) (/ t_1 (* c (* s x))))
(if (<= c 1.22e-111)
(* (/ 1.0 t_0) (/ t_1 t_0))
(* (/ (cos (* x 2.0)) (* c c)) (/ 1.0 (* x (* s (* s x)))))))))double code(double x, double c, double s) {
return cos((2.0 * x)) / (pow(c, 2.0) * ((x * pow(s, 2.0)) * x));
}
double code(double x, double c, double s) {
double t_0 = s * (c * x);
double t_1 = cos((x + x));
double tmp;
if (c <= -6.6e-207) {
tmp = ((1.0 / c) / (s * x)) * (t_1 / (c * (s * x)));
} else if (c <= 1.22e-111) {
tmp = (1.0 / t_0) * (t_1 / t_0);
} else {
tmp = (cos((x * 2.0)) / (c * c)) * (1.0 / (x * (s * (s * x))));
}
return tmp;
}
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
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 * (c * x)
t_1 = cos((x + x))
if (c <= (-6.6d-207)) then
tmp = ((1.0d0 / c) / (s * x)) * (t_1 / (c * (s * x)))
else if (c <= 1.22d-111) then
tmp = (1.0d0 / t_0) * (t_1 / t_0)
else
tmp = (cos((x * 2.0d0)) / (c * c)) * (1.0d0 / (x * (s * (s * x))))
end if
code = tmp
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));
}
public static double code(double x, double c, double s) {
double t_0 = s * (c * x);
double t_1 = Math.cos((x + x));
double tmp;
if (c <= -6.6e-207) {
tmp = ((1.0 / c) / (s * x)) * (t_1 / (c * (s * x)));
} else if (c <= 1.22e-111) {
tmp = (1.0 / t_0) * (t_1 / t_0);
} else {
tmp = (Math.cos((x * 2.0)) / (c * c)) * (1.0 / (x * (s * (s * x))));
}
return tmp;
}
def code(x, c, s): return math.cos((2.0 * x)) / (math.pow(c, 2.0) * ((x * math.pow(s, 2.0)) * x))
def code(x, c, s): t_0 = s * (c * x) t_1 = math.cos((x + x)) tmp = 0 if c <= -6.6e-207: tmp = ((1.0 / c) / (s * x)) * (t_1 / (c * (s * x))) elif c <= 1.22e-111: tmp = (1.0 / t_0) * (t_1 / t_0) else: tmp = (math.cos((x * 2.0)) / (c * c)) * (1.0 / (x * (s * (s * x)))) return tmp
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 code(x, c, s) t_0 = Float64(s * Float64(c * x)) t_1 = cos(Float64(x + x)) tmp = 0.0 if (c <= -6.6e-207) tmp = Float64(Float64(Float64(1.0 / c) / Float64(s * x)) * Float64(t_1 / Float64(c * Float64(s * x)))); elseif (c <= 1.22e-111) tmp = Float64(Float64(1.0 / t_0) * Float64(t_1 / t_0)); else tmp = Float64(Float64(cos(Float64(x * 2.0)) / Float64(c * c)) * Float64(1.0 / Float64(x * Float64(s * Float64(s * x))))); end return tmp end
function tmp = code(x, c, s) tmp = cos((2.0 * x)) / ((c ^ 2.0) * ((x * (s ^ 2.0)) * x)); end
function tmp_2 = code(x, c, s) t_0 = s * (c * x); t_1 = cos((x + x)); tmp = 0.0; if (c <= -6.6e-207) tmp = ((1.0 / c) / (s * x)) * (t_1 / (c * (s * x))); elseif (c <= 1.22e-111) tmp = (1.0 / t_0) * (t_1 / t_0); else tmp = (cos((x * 2.0)) / (c * c)) * (1.0 / (x * (s * (s * x)))); end tmp_2 = tmp; 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]
code[x_, c_, s_] := Block[{t$95$0 = N[(s * N[(c * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[c, -6.6e-207], N[(N[(N[(1.0 / c), $MachinePrecision] / N[(s * x), $MachinePrecision]), $MachinePrecision] * N[(t$95$1 / N[(c * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 1.22e-111], N[(N[(1.0 / t$95$0), $MachinePrecision] * N[(t$95$1 / t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(x * N[(s * N[(s * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\begin{array}{l}
t_0 := s \cdot \left(c \cdot x\right)\\
t_1 := \cos \left(x + x\right)\\
\mathbf{if}\;c \leq -6.6 \cdot 10^{-207}:\\
\;\;\;\;\frac{\frac{1}{c}}{s \cdot x} \cdot \frac{t_1}{c \cdot \left(s \cdot x\right)}\\
\mathbf{elif}\;c \leq 1.22 \cdot 10^{-111}:\\
\;\;\;\;\frac{1}{t_0} \cdot \frac{t_1}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(x \cdot 2\right)}{c \cdot c} \cdot \frac{1}{x \cdot \left(s \cdot \left(s \cdot x\right)\right)}\\
\end{array}
Results
if c < -6.5999999999999996e-207Initial program 26.1
Simplified20.8
[Start]26.1 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
associate-*r* [=>]24.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right) \cdot x}}
\] |
*-commutative [=>]24.5 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{x \cdot \left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right)}}
\] |
unpow2 [=>]24.5 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot {s}^{2}\right)\right)}
\] |
associate-*l* [=>]20.8 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \color{blue}{\left(c \cdot \left(c \cdot \left(x \cdot {s}^{2}\right)\right)\right)}}
\] |
unpow2 [=>]20.8 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(c \cdot \left(c \cdot \left(x \cdot \color{blue}{\left(s \cdot s\right)}\right)\right)\right)}
\] |
Taylor expanded in x around 0 29.6
Simplified2.2
[Start]29.6 | \[ \frac{\cos \left(2 \cdot x\right)}{{s}^{2} \cdot \left({c}^{2} \cdot {x}^{2}\right)}
\] |
|---|---|
*-commutative [=>]29.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {x}^{2}\right) \cdot {s}^{2}}}
\] |
associate-*r* [<=]29.7 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{c}^{2} \cdot \left({x}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]29.7 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(c \cdot c\right)} \cdot \left({x}^{2} \cdot {s}^{2}\right)}
\] |
unpow2 [=>]29.7 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(\color{blue}{\left(x \cdot x\right)} \cdot {s}^{2}\right)}
\] |
unpow2 [=>]29.7 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(\left(x \cdot x\right) \cdot \color{blue}{\left(s \cdot s\right)}\right)}
\] |
swap-sqr [<=]16.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(x \cdot s\right) \cdot \left(x \cdot s\right)\right)}}
\] |
sqr-abs [<=]16.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left|x \cdot s\right| \cdot \left|x \cdot s\right|\right)}}
\] |
rem-sqrt-square [<=]16.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(\color{blue}{\sqrt{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}} \cdot \left|x \cdot s\right|\right)}
\] |
unpow2 [<=]16.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(\sqrt{\color{blue}{{\left(x \cdot s\right)}^{2}}} \cdot \left|x \cdot s\right|\right)}
\] |
rem-sqrt-square [<=]16.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(\sqrt{{\left(x \cdot s\right)}^{2}} \cdot \color{blue}{\sqrt{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}}\right)}
\] |
unpow2 [<=]16.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(c \cdot c\right) \cdot \left(\sqrt{{\left(x \cdot s\right)}^{2}} \cdot \sqrt{\color{blue}{{\left(x \cdot s\right)}^{2}}}\right)}
\] |
swap-sqr [<=]12.3 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(c \cdot \sqrt{{\left(x \cdot s\right)}^{2}}\right) \cdot \left(c \cdot \sqrt{{\left(x \cdot s\right)}^{2}}\right)}}
\] |
unpow2 [<=]12.3 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{{\left(c \cdot \sqrt{{\left(x \cdot s\right)}^{2}}\right)}^{2}}}
\] |
unpow2 [=>]12.3 | \[ \frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \sqrt{\color{blue}{\left(x \cdot s\right) \cdot \left(x \cdot s\right)}}\right)}^{2}}
\] |
rem-sqrt-square [=>]2.2 | \[ \frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \color{blue}{\left|x \cdot s\right|}\right)}^{2}}
\] |
unpow1 [<=]2.2 | \[ \frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \left|\color{blue}{{\left(x \cdot s\right)}^{1}}\right|\right)}^{2}}
\] |
sqr-pow [=>]28.8 | \[ \frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \left|\color{blue}{{\left(x \cdot s\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(x \cdot s\right)}^{\left(\frac{1}{2}\right)}}\right|\right)}^{2}}
\] |
fabs-sqr [=>]28.8 | \[ \frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \color{blue}{\left({\left(x \cdot s\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(x \cdot s\right)}^{\left(\frac{1}{2}\right)}\right)}\right)}^{2}}
\] |
sqr-pow [<=]2.2 | \[ \frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \color{blue}{{\left(x \cdot s\right)}^{1}}\right)}^{2}}
\] |
unpow1 [=>]2.2 | \[ \frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \color{blue}{\left(x \cdot s\right)}\right)}^{2}}
\] |
*-commutative [=>]2.2 | \[ \frac{\cos \left(2 \cdot x\right)}{{\left(c \cdot \color{blue}{\left(s \cdot x\right)}\right)}^{2}}
\] |
Applied egg-rr1.9
if -6.5999999999999996e-207 < c < 1.22e-111Initial program 57.0
Simplified37.4
[Start]57.0 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
associate-*r* [=>]55.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right) \cdot x}}
\] |
*-commutative [=>]55.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{x \cdot \left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right)}}
\] |
unpow2 [=>]55.6 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot \left(x \cdot {s}^{2}\right)\right)}
\] |
associate-*l* [=>]37.4 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \color{blue}{\left(c \cdot \left(c \cdot \left(x \cdot {s}^{2}\right)\right)\right)}}
\] |
unpow2 [=>]37.4 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(c \cdot \left(c \cdot \left(x \cdot \color{blue}{\left(s \cdot s\right)}\right)\right)\right)}
\] |
Taylor expanded in x around 0 57.6
Simplified57.6
[Start]57.6 | \[ \frac{\cos \left(2 \cdot x\right)}{{s}^{2} \cdot \left({c}^{2} \cdot {x}^{2}\right)}
\] |
|---|---|
unpow2 [=>]57.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(s \cdot s\right)} \cdot \left({c}^{2} \cdot {x}^{2}\right)}
\] |
unpow2 [=>]57.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(s \cdot s\right) \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot {x}^{2}\right)}
\] |
unpow2 [=>]57.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(s \cdot s\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)}
\] |
Applied egg-rr4.9
if 1.22e-111 < c Initial program 13.0
Applied egg-rr6.4
Final simplification3.0
| Alternative 1 | |
|---|---|
| Error | 2.1 |
| Cost | 7752 |
| Alternative 2 | |
|---|---|
| Error | 3.1 |
| Cost | 7752 |
| Alternative 3 | |
|---|---|
| Error | 10.3 |
| Cost | 7625 |
| Alternative 4 | |
|---|---|
| Error | 8.2 |
| Cost | 7625 |
| Alternative 5 | |
|---|---|
| Error | 3.8 |
| Cost | 7625 |
| Alternative 6 | |
|---|---|
| Error | 3.6 |
| Cost | 7625 |
| Alternative 7 | |
|---|---|
| Error | 2.3 |
| Cost | 7625 |
| Alternative 8 | |
|---|---|
| Error | 2.5 |
| Cost | 7624 |
| Alternative 9 | |
|---|---|
| Error | 2.2 |
| Cost | 7624 |
| Alternative 10 | |
|---|---|
| Error | 17.5 |
| Cost | 1225 |
| Alternative 11 | |
|---|---|
| Error | 20.2 |
| Cost | 1097 |
| Alternative 12 | |
|---|---|
| Error | 19.4 |
| Cost | 1097 |
| Alternative 13 | |
|---|---|
| Error | 16.7 |
| Cost | 960 |
| Alternative 14 | |
|---|---|
| Error | 17.0 |
| Cost | 960 |
| Alternative 15 | |
|---|---|
| Error | 20.1 |
| Cost | 832 |
herbie shell --seed 2022364
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))