[BACK]Return to weight CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / lib

Diff for /OpenXM_contrib2/asir2000/lib/weight between version 1.3 and 1.6

version 1.3, 2003/11/05 08:26:57 version 1.6, 2003/11/15 06:28:21
Line 1 
Line 1 
 load("solve")$  load("solve")$
 load("gr")$  load("gr")$
   
 def nonposdegchk(Res){  def nonposdegchk(Res){
   
         for(I=0;I<length(Res);I++)          for(I=0;I<length(Res);I++)
                 if(Res[I][1]<=0)                  if(Res[I][1]<=0)
                         return 0$                          return 0$
   
         return 1$          return 1$
 }  }
   
 def resvars(Res,Vars){  
   def notzerovec(Vec){
         ResVars=newvect(length(Vars),Vars)$  
           for(I=0;I<size(Vec)[0];I++)
         for(I=0;I<length(Res);I++){                  if(Vec[I]!=0)
                                   return 1$
                 for(J=0;J<size(ResVars)[0];J++)  
                         if(Res[I][0]==ResVars[J])          return 0$
                                 break$  }
   
                 ResVars[J]=Res[I][1]$  def resvars(Res,Vars){
         }  
           ResVars=newvect(length(Vars),Vars)$
         return(ResVars)$          for(I=0;I<length(Res);I++){
 }  
                   for(J=0;J<size(ResVars)[0];J++)
 def makeret1(Res,Vars){                          if(Res[I][0]==ResVars[J])
                                   break$
         VarsNum=length(Vars)$  
                   if(J<size(ResVars)[0])
         ResVec=newvect(VarsNum,Vars)$                          ResVars[J]=Res[I][1]$
           }
         for(I=0,M=0;I<length(Res);I++){          return(ResVars)$
   }
                 for(J=0;J<VarsNum;J++)  
                         if(Res[I][0]==Vars[J])  def makeret1(Res,Vars){
                                 break$  
           VarsNum=length(Vars)$
                 if(J<VarsNum){  
                         ResVec[J]=Res[I][1]$          ResVec=newvect(VarsNum,Vars)$
   
                         if(type(ResVec[J])==1){          for(F=0,I=0,M=0;I<length(Res);I++){
                                 if(M==0)  
                                         M=ResVec[J]$                  for(J=0;J<VarsNum;J++)
                                 else                          if(Res[I][0]==Vars[J])
                                         if(ResVec[J]<M)                                  break$
                                                 M=ResVec[J]$  
                         }                  if(J<VarsNum){
                 }                          ResVec[J]=Res[I][1]$
   
         }                          if(F==0 && type(ResVec[J])==1){
                                   if(M==0)
         for(F=0,I=0;I<VarsNum;I++)                                          M=ResVec[J]$
                 if(type(ResVec[I])!=1){                                  else
                         F=1$                                          if(ResVec[J]<M)
                         break$                                                  M=ResVec[J]$
                 }                          }
                           else
         if(F==0)                                  F=1$
                 for(I=0;I<VarsNum;I++)                  }
                         ResVec[I]=ResVec[I]/M*1.0$  
           }
         for(I=0;I<VarsNum;I++)  
                 for(J=0;J<length(Vars);J++)          if(F==0)
                         ResVec[I]=subst(ResVec[I],Vars[J],                  for(I=0;I<VarsNum;I++)
                                 strtov(rtostr(Vars[J])+"_deg"))$                          ResVec[I]=ResVec[I]/M*1.0$
   
         ResVec=cons(F,vtol(ResVec))$          for(I=0;I<VarsNum;I++)
         return ResVec$                  for(J=0;J<length(Vars);J++)
 }                          ResVec[I]=subst(ResVec[I],Vars[J],
                                   strtov(rtostr(Vars[J])+"_deg"))$
 def junban1(A,B){  
         return (nmono(A)<nmono(B) ? -1:(nmono(A)>nmono(B) ? 1:0))$          ResVec=cons(F,vtol(ResVec))$
 }          return ResVec$
   }
 def junban2(A,B){  
   def junban(A,B){
         for(I=0;I<size(A)[0];I++){  
                 if(A[I]<B[I])          for(I=0;I<size(A)[0];I++){
                         return 1$                  if(A[I]<B[I])
                                           return 1$
                 if(A[I]>B[I])  
                         return -1$                  if(A[I]>B[I])
         }                          return -1$
           }
         return 0$  
 }          return 0$
   }
 def roundret(V){  
   def roundret(V){
         VN=length(V)$  
         RET0=newvect(VN,V)$          VN=length(V)$
           RET0=newvect(VN,V)$
         for(I=1;I<1000;I++){  
                 RET1=I*RET0$          for(I=1;I<1000;I++){
                 for(J=0;J<VN;J++){                  RET1=I*RET0$
                         X=drint(RET1[J])$                  for(J=0;J<VN;J++){
                         if(dabs(X-RET1[J])<0.2)                          X=drint(RET1[J])$
                                 RET1[J]=X$                          if(dabs(X-RET1[J])<0.2)
                         else                                  RET1[J]=X$
                                 break$                          else
                 }                                  break$
                 if(J==VN)                  }
                         break$                  if(J==VN)
         }                          break$
                   }
         if(I==1000)  
                 return []$          if(I==1000)
         else                  return []$
                 return RET1$          else
 }                  return RET1$
   }
 def chkou(L,ExpMat,CHAGORD){  
   def chkou(L,ExpMat,CHAGORD){
         P=1$  
         F=ExpMat[L]$          P=1$
           F=ExpMat[L]$
         for(I=0;I<L;I++){  
                 Q=ExpMat[L][CHAGORD[I]]$          for(I=0;I<L;I++){
                 for(J=0;J<size(ExpMat[0])[0];J++){                  Q=ExpMat[L][CHAGORD[I]]$
                         ExpMat[L][CHAGORD[J]]=red((ExpMat[I][CHAGORD[I]]                  for(J=0;J<size(ExpMat[0])[0];J++){
                                 *ExpMat[L][CHAGORD[J]]-                          ExpMat[L][CHAGORD[J]]=red((ExpMat[I][CHAGORD[I]]
                                         Q*ExpMat[I][CHAGORD[J]])/P)$                                  *ExpMat[L][CHAGORD[J]]-
                 }                                          Q*ExpMat[I][CHAGORD[J]])/P)$
                   }
                 P=ExpMat[I][CHAGORD[I]]$  
         }                  P=ExpMat[I][CHAGORD[I]]$
           }
         for(J=0;J<size(ExpMat[0])[0];J++)  
                 if(ExpMat[L][CHAGORD[J]]!=0)          for(J=0;J<size(ExpMat[0])[0];J++)
                         break$                  if(ExpMat[L][CHAGORD[J]]!=0)
                           break$
         if(J==size(ExpMat[0])[0])  
                 return L$          if(J==size(ExpMat[0])[0])
         else{                  return L$
                 TMP=CHAGORD[L]$          else{
                 CHAGORD[L]=CHAGORD[J]$                  TMP=CHAGORD[L]$
                 CHAGORD[J]=TMP$                  CHAGORD[L]=CHAGORD[J]$
                 return (L+1)$                  CHAGORD[J]=TMP$
         }                  return (L+1)$
 }          }
   }
 def qcheck0(PolyList,Vars){  
   def qcheck0(PolyList,Vars){
         RET=[]$  
         PolyListNum=length(PolyList)$          RET=[]$
         VarsNum=length(Vars)$          PolyListNum=length(PolyList)$
           VarsNum=length(Vars)$
         ExpMat=newvect(VarsNum)$  
         CHAGORD=newvect(VarsNum)$          ExpMat=newvect(VarsNum)$
         for(I=0;I<VarsNum;I++)          CHAGORD=newvect(VarsNum)$
                 CHAGORD[I]=I$          for(I=0;I<VarsNum;I++)
                   CHAGORD[I]=I$
         L=0$  
         for(I=0;I<PolyListNum;I++){          L=0$
                 Poly=dp_ptod(PolyList[I],Vars)$          for(I=0;I<PolyListNum;I++){
                 BASE0=dp_etov(dp_ht(Poly))$                  Poly=dp_ptod(PolyList[I],Vars)$
                 Poly=dp_rest(Poly)$                  BASE0=dp_etov(dp_ht(Poly))$
                 for(;Poly!=0;Poly=dp_rest(Poly)){                  Poly=dp_rest(Poly)$
                         ExpMat[L]=dp_etov(dp_ht(Poly))-BASE0$                  for(;Poly!=0;Poly=dp_rest(Poly)){
                         L=chkou(L,ExpMat,CHAGORD)$                          ExpMat[L]=dp_etov(dp_ht(Poly))-BASE0$
                         if(L==VarsNum-1){                          L=chkou(L,ExpMat,CHAGORD)$
                                 RET=cons(ExpMat,RET)$                          if(L==VarsNum-1){
                                 RET=cons(CHAGORD,RET)$                                  RET=cons(ExpMat,RET)$
                                 RET=cons(L,RET)$                                  RET=cons(CHAGORD,RET)$
                                 return RET$                                  RET=cons(L,RET)$
                         }                                  return RET$
                 }                                }
         }                  }
                   }
         RET=cons(ExpMat,RET)$  
         RET=cons(CHAGORD,RET)$          RET=cons(ExpMat,RET)$
         RET=cons(L,RET)$          RET=cons(CHAGORD,RET)$
         return RET$          RET=cons(L,RET)$
 }          return RET$
   }
 def inner(A,B){  
   def inner(A,B){
         SUM=0$  
         for(I=0;I<size(A)[0];I++)          SUM=0$
                 SUM+=A[I]*B[I]$          for(I=0;I<size(A)[0];I++)
                   SUM+=A[I]*B[I]$
         return SUM$  
 }          return SUM$
   }
 def checktd(PolyList,Vars,ResVars){  
   def checktd(PolyList,Vars,ResVars){
         PolyListNum=length(PolyList)$  
         VarsNum=length(Vars)$          PolyListNum=length(PolyList)$
           VarsNum=length(Vars)$
         L=0$  
         for(I=0;I<PolyListNum;I++){          L=0$
                 Poly=dp_ptod(PolyList[I],Vars)$          for(I=0;I<PolyListNum;I++){
                 J0=inner(dp_etov(dp_ht(Poly)),ResVars)$                  Poly=dp_ptod(PolyList[I],Vars)$
                 Poly=dp_rest(Poly)$                  J0=inner(dp_etov(dp_ht(Poly)),ResVars)$
                 for(;Poly!=0;Poly=dp_rest(Poly))                  Poly=dp_rest(Poly)$
                         if(J0!=inner(dp_etov(dp_ht(Poly)),ResVars))                  for(;Poly!=0;Poly=dp_rest(Poly))
                                 return 0$                          if(J0!=inner(dp_etov(dp_ht(Poly)),ResVars))
         }                                  return 0$
                   }
         return 1$  
 }          return 1$
   }
 def getgcd(A,B){  
   def getgcd(A,B){
         VarsNumA=length(A)$  
         VarsNumB=length(B)$          VarsNumA=length(A)$
           VarsNumB=length(B)$
         C=newvect(VarsNumB,B)$  
           C=newvect(VarsNumB,B)$
         for(I=0;I<VarsNumA;I++){  
           for(I=0;I<VarsNumA;I++){
                 for(J=0;J<VarsNumB;J++)  
                         if(C[J]==A[I][0])                  for(J=0;J<VarsNumB;J++)
                                 break$                          if(C[J]==A[I][0])
                                   break$
                 C[J]=A[I][1]$  
         }                  C[J]=A[I][1]$
           }
         D=0$  
         for(I=0;I<VarsNumB;I++)          D=0$
                 D=gcd(D,C[I])$          for(I=0;I<VarsNumB;I++)
                   D=gcd(D,C[I])$
         if(D!=0){  
           if(D!=0){
                 for(I=0;I<VarsNumB;I++)  
                         C[I]=red(C[I]/D)$                  for(I=0;I<VarsNumB;I++)
                           C[I]=red(C[I]/D)$
         }  
           }
         for(L=1,D=0,I=0;I<VarsNumB;I++){  
           for(L=1,D=0,I=0;I<VarsNumB;I++){
                 if(type(C[I])==1){                  if(type(TMP=dn(C[I]))==1)
                         L=ilcm(L,dn(C[I]))$                          L=ilcm(L,TMP)$
                         D=igcd(D,nm(C[I]))$  
                 }                  if(type(TMP=nm(C[I]))==1)
                 else                          D=igcd(D,TMP)$
                         break$          }
   
         }          for(I=0;I<VarsNumB;I++)
                   C[I]=C[I]*L$
         if(I==VarsNumB)  
                 for(I=0;I<VarsNumB;I++)          if(D!=0)
                         C[I]=C[I]*L/D$                  for(I=0;I<VarsNumB;I++)
                           C[I]=C[I]/D$
         RET=newvect(VarsNumB)$  
         for(I=0;I<VarsNumB;I++){  
                 RET[I]=newvect(2)$          RET=newvect(VarsNumB)$
                 RET[I][0]=B[I]$          for(I=0;I<VarsNumB;I++){
                 RET[I][1]=C[I]$                  RET[I]=newvect(2)$
         }                  RET[I][0]=B[I]$
                   RET[I][1]=C[I]$
         return vtol(map(vtol,RET))$          }
 }  
           return vtol(map(vtol,RET))$
 def qcheck(PolyList,Vars){  }
   
         RET=[]$  def qcheck(PolyList,Vars){
         Res=qcheck0(PolyList,Vars)$  
         VarsNum=length(Vars)$          RET=[]$
           Res=qcheck0(PolyList,Vars)$
         IndNum=Res[0]$          VarsNum=length(Vars)$
         CHAGORD=Res[1]$  
         ExpMat=Res[2]$          IndNum=Res[0]$
           CHAGORD=Res[1]$
         SolveList=[]$          ExpMat=Res[2]$
         for(I=0;I<IndNum;I++){  
                 TMP=0$          SolveList=[]$
                 for(J=0;J<VarsNum;J++)          for(I=0;I<IndNum;I++){
                         TMP+=ExpMat[I][CHAGORD[J]]*Vars[CHAGORD[J]]$                  TMP=0$
                   for(J=0;J<VarsNum;J++)
                 SolveList=cons(TMP,SolveList)$                          TMP+=ExpMat[I][CHAGORD[J]]*Vars[CHAGORD[J]]$
         }  
                   SolveList=cons(TMP,SolveList)$
         VarsList=[]$          }
         for(I=0;I<VarsNum;I++)  
                 VarsList=cons(Vars[CHAGORD[I]],VarsList)$          VarsList=[]$
           for(I=0;I<VarsNum;I++)
         Rea=vars(SolveList)$                  VarsList=cons(Vars[CHAGORD[I]],VarsList)$
         Res=solve(reverse(SolveList),reverse(VarsList))$  
           Rea=vars(SolveList)$
         if(nonposdegchk(Res)){          Res=solve(reverse(SolveList),reverse(VarsList))$
   
                 Res=getgcd(Res,Rea)$          if(nonposdegchk(Res)){
         ResVars=resvars(Res,Vars)$  
                   Res=getgcd(Res,Rea)$
                 if(checktd(PolyList,Vars,ResVars)==1){                  ResVars=resvars(Res,Vars)$
   
                         for(J=0;J<length(Vars);J++)                  if(checktd(PolyList,Vars,ResVars)==1){
                                 ResVars=map(subst,ResVars,Vars[J],  
                                         strtov(rtostr(Vars[J])+"_deg"))$                          for(J=0;J<length(Vars);J++)
                                   ResVars=map(subst,ResVars,Vars[J],
                         RET=cons([vtol(ResVars),ResVars,[]],RET)$                                          strtov(rtostr(Vars[J])+"_deg"))$
                         return cons(1,RET)$  
                 }                          RET=cons([vtol(ResVars),ResVars,[]],RET)$
                 else                          return cons(1,RET)$
                         return cons(0,RET)$                  }
         }                  else
         else                          return cons(0,RET)$
                 return cons(0,RET)$          }
           else
 }                  return cons(0,RET)$
   
 def weight(PolyList,Vars){  }
   
         Vars0=vars(PolyList)$  def leastsq(ExpMat,Vars){
         Vars1=[]$  
         for(I=0;I<length(Vars);I++)          ExpMatRowNum=size(ExpMat)[0]$
                 if(member(Vars[I],Vars0))          ExpMatColNum=size(ExpMat[0])[0]$
                         Vars1=cons(Vars[I],Vars1)$  
           NormMat=newmat(ExpMatColNum,ExpMatColNum+1)$
         Vars=reverse(Vars1)$  
           for(I=0;I<ExpMatColNum;I++)
         RET=[]$                  for(J=0;J<ExpMatColNum;J++)
                           for(K=0;K<ExpMatRowNum;K++)
         TMP=qcheck(PolyList,Vars)$                                  NormMat[I][J]+=ExpMat[K][I]*ExpMat[K][J]$
   
         if(car(TMP)==1){          for(I=0;I<ExpMatColNum;I++)
                 RET=cdr(TMP)$                  for(J=0;J<ExpMatRowNum;J++)
                 RET=cons(Vars,RET)$                          NormMat[I][ExpMatColNum]+=ExpMat[J][I]$
                 RET=cons(1,RET)$  
                 return RET$              SolveList=[]$
         }          for(I=0;I<ExpMatColNum;I++){
                   TMP=0$
         dp_ord(2)$                  for(J=0;J<ExpMatColNum;J++)
                           TMP+=NormMat[I][J]*Vars[J]$
         PolyListNum=length(PolyList)$  
         VPolyList=qsort(newvect(PolyListNum,PolyList),junban1)$                  TMP-=NormMat[I][ExpMatColNum]$
         VPolyList=vtol(VPolyList)$                  SolveList=cons(TMP,SolveList)$
           }
         ExpMat=[]$  
         for(I=0;I<PolyListNum;I++)          Rea=vars(SolveList)$
                 for(Poly=dp_ptod(VPolyList[I],Vars);Poly!=0;Poly=dp_rest(Poly))          Res=solve(SolveList,Vars)$
                         ExpMat=cons(dp_etov(dp_ht(Poly)),ExpMat)$  
           if(nonposdegchk(Res)){
         ExpMat=reverse(ExpMat)$                  Res=getgcd(Res,Rea)$
         ExpMat=newvect(length(ExpMat),ExpMat)$                  TMP1=makeret1(Res,Vars);
                   if(car(TMP1)==0){
                           TMP2=roundret(cdr(TMP1));
 /* first */                          TMP3=map(drint,cdr(TMP1))$
                           return([cdr(TMP1),newvect(length(TMP3),TMP3),TMP2])$
         ExpMatRowNum=size(ExpMat)[0]$                  }
         ExpMatColNum=size(ExpMat[0])[0]$                  else
         ExtMatColNum=ExpMatColNum+PolyListNum$                          return([cdr(TMP1),[],[]])$
           }
         OneMat=newvect(PolyListNum+1,[0])$  
         for(I=0,SUM=0;I<PolyListNum;I++){  }
                 SUM+=nmono(VPolyList[I])$  
                 OneMat[I+1]=SUM$  def weight(PolyList,Vars){
         }  
           Vars0=vars(PolyList)$
         RevOneMat=newvect(ExpMatRowNum)$          Vars1=[]$
         for(I=0;I<PolyListNum;I++)          for(I=0;I<length(Vars);I++)
                 for(J=OneMat[I];J<OneMat[I+1];J++)                  if(member(Vars[I],Vars0))
                         RevOneMat[J]=I$                          Vars1=cons(Vars[I],Vars1)$
   
         NormMat=newmat(ExpMatColNum,ExtMatColNum)$          Vars=reverse(Vars1)$
   
         for(I=0;I<ExpMatColNum;I++)          RET=[]$
                 for(J=0;J<ExpMatColNum;J++)  
                         for(K=0;K<ExpMatRowNum;K++)          TMP=qcheck(PolyList,Vars)$
                                 NormMat[I][J]+=ExpMat[K][I]*ExpMat[K][J]$  
           if(car(TMP)==1){
         for(I=0;I<ExpMatColNum;I++)                  RET=cdr(TMP)$
                 for(J=0;J<PolyListNum-1;J++)                  RET=cons(Vars,RET)$
                         for(K=OneMat[J];K<OneMat[J+1];K++)                  RET=cons(1,RET)$
                                 NormMat[I][J+ExpMatColNum]-=ExpMat[K][I]$                  return RET$
           }
         for(I=0;I<ExpMatColNum;I++)  
                 for(J=OneMat[PolyListNum-1];J<OneMat[PolyListNum];J++)          dp_ord(2)$
                         NormMat[I][ExtMatColNum-1]+=ExpMat[J][I]$  
           PolyListNum=length(PolyList)$
         NormMat2=newmat(PolyListNum-1,ExpMatColNum+1)$          VPolyList=newvect(PolyListNum,PolyList)$
   
         for(I=0;I<PolyListNum-1;I++)          ExpMat=[]$
                 for(J=0;J<ExpMatColNum;J++)          for(I=0;I<PolyListNum;I++)
                         for(K=OneMat[I];K<OneMat[I+1];K++)                  for(Poly=dp_ptod(VPolyList[I],Vars);
                                 NormMat2[I][J]-=ExpMat[K][J]$                          Poly!=0;Poly=dp_rest(Poly)){
                           Exp=dp_etov(dp_ht(Poly))$
         for(I=0;I<PolyListNum-1;I++)                          if(notzerovec(Exp))
                 NormMat2[I][ExpMatColNum]=OneMat[I+1]-OneMat[I]$                                  ExpMat=cons(Exp,ExpMat)$
                           }
         ExtVars=Vars$  
         for(I=0;I<PolyListNum-1;I++)          ExpMat=reverse(ExpMat)$
                 ExtVars=append(ExtVars,[uc()])$          ExpMat=newvect(length(ExpMat),ExpMat)$
   
         SolveList=[]$  /* first */
         for(I=0;I<ExpMatColNum;I++){  
                 TMP=0$          RET=cons(leastsq(ExpMat,Vars),RET)$
                 for(J=0;J<ExtMatColNum-1;J++)  
                         TMP+=NormMat[I][J]*ExtVars[J]$  /* second */
   
                 TMP-=NormMat[I][ExtMatColNum-1]$          ExpMat=qsort(ExpMat,junban)$
                 SolveList=cons(TMP,SolveList)$          ExpMat2=[]$
         }          for(I=0;I<size(ExpMat)[0];I++)
                   if(car(ExpMat2)!=ExpMat[I])
         for(I=0;I<PolyListNum-1;I++){                          ExpMat2=cons(ExpMat[I],ExpMat2)$
                 TMP=0$  
                 for(J=0;J<ExpMatColNum;J++)          if(size(ExpMat)[0]!=length(ExpMat2)){
                         TMP+=NormMat2[I][J]*ExtVars[J]$                  ExpMat=newvect(length(ExpMat2),ExpMat2)$
                   RET=cons(leastsq(ExpMat,Vars),RET)$
                 TMP+=NormMat2[I][ExpMatColNum]*ExtVars[I+ExpMatColNum]$          }
   
                 SolveList=cons(TMP,SolveList)$          RET=cons(Vars,reverse(RET))$
         }          RET=cons(0,RET)$
           return RET$
         Rea=vars(SolveList)$  }
         Res=solve(SolveList,reverse(ExtVars))$  
   end$
         if(nonposdegchk(Res)){  
                 Res=getgcd(Res,Rea)$  
                 TMP1=makeret1(Res,Vars);  
                 if(car(TMP1)==0){        
                         TMP2=roundret(cdr(TMP1));  
                         TMP3=map(drint,cdr(TMP1))$  
                         RET=cons([cdr(TMP1),newvect(length(TMP3),TMP3),TMP2],RET)$  
                 }  
                 else  
                         RET=cons([cdr(TMP1),[],[]],RET)$  
         }  
   
 /* second */  
   
         NormMat=newmat(ExpMatColNum,ExpMatColNum+1)$  
   
         for(I=0;I<ExpMatColNum;I++)  
                 for(J=0;J<ExpMatColNum;J++)  
                         for(K=0;K<ExpMatRowNum;K++)  
                                 NormMat[I][J]+=ExpMat[K][I]*ExpMat[K][J]$  
   
         for(I=0;I<ExpMatColNum;I++)  
                 for(J=0;J<ExpMatRowNum;J++)  
                         NormMat[I][ExpMatColNum]+=ExpMat[J][I]$  
   
         SolveList=[]$  
         for(I=0;I<ExpMatColNum;I++){  
                 TMP=0$  
                 for(J=0;J<ExpMatColNum;J++)  
                         TMP+=NormMat[I][J]*Vars[J]$  
   
                 TMP-=NormMat[I][ExpMatColNum]$  
                 SolveList=cons(TMP,SolveList)$  
         }  
   
         Rea=vars(SolveList)$  
         Res=solve(SolveList,Vars)$  
   
         if(nonposdegchk(Res)){  
                 Res=getgcd(Res,Rea)$  
                 TMP1=makeret1(Res,Vars);  
                 if(car(TMP1)==0){        
                         TMP2=roundret(cdr(TMP1));  
                         TMP3=map(drint,cdr(TMP1))$  
                         RET=cons([cdr(TMP1),newvect(length(TMP3),TMP3),TMP2],RET)$  
                 }  
                 else  
                         RET=cons([cdr(TMP1),[],[]],RET)$  
         }  
   
 /* third */  
   
         ExpMat=qsort(ExpMat,junban2)$  
         ExpMat2=[]$  
         for(I=0;I<size(ExpMat)[0];I++)  
                 if(car(ExpMat2)!=ExpMat[I])  
                         ExpMat2=cons(ExpMat[I],ExpMat2)$  
   
         ExpMat=newvect(length(ExpMat2),ExpMat2)$  
         ExpMatRowNum=size(ExpMat)[0]$  
         ExpMatColNum=size(ExpMat[0])[0]$  
   
         NormMat=newmat(ExpMatColNum,ExpMatColNum+1)$  
   
         for(I=0;I<ExpMatColNum;I++)  
                 for(J=0;J<ExpMatColNum;J++)  
                         for(K=0;K<ExpMatRowNum;K++)  
                                 NormMat[I][J]+=ExpMat[K][I]*ExpMat[K][J]$  
   
         for(I=0;I<ExpMatColNum;I++)  
                 for(J=0;J<ExpMatRowNum;J++)  
                         NormMat[I][ExpMatColNum]+=ExpMat[J][I]$  
   
         SolveList=[]$  
         for(I=0;I<ExpMatColNum;I++){  
                 TMP=0$  
                 for(J=0;J<ExpMatColNum;J++)  
                         TMP+=NormMat[I][J]*Vars[J]$  
   
                 TMP-=NormMat[I][ExpMatColNum]$  
                 SolveList=cons(TMP,SolveList)$  
         }  
   
         Rea=vars(SolveList)$  
         Res=solve(SolveList,Vars)$  
   
         if(nonposdegchk(Res)){  
                 Res=getgcd(Res,Rea)$  
                 TMP1=makeret1(Res,Vars);  
                 if(car(TMP1)==0){        
                         TMP2=roundret(cdr(TMP1));  
                         TMP3=map(drint,cdr(TMP1))$  
                         RET=cons([cdr(TMP1),newvect(length(TMP3),TMP3),TMP2],RET)$  
                 }  
                 else  
                         RET=cons([cdr(TMP1),[],[]],RET)$  
         }  
   
         RET=cons(Vars,reverse(RET))$  
         RET=cons(0,RET)$  
         return RET$  
 }  
   
 def average(PolyList,Vars){  
   
         RET=[]$  
         dp_ord(2)$  
   
         PolyListNum=length(PolyList)$  
   
         ExpMat=[]$  
         for(I=0;I<PolyListNum;I++)  
                 for(Poly=dp_ptod(PolyList[I],Vars);Poly!=0;Poly=dp_rest(Poly))  
                         ExpMat=cons(dp_etov(dp_ht(Poly)),ExpMat)$  
   
         ExpMat=reverse(ExpMat)$  
         ExpMat=newvect(length(ExpMat),ExpMat)$  
   
         ExpMat=qsort(ExpMat,junban2)$  
         ExpMat2=[]$  
         for(I=0;I<size(ExpMat)[0];I++)  
                 if(car(ExpMat2)!=ExpMat[I])  
                         ExpMat2=cons(ExpMat[I],ExpMat2)$  
   
         ExpMat=newvect(length(ExpMat2),ExpMat2)$  
         ExpMatRowNum=size(ExpMat)[0]$  
         ExpMatColNum=size(ExpMat[0])[0]$  
   
         Res=newvect(ExpMatColNum);  
         for(I=0;I<ExpMatColNum;I++)  
                 Res[I]=newvect(2,[Vars[I]])$  
   
         for(I=0;I<ExpMatRowNum;I++)  
                 for(J=0;J<ExpMatColNum;J++)  
                         Res[J][1]+=ExpMat[I][J]$  
   
         for(I=0;I<ExpMatColNum;I++)  
                 if(Res[I][1]==0)  
                         Res[I][1]=1$  
                 else  
                         Res[I][1]=1/Res[I][1]$  
   
         RET=cons(makeret(vtol(Res),Vars,1),RET)$  
         RET=cons(Vars,RET)$  
   
         return RET$  
 }  
   
 end$  

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.6

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>