What is wrong with this rule?



Hi,
I set sumexpand already but doesnt work even then. The rule to be applied
is not known untill the user enters the expression; so need to use the
variable for rulename and thus have to use "apply".

Right now I am using apply in the following fashion, where rulelist is the
list of rules to be applied. Even if I apply single rule at a time I will
have use varaible for rulename.

apply (apply1, cons (eq1, rulelist))

If you know any alternative for above, please share.

The bizzare thing is that it works for product of 1 and 2 terms but not
more than that:

(%i1) sumexpand:true;
(%o1) 				     true
(%i2) matchdeclare([I,L,J,K,e],all);
(%o2) 				     done
(%i3) defrule(r1,x(I,L)*x(J,K)*e,(r(L)*d(L, K)*d(I, J) + r(L)*r(L, 1)*d(L,
K)*(1 - d(I, J)) + r(L)*r(K)*(1 - d(I, J))*(1 - d(L, K)))*e);
(%o3) r1 : e x(I, L) x(J, K) -> e ((1 - d(I, J)) r(L) r(L, 1) d(L, K)
	        + d(I, J) r(L) d(L, K) + (1 - d(I, J)) r(K) r(L) (1 - d(L, K)))
(%i5) eq1:sum(x(i1, l)*f(i1), i1, 1, n)* sum(x(i2, m)*f(i2), i2, 1, n);

		   n	  n
		  ====	 ====
		  \	 \
(%o5) 		   >	  >     f(i1) x(i1, l) f(i2) x(i2, m)
		  /	 /
		  ====	 ====
		  i1 = 1 i2 = 1
(%i7) apply(apply1,[eq1,r1]);
       n	    n
      ====	   ====
      \		   \
(%o7)  >     f(i3)  >	  f(i4) ((1 - d(i4, i3)) r(m) r(m, 1) d(m, l)
      /		   /
      ====	   ====
      i3 = 1	   i4 = 1
	  + d(i4, i3) r(m) d(m, l) + (1 - d(i4, i3)) r(l) r(m) (1 - d(m, l)))


But does not work for product of 3 terms:

(%i9) matchdeclare([I,J,K,L,M,N,e],all);
(%o9) 				     done
(%i10) defrule(r1,x(I,L)*x(J,K)*x(M,N)*e,(r(L)*d(L, K)*d(I, J) + r(M)*r(L,
1)*d(N, K)*(1 - d(I, J)) + r(L)*r(K)*(1 - d(I, J))*(1 - d(L, K)))*e);

(%o10) r1 : e x(I, L) x(J, K) x(M, N) ->
e ((1 - d(I, J)) r(L, 1) r(M) d(N, K) + d(I, J) r(L) d(L, K)
 + (1 - d(I, J)) r(K) r(L) (1 - d(L, K)))

(%i13) eq1:sum(x(i1, l)*f(i1), i1, 1, n)* sum(x(i2, l)*f(i2), i2, 1,
n)*sum(x(i3, l)*f(i3), i3, 1, n);

	n       n       n
       ====    ====    ====
       \       \       \
(%o13)  >       >       >      f(i10) x(i10, l) f(i11) x(i11, l) f(i12)
       /       /       /
       ====    ====    ====
       i11 = 1 i12 = 1 i10 = 1
								   x(i12, l)
(%i14) apply(apply1,[eq1,r1]);
	n       n       n
       ====    ====    ====
       \       \       \
(%o14)  >       >       >      f(i18) x(i18, l) f(i19) x(i19, l) f(i20)
       /       /       /
       ====    ====    ====
       i19 = 1 i20 = 1 i18 = 1
								   x(i20, l)
(%i15) apply1(eq1,r1);
	n	       n	      n
       ====	      ====	     ====
       \	      \		     \
(%o15)  >      f(i11)  >      f(i12)  >	     f(i10)
       /	      /		     /
       ====	      ====	     ====
       i11 = 1	      i12 = 1	     i10 = 1
 (r(i10) (1 - d(i12, i11)) r(l, 1) d(l, l) + d(i12, i11) r(l) d(l, l)
		      2
 + (1 - d(i12, i11)) r (l) (1 - d(l, l)))

If you have any clue, please share.

Regards
Dileep

> dileep,
>
> try setting sumexpand : true;
>
> ? sumexpand
> should have a little information.
>
> hth robert
>
>