print(`Welcome to the q-Bi/Trinomial Recurrence Proof assistance package.`); print(`Version of April 9, 2003`); print(`[annop, annopf, annop0, annopf0, applyshiftop, asoe, asoo, e0, eG0, eG1, eT0, eT02, eT02s, eT1, eTrb0, eTrb00, eTrb1, eTrb28, eTrb29, eU0, eU1, eV, expandall, gpsym, listqcoeffs, maxrepeat, mostfreqqcoeff, neg, printqmatch, printqmatchall, printsameq, printU, printT1, sameqcoeff, shiftup, shiftdown, splitU, splitV, sym]`); print(`Remember that the default value of the global variable 'altsign' is false.`); print(`---------------------------------------------------------------------`); print(`Automatically loading RRtools package...`); read(RRtools1); print(`Done loading RRtools package.`); altsign:=false: annop:= proc(a,nd,dd,m,b,c); annops(a,nd,dd,m,b,c)[1] end: annopf:=proc(a,nd,dd,m,b,c); annops(a,nd,dd,m,b,c)[2] end: annop0:=proc(a,nd,dd,m,b,c); annops0(a,nd,dd,m,b,c)[1] end: annopf0:=proc(a,nd,dd,m,b,c); annops0(a,nd,dd,m,b,c)[2] end: applyshiftop := proc(oper, summand) local antideg, B, C, deg, i,j, new, tmp; B:=0; deg := degree(oper,N); #antideg := degree(subs(N=1/N,oper),N); antideg := ldegree(oper,N); for i from antideg to deg do B:= B + coeff(oper,N,i) * subs(n=n+i,summand) od; B:= expand(B); B:= combine(B,power); B end: asoe := proc(oper, evensummand, oddsummand ) local antideg, B, deg, i,j, new, tmp; B:=0; deg := degree(oper,N); #antideg := degree(subs(N=1/N,oper),N); antideg:= ldegree(oper,N); #m:= antideg mod 2; # build up the even parts: for i from 2*ceil(antideg/2) to deg by 2 do B:= B + subs(n=2*m, coeff(oper,N,i)) * subs(n=m+i/2,evensummand) od; # build up the odd parts: for i from 1+2*floor(antideg/2) to deg by 2 do B := B + subs(n=2*m,coeff(oper,N,i)) * subs(n=m+ (i-1)/2,oddsummand) od; B:= expand(B); B:= combine(B,power); B end: asoo := proc(oper, evensummand, oddsummand ) local antideg, B, deg, i,j, new, tmp; B:=0; deg := degree(oper,N); antideg:=ldegree(oper,N); # build up the odd parts: for i from 2*ceil(antideg/2) to deg by 2 do B:= B + subs(n=2*m + 1, coeff(oper,N,i)) * subs(n=m+i/2,oddsummand) od; # build up the even parts: for i from 1+floor(antideg/2) to deg by 2 do B := B + subs(n=2*m + 1,coeff(oper,N,i)) * subs(n=m+ (i+1)/2,evensummand) od; B:= expand(B); B:= combine(B,power); B end: EG0 :=proc(s,c,n,m,p) s *q^c * gp(n-1,m,p) + s* q^(c + p*(n-m))*gp(n-1,m-1,p) end: EG1:= proc(s,c,n,m,p) s*q^c * gp(n-1,m-1,p) + s*q^(c + p*m)*gp(n-1,m,p) end: ET1 := proc(s,c,m,A,pwr) s*q^(c)*T1(m-1,A,pwr) + s*q^(c+pwr*(m+A))*T0(m-1,A+1,pwr) + s*q^(c+pwr*(m-A))*T0(m-1,A-1,pwr) end: ET0 := proc(s,c,m,A,pwr) s*q^(c)*T0(m-1,A-1,pwr) + s*q^(c+pwr*(m+A))*T1(m-1,A,pwr) + s*q^(c+pwr*(2*m+2*A))*T0(m-1,A+1,pwr) end: ET02 := proc(s,c,m,A,pwr) s*q^(c)*T0(m-2,A,pwr) + s*q^(c+pwr*(m-A))*T1(m-2,A-1,pwr) + s*q^(c+pwr*(2*m-2*A))*T0(m-2,A-2,pwr) + s*q^(c+pwr*(m+A))*T1(m-1,A,pwr) + s*q^(c+pwr*(2*m+2*A))*T0(m-1,A+1,pwr) end: ET02s := proc(s,c,m,A,pwr) s*q^(c)*T0(m-2,A,pwr) + s*q^(c+pwr*(m+A))*T1(m-2,A+1,pwr) + s*q^(c+pwr*(2*m+2*A))*T0(m-2,A+2,pwr) + s*q^(c+pwr*(m-A))*T1(m-1,A,pwr) + s*q^(c+pwr*(2*m-2*A))*T0(m-1,A-1,pwr) end: E0 := proc(s,c,m,A,pwr) s*q^(c+pwr*(m-A))*T0(m,A,pwr) + s*q^(c)*T1(m,A+1,pwr) - s*q^(c+pwr*(m+A+1))*T0(m,A+1,pwr); end: EU0 := proc(s,c,m,A,pwr) s*q^c * U(m-1,A,pwr) + s*q^(c + pwr)* U(m-1,A,pwr) + s*q^(c+pwr*(2*m-1)) * U(m-1,A,pwr) - s*q^(c + pwr) * U(m-2,A,pwr) +s* q^(c + pwr*(2*m-2*A))* T0(m-2,A-2,pwr) + s*q^(c + pwr*(2*m + 2*A + 2)) * T0(m-2,A+3,1) end: EU1 := proc(s,c,m,A,pwr) s*q^c * U(m-1,A,pwr) + s* q^(c+pwr*(2*m-1)) * U(m-1,A,pwr) + s*q^(c + pwr*(m-A)) * T1(m-1,A-1,pwr) + s*q^(c + pwr*(m+A+1)) * T1(m-1, A+2, pwr) end: EV:= proc(s,c,m,A,pwr) s*q^c * V(m-1,A,pwr) + s* q^(c+pwr*(2*m-2)) * V(m-1,A,pwr) + s*q^(c + pwr*(m-A)) * T0(m-2,A-2,pwr) + s*q^(c + pwr*(m+A-1)) * T0(m-2, A+1, pwr) end: ETrb1:= proc(s,c,m,A,pwr) s*q^(c+pwr*(m-1)) *Trb(m-1,A-1,A,pwr) + s*q^(c+pwr*A)*Trb(m-1,A+1,A+1,pwr) +s*q^c *Trb(m-1,A-1,A-1,pwr) end: ETrb0:= proc(s,c,m,A,pwr) s*q^(c+pwr*(m-A)) * Trb(m-1,A-1,A-1,pwr) + s*q^(c+pwr*(m-A-1))*Trb(m-1,A-1,A,pwr) +s* q^c * Trb(m-1,A+1,A+1,pwr) end: ETrb00:= proc(s,c,m,B,A,pwr) s*q^c*Trb(m,A+1,A+1,pwr) -s*q^(c+pwr*m)*Trb(m,A,A+1,pwr) + s*q^(c+pwr*(m-A))*Trb(m,A-1,A,pwr) end: ETrb28:= proc(s,c,m,B,A,pwr) s*q^c*Trb(m-1,B,A,pwr) + s*q^(c+pwr*(m-A-1+B))*Trb(m-1,B,A+1,pwr) +s*q^(c+pwr*(m-A)) * Trb(m-1,B-1,A-1,pwr) end: ETrb29:= proc(s,c,m,B,A,pwr) s*q^c*Trb(m-1,B,A,pwr) + s*q^(c+pwr*(m-A))*Trb(m-1,B-2,A-1,pwr) +s*q^(c+pwr*(m+B))*Trb(m-1,B+1,A+1,pwr) end: eG0 :=proc(t,P) local A,B,c,i,m,pwr,sign,switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> gp then ERROR(`term indicated does not contain gp.`) fi; B:=0; for i from 1 to t-1 do B:= B + op(i,P) od; c:= expand(ln(op(-2+switch,op(t,P)))/ln(q)); m:= op(1,op(-1-switch,op(t,P))); A:= op(2,op(-1-switch,op(t,P))); pwr:=op(3,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + EG0(sign,c,m,A,pwr); for i from t+1 to nops(P) do B:= B + op(i,P) od; B end: eG1 :=proc(t,P) local A,B,c,i,m,pwr,sign,switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> gp then ERROR(`term indicated does not contain gp.`) fi; B:=0; for i from 1 to t-1 do B:= B + op(i,P) od; c:= expand(ln(op(-2+switch,op(t,P)))/ln(q)); m:= op(1,op(-1-switch,op(t,P))); A:= op(2,op(-1-switch,op(t,P))); pwr:=op(3,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + EG1(sign,c,m,A,pwr); for i from t+1 to nops(P) do B:= B + op(i,P) od; B end: eT1 :=proc(t,P) local A,B,c,i,m,pwr,sign,switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> T1 then ERROR(`term indicated does not contain T1.`) fi; B:=0; for i from 1 to t-1 do B:= B + op(i,P) od; c:= expand(ln(op(-2+switch,op(t,P)))/ln(q)); m:= op(1,op(-1-switch,op(t,P))); A:= op(2,op(-1-switch,op(t,P))); pwr:=op(3,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + ET1(sign,c,m,A,pwr); for i from t+1 to nops(P) do B:= B + op(i,P) od; B end: eT0 := proc(t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0, op(-1-switch, op(t, P))) <> T0 then ERROR(`Term indicated does not contain T0`) fi; B := 0; for i to t - 1 do B := B + op(i, P) od; c := expand(ln(op(-2+switch, op(t, P)))/ln(q)); m := op(1, op(-1-switch, op(t, P))); A := op(2, op(-1-switch, op(t, P))); pwr := op(3, op(-1-switch, op(t, P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + ET0(sign, c, m, A, pwr); for i from t + 1 to nops(P) do B := B + op(i, P) od; B end: eT02 := proc(t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0, op(-1-switch, op(t, P))) <> T0 then ERROR(`Term indicated does not contain T0`) fi; B := 0; for i to t - 1 do B := B + op(i, P) od; c := expand(ln(op(-2+switch, op(t, P)))/ln(q)); m := op(1, op(-1-switch, op(t, P))); A := op(2, op(-1-switch, op(t, P))); pwr := op(3, op(-1-switch, op(t, P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + ET02(sign, c, m, A, pwr); for i from t + 1 to nops(P) do B := B + op(i, P) od; B end: eT02s := proc(t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0, op(-1-switch, op(t, P))) <> T0 then ERROR(`Term indicated does not contain T0`) fi; B := 0; for i to t - 1 do B := B + op(i, P) od; c := expand(ln(op(-2+switch, op(t, P)))/ln(q)); m := op(1, op(-1-switch, op(t, P))); A := op(2, op(-1-switch, op(t, P))); pwr := op(3, op(-1-switch, op(t, P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + ET02s(sign, c, m, A, pwr); for i from t + 1 to nops(P) do B := B + op(i, P) od; B end: eU0 := proc(t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0, op(-1-switch, op(t, P))) <> U then ERROR(`Term indicated does not contain U`) fi; B := 0; for i to t - 1 do B := B + op(i, P) od; c := expand(ln(op(-2+switch, op(t, P)))/ln(q)); m := op(1, op(-1-switch, op(t, P))); A := op(2, op(-1-switch, op(t, P))); pwr := op(3, op(-1-switch, op(t, P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + EU0(sign, c, m, A, pwr); for i from t + 1 to nops(P) do B := B + op(i, P) od; B end: eU1 := proc(t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0, op(-1-switch, op(t, P))) <> U then ERROR(`Term indicated does not contain U`) fi; B := 0; for i to t - 1 do B := B + op(i, P) od; c := expand(ln(op(-2+switch, op(t, P)))/ln(q)); m := op(1, op(-1-switch, op(t, P))); A := op(2, op(-1-switch, op(t, P))); pwr := op(3, op(-1-switch, op(t, P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + EU1(sign, c, m, A, pwr); for i from t + 1 to nops(P) do B := B + op(i, P) od; B end: eV := proc(t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0, op(-1-switch, op(t, P))) <> V then ERROR(`Term indicated does not contain V`) fi; B := 0; for i to t - 1 do B := B + op(i, P) od; c := expand(ln(op(-2+switch, op(t, P)))/ln(q)); m := op(1, op(-1-switch, op(t, P))); A := op(2, op(-1-switch, op(t, P))); pwr := op(3, op(-1-switch, op(t, P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B + EV(sign, c, m, A, pwr); for i from t + 1 to nops(P) do B := B + op(i, P) od; B end: e0 := proc (t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> T1 then ERROR(`Term indicated does not contain T1`) fi; B := 0; for i to t-1 do B := B+op(i,P) od; c := expand(ln(op(-2+switch,op(t,P)))/ln(q)); m := op(1,op(-1-switch,op(t,P))); A := op(2,op(-1-switch,op(t,P))); pwr := op(3,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B+E0(sign,c,m,A,pwr); for i from t+1 to nops(P) do B := B+op(i,P) od; B end: eTrb1 := proc (t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> Trb then ERROR(`Term indicated does not contain Trb`) fi; if op(3,op(-1-switch,op(t,P))) - op(2,op(-1-switch,op(t,P))) <> 1 then ERROR(`Term indicated is not a t1`) fi; B := 0; for i to t-1 do B := B+op(i,P) od; c := expand(ln(op(-2+switch,op(t,P)))/ln(q)); m := op(1,op(-1-switch,op(t,P))); A := op(3,op(-1-switch,op(t,P))); pwr := op(4,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B+ETrb1(sign,c,m,A,pwr); for i from t+1 to nops(P) do B := B+op(i,P) od; B end: eTrb0 := proc (t, P) local A, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> Trb then ERROR(`Term indicated does not contain Trb`) fi; if op(3,op(-1-switch,op(t,P))) <> op(2,op(-1-switch,op(t,P))) then ERROR(`Term indicated is not a tau0`) fi; B := 0; for i to t-1 do B := B+op(i,P) od; c := expand(ln(op(-2+switch,op(t,P)))/ln(q)); m := op(1,op(-1-switch,op(t,P))); A := op(3,op(-1-switch,op(t,P))); pwr := op(4,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B+ETrb0(sign,c,m,A,pwr); for i from t+1 to nops(P) do B := B+op(i,P) od; B end: eTrb00 := proc (t, P) local A,A1,B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> Trb then ERROR(`Term indicated does not contain Trb`) fi; if op(3,op(-1-switch,op(t,P))) <> op(3,op(-1-switch,op(t,P))) then ERROR(`Term indicated is not a tau0`) fi; B := 0; for i to t-1 do B := B+op(i,P) od; c := expand(ln(op(-2+switch,op(t,P)))/ln(q)); m := op(1,op(-1-switch,op(t,P))); A := op(2,op(-1-switch,op(t,P))); A1:= op(3,op(-1-switch,op(t,P))); pwr := op(4,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B+ETrb00(sign,c,m,A,A1,pwr); for i from t+1 to nops(P) do B := B+op(i,P) od; B end: eTrb28 := proc (t, P) local A, A2, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> Trb then ERROR(`Term indicated does not contain Trb`) fi; B := 0; for i to t-1 do B := B+op(i,P) od; c := expand(ln(op(-2+switch,op(t,P)))/ln(q)); m := op(1,op(-1-switch,op(t,P))); A := op(2,op(-1-switch,op(t,P))); A2:= op(3,op(-1-switch,op(t,P))); pwr := op(4,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B+ETrb28(sign,c,m,A,A2,pwr); for i from t+1 to nops(P) do B := B+op(i,P) od; B end: eTrb29 := proc (t, P) local A, A2, B, c, i, m, pwr, sign, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> Trb then ERROR(`Term indicated does not contain Trb`) fi; B := 0; for i to t-1 do B := B+op(i,P) od; c := expand(ln(op(-2+switch,op(t,P)))/ln(q)); m := op(1,op(-1-switch,op(t,P))); A := op(2,op(-1-switch,op(t,P))); A2:= op(3,op(-1-switch,op(t,P))); pwr := op(4,op(-1-switch,op(t,P))); if type(op(1,op(t,P)),integer) then sign := op(1,op(t,P)) else sign := 1 fi; B := B+ETrb29(sign,c,m,A,A2,pwr); for i from t+1 to nops(P) do B := B+op(i,P) od; B end: splitU := proc (t, P) local B, i, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> U then ERROR(`Term indicated does not contain U.`) fi; B := 0; for i to t-1 do B := B+op(i,P) od; B := B + IsplitoneU(op(t,P)); for i from t+1 to nops(P) do B := B+op(i,P) od; B end: splitV := proc (t, P) local B, i, switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> V then ERROR(`Term indicated does not contain V.`) fi; B := 0; for i to t-1 do B := B+op(i,P) od; B := B + IsplitoneV(op(t,P)); for i from t+1 to nops(P) do B := B+op(i,P) od; B end: sym := proc(t,P) local B,first,i,new,switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> T0 and op(0,op(-1-switch,op(t,P))) <> T1 then ERROR(`Term indicated does not contain T0 or T1.`) fi; B:=0; for i from 1 to t-1 do B:= B+op(i,P) od; first := op(t,P)/op(-1-switch,op(t,P)); #separates off the coefficient of the T0 or T1. new := op(0,op(-1-switch,op(t,P))) (op(1,op(-1-switch,op(t,P))), -1*op(2,op(-1-switch,op(t,P))), op(3,op(-1-switch,op(t,P)))); # negates the middle parameter of the T0 or T1. B := B + first * new; for i from t+1 to nops(P) do B:= B + op(i,P) od; B end: gpsym := proc(t,P) local B,first,i,new,switch; if depends(op(-1,op(t,P)),q) then switch:= 1 else switch :=0 fi; if op(0,op(-1-switch,op(t,P))) <> gp then ERROR(`Term indicated does not contain gp.`) fi; B:=0; for i from 1 to t-1 do B:= B+op(i,P) od; first := op(t,P)/op(-1-switch,op(t,P)); #separates off the coefficient of the T0 or T1. new := op(0,op(-1-switch,op(t,P))) (op(1,op(-1-switch,op(t,P))), op(1,op(-1-switch,op(t,P))) - op(2,op(-1-switch,op(t,P))), op(3,op(-1-switch,op(t,P)))); # changes gp(A,B) to gp(A,A-B). B := B + first * new; for i from t+1 to nops(P) do B:= B + op(i,P) od; B end: shiftup:= proc(t,P) global altsign; local B, i, sign; B:=0; for i from 1 to t-1 do B:= B + op(i,P) od; if altsign = true then sign := -1 else sign :=1 fi; B := B + expandexponent(sign*subs(j=j+1,op(t,P))); for i from t+1 to nops(P) do B:= B + op(i,P) od; B end: shiftdown:= proc(t,P) global altsign; local B, i, sign; B:=0; for i from 1 to t-1 do B:= B + op(i,P) od; if altsign = true then sign := -1 else sign :=1 fi; B := B + expandexponent(sign*subs(j=j-1,op(t,P))); for i from t+1 to nops(P) do B:= B + op(i,P) od; B end: IsplitoneU := proc(term) local last,qandsign,switch, Upart; if depends(op(-1,term),q) then switch:=1 else switch :=0 fi; qandsign := term/op(-1-switch,term); Upart := term/qandsign; if op(0,Upart) <> U then ERROR(`Term does not contain U.`) fi; qandsign * T0( op(1,Upart), op(2,Upart) , op(3,Upart)) +qandsign * T0( op(1,Upart), op(2,Upart)+1, op(3,Upart)) end: IsplitoneV := proc(term) local coeff, last,out,qandsign, qpart, switch, origexp, Upart; if depends(op(-1,term),q) then switch:=1 else switch :=0 fi; qandsign := term/op(-1-switch,term); Upart := term/qandsign; if op(0,Upart) <> V then ERROR(`Term does not contain V.`) fi; if not depends(op(1,qandsign),q) then qpart:= qandsign/op(1,qandsign) else qpart:=qandsign fi; coeff:= qandsign/qpart; origexp:= expand(ln(qpart)/ln(q)); out:= coeff*q^(origexp) * T1( op(1,Upart)-1, op(2,Upart) , op(3,Upart)) +coeff*q^(expand(origexp + op(3,Upart)*(op(1,Upart)-op(2,Upart)))) *T0( op(1,Upart)-1, op(2,Upart)-1, op(3,Upart)) end: expandexponent := proc(term) local last,qpart,switch,x; if depends(op(-1,term),q) then switch:= 1 else switch :=0 fi; last := term/op(-2+switch,term); qpart := term/last; x:= expand(log[q](qpart)); q^x * last end: expandall:=proc(P) local i,B; B:=0; for i from 1 to nops(P) do B:=B+expandexponent(op(i,P)) od; B end: neg := proc(t,P) local B,i,sign; B:=0; for i from 1 to t-1 do B:= B + op(i,P) od; B := B + subs(j=-j, op(i,P)); for i from t+1 to nops(P) do B:= B + op(i,P) od; B end: printT1:=proc(A) local i, shift; for i from 1 to nops(A) do if depends(op(-1,op(i,A)),q) then shift:=1 else shift:=0 fi; if op(0,op(-1-shift, op(i,A))) = T1 then print(`Term number`,i,`...`, op(i,A)) fi od end: printU:=proc(A) local i, shift; for i from 1 to nops(A) do if depends(op(-1,op(i,A)),q) then shift:=1 else shift:=0 fi; if op(0,op(-1-shift, op(i,A))) = U then print(`Term number`,i,`...`, op(i,A)) fi od end: listqcoeffs:= proc(A) local B,i,shift,tmp; # Input: a typical q-binomal or q-trinomial expression # Output: a list containing the q-coefficients in the same order B:=[]; for i from 1 to nops(A) do if depends ( op(-1,op(i,A)),q) then shift:=0 else shift:=1 fi; B:= [op(B), op(-1-shift,op(i,A))] od; B end: sameqcoeff:=proc(pos,B) local C,i; # Input: list of q coeffs (B) and a position (pos) # Output: a list containing the operand number pos and all other operands which # have the same q coefficient as the one in operand pos. C:=[]; for i from 1 to pos-1 do if op(i,B) = op(pos,B) then C:= [op(C),i] fi od; C:=[op(C),pos]; for i from pos+1 to nops(B) do if op(i,B) = op(pos,B) then C:= [op(C),i] fi od; C end: mostfreqqcoeff:= proc(B) local F,i, M, MFC; # input: list of q coefficients # output: list containing the operand numbers of a most frequently # repeated coefficient. for i from 1 to nops(B) do F[i]:= sameqcoeff(i,B) od; # Let M be the maximum length of an F[i]: M:= max( seq(nops(F[i]), i=1..nops(B))); MFC:=[]; i:=0; while nops(MFC)