| Alternative 1 | |
|---|---|
| Error | 2.6 |
| Cost | 13440 |
\[\cos \left(x + x\right) \cdot {\left(s \cdot \left(x \cdot c\right)\right)}^{-2}
\]
(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))))
(if (or (<= x -3.2e-189) (not (<= x 2e-45)))
(* (/ (cos (+ x x)) t_0) (/ 1.0 t_0))
(/ 1.0 (pow (* s (* x c)) 2.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 tmp;
if ((x <= -3.2e-189) || !(x <= 2e-45)) {
tmp = (cos((x + x)) / t_0) * (1.0 / t_0);
} else {
tmp = 1.0 / pow((s * (x * c)), 2.0);
}
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) :: tmp
t_0 = x * (s * c)
if ((x <= (-3.2d-189)) .or. (.not. (x <= 2d-45))) then
tmp = (cos((x + x)) / t_0) * (1.0d0 / t_0)
else
tmp = 1.0d0 / ((s * (x * c)) ** 2.0d0)
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 tmp;
if ((x <= -3.2e-189) || !(x <= 2e-45)) {
tmp = (Math.cos((x + x)) / t_0) * (1.0 / t_0);
} else {
tmp = 1.0 / Math.pow((s * (x * c)), 2.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) tmp = 0 if (x <= -3.2e-189) or not (x <= 2e-45): tmp = (math.cos((x + x)) / t_0) * (1.0 / t_0) else: tmp = 1.0 / math.pow((s * (x * c)), 2.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)) tmp = 0.0 if ((x <= -3.2e-189) || !(x <= 2e-45)) tmp = Float64(Float64(cos(Float64(x + x)) / t_0) * Float64(1.0 / t_0)); else tmp = Float64(1.0 / (Float64(s * Float64(x * c)) ^ 2.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 = x * (s * c); tmp = 0.0; if ((x <= -3.2e-189) || ~((x <= 2e-45))) tmp = (cos((x + x)) / t_0) * (1.0 / t_0); else tmp = 1.0 / ((s * (x * c)) ^ 2.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[(x * N[(s * c), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[x, -3.2e-189], N[Not[LessEqual[x, 2e-45]], $MachinePrecision]], N[(N[(N[Cos[N[(x + x), $MachinePrecision]], $MachinePrecision] / t$95$0), $MachinePrecision] * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Power[N[(s * N[(x * c), $MachinePrecision]), $MachinePrecision], 2.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)\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{-189} \lor \neg \left(x \leq 2 \cdot 10^{-45}\right):\\
\;\;\;\;\frac{\cos \left(x + x\right)}{t_0} \cdot \frac{1}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{{\left(s \cdot \left(x \cdot c\right)\right)}^{2}}\\
\end{array}
Results
if x < -3.2000000000000001e-189 or 1.99999999999999997e-45 < x Initial program 26.0
Simplified1.9
[Start]26.0 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]26.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* [=>]27.7 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \color{blue}{\left({s}^{2} \cdot \left(x \cdot x\right)\right)}}
\] |
associate-*r* [=>]27.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]27.9 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]27.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 [=>]27.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 [=>]14.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 [=>]1.9 | \[ \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-rr1.6
if -3.2000000000000001e-189 < x < 1.99999999999999997e-45Initial program 38.6
Simplified7.1
[Start]38.6 | \[ \frac{\cos \left(2 \cdot x\right)}{{c}^{2} \cdot \left(\left(x \cdot {s}^{2}\right) \cdot x\right)}
\] |
|---|---|
*-commutative [=>]38.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* [=>]50.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* [=>]50.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left({c}^{2} \cdot {s}^{2}\right) \cdot \left(x \cdot x\right)}}
\] |
*-commutative [=>]50.6 | \[ \frac{\cos \left(2 \cdot x\right)}{\color{blue}{\left(x \cdot x\right) \cdot \left({c}^{2} \cdot {s}^{2}\right)}}
\] |
unpow2 [=>]50.6 | \[ \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 [=>]50.6 | \[ \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 [=>]44.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 [=>]7.1 | \[ \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 0 50.8
Simplified4.9
[Start]50.8 | \[ \frac{1}{{c}^{2} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
|---|---|
unpow2 [=>]50.8 | \[ \frac{1}{\color{blue}{\left(c \cdot c\right)} \cdot \left({s}^{2} \cdot {x}^{2}\right)}
\] |
unpow2 [=>]50.8 | \[ \frac{1}{\left(c \cdot c\right) \cdot \left(\color{blue}{\left(s \cdot s\right)} \cdot {x}^{2}\right)}
\] |
unpow2 [=>]50.8 | \[ \frac{1}{\left(c \cdot c\right) \cdot \left(\left(s \cdot s\right) \cdot \color{blue}{\left(x \cdot x\right)}\right)}
\] |
unswap-sqr [=>]26.0 | \[ \frac{1}{\left(c \cdot c\right) \cdot \color{blue}{\left(\left(s \cdot x\right) \cdot \left(s \cdot x\right)\right)}}
\] |
swap-sqr [<=]5.1 | \[ \frac{1}{\color{blue}{\left(c \cdot \left(s \cdot x\right)\right) \cdot \left(c \cdot \left(s \cdot x\right)\right)}}
\] |
associate-*r* [=>]11.2 | \[ \frac{1}{\color{blue}{\left(\left(c \cdot s\right) \cdot x\right)} \cdot \left(c \cdot \left(s \cdot x\right)\right)}
\] |
*-commutative [<=]11.2 | \[ \frac{1}{\color{blue}{\left(x \cdot \left(c \cdot s\right)\right)} \cdot \left(c \cdot \left(s \cdot x\right)\right)}
\] |
associate-*r* [=>]7.1 | \[ \frac{1}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \color{blue}{\left(\left(c \cdot s\right) \cdot x\right)}}
\] |
*-commutative [<=]7.1 | \[ \frac{1}{\left(x \cdot \left(c \cdot s\right)\right) \cdot \color{blue}{\left(x \cdot \left(c \cdot s\right)\right)}}
\] |
unpow2 [<=]7.1 | \[ \frac{1}{\color{blue}{{\left(x \cdot \left(c \cdot s\right)\right)}^{2}}}
\] |
associate-*r* [=>]4.9 | \[ \frac{1}{{\color{blue}{\left(\left(x \cdot c\right) \cdot s\right)}}^{2}}
\] |
*-commutative [<=]4.9 | \[ \frac{1}{{\left(\color{blue}{\left(c \cdot x\right)} \cdot s\right)}^{2}}
\] |
*-commutative [<=]4.9 | \[ \frac{1}{{\color{blue}{\left(s \cdot \left(c \cdot x\right)\right)}}^{2}}
\] |
Final simplification2.2
| Alternative 1 | |
|---|---|
| Error | 2.6 |
| Cost | 13440 |
| Alternative 2 | |
|---|---|
| Error | 6.1 |
| Cost | 7625 |
| Alternative 3 | |
|---|---|
| Error | 3.7 |
| Cost | 7625 |
| Alternative 4 | |
|---|---|
| Error | 2.5 |
| Cost | 7625 |
| Alternative 5 | |
|---|---|
| Error | 12.5 |
| Cost | 7624 |
| Alternative 6 | |
|---|---|
| Error | 3.8 |
| Cost | 7624 |
| Alternative 7 | |
|---|---|
| Error | 3.0 |
| Cost | 7488 |
| Alternative 8 | |
|---|---|
| Error | 22.0 |
| Cost | 1097 |
| Alternative 9 | |
|---|---|
| Error | 22.1 |
| Cost | 1096 |
| Alternative 10 | |
|---|---|
| Error | 28.5 |
| Cost | 832 |
| Alternative 11 | |
|---|---|
| Error | 19.9 |
| Cost | 832 |
| Alternative 12 | |
|---|---|
| Error | 19.1 |
| Cost | 832 |
| Alternative 13 | |
|---|---|
| Error | 17.0 |
| Cost | 832 |
| Alternative 14 | |
|---|---|
| Error | 16.8 |
| Cost | 832 |
herbie shell --seed 2023025
(FPCore (x c s)
:name "mixedcos"
:precision binary64
(/ (cos (* 2.0 x)) (* (pow c 2.0) (* (* x (pow s 2.0)) x))))