# [GiNaC-list] collecting on similar series expansion

Charlls Quarra charlls_quarra at yahoo.com.ar
Sun Jan 28 13:31:18 CET 2007

Hi ,

I'm just trying out ginac for the first time. I have
an expression with sumands of this type (in latex
format):

1-\frac{1}{3} \frac{ p D[0](F)(q) D[0,0](F)(q) \nu
\epsilon^{2} dt^{5} \delta}{m^{3}}-\frac{1}{9} \frac{
p D[0](F)(q) D[0,0](F)(q)^{2} \alpha^{2} \nu^{2}
\epsilon^{2} dt^{9} \F(q) \delta
\gamma}{m^{5}}-\frac{1}{18} \frac{ p^{2} D[0,0](F)(q)
D[0,0,0](F)(q) \beta \alpha^{2} \epsilon^{2} dt^{8}
\F(q) \delta \gamma}{m^{5}}+\frac{1}{2} \frac{
D[0](F)(q) D[0,0](F)(q) \alpha \nu \epsilon dt^{6}
\F(q)}{m^{3}} ....

so i want to collect terms that have the same
coefficients of the form D[0..i times] (F)(q) * D[ 0..
j times] (F)(q) .... but the polynomial collect won't
work. Initially i thought about substituting each D[ ]
(F)(q) with a different symbol, then collect on the
multivariate polynomials of these symbols and then
finally substitute back the D[] expressions, however,
I don't know how the collect call is supposed to
receive the symbols that it must collect, the code
looks like this:

ex jacobian = diff( q + dq_new*dt , q )*diff( p
+ dp_new*dt , p ) - diff( q + dq_new*dt , p )*diff( p
+ dp_new*dt , q );
cout << " the jacobian of the integrator is "
<< expand(jacobian) << endl;
exmap diff_map , inv_diff_map;
symbol foo[10];
diff_map[ F(q) ] = foo[0]; inv_diff_map[
foo[0] ] = F(q);
diff_map[ F(q).diff(q) ] = foo[1];
inv_diff_map[ foo[1] ] = F(q).diff(q);
diff_map[ F(q).diff(q,2) ] = foo[2];
inv_diff_map[ foo[2] ] = F(q).diff(q,2);
diff_map[ F(q).diff(q,3) ] = foo[3];
inv_diff_map[ foo[3] ] = F(q).diff(q,3);
diff_map[ F(q).diff(q,4) ] = foo[4];
inv_diff_map[ foo[4] ] = F(q).diff(q,4);
ex rord = collect( jacobian.subs( diff_map ) ,
{ foo[0] , foo[1] , foo[2] , foo[3] , foo[4] } ); // i
know this is an error in C++, but this is the idea
rord = rord.subs( inv_diff_map );
cout << "reordered we obtain " << rord <<
endl;

any thoughts on this?

__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas