# [Maxima] Plz suggest

dp2 at cise.ufl.edu dp2 at cise.ufl.edu
Sat Feb 18 02:21:52 CST 2006

```Hi,

I am trying to find the patterns of kind, sum(d(i,j)*g(j,k),j,1,n), where
g(j,k) can be any function of j and any other variable say k, that may
contain multiple terms or simply be nothing like 1. Please note that i,j,k
can be anything e.g. i2,i3,n2,m1,etc. These patterns are to be found in a
very long expression that may contain products of sum() as well as sums of
sum. And once these patterns are found, I need to replace these patterns
using: sum(d(i,j)*g(j,k),j,1,n) -> g(i,k) ; plz note here all js are to be
replaced by i in g(j,k) which may contain multiple terms. These d are
actually representing delta terms, which are random variables.

I cannot use divide because I don't know what to divide, the variables may
be anything. The other option is to recursively look each term of the
expression and then looking at its arguments of sum operator apply subst,
which is obviously a long method.

As I have very little experience with maxima, I strongly believe that
defrule can do the job. The only thing I am not able to get is that how do
I make a rule that will extract multiple terms after having d(i,j) in sum,
and those terms may also contain some function of d itself. See the
following which I tried and failed.

matchdeclare([i,j,k,l,q],all);
(%i15)   apply(defrule,[rd5,intosum('sum(d(i,j)*q,j,1,k)),1*q]);
k
====
\
(%o15)                            rd5 :  >    d(i, j) q -> q
/
====
j = 1
(%i16) apply(apply1,[eq2,rd5]);

(%o16)                                  g(i2) f(i2, i3)

It works till here but as soon as I have product having another d; it
doesn’t work. May be I am not using the right way.

(%i17) eq2:'sum(d(i1,i2)*g(i2)*f(i2,i3)*d(i2,i3),i2,1,n);
n
====
\
(%o17)                 >       d(i1, i2) g(i2) d(i2, i3) f(i2, i3)
/
====
i2 = 1

(%i18) apply(apply1,[eq2,rd5]);
n
====
\
(%o18)                 >       d(i1, i2) g(i2) d(i2, i3) f(i2, i3)
/
====
i2 = 1

I hope its much clear now. Please suggest any solution for the above
scenario or should I do the longer method of recursion.

Regards
Dileep

> hello dileep,
>
>> I am trying to extract any product which is found after first d(i,j) in
>>  the following sum.
>>
>> sum(d(i1,i2)*g(i2)*f(i2,i3)*d(i2,i3),i2,1,n)
>
> my advice at this point is to back up and try something other than
> defrule.
>
> it appears that you don't need to handle this problem in any generality.
> if so how about something like this?
>
> summand (e) := if atom(e) then e else if op(e) = verbify(sum) or op(e) =
> nounify(sum) then summand (first (args (e))) else e; expr:
> sum(d(i1,i2)*g(i2)*f(i2,i3)*d(i2,i3),i2,1,n); summand (expr) / d (i1, i2);
> => g(i2) d(i2, i3) f(i2, i3)
>
>
> i.e. grab the summand and divide out the d(i1,i2).
>
> or maybe you are working with products of matrices and vectors or
> something. in that case maybe you can forget the summations and work
> directly with multiplication of symbols. stuff like A' . A = I is a lot
> more compact than an equivalent statement in terms of summation.
>
> finally two more bits of unsolicited advice. about maxima in particular,
> display2d : false; before generating stuff to paste into an email helps. in
> general, other people might be able to help more if you give them some
> clue about what you're trying to accomplish.
>
> hope this helps & sorry i can't be more helpful,
>
> robert dodier
>
>

```