Subject: Help matching variables and their indices
From: Richard Fateman
Date: Mon, 25 Feb 2013 19:07:02 -0800
You are trying to match products. You got a warning but you ignored it,
perhaps because it
is not sufficiently detailed.
While it may be overkill, perhaps it will help in the future. I suggest
you read..
http://www.cs.berkeley.edu/~fateman/papers/partition.pdf
entitled
Partitioning of Algebraic Subexpressions: in Computer Algebra
Systems: Or, Don't use matching so much.
On 2/25/2013 2:01 PM, Mike Valenzuela wrote:
> Okay, I figured something out.
>
> I got some simpler rules working, but I still have a problem (and I
> think I know why there is a problem, just not how to get around it)
> with the following:
>
> matchdeclare([xx,yy], symbolp)$
> matchdeclare([gg,hh,ii,jj], lambda([x], freeof(xx,x))$
>
> defrule(r3, msum(xx[ii])*msum(xx[jj]), "It matches an indexed variable
> with the index" = [xx,ii])$
> defrule(r4, msum(gg*xx[ii])*msum(xx[jj]), "R4 matches")$
>
> r3( msum( x[i]) * msum( x[j]) );
> r4( msum(2*x[i]) * msum( x[j]) );
>
> r3 matches, but r4 does not match. I suspect that gg is being greedy.
> However, I am unsure how to "nest" matches so that gg is free of xx.
>
>
>
> On Mon, Feb 25, 2013 at 2:49 PM, Mike Valenzuela
> <mickle.mouse at gmail.com <mailto:mickle.mouse at gmail.com>> wrote:
>
> Hello again,
>
> I'm sorry if the community is getting tired of many of my
> questions, but I think Maxima could use a tutorial on writing
> custom rules.
>
> I have tried something similar using the following:
> (%i6) matchdeclare([aa,bb,ii,jj],true)$
> (%i7) matchdeclare([xx,yy], symbolp)$
> (%i8) defrule(sum_power_collapse,
> msum(xx[ii],ii,aa,bb)*msum(xx[jj],jj,aa,bb), msum(xx[ii],ii,aa,bb)^2)$
> % defmatch: xx[aa] will be matched uniquely since sub-parts would
> otherwise be ambigious.
>
> (%i9) apply1( msum(x[i],i,b,c)*msum(x[j],j,b,c), sum_power_collapse);
> (%o9) msum(x[i],a,b,c)*msum(x[j],j,b,c)
>
> I had hoped the outcome would have been: msum(x[i],a,b,c)^2.
> However, you can see it is not working as I had hoped. I am not
> sure if I am overlooking something or a different approach is needed.
>
> Thanks in advance for any advice.
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima