questions about functions



Dear all,

I want to define a function to choose highest weight in a polynomial f, for
example, f=pq+q^2+q/p+q/p^2. The first step is define
monomials:args(f)=[pq, q^2, ...]. Then I compare the weights of monomials
in [pq, q^2, ...].
The codes are in the following. I checked that the function
compare_weights() is correct. But I don't know what is wrong on the
function highest_weight(). I check it many times and cannot find the
problem. Thank you very much.

Best wishes,
Jianrong.





monomials: args(ratexpand(f);

Cartan:matrix ([2, -1], [-2, 2]);


compare_weights(vector1, vector2):=block([a:a],

a:invert(Cartan).(vector1-vector2),

if(a[1][1]>=0 and a[2][1]>=0) then 1
else -1

);

highest:matrix([hipow(monomials[1], p)], [hipow(monomials[1], q)]);

highest_weight(monomials):=block([i, highest],

highest:matrix([hipow(monmials[1], p)], [hipow(monomials[1], q)]);

for i:2 thru length(list) step 1 do
   (
    if(compare_weights(matrix([hipow(monomials[i],p)], [hipow(monmials[i],
q)]), highest)=1) then
                    highest:matrix([hipow(monomials[i],p)],
[hipow(monomials[i], q)])
   ),


highest

);

highest_weight(monomials);