| Alternative 1 | |
|---|---|
| Error | 1.8 |
| Cost | 13960 |
(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 (pow t_0 2.0)))
(if (<= s 2.6e-147)
(* (/ (/ (/ 1.0 x) (* s c)) t_0) (cos (+ x x)))
(if (<= s 2.4e+213)
(* (pow (* s (* x c)) -2.0) (/ 1.0 (/ 1.0 (cos (* x 2.0)))))
(- (/ (pow (cos x) 2.0) t_1) (/ (pow (sin x) 2.0) 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 = x * (s * c);
double t_1 = pow(t_0, 2.0);
double tmp;
if (s <= 2.6e-147) {
tmp = (((1.0 / x) / (s * c)) / t_0) * cos((x + x));
} else if (s <= 2.4e+213) {
tmp = pow((s * (x * c)), -2.0) * (1.0 / (1.0 / cos((x * 2.0))));
} else {
tmp = (pow(cos(x), 2.0) / t_1) - (pow(sin(x), 2.0) / 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) :: tmp
t_0 = x * (s * c)
t_1 = t_0 ** 2.0d0
if (s <= 2.6d-147) then
tmp = (((1.0d0 / x) / (s * c)) / t_0) * cos((x + x))
else if (s <= 2.4d+213) then
tmp = ((s * (x * c)) ** (-2.0d0)) * (1.0d0 / (1.0d0 / cos((x * 2.0d0))))
else
tmp = ((cos(x) ** 2.0d0) / t_1) - ((sin(x) ** 2.0d0) / 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 = x * (s * c);
double t_1 = Math.pow(t_0, 2.0);
double tmp;
if (s <= 2.6e-147) {
tmp = (((1.0 / x) / (s * c)) / t_0) * Math.cos((x + x));
} else if (s <= 2.4e+213) {
tmp = Math.pow((s * (x * c)), -2.0) * (1.0 / (1.0 / Math.cos((x * 2.0))));
} else {
tmp = (Math.pow(Math.cos(x), 2.0) / t_1) - (Math.pow(Math.sin(x), 2.0) / 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 = x * (s * c) t_1 = math.pow(t_0, 2.0) tmp = 0 if s <= 2.6e-147: tmp = (((1.0 / x) / (s * c)) / t_0) * math.cos((x + x)) elif s <= 2.4e+213: tmp = math.pow((s * (x * c)), -2.0) * (1.0 / (1.0 / math.cos((x * 2.0)))) else: tmp = (math.pow(math.cos(x), 2.0) / t_1) - (math.pow(math.sin(x), 2.0) / 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(x * Float64(s * c)) t_1 = t_0 ^ 2.0 tmp = 0.0 if (s <= 2.6e-147) tmp = Float64(Float64(Float64(Float64(1.0 / x) / Float64(s * c)) / t_0) * cos(Float64(x + x))); elseif (s <= 2.4e+213) tmp = Float64((Float64(s * Float64(x * c)) ^ -2.0) * Float64(1.0 / Float64(1.0 / cos(Float64(x * 2.0))))); else tmp = Float64(Float64((cos(x) ^ 2.0) / t_1) - Float64((sin(x) ^ 2.0) / 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 = x * (s * c); t_1 = t_0 ^ 2.0; tmp = 0.0; if (s <= 2.6e-147) tmp = (((1.0 / x) / (s * c)) / t_0) * cos((x + x)); elseif (s <= 2.4e+213) tmp = ((s * (x * c)) ^ -2.0) * (1.0 / (1.0 / cos((x * 2.0)))); else tmp = ((cos(x) ^ 2.0) / t_1) - ((sin(x) ^ 2.0) / 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[(x * N[(s * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 2.0], $MachinePrecision]}, If[LessEqual[s, 2.6e-147], N[(N[(N[(N[(1.0 / x), $MachinePrecision] / N[(s * c), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision] * N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[s, 2.4e+213], N[(N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision] * N[(1.0 / N[(1.0 / N[Cos[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[Cos[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $MachinePrecision] - N[(N[Power[N[Sin[x], $MachinePrecision], 2.0], $MachinePrecision] / t$95$1), $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 := {t_0}^{2}\\
\mathbf{if}\;s \leq 2.6 \cdot 10^{-147}:\\
\;\;\;\;\frac{\frac{\frac{1}{x}}{s \cdot c}}{t_0} \cdot \cos \left(x + x\right)\\
\mathbf{elif}\;s \leq 2.4 \cdot 10^{+213}:\\
\;\;\;\;{\left(s \cdot \left(x \cdot c\right)\right)}^{-2} \cdot \frac{1}{\frac{1}{\cos \left(x \cdot 2\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\cos x}^{2}}{t_1} - \frac{{\sin x}^{2}}{t_1}\\
\end{array}
Results
if s < 2.5999999999999999e-147Initial program 35.5
Simplified3.3
[Start]35.5 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]35.5 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\color{blue}{\left({s}^{2} \cdot x\right)} \cdot x\right)}
\] |
associate-*l* [=>]38.2 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]38.2 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]38.2 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]38.2 | \[ \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 [=>]38.2 | \[ \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.3 | \[ \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.3 | \[ \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.1
Applied egg-rr3.1
if 2.5999999999999999e-147 < s < 2.4e213Initial program 25.3
Simplified2.8
[Start]25.3 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]25.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* [=>]28.6 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]28.4 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]28.4 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]28.4 | \[ \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 [=>]28.4 | \[ \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 [=>]20.8 | \[ \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.8 | \[ \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.6
Simplified0.8
[Start]2.6 | \[ {\left(x \cdot \left(c \cdot s\right)\right)}^{-2} \cdot {\cos x}^{2} + {\left(x \cdot \left(c \cdot s\right)\right)}^{-2} \cdot \left(-{\sin x}^{2}\right)
\] |
|---|---|
distribute-lft-out [=>]2.5 | \[ \color{blue}{{\left(x \cdot \left(c \cdot s\right)\right)}^{-2} \cdot \left({\cos x}^{2} + \left(-{\sin x}^{2}\right)\right)}
\] |
associate-*r* [=>]0.8 | \[ {\color{blue}{\left(\left(x \cdot c\right) \cdot s\right)}}^{-2} \cdot \left({\cos x}^{2} + \left(-{\sin x}^{2}\right)\right)
\] |
*-commutative [<=]0.8 | \[ {\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right)}^{-2} \cdot \left({\cos x}^{2} + \left(-{\sin x}^{2}\right)\right)
\] |
*-commutative [<=]0.8 | \[ {\color{blue}{\left(s \cdot \left(c \cdot x\right)\right)}}^{-2} \cdot \left({\cos x}^{2} + \left(-{\sin x}^{2}\right)\right)
\] |
unsub-neg [=>]0.8 | \[ {\left(s \cdot \left(c \cdot x\right)\right)}^{-2} \cdot \color{blue}{\left({\cos x}^{2} - {\sin x}^{2}\right)}
\] |
Applied egg-rr0.7
if 2.4e213 < s Initial program 24.3
Simplified24.3
[Start]24.3 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
associate-*r* [=>]24.3 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right) \cdot x}}
\] |
*-commutative [=>]24.3 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{x \cdot \left({c}^{2} \cdot \left(x \cdot {s}^{2}\right)\right)}}
\] |
*-commutative [=>]24.3 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left({c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot x\right)}\right)}
\] |
associate-*r* [=>]24.3 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \color{blue}{\left(\left({c}^{2} \cdot {s}^{2}\right) \cdot x\right)}}
\] |
*-commutative [=>]24.3 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \color{blue}{\left(x \cdot \left({c}^{2} \cdot {s}^{2}\right)\right)}}
\] |
unpow2 [=>]24.3 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(x \cdot \left(\color{blue}{\left(c \cdot c\right)} \cdot {s}^{2}\right)\right)}
\] |
unpow2 [=>]24.3 | \[ \frac{\cos \left(2 \cdot x\right)}{x \cdot \left(x \cdot \left(\left(c \cdot c\right) \cdot \color{blue}{\left(s \cdot s\right)}\right)\right)}
\] |
Applied egg-rr2.5
Simplified2.5
[Start]2.5 | \[ \frac{{\cos x}^{2}}{{\left(x \cdot \left(c \cdot s\right)\right)}^{2}} - \frac{{\sin x}^{2}}{{\left(x \cdot \left(c \cdot s\right)\right)}^{2}}
\] |
|---|---|
*-commutative [=>]2.5 | \[ \frac{{\cos x}^{2}}{{\left(x \cdot \color{blue}{\left(s \cdot c\right)}\right)}^{2}} - \frac{{\sin x}^{2}}{{\left(x \cdot \left(c \cdot s\right)\right)}^{2}}
\] |
*-commutative [=>]2.5 | \[ \frac{{\cos x}^{2}}{{\left(x \cdot \left(s \cdot c\right)\right)}^{2}} - \frac{{\sin x}^{2}}{{\left(x \cdot \color{blue}{\left(s \cdot c\right)}\right)}^{2}}
\] |
Final simplification1.8
| Alternative 1 | |
|---|---|
| Error | 1.8 |
| Cost | 13960 |
| Alternative 2 | |
|---|---|
| Error | 1.8 |
| Cost | 13704 |
| Alternative 3 | |
|---|---|
| Error | 9.7 |
| Cost | 7625 |
| Alternative 4 | |
|---|---|
| Error | 6.8 |
| Cost | 7625 |
| Alternative 5 | |
|---|---|
| Error | 4.3 |
| Cost | 7625 |
| Alternative 6 | |
|---|---|
| Error | 4.1 |
| Cost | 7624 |
| Alternative 7 | |
|---|---|
| Error | 2.7 |
| Cost | 7488 |
| Alternative 8 | |
|---|---|
| Error | 2.6 |
| Cost | 7488 |
| Alternative 9 | |
|---|---|
| Error | 2.9 |
| Cost | 7360 |
| Alternative 10 | |
|---|---|
| Error | 19.3 |
| Cost | 964 |
| Alternative 11 | |
|---|---|
| Error | 16.9 |
| Cost | 960 |
| Alternative 12 | |
|---|---|
| Error | 20.5 |
| Cost | 832 |
| Alternative 13 | |
|---|---|
| Error | 16.9 |
| Cost | 832 |
herbie shell --seed 2022356
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))