| Alternative 1 | |
|---|---|
| Error | 2.1 |
| Cost | 13705 |
(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 (cos (+ x x))))
(if (<=
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* x (* x (pow s 2.0)))))
INFINITY)
(* (pow (* c (* x s)) -2.0) t_0)
(pow (/ (pow (* x (* c s)) 2.0) t_0) -1.0))))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 = cos((x + x));
double tmp;
if ((cos((2.0 * x)) / (pow(c, 2.0) * (x * (x * pow(s, 2.0))))) <= ((double) INFINITY)) {
tmp = pow((c * (x * s)), -2.0) * t_0;
} else {
tmp = pow((pow((x * (c * s)), 2.0) / t_0), -1.0);
}
return tmp;
}
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 = Math.cos((x + x));
double tmp;
if ((Math.cos((2.0 * x)) / (Math.pow(c, 2.0) * (x * (x * Math.pow(s, 2.0))))) <= Double.POSITIVE_INFINITY) {
tmp = Math.pow((c * (x * s)), -2.0) * t_0;
} else {
tmp = Math.pow((Math.pow((x * (c * s)), 2.0) / t_0), -1.0);
}
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 = math.cos((x + x)) tmp = 0 if (math.cos((2.0 * x)) / (math.pow(c, 2.0) * (x * (x * math.pow(s, 2.0))))) <= math.inf: tmp = math.pow((c * (x * s)), -2.0) * t_0 else: tmp = math.pow((math.pow((x * (c * s)), 2.0) / t_0), -1.0) 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 = cos(Float64(x + x)) tmp = 0.0 if (Float64(cos(Float64(2.0 * x)) / Float64((c ^ 2.0) * Float64(x * Float64(x * (s ^ 2.0))))) <= Inf) tmp = Float64((Float64(c * Float64(x * s)) ^ -2.0) * t_0); else tmp = Float64((Float64(x * Float64(c * s)) ^ 2.0) / t_0) ^ -1.0; 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 = cos((x + x)); tmp = 0.0; if ((cos((2.0 * x)) / ((c ^ 2.0) * (x * (x * (s ^ 2.0))))) <= Inf) tmp = ((c * (x * s)) ^ -2.0) * t_0; else tmp = (((x * (c * s)) ^ 2.0) / t_0) ^ -1.0; 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[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[Cos[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[(N[Power[c, 2.0], $MachinePrecision] * N[(x * N[(x * N[Power[s, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[Power[N[(c * N[(x * s), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision] * t$95$0), $MachinePrecision], N[Power[N[(N[Power[N[(x * N[(c * s), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] / t$95$0), $MachinePrecision], -1.0], $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 := \cos \left(x + x\right)\\
\mathbf{if}\;\frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(x \cdot \left(x \cdot {s}^{2}\right)\right)} \leq \infty:\\
\;\;\;\;{\left(c \cdot \left(x \cdot s\right)\right)}^{-2} \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{{\left(x \cdot \left(c \cdot s\right)\right)}^{2}}{t_0}\right)}^{-1}\\
\end{array}
Results
if (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 (pow.f64 c 2) (*.f64 (*.f64 x (pow.f64 s 2)) x))) < +inf.0Initial program 18.3
Simplified3.0
[Start]18.3 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]18.3 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]22.9 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]23.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]23.0 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]23.0 | \[ \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 [=>]23.0 | \[ \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 [=>]18.7 | \[ \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 [=>]3.0 | \[ \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)}}
\] |
Applied egg-rr2.7
Taylor expanded in x around 0 22.9
Simplified0.3
[Start]22.9 | \[ \frac{1}{{s}^{2} \cdot \left({c}^{2} \cdot {x}^{2}\right)} \cdot \cos \left(x + x\right)
\] |
|---|---|
associate-*r* [=>]23.0 | \[ \frac{1}{\color{blue}{\left({s}^{2} \cdot {c}^{2}\right) \cdot {x}^{2}}} \cdot \cos \left(x + x\right)
\] |
unpow2 [=>]23.0 | \[ \frac{1}{\left({s}^{2} \cdot {c}^{2}\right) \cdot \color{blue}{\left(x \cdot x\right)}} \cdot \cos \left(x + x\right)
\] |
associate-*r* [=>]18.7 | \[ \frac{1}{\color{blue}{\left(\left({s}^{2} \cdot {c}^{2}\right) \cdot x\right) \cdot x}} \cdot \cos \left(x + x\right)
\] |
associate-/r* [=>]18.6 | \[ \color{blue}{\frac{\frac{1}{\left({s}^{2} \cdot {c}^{2}\right) \cdot x}}{x}} \cdot \cos \left(x + x\right)
\] |
associate-/l/ [<=]18.6 | \[ \frac{\color{blue}{\frac{\frac{1}{x}}{{s}^{2} \cdot {c}^{2}}}}{x} \cdot \cos \left(x + x\right)
\] |
unpow-1 [<=]18.6 | \[ \frac{\frac{\color{blue}{{x}^{-1}}}{{s}^{2} \cdot {c}^{2}}}{x} \cdot \cos \left(x + x\right)
\] |
associate-/l/ [=>]18.6 | \[ \color{blue}{\frac{{x}^{-1}}{x \cdot \left({s}^{2} \cdot {c}^{2}\right)}} \cdot \cos \left(x + x\right)
\] |
*-commutative [<=]18.6 | \[ \frac{{x}^{-1}}{x \cdot \color{blue}{\left({c}^{2} \cdot {s}^{2}\right)}} \cdot \cos \left(x + x\right)
\] |
unpow2 [=>]18.6 | \[ \frac{{x}^{-1}}{x \cdot \left({c}^{2} \cdot \color{blue}{\left(s \cdot s\right)}\right)} \cdot \cos \left(x + x\right)
\] |
unpow2 [=>]18.6 | \[ \frac{{x}^{-1}}{x \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot \left(s \cdot s\right)\right)} \cdot \cos \left(x + x\right)
\] |
unswap-sqr [=>]13.0 | \[ \frac{{x}^{-1}}{x \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot \left(c \cdot s\right)\right)}} \cdot \cos \left(x + x\right)
\] |
associate-*l* [<=]6.5 | \[ \frac{{x}^{-1}}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(c \cdot s\right)}} \cdot \cos \left(x + x\right)
\] |
unpow-1 [=>]6.5 | \[ \frac{\color{blue}{\frac{1}{x}}}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \left(c \cdot s\right)} \cdot \cos \left(x + x\right)
\] |
associate-/l/ [<=]2.7 | \[ \color{blue}{\frac{\frac{\frac{1}{x}}{c \cdot s}}{x \cdot \left(c \cdot s\right)}} \cdot \cos \left(x + x\right)
\] |
*-rgt-identity [<=]2.7 | \[ \frac{\color{blue}{\frac{\frac{1}{x}}{c \cdot s} \cdot 1}}{x \cdot \left(c \cdot s\right)} \cdot \cos \left(x + x\right)
\] |
associate-*r/ [<=]2.7 | \[ \color{blue}{\left(\frac{\frac{1}{x}}{c \cdot s} \cdot \frac{1}{x \cdot \left(c \cdot s\right)}\right)} \cdot \cos \left(x + x\right)
\] |
associate-/r* [<=]2.8 | \[ \left(\color{blue}{\frac{1}{x \cdot \left(c \cdot s\right)}} \cdot \frac{1}{x \cdot \left(c \cdot s\right)}\right) \cdot \cos \left(x + x\right)
\] |
unpow-1 [<=]2.8 | \[ \left(\color{blue}{{\left(x \cdot \left(c \cdot s\right)\right)}^{-1}} \cdot \frac{1}{x \cdot \left(c \cdot s\right)}\right) \cdot \cos \left(x + x\right)
\] |
if +inf.0 < (/.f64 (cos.f64 (*.f64 2 x)) (*.f64 (pow.f64 c 2) (*.f64 (*.f64 x (pow.f64 s 2)) x))) Initial program 64.0
Simplified3.4
[Start]64.0 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]64.0 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]64.0 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]63.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]63.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]63.9 | \[ \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 [=>]63.9 | \[ \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 [=>]24.5 | \[ \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 [=>]3.4 | \[ \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)}}
\] |
Applied egg-rr3.4
Final simplification1.0
| Alternative 1 | |
|---|---|
| Error | 2.1 |
| Cost | 13705 |
| Alternative 2 | |
|---|---|
| Error | 1.7 |
| Cost | 13704 |
| Alternative 3 | |
|---|---|
| Error | 2.2 |
| Cost | 7753 |
| Alternative 4 | |
|---|---|
| Error | 2.2 |
| Cost | 7753 |
| Alternative 5 | |
|---|---|
| Error | 7.5 |
| Cost | 7625 |
| Alternative 6 | |
|---|---|
| Error | 3.9 |
| Cost | 7625 |
| Alternative 7 | |
|---|---|
| Error | 2.5 |
| Cost | 7625 |
| Alternative 8 | |
|---|---|
| Error | 13.8 |
| Cost | 7624 |
| Alternative 9 | |
|---|---|
| Error | 8.1 |
| Cost | 7624 |
| Alternative 10 | |
|---|---|
| Error | 4.1 |
| Cost | 7624 |
| Alternative 11 | |
|---|---|
| Error | 16.4 |
| Cost | 7044 |
| Alternative 12 | |
|---|---|
| Error | 16.3 |
| Cost | 6916 |
| Alternative 13 | |
|---|---|
| Error | 22.4 |
| Cost | 1097 |
| Alternative 14 | |
|---|---|
| Error | 16.8 |
| Cost | 1092 |
| Alternative 15 | |
|---|---|
| Error | 16.4 |
| Cost | 1092 |
| Alternative 16 | |
|---|---|
| Error | 19.0 |
| Cost | 964 |
| Alternative 17 | |
|---|---|
| Error | 17.1 |
| Cost | 964 |
| Alternative 18 | |
|---|---|
| Error | 17.1 |
| Cost | 964 |
| Alternative 19 | |
|---|---|
| Error | 28.7 |
| Cost | 832 |
| Alternative 20 | |
|---|---|
| Error | 20.2 |
| Cost | 832 |
| Alternative 21 | |
|---|---|
| Error | 17.6 |
| Cost | 832 |
herbie shell --seed 2023066
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))