rule for nn^3*K3(xx,yy) --> K3(nn*xx, nn*yy)?



On Fri, 26 Nov 2010 12:39:53 -0700
Robert Dodier <robert.dodier at gmail.com> wrote:

>On 11/23/10, Rhys Pratt <listofx at gmail.com> wrote:
>
>> K3 is a homogeneous polynomial of order 3.
>> I want to pull the factor a/n out of its parameters to
>> make K3() evaluated near (1,1) (assumed that n->infinity)
>>
>> (%i3) matchdeclare([xx,yy], true, cc, true);
>> (%o3) done
>>
>> (%i14) defrule(r1, cc^3*K3(xx,yy), K3(cc*xx, cc*yy));
>> (%o14) r1:cc^3*K3(xx,yy)->K3(cc*xx,cc*yy)
>>
>> (%i15) r1((n/a)^3*K3((b*log(n))/n^2+a/n,(b*log(n-1))/(n-1)^2+a/(n-1)));
>> (%o15) false
>
>It turns out Maxima doesn't keep (n/a)^3 together as one term
>(instead it simplifies to n^3 * a^(-3)). How about this.
>
>matchdeclare ([aa, bb, cc, dd], all);
>defrule (r1, aa * bb^3 * K3(cc, dd), aa * K3(bb*cc, bb*dd));
>defrule (r2, aa * (1/bb^3) * K3(cc, dd), aa * K3(cc/bb, dd/bb));
>
>e : (n/a)^3*K3((b*log(n))/n^2+a/n,(b*log(n-1))/(n-1)^2+a/(n-1));
>apply1 (e, r1, r2);
> => K3(n*(b*log(n)/n^2+a/n)/a,n*(b*log(n-1)/(n-1)^2+a/(n-1))/a)
>expand (%);
> => K3(b*log(n)/(a*n)+1,b*n*log(n-1)/(a*n^2-2*a*n+a)+n/(n-1))
>
>Hope this helps, but I wouldn't be too surprised if it fails
>to match some expression which nominally has the form
>required by r1 or r2.
>

Certainly it helps! :-) 

Why does not the pattern variable aa match the whole expression, i.e.
the whole (n/a)^3*K3((b*log(n))/n^2+a/n,(b*log(n-1))/(n-1)^2+a/(n-1)). I
have learned from "? matchdeclare" that the matching algorithm is
greedy. (I am not native to English, so, sometimes, I really feel
English language is disturbing. :-))

>     Such multiple-term matching is greedy: predicates are evaluated in
>     the order in which their associated variables appear in the match
>     pattern, and a term which satisfies more than one predicate is
>     taken by the first predicate which it satisfies.  Each predicate
>     is tested against all operands of the sum or product before the
>     next predicate is evaluated.  In addition, if 0 or 1