| Alternative 1 | |
|---|---|
| Error | 19.75% |
| Cost | 7888 |
(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 (* c (* x s))) (t_2 (cos (+ x x))))
(if (or (<= c -1e+158) (not (<= c -7.5e-269)))
(* t_2 (/ (/ 1.0 t_0) t_0))
(/ (/ t_2 t_1) t_1))))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 = c * (x * s);
double t_2 = cos((x + x));
double tmp;
if ((c <= -1e+158) || !(c <= -7.5e-269)) {
tmp = t_2 * ((1.0 / t_0) / t_0);
} else {
tmp = (t_2 / t_1) / t_1;
}
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) :: t_2
real(8) :: tmp
t_0 = s * (c * x)
t_1 = c * (x * s)
t_2 = cos((x + x))
if ((c <= (-1d+158)) .or. (.not. (c <= (-7.5d-269)))) then
tmp = t_2 * ((1.0d0 / t_0) / t_0)
else
tmp = (t_2 / t_1) / t_1
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 = c * (x * s);
double t_2 = Math.cos((x + x));
double tmp;
if ((c <= -1e+158) || !(c <= -7.5e-269)) {
tmp = t_2 * ((1.0 / t_0) / t_0);
} else {
tmp = (t_2 / t_1) / t_1;
}
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 = c * (x * s) t_2 = math.cos((x + x)) tmp = 0 if (c <= -1e+158) or not (c <= -7.5e-269): tmp = t_2 * ((1.0 / t_0) / t_0) else: tmp = (t_2 / t_1) / t_1 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 = Float64(c * Float64(x * s)) t_2 = cos(Float64(x + x)) tmp = 0.0 if ((c <= -1e+158) || !(c <= -7.5e-269)) tmp = Float64(t_2 * Float64(Float64(1.0 / t_0) / t_0)); else tmp = Float64(Float64(t_2 / t_1) / t_1); 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 = c * (x * s); t_2 = cos((x + x)); tmp = 0.0; if ((c <= -1e+158) || ~((c <= -7.5e-269))) tmp = t_2 * ((1.0 / t_0) / t_0); else tmp = (t_2 / t_1) / t_1; 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[(c * N[(x * s), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[c, -1e+158], N[Not[LessEqual[c, -7.5e-269]], $MachinePrecision]], N[(t$95$2 * N[(N[(1.0 / t$95$0), $MachinePrecision] / t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$2 / t$95$1), $MachinePrecision] / t$95$1), $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 := c \cdot \left(x \cdot s\right)\\
t_2 := \cos \left(x + x\right)\\
\mathbf{if}\;c \leq -1 \cdot 10^{+158} \lor \neg \left(c \leq -7.5 \cdot 10^{-269}\right):\\
\;\;\;\;t_2 \cdot \frac{\frac{1}{t_0}}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{t_2}{t_1}}{t_1}\\
\end{array}
Results
if c < -9.99999999999999953e157 or -7.4999999999999993e-269 < c Initial program 46.33
Simplified4.7
[Start]46.33 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]46.33 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]51.32 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]51.09 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]51.09 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]51.09 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}\right)}
\] |
unpow2 [=>]51.09 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right)}
\] |
unswap-sqr [=>]28.06 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}}
\] |
unswap-sqr [=>]4.7 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}}
\] |
Taylor expanded in x around inf 51.32
Simplified3.98
[Start]51.32 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
|---|---|
count-2 [<=]51.32 | \[ \frac{\cos \color{blue}{\left(x + x\right)}}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
associate-*r* [=>]51.09 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}}
\] |
unpow2 [=>]51.09 | \[ \frac{\cos \left(x + x\right)}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{\left(x \cdot x\right)}}
\] |
associate-/r* [=>]51.15 | \[ \color{blue}{\frac{\frac{\cos \left(x + x\right)}{{c}^{2} \cdot {s}^{2}}}{x \cdot x}}
\] |
unpow2 [=>]51.15 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}}}{x \cdot x}
\] |
unpow2 [=>]51.15 | \[ \frac{\frac{\cos \left(x + x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}}}{x \cdot x}
\] |
swap-sqr [<=]28.09 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}}{x \cdot x}
\] |
unpow2 [<=]28.09 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}}}}{x \cdot x}
\] |
*-lft-identity [<=]28.09 | \[ \frac{\color{blue}{1 \cdot \frac{\cos \left(x + x\right)}{{\left(c \cdot s\right)}^{2}}}}{x \cdot x}
\] |
associate-*l/ [<=]28.68 | \[ \color{blue}{\frac{1}{x \cdot x} \cdot \frac{\cos \left(x + x\right)}{{\left(c \cdot s\right)}^{2}}}
\] |
unpow2 [=>]28.68 | \[ \frac{1}{x \cdot x} \cdot \frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}
\] |
associate-/r* [=>]28.53 | \[ \frac{1}{x \cdot x} \cdot \color{blue}{\frac{\frac{\cos \left(x + x\right)}{c \cdot s}}{c \cdot s}}
\] |
times-frac [<=]23.07 | \[ \color{blue}{\frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\left(x \cdot x\right) \cdot \left(c \cdot s\right)}}
\] |
*-commutative [<=]23.07 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(c \cdot s\right) \cdot \left(x \cdot x\right)}}
\] |
associate-*r* [=>]9.08 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right) \cdot x}}
\] |
*-commutative [<=]9.08 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right)} \cdot x}
\] |
Applied egg-rr7.76
Taylor expanded in x around 0 4
if -9.99999999999999953e157 < c < -7.4999999999999993e-269Initial program 42.21
Simplified4.65
[Start]42.21 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]42.21 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]48.57 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]48.13 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]48.13 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]48.13 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}\right)}
\] |
unpow2 [=>]48.13 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right)}
\] |
unswap-sqr [=>]35.65 | \[ \frac{\cos \left(2 \cdot x\right)}{\left(x \cdot x\right) \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}}
\] |
unswap-sqr [=>]4.65 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(x \cdot \left(c \cdot s\right)\right)}}
\] |
Taylor expanded in x around inf 48.57
Simplified3.94
[Start]48.57 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
|---|---|
count-2 [<=]48.57 | \[ \frac{\cos \color{blue}{\left(x + x\right)}}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
associate-*r* [=>]48.13 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}}
\] |
unpow2 [=>]48.13 | \[ \frac{\cos \left(x + x\right)}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \color{blue}{\left(x \cdot x\right)}}
\] |
associate-/r* [=>]48.21 | \[ \color{blue}{\frac{\frac{\cos \left(x + x\right)}{{c}^{2} \cdot {s}^{2}}}{x \cdot x}}
\] |
unpow2 [=>]48.21 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}}}{x \cdot x}
\] |
unpow2 [=>]48.21 | \[ \frac{\frac{\cos \left(x + x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}}}{x \cdot x}
\] |
swap-sqr [<=]35.95 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}}{x \cdot x}
\] |
unpow2 [<=]35.95 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{{\left(c \cdot s\right)}^{2}}}}{x \cdot x}
\] |
*-lft-identity [<=]35.95 | \[ \frac{\color{blue}{1 \cdot \frac{\cos \left(x + x\right)}{{\left(c \cdot s\right)}^{2}}}}{x \cdot x}
\] |
associate-*l/ [<=]36.44 | \[ \color{blue}{\frac{1}{x \cdot x} \cdot \frac{\cos \left(x + x\right)}{{\left(c \cdot s\right)}^{2}}}
\] |
unpow2 [=>]36.44 | \[ \frac{1}{x \cdot x} \cdot \frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}
\] |
associate-/r* [=>]36.27 | \[ \frac{1}{x \cdot x} \cdot \color{blue}{\frac{\frac{\cos \left(x + x\right)}{c \cdot s}}{c \cdot s}}
\] |
times-frac [<=]27.97 | \[ \color{blue}{\frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\left(x \cdot x\right) \cdot \left(c \cdot s\right)}}
\] |
*-commutative [<=]27.97 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(c \cdot s\right) \cdot \left(x \cdot x\right)}}
\] |
associate-*r* [=>]12.91 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right) \cdot x}}
\] |
*-commutative [<=]12.91 | \[ \frac{1 \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right)} \cdot x}
\] |
Applied egg-rr7.37
Applied egg-rr2.02
Final simplification3.16
| Alternative 1 | |
|---|---|
| Error | 19.75% |
| Cost | 7888 |
| Alternative 2 | |
|---|---|
| Error | 12.03% |
| Cost | 7756 |
| Alternative 3 | |
|---|---|
| Error | 10.53% |
| Cost | 7625 |
| Alternative 4 | |
|---|---|
| Error | 3.99% |
| Cost | 7625 |
| Alternative 5 | |
|---|---|
| Error | 7.17% |
| Cost | 7624 |
| Alternative 6 | |
|---|---|
| Error | 4.72% |
| Cost | 7624 |
| Alternative 7 | |
|---|---|
| Error | 25.02% |
| Cost | 7048 |
| Alternative 8 | |
|---|---|
| Error | 24.88% |
| Cost | 6916 |
| Alternative 9 | |
|---|---|
| Error | 26.11% |
| Cost | 1225 |
| Alternative 10 | |
|---|---|
| Error | 25.05% |
| Cost | 1224 |
| Alternative 11 | |
|---|---|
| Error | 28.01% |
| Cost | 1097 |
| Alternative 12 | |
|---|---|
| Error | 27.09% |
| Cost | 1097 |
| Alternative 13 | |
|---|---|
| Error | 27.14% |
| Cost | 1096 |
| Alternative 14 | |
|---|---|
| Error | 27.1% |
| Cost | 1096 |
| Alternative 15 | |
|---|---|
| Error | 28.9% |
| Cost | 832 |
herbie shell --seed 2023115
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))