| Alternative 1 | |
|---|---|
| Error | 2.3 |
| Cost | 13572 |
(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 (* x (* s c))) (t_1 (cos (+ x x))))
(if (<= s 1e+173)
(* t_1 (pow (* s (* x c)) -2.0))
(/ (log1p (expm1 t_1)) (* t_0 t_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 = x * (s * c);
double t_1 = cos((x + x));
double tmp;
if (s <= 1e+173) {
tmp = t_1 * pow((s * (x * c)), -2.0);
} else {
tmp = log1p(expm1(t_1)) / (t_0 * t_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 = x * (s * c);
double t_1 = Math.cos((x + x));
double tmp;
if (s <= 1e+173) {
tmp = t_1 * Math.pow((s * (x * c)), -2.0);
} else {
tmp = Math.log1p(Math.expm1(t_1)) / (t_0 * t_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 = x * (s * c) t_1 = math.cos((x + x)) tmp = 0 if s <= 1e+173: tmp = t_1 * math.pow((s * (x * c)), -2.0) else: tmp = math.log1p(math.expm1(t_1)) / (t_0 * t_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 = Float64(x * Float64(s * c)) t_1 = cos(Float64(x + x)) tmp = 0.0 if (s <= 1e+173) tmp = Float64(t_1 * (Float64(s * Float64(x * c)) ^ -2.0)); else tmp = Float64(log1p(expm1(t_1)) / Float64(t_0 * t_0)); end return 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[(x * N[(s * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[s, 1e+173], N[(t$95$1 * N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], N[(N[Log[1 + N[(Exp[t$95$1] - 1), $MachinePrecision]], $MachinePrecision] / N[(t$95$0 * t$95$0), $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 := x \cdot \left(s \cdot c\right)\\
t_1 := \cos \left(x + x\right)\\
\mathbf{if}\;s \leq 10^{+173}:\\
\;\;\;\;t_1 \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\mathsf{expm1}\left(t_1\right)\right)}{t_0 \cdot t_0}\\
\end{array}
Results
if s < 1e173Initial program 28.6
Simplified3.4
[Start]28.6 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]28.6 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]31.8 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]32.1 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]32.1 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]32.1 | \[ \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 [=>]32.1 | \[ \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 [=>]21.9 | \[ \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)}}
\] |
Taylor expanded in x around inf 31.8
Simplified2.2
[Start]31.8 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
|---|---|
count-2 [<=]31.8 | \[ \frac{\cos \color{blue}{\left(x + x\right)}}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
associate-*r* [=>]32.1 | \[ \frac{\cos \left(x + x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot {x}^{2}}}
\] |
associate-/r* [=>]32.1 | \[ \color{blue}{\frac{\frac{\cos \left(x + x\right)}{{c}^{2} \cdot {s}^{2}}}{{x}^{2}}}
\] |
unpow2 [=>]32.1 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}}}{{x}^{2}}
\] |
unpow2 [=>]32.1 | \[ \frac{\frac{\cos \left(x + x\right)}{\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}}}{{x}^{2}}
\] |
swap-sqr [<=]21.9 | \[ \frac{\frac{\cos \left(x + x\right)}{\color{blue}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}}{{x}^{2}}
\] |
*-lft-identity [<=]21.9 | \[ \frac{\frac{\color{blue}{1 \cdot \cos \left(x + x\right)}}{\left(c \cdot s\right) \cdot \left(c \cdot s\right)}}{{x}^{2}}
\] |
times-frac [=>]21.8 | \[ \frac{\color{blue}{\frac{1}{c \cdot s} \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}}{{x}^{2}}
\] |
associate-*l/ [<=]17.2 | \[ \color{blue}{\frac{\frac{1}{c \cdot s}}{{x}^{2}} \cdot \frac{\cos \left(x + x\right)}{c \cdot s}}
\] |
unpow2 [=>]17.2 | \[ \frac{\frac{1}{c \cdot s}}{\color{blue}{x \cdot x}} \cdot \frac{\cos \left(x + x\right)}{c \cdot s}
\] |
associate-/r* [<=]17.2 | \[ \color{blue}{\frac{1}{\left(c \cdot s\right) \cdot \left(x \cdot x\right)}} \cdot \frac{\cos \left(x + x\right)}{c \cdot s}
\] |
associate-*r* [=>]8.1 | \[ \frac{1}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right) \cdot x}} \cdot \frac{\cos \left(x + x\right)}{c \cdot s}
\] |
*-commutative [<=]8.1 | \[ \frac{1}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right)} \cdot x} \cdot \frac{\cos \left(x + x\right)}{c \cdot s}
\] |
associate-/r* [=>]7.8 | \[ \color{blue}{\frac{\frac{1}{x \cdot \left(c \cdot s\right)}}{x}} \cdot \frac{\cos \left(x + x\right)}{c \cdot s}
\] |
if 1e173 < s Initial program 25.0
Simplified2.4
[Start]25.0 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]25.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* [=>]29.1 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]29.1 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]29.1 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]29.1 | \[ \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 [=>]29.1 | \[ \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 [=>]14.9 | \[ \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 [=>]2.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-rr2.4
Final simplification2.3
| Alternative 1 | |
|---|---|
| Error | 2.3 |
| Cost | 13572 |
| Alternative 2 | |
|---|---|
| Error | 8.4 |
| Cost | 7756 |
| Alternative 3 | |
|---|---|
| Error | 2.3 |
| Cost | 7753 |
| Alternative 4 | |
|---|---|
| Error | 9.6 |
| Cost | 7625 |
| Alternative 5 | |
|---|---|
| Error | 4.3 |
| Cost | 7625 |
| Alternative 6 | |
|---|---|
| Error | 9.8 |
| Cost | 7624 |
| Alternative 7 | |
|---|---|
| Error | 4.5 |
| Cost | 7624 |
| Alternative 8 | |
|---|---|
| Error | 3.6 |
| Cost | 7624 |
| Alternative 9 | |
|---|---|
| Error | 16.6 |
| Cost | 6784 |
| Alternative 10 | |
|---|---|
| Error | 16.6 |
| Cost | 960 |
| Alternative 11 | |
|---|---|
| Error | 34.2 |
| Cost | 832 |
| Alternative 12 | |
|---|---|
| Error | 30.7 |
| Cost | 832 |
| Alternative 13 | |
|---|---|
| Error | 27.4 |
| Cost | 832 |
| Alternative 14 | |
|---|---|
| Error | 17.9 |
| Cost | 832 |
| Alternative 15 | |
|---|---|
| Error | 16.8 |
| Cost | 832 |
herbie shell --seed 2023018
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))