On Thursday 26 June 2008, andre maute wrote:
> I have the following terms
>
> ------------------------------------------------------------------
> display2d : false;
>
> t1:(J(r,a+1,b,s+1,t)*(-s+a+1)-J(r,a,b+1,s+1,t)*(a-s))*(t+r+1)
> +(s+r+1)*(J(r,a,b+1,s,t+1)*(-t+b+1)-J(r,a+1,b,s,t+1)*(b-t));
>
> t2:(s+r+2)*((-t+b+2)*((J(r,a+1,b+1,s+1,t+1)*(-s+a+1)
> -J(r,a,b+2,s+1,t+1)*(a-s))
> *(t+r+2)
> +(s+r+1)*(J(r,a,b+2,s,t+2)*(-t+b+1)
> -J(r,a+1,b+1,s,t+2)*(b-t)))
> -(b-t)*((J(r,a+2,b,s+1,t+1)*(-s+a+2)
> -J(r,a+1,b+1,s+1,t+1)*(-s+a+1))
> *(t+r+2)
> +(s+r+1)*(J(r,a+1,b+1,s,t+2)*(b-t)
> -J(r,a+2,b,s,t+2)*(-t+b-1))))
> +(t+r+2)*((-s+a+2)*((J(r,a+2,b,s+2,t)*(-s+a+1)
> -J(r,a+1,b+1,s+2,t)*(a-s))
> *(t+r+1)
> +(s+r+2)*(J(r,a+1,b+1,s+1,t+1)*(-t+b+1)
> -J(r,a+2,b,s+1,t+1)*(b-t)))
> -(a-s)*((J(r,a+1,b+1,s+2,t)*(a-s)-J(r,a,b+2,s+2,t)*(-s+a-1))
> *(t+r+1)
> +(s+r+2)*(J(r,a,b+2,s+1,t+1)*(-t+b+2)
> -J(r,a+1,b+1,s+1,t+1)*(-t+b+1))));
> ----------------------------------------------------------------------
>
> t1 and t2 were generated with a recursion rule.
> t1 and t2 are linear combinations of the J-Terms and r,a,b,s,t are
> parameters.
>
> Is it possible to combine the J-Terms and apply a function,
> e.g. factor(), to their coefficients?
O.k. I have all J-Terms with
-----------------------------------------------------------------------
e2 : expand(t2);
e2parts : makelist(part(e2,i),i,1,length(e2));
matchdeclare(rr,true);
matchdeclare(aa,true);
matchdeclare(bb,true);
matchdeclare(ss,true);
matchdeclare(tt,true);
defmatch(Jp,J(rr,aa,bb,ss,tt));
isJp : lambda([x],is(Jp(x) # false));
matchdeclare(JJ,isJp);
matchdeclare(ff,true);
defmatch(SJp,ff*JJ);
Jparts : makelist(rhs(SJp(e2parts[i])[1]),i,1,length(e2parts));
-----------------------------------------------------------------------
then Jparts is a list of the following form
-----------------------------------------------------------------------
[J(r,a+2,b,s+2,t),J(r,a+2,b,s+1,t+1),J(r,a+2,b,s,t+2), ... ]
-----------------------------------------------------------------------
Sorting that list and finding the unique elements should be no problem.
The last step is then to extract the coefficients of the J-Terms.
To split the linear combination I used expand with a combined makelist.
Does somebody know perhaps of a faster solution?
The above took already 7s on my computer (2Ghz)
Andre