how to do this substitution? Plz suggest



Hi,
I need to apply a substitution rule in the following manner:
Lets say

(%i14) eq:sum(d(i1,i2)*f(i1)*d(i3,i1),i1,1,n);

                                    n

                               ====

                               \

(%o14)                      >     f(i1) d(i1, i2) d(i3, i1)

                               /

                               ====

                               i1 = 1



Now, I need to substitute it with
            f(i2)*d(i3,i2)
i.e. I am removing summation and function ?d(index of the summation, any
variable say i2)?, as well as replacing index of summation in all the
functions within the summation with the i2 (the second variable of
function d).

I tried the following thing but didn?t work.

 (%i10) matchdeclare([i,j,k,q],all);

(%o10)                                           done

(%i12)   apply(defrule,[rule1,sum(d(i,j)*q(i),i,1,k),q(j)]);



                                           k

                                          ====

                                          \

(%o12)                    rule1 :  >    q(i) d(i, j) -> q(j)

                                          /

                                          ====

                                          i = 1

(%i13) apply(apply1,[eq,rule1]);

                                    n

                               ====

                               \

(%o13)                      >     d(i1, i2) f(i2) d(i3, i2)

                               /

                               ====

                               i2 = 1


Although I was able to do it with one specific function, like this:

(%i16)   apply(defrule,[rule1,sum(d(i,j)*f(i),i,1,k),f(j)]);



                                           k

                                          ====

                                          \

(%o16)                    rule1 :  >    f(i) d(i, j) -> f(j)

                                          /

                                          ====

                                          i = 1

(%i17) eq:sum(d(i1,i2)*f(i1),i1,1,n);

                                         n

                                        ====

                                        \

(%o17)                               >        f(i1) d(i1, i2)

                                        /

                                        ====

                                        i1 = 1

(%i18) apply(apply1,[eq,rule1]);

(%o18)                                           f(i2)



But, the equation within summation can have more functions in product.

If you have any clue, please suggest.
Regards

Dileep