Odd behaviour with Keep_Weight

Greetings,

I'm trying to use keep_weight to extract the leading quadratic terms in a simple cubic. In the following example I use two methods that I was expecting to give the same results. The first method gives the correct result while the second only returns the linear term. Here is the code.

{a,b,c,d,e,f,g,h,i,j}::Indices.

eps::LaTeXForm("{\epsilon}").

eps::Weight(label=num).
x^{a}::Weight(label=num).

abc := x^{a} + A_{b} x^{a} x^{b} + A_{b c} x^{a} x^{b} x^{c};

tmp0 := @(abc).
tmp1 := @(abc).
tmp2 := @(abc).
tmp3 := @(abc).

keep_weight (tmp0, $num=0$)
keep_weight (tmp1, $num=1$)
keep_weight (tmp2, $num=2$)
keep_weight (tmp3, $num=3$)

abc := @(tmp0) + @(tmp1) + @(tmp2);

pqr := x^{a} + A_{b} x^{a} x^{b} + A_{b c} x^{a} x^{b} x^{c};

substitute (pqr, $x^{a} -> eps x^{a}$)
collect_factors (pqr)

tmp0 := @(pqr).
tmp1 := @(pqr).
tmp2 := @(pqr).
tmp3 := @(pqr).

keep_weight (tmp0, $num=0$)
keep_weight (tmp1, $num=1$)
keep_weight (tmp2, $num=2$)
keep_weight (tmp3, $num=3$)

pqr := @(tmp0) + @(tmp1) + @(tmp2);

The even stranger thing is if I replace x^{#} with x1^{#} (as in the following code) then the results are swapped -- the first method is wrong (it returns the original cubic) while the second method is correct. I'm confused :).

{a,b,c,d,e,f,g,h,i,j}::Indices.

eps::LaTeXForm("{\epsilon}").

eps::Weight(label=num).
x1^{a}::Weight(label=num).

abc := x1^{a} + A_{b} x1^{a} x1^{b} + A_{b c} x1^{a} x1^{b} x1^{c};

tmp0 := @(abc).
tmp1 := @(abc).
tmp2 := @(abc).
tmp3 := @(abc).

keep_weight (tmp0, $num=0$)
keep_weight (tmp1, $num=1$)
keep_weight (tmp2, $num=2$)
keep_weight (tmp3, $num=3$)

abc := @(tmp0) + @(tmp1) + @(tmp2);

pqr := x1^{a} + A_{b} x1^{a} x1^{b} + A_{b c} x1^{a} x1^{b} x1^{c};

substitute (pqr, $x1^{a} -> eps x1^{a}$)
collect_factors (pqr)

tmp0 := @(pqr).
tmp1 := @(pqr).
tmp2 := @(pqr).
tmp3 := @(pqr).

keep_weight (tmp0, $num=0$)
keep_weight (tmp1, $num=1$)
keep_weight (tmp2, $num=2$)
keep_weight (tmp3, $num=3$)

pqr := @(tmp0) + @(tmp1) + @(tmp2);

Any suggestions?

Cheers,
Leo

The reason for the weird behaviour with x1^{a} has to do with 'autodeclare' objects. At some point in the distant past, I decided to borrow this idea from FORM. So you can do

{a,b,c#}::Indices;
ex:= A_{a b} A^{a b};
ex2:= @(ex) @(ex);

to get

A_{a b} A^{a b} A_{c1 c2} A^{c1 c2}

This is all fine and useful (sometimes you want to be sure that there are always enough dummies available). You have to be careful though (and I wasn't) when matching properties. I had some fast lookup of properties which essentially only looked at the non-numerical bit of the name, so that I could quickly match 'c7' with the property attached to 'c#'. However, I failed to do that correctly, and hence your property for 'x1^{a}' failed to match against an actual pattern 'x1^{a}'. For reasons I won't go into (related to property inheritance), this would only fail for Weight, but not for many other properties, hence it slipped the testing net.

Pull the latest from github and things will work as they should. Thanks for reporting this.

selected

Many thanks for the quick fix and the detailed explanation. It all works as expected with the latest version from GitHub. Thanks.

In your first code sample, the pqr computation is correct too because your eps is still of weight 1. The terms proportional to $A_{b}$ and $A_{b c}$ are therefore of order 4 and 6 respectively.