[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.15

version 1.3, 2003/11/05 08:26:57 version 1.15, 2004/01/06 08:38:05
Line 1 
Line 1 
 load("solve")$  load("solve")$
 load("gr")$  load("gr")$
   
 def nonposdegchk(Res){  def nonzerovec(A){
   
         for(I=0;I<length(Res);I++)          for(I=0;I<size(A)[0];I++)
                 if(Res[I][1]<=0)                  if(A[I]!=0)
                         return 0$                          return 1$
   
         return 1$          return 0$
 }  }
   
 def resvars(Res,Vars){  def junban(A,B){
           return (A<B ? 1:(A>B ? -1:0))$
         ResVars=newvect(length(Vars),Vars)$  }
   
         for(I=0;I<length(Res);I++){  def worder(A,B){
                   return (A[0]<B[0] ? 1:(A[0]>B[0] ? -1:0))$
                 for(J=0;J<size(ResVars)[0];J++)  }
                         if(Res[I][0]==ResVars[J])  
                                 break$  def bsort(A){
   
                 ResVars[J]=Res[I][1]$          K=size(A)[0]-1$
         }          while(K>=0){
                   J=-1$
         return(ResVars)$                  for(I=1;I<=K;I++)
 }                          if(A[I-1][0]<A[I][0]){
                                   J=I-1$
 def makeret1(Res,Vars){                                  X=A[J]$
                                   A[J]=A[I]$
         VarsNum=length(Vars)$                                  A[I]=X$
                           }
         ResVec=newvect(VarsNum,Vars)$                  K=J$
           }
         for(I=0,M=0;I<length(Res);I++){          return A$
   }
                 for(J=0;J<VarsNum;J++)  
                         if(Res[I][0]==Vars[J])  def perm(I,P,TMP){
                                 break$  
           if(I>0){
                 if(J<VarsNum){                  TMP=perm(I-1,P,TMP)$
                         ResVec[J]=Res[I][1]$                  for(J=I-1;J>=0;J--){
                           T=P[I]$
                         if(type(ResVec[J])==1){                          P[I]=P[J]$
                                 if(M==0)                          P[J]=T$
                                         M=ResVec[J]$                          TMP=perm(I-1,P,TMP)$
                                 else                          T=P[I]$
                                         if(ResVec[J]<M)                          P[I]=P[J]$
                                                 M=ResVec[J]$                          P[J]=T$
                         }                  }
                 }  
                   return TMP$
         }          }
           else{
         for(F=0,I=0;I<VarsNum;I++)                  for(TMP0=[],K=0;K<size(P)[0];K++)
                 if(type(ResVec[I])!=1){                          TMP0=cons(P[K],TMP0)$
                         F=1$  
                         break$                  TMP=cons(TMP0,TMP)$
                 }                  return TMP$
           }
         if(F==0)  }
                 for(I=0;I<VarsNum;I++)  
                         ResVec[I]=ResVec[I]/M*1.0$  def marge(A,B){
   
         for(I=0;I<VarsNum;I++)          RET=[]$
                 for(J=0;J<length(Vars);J++)          for(I=0;I<length(A);I++)
                         ResVec[I]=subst(ResVec[I],Vars[J],                  for(J=0;J<length(B);J++)
                                 strtov(rtostr(Vars[J])+"_deg"))$                          RET=cons(append(A[I],B[J]),RET)$
   
         ResVec=cons(F,vtol(ResVec))$          return RET$
         return ResVec$  }
 }  
   def wsort(A,B,C,FLAG){
 def junban1(A,B){  
         return (nmono(A)<nmono(B) ? -1:(nmono(A)>nmono(B) ? 1:0))$          if(FLAG==0){
 }                  D=newvect(length(B))$
                   for(I=0;I<length(B);I++)
 def junban2(A,B){                          D[I]=[A[I],B[I],C[I]]$
   
         for(I=0;I<size(A)[0];I++){                  D=bsort(D)$
                 if(A[I]<B[I])                  E=[]$
                         return 1$                  for(I=0;I<length(B);I++)
                                           E=cons(D[I][1],E)$
                 if(A[I]>B[I])                  E=reverse(E)$
                         return -1$                  F=[]$
         }                  for(I=0;I<length(B);I++)
                           F=cons(D[I][2],F)$
         return 0$                  F=reverse(F)$
 }  
                   return [[E,F]]$
 def roundret(V){          }
           else{
         VN=length(V)$                  D=newvect(length(B))$
         RET0=newvect(VN,V)$                  for(I=0;I<length(B);I++)
                           D[I]=[A[I],B[I],C[I]]$
         for(I=1;I<1000;I++){  
                 RET1=I*RET0$                  D=qsort(D,worder)$
                 for(J=0;J<VN;J++){                  D0=[]$
                         X=drint(RET1[J])$  
                         if(dabs(X-RET1[J])<0.2)                  for(I=0,J=0,TMP=[],X=0;I<size(D)[0];I++){
                                 RET1[J]=X$                          if(X==D[I][0])
                         else                                  TMP=cons(cdr(D[I]),TMP)$
                                 break$                          else{
                 }                                  D0=cons(TMP,D0)$
                 if(J==VN)                                  TMP=[]$
                         break$                                  TMP=cons(cdr(D[I]),TMP)$
         }                                  X=car(D[I])$
                                   }
         if(I==1000)                  }
                 return []$                  D0=cdr(reverse(cons(TMP,D0)))$
         else                  D0=map(ltov,D0)$
                 return RET1$                  for(I=0,TMP=[[]];I<length(D0);I++){
 }                          TMP0=perm(length(D0[I])-1,D0[I],[])$
                           TMP=marge(TMP,TMP0)$
 def chkou(L,ExpMat,CHAGORD){                  }
   
         P=1$                  RET=[]$
         F=ExpMat[L]$                  for(I=0;I<length(TMP);I++){
                           TMP0=[]$
         for(I=0;I<L;I++){                          TMP1=[]$
                 Q=ExpMat[L][CHAGORD[I]]$                          for(J=0;J<length(TMP[I]);J++){
                 for(J=0;J<size(ExpMat[0])[0];J++){                                  TMP0=cons(TMP[I][J][0],TMP0)$
                         ExpMat[L][CHAGORD[J]]=red((ExpMat[I][CHAGORD[I]]                                  TMP1=cons(TMP[I][J][1],TMP1)$
                                 *ExpMat[L][CHAGORD[J]]-                          }
                                         Q*ExpMat[I][CHAGORD[J]])/P)$                          TMP0=reverse(TMP0)$
                 }                          TMP1=reverse(TMP1)$
   
                 P=ExpMat[I][CHAGORD[I]]$                          RET=cons([TMP0,TMP1],RET)$
         }                  }
   
         for(J=0;J<size(ExpMat[0])[0];J++)                  return RET$
                 if(ExpMat[L][CHAGORD[J]]!=0)          }
                         break$  }
   
         if(J==size(ExpMat[0])[0])  def derase(A){
                 return L$  
         else{          B=newvect(length(A),A)$
                 TMP=CHAGORD[L]$          B=qsort(B,junban)$
                 CHAGORD[L]=CHAGORD[J]$          C=[]$
                 CHAGORD[J]=TMP$          for(I=0;I<size(B)[0];I++)
                 return (L+1)$                  if(car(C)!=B[I])
         }                          C=cons(B[I],C)$
 }  
           return reverse(C)$
 def qcheck0(PolyList,Vars){  }
   
         RET=[]$  def nonposdegchk(Res){
         PolyListNum=length(PolyList)$  
         VarsNum=length(Vars)$          for(I=0;I<length(Res);I++)
                   if(Res[I][1]<=0)
         ExpMat=newvect(VarsNum)$                          return 0$
         CHAGORD=newvect(VarsNum)$  
         for(I=0;I<VarsNum;I++)          return 1$
                 CHAGORD[I]=I$  }
   
         L=0$  def getgcd(A,B){
         for(I=0;I<PolyListNum;I++){  
                 Poly=dp_ptod(PolyList[I],Vars)$          VarsNumA=length(A)$
                 BASE0=dp_etov(dp_ht(Poly))$          VarsNumB=length(B)$
                 Poly=dp_rest(Poly)$  
                 for(;Poly!=0;Poly=dp_rest(Poly)){          C=newvect(VarsNumB,B)$
                         ExpMat[L]=dp_etov(dp_ht(Poly))-BASE0$  
                         L=chkou(L,ExpMat,CHAGORD)$          for(I=0;I<VarsNumA;I++){
                         if(L==VarsNum-1){  
                                 RET=cons(ExpMat,RET)$                  for(J=0;J<VarsNumB;J++)
                                 RET=cons(CHAGORD,RET)$                          if(C[J]==A[I][0])
                                 RET=cons(L,RET)$                                  break$
                                 return RET$  
                         }                  if(J<VarsNumB)
                 }                                C[J]=A[I][1]$
         }          }
           
         RET=cons(ExpMat,RET)$          D=0$
         RET=cons(CHAGORD,RET)$          for(I=0;I<VarsNumB;I++)
         RET=cons(L,RET)$                  D=gcd(D,C[I])$
         return RET$  
 }          if(D!=0){
                   C=C/D$
 def inner(A,B){                  C=map(red,C)$
           }
         SUM=0$  
         for(I=0;I<size(A)[0];I++)          for(L=1,D=0,I=0;I<VarsNumB;I++){
                 SUM+=A[I]*B[I]$                  if(type(TMP=dn(C[I]))==1)
                           L=ilcm(L,TMP)$
         return SUM$  
 }                  if(type(TMP=nm(C[I]))==1)
                           D=igcd(D,TMP)$
 def checktd(PolyList,Vars,ResVars){          }
   
         PolyListNum=length(PolyList)$          C=C*L$
         VarsNum=length(Vars)$          if(D!=0)
                   C=C/D$
         L=0$  
         for(I=0;I<PolyListNum;I++){          RET=[]$
                 Poly=dp_ptod(PolyList[I],Vars)$          for(I=0;I<VarsNumB;I++)
                 J0=inner(dp_etov(dp_ht(Poly)),ResVars)$                  RET=cons([B[I],C[I]],RET)$
                 Poly=dp_rest(Poly)$  
                 for(;Poly!=0;Poly=dp_rest(Poly))          return RET$
                         if(J0!=inner(dp_etov(dp_ht(Poly)),ResVars))  }
                                 return 0$  
         }  def makeret(Res,Vars,FLAG){
           
         return 1$          ResNum=length(Res)$
 }          VarsNum=length(Vars)$
   
 def getgcd(A,B){          ResVec=newvect(ResNum)$
           for(M=0,I=0;I<ResNum;I++){
         VarsNumA=length(A)$                  if(member(Res[I][0],Vars)){
         VarsNumB=length(B)$                          ResVec[I]=Res[I][1]$
   
         C=newvect(VarsNumB,B)$                          if(FLAG && type(ResVec[I])==1){
                                   if(M==0)
         for(I=0;I<VarsNumA;I++){                                          M=ResVec[I]$
                                   else
                 for(J=0;J<VarsNumB;J++)                                          if(ResVec[I]<M)
                         if(C[J]==A[I][0])                                                  M=ResVec[I]$
                                 break$                          }
                   }
                 C[J]=A[I][1]$          }
         }  
           if(M!=0)
         D=0$                  ResVec=ResVec/M;
         for(I=0;I<VarsNumB;I++)  
                 D=gcd(D,C[I])$          RET=newvect(VarsNum,Vars)$
   
         if(D!=0){          for(I=0;I<ResNum;I++){
                   for(J=0;J<VarsNum;J++)
                 for(I=0;I<VarsNumB;I++)                          if(Vars[J]==Res[I][0])
                         C[I]=red(C[I]/D)$                                  break$
   
         }                  if(J<VarsNum)
                           RET[J]=ResVec[I]$
         for(L=1,D=0,I=0;I<VarsNumB;I++){          }
   
                 if(type(C[I])==1){  
                         L=ilcm(L,dn(C[I]))$          for(J=0;J<length(Vars);J++)
                         D=igcd(D,nm(C[I]))$                  RET=map(subst,RET,Vars[J],
                 }                          strtov(rtostr(Vars[J])+"_deg"))$
                 else  
                         break$          for(I=0;I<VarsNum;I++)
                   if(type(RET[I])!=1)
         }                          return [1,RET]$
   
         if(I==VarsNumB)          return [0,RET]$
                 for(I=0;I<VarsNumB;I++)  }
                         C[I]=C[I]*L/D$  
   def roundret(V){
         RET=newvect(VarsNumB)$  
         for(I=0;I<VarsNumB;I++){          VN=size(V)[0]$
                 RET[I]=newvect(2)$  
                 RET[I][0]=B[I]$          RET0=V$
                 RET[I][1]=C[I]$          for(I=1;I<1000;I++){
         }                  RET1=I*RET0$
                   for(J=0;J<VN;J++){
         return vtol(map(vtol,RET))$                          X=drint(RET1[J])$
 }                          if(dabs(X-RET1[J])<0.2)
                                   RET1[J]=X$
 def qcheck(PolyList,Vars){                          else
                                   break$
         RET=[]$                  }
         Res=qcheck0(PolyList,Vars)$                  if(J==VN)
         VarsNum=length(Vars)$                          break$
           }
         IndNum=Res[0]$  
         CHAGORD=Res[1]$          if(I==1000)
         ExpMat=Res[2]$                  return []$
           else
         SolveList=[]$                  return RET1$
         for(I=0;I<IndNum;I++){  }
                 TMP=0$  
                 for(J=0;J<VarsNum;J++)  def chkou(L,ExpMat,CHAGORD){
                         TMP+=ExpMat[I][CHAGORD[J]]*Vars[CHAGORD[J]]$  
           for(P=1,I=0;I<L;I++){
                 SolveList=cons(TMP,SolveList)$                  Q=ExpMat[L][CHAGORD[I]]$
         }                  for(J=0;J<size(ExpMat[0])[0];J++){
                           ExpMat[L][CHAGORD[J]]=red((ExpMat[I][CHAGORD[I]]
         VarsList=[]$                                  *ExpMat[L][CHAGORD[J]]-
         for(I=0;I<VarsNum;I++)                                          Q*ExpMat[I][CHAGORD[J]])/P)$
                 VarsList=cons(Vars[CHAGORD[I]],VarsList)$                  }
   
         Rea=vars(SolveList)$                  P=ExpMat[I][CHAGORD[I]]$
         Res=solve(reverse(SolveList),reverse(VarsList))$          }
   
         if(nonposdegchk(Res)){          for(J=0;J<size(ExpMat[0])[0];J++)
                   if(ExpMat[L][CHAGORD[J]]!=0)
                 Res=getgcd(Res,Rea)$                          break$
         ResVars=resvars(Res,Vars)$  
           if(J==size(ExpMat[0])[0])
                 if(checktd(PolyList,Vars,ResVars)==1){                  return L$
           else{
                         for(J=0;J<length(Vars);J++)                  TMP=CHAGORD[L]$
                                 ResVars=map(subst,ResVars,Vars[J],                  CHAGORD[L]=CHAGORD[J]$
                                         strtov(rtostr(Vars[J])+"_deg"))$                  CHAGORD[J]=TMP$
                   return (L+1)$
                         RET=cons([vtol(ResVars),ResVars,[]],RET)$          }
                         return cons(1,RET)$  }
                 }  
                 else  def qcheckmain(PolyList,Vars){
                         return cons(0,RET)$  
         }          RET=[]$
         else          PolyListNum=length(PolyList)$
                 return cons(0,RET)$          VarsNum=length(Vars)$
   
 }          ExpMat=newvect(VarsNum)$
           CHAGORD=newvect(VarsNum)$
 def weight(PolyList,Vars){          for(I=0;I<VarsNum;I++)
                   CHAGORD[I]=I$
         Vars0=vars(PolyList)$  
         Vars1=[]$          L=0$
         for(I=0;I<length(Vars);I++)          for(I=0;I<PolyListNum;I++){
                 if(member(Vars[I],Vars0))                  Poly=dp_ptod(PolyList[I],Vars)$
                         Vars1=cons(Vars[I],Vars1)$                  BASE0=dp_etov(dp_ht(Poly))$
                   Poly=dp_rest(Poly)$
         Vars=reverse(Vars1)$                  for(;Poly!=0;Poly=dp_rest(Poly)){
                           ExpMat[L]=dp_etov(dp_ht(Poly))-BASE0$
         RET=[]$                          L=chkou(L,ExpMat,CHAGORD)$
                           if(L==VarsNum-1)
         TMP=qcheck(PolyList,Vars)$                                  return [L,CHAGORD,ExpMat]$
                   }
         if(car(TMP)==1){          }
                 RET=cdr(TMP)$  
                 RET=cons(Vars,RET)$          return [L,CHAGORD,ExpMat]$
                 RET=cons(1,RET)$  }
                 return RET$      
         }  def inner(A,B){
   
         dp_ord(2)$          SUM=0$
           for(I=0;I<size(A)[0];I++)
         PolyListNum=length(PolyList)$                  SUM+=A[I]*B[I]$
         VPolyList=qsort(newvect(PolyListNum,PolyList),junban1)$  
         VPolyList=vtol(VPolyList)$          return SUM$
   }
         ExpMat=[]$  
         for(I=0;I<PolyListNum;I++)  def checktd(PolyList,Vars,ResVars){
                 for(Poly=dp_ptod(VPolyList[I],Vars);Poly!=0;Poly=dp_rest(Poly))  
                         ExpMat=cons(dp_etov(dp_ht(Poly)),ExpMat)$          PolyListNum=length(PolyList)$
           VarsNum=length(Vars)$
         ExpMat=reverse(ExpMat)$  
         ExpMat=newvect(length(ExpMat),ExpMat)$          L=0$
           for(I=0;I<PolyListNum;I++){
                   Poly=dp_ptod(PolyList[I],Vars)$
 /* first */                  J0=inner(dp_etov(dp_ht(Poly)),ResVars)$
                   Poly=dp_rest(Poly)$
         ExpMatRowNum=size(ExpMat)[0]$                  for(;Poly!=0;Poly=dp_rest(Poly))
         ExpMatColNum=size(ExpMat[0])[0]$                          if(J0!=inner(dp_etov(dp_ht(Poly)),ResVars))
         ExtMatColNum=ExpMatColNum+PolyListNum$                                  return 0$
           }
         OneMat=newvect(PolyListNum+1,[0])$  
         for(I=0,SUM=0;I<PolyListNum;I++){          return 1$
                 SUM+=nmono(VPolyList[I])$  }
                 OneMat[I+1]=SUM$  
         }  def qcheck(PolyList,Vars,FLAG){
   
         RevOneMat=newvect(ExpMatRowNum)$          RET=[]$
         for(I=0;I<PolyListNum;I++)          Res=qcheckmain(PolyList,Vars)$
                 for(J=OneMat[I];J<OneMat[I+1];J++)          VarsNum=length(Vars)$
                         RevOneMat[J]=I$  
           IndNum=Res[0]$
         NormMat=newmat(ExpMatColNum,ExtMatColNum)$          CHAGORD=Res[1]$
           ExpMat=Res[2]$
         for(I=0;I<ExpMatColNum;I++)  
                 for(J=0;J<ExpMatColNum;J++)          SolveList=[]$
                         for(K=0;K<ExpMatRowNum;K++)          for(I=0;I<IndNum;I++){
                                 NormMat[I][J]+=ExpMat[K][I]*ExpMat[K][J]$                  TMP=0$
                   for(J=0;J<VarsNum;J++)
         for(I=0;I<ExpMatColNum;I++)                          TMP+=ExpMat[I][CHAGORD[J]]*Vars[CHAGORD[J]]$
                 for(J=0;J<PolyListNum-1;J++)  
                         for(K=OneMat[J];K<OneMat[J+1];K++)                  SolveList=cons(TMP,SolveList)$
                                 NormMat[I][J+ExpMatColNum]-=ExpMat[K][I]$          }
   
         for(I=0;I<ExpMatColNum;I++)          Rea=vars(SolveList)$
                 for(J=OneMat[PolyListNum-1];J<OneMat[PolyListNum];J++)  
                         NormMat[I][ExtMatColNum-1]+=ExpMat[J][I]$          VarsList=[]$
           for(I=0;I<VarsNum;I++)
         NormMat2=newmat(PolyListNum-1,ExpMatColNum+1)$                  if(member(Vars[CHAGORD[I]],Rea))
                           VarsList=cons(Vars[CHAGORD[I]],VarsList)$
         for(I=0;I<PolyListNum-1;I++)  
                 for(J=0;J<ExpMatColNum;J++)          Res=solve(reverse(SolveList),reverse(VarsList))$
                         for(K=OneMat[I];K<OneMat[I+1];K++)          Res=getgcd(Res,Rea)$
                                 NormMat2[I][J]-=ExpMat[K][J]$  
           if(nonposdegchk(Res)){
         for(I=0;I<PolyListNum-1;I++)  
                 NormMat2[I][ExpMatColNum]=OneMat[I+1]-OneMat[I]$                  ResVars=makeret(Res,Vars,0)$
   
         ExtVars=Vars$                  if(checktd(PolyList,Vars,ResVars[1])==1){
         for(I=0;I<PolyListNum-1;I++)                          if(ResVars[0]==0){
                 ExtVars=append(ExtVars,[uc()])$                                  RET=append(RET,wsort(ResVars[1],Vars,
                                           ResVars[1],FLAG))$
         SolveList=[]$                                  return RET$
         for(I=0;I<ExpMatColNum;I++){                          }
                 TMP=0$                          else{
                 for(J=0;J<ExtMatColNum-1;J++)                                  RET=append(RET,[[Vars,vtol(ResVars[1])]])$
                         TMP+=NormMat[I][J]*ExtVars[J]$                                  return RET$
                           }
                 TMP-=NormMat[I][ExtMatColNum-1]$                  }
                 SolveList=cons(TMP,SolveList)$                  else
         }                          return []$
           }
         for(I=0;I<PolyListNum-1;I++){          else
                 TMP=0$                  return []$
                 for(J=0;J<ExpMatColNum;J++)  
                         TMP+=NormMat2[I][J]*ExtVars[J]$  }
   
                 TMP+=NormMat2[I][ExpMatColNum]*ExtVars[I+ExpMatColNum]$  def leastsq(NormMat,ExpMat,Vars,FLAG){
   
                 SolveList=cons(TMP,SolveList)$          RET=[]$
         }  
           ExpMatRowNum=size(ExpMat)[0]$
         Rea=vars(SolveList)$          ExpMatColNum=size(ExpMat[0])[0]$
         Res=solve(SolveList,reverse(ExtVars))$  
           if(NormMat==0){
         if(nonposdegchk(Res)){                  NormMat=newmat(ExpMatColNum,ExpMatColNum)$
                 Res=getgcd(Res,Rea)$  
                 TMP1=makeret1(Res,Vars);                  for(I=0;I<ExpMatColNum;I++)
                 if(car(TMP1)==0){                                for(J=I;J<ExpMatColNum;J++)
                         TMP2=roundret(cdr(TMP1));                                  for(K=0;K<ExpMatRowNum;K++)
                         TMP3=map(drint,cdr(TMP1))$                                          NormMat[I][J]+=
                         RET=cons([cdr(TMP1),newvect(length(TMP3),TMP3),TMP2],RET)$                                                  ExpMat[K][I]*ExpMat[K][J]$
                 }          }
                 else  
                         RET=cons([cdr(TMP1),[],[]],RET)$          BVec=newvect(ExpMatColNum)$
         }  
           for(I=0;I<ExpMatColNum;I++)
 /* second */                  for(J=0;J<ExpMatRowNum;J++)
                           BVec[I]+=ExpMat[J][I]$
         NormMat=newmat(ExpMatColNum,ExpMatColNum+1)$  
           SolveList=[]$
         for(I=0;I<ExpMatColNum;I++)          for(I=0;I<ExpMatColNum;I++){
                 for(J=0;J<ExpMatColNum;J++)                  TMP=0$
                         for(K=0;K<ExpMatRowNum;K++)                  for(J=0;J<I;J++)
                                 NormMat[I][J]+=ExpMat[K][I]*ExpMat[K][J]$                          TMP+=NormMat[J][I]*Vars[J]$
   
         for(I=0;I<ExpMatColNum;I++)                  for(J=I;J<ExpMatColNum;J++)
                 for(J=0;J<ExpMatRowNum;J++)                          TMP+=NormMat[I][J]*Vars[J]$
                         NormMat[I][ExpMatColNum]+=ExpMat[J][I]$  
                   TMP-=BVec[I]$
         SolveList=[]$                  SolveList=cons(TMP,SolveList)$
         for(I=0;I<ExpMatColNum;I++){          }
                 TMP=0$  
                 for(J=0;J<ExpMatColNum;J++)          Rea=vars(SolveList)$
                         TMP+=NormMat[I][J]*Vars[J]$  
           VarsList=[]$
                 TMP-=NormMat[I][ExpMatColNum]$          for(I=0;I<length(Vars);I++)
                 SolveList=cons(TMP,SolveList)$                  if(member(Vars[I],Rea))
         }                          VarsList=cons(Vars[I],VarsList)$
   
         Rea=vars(SolveList)$          Res=solve(SolveList,VarsList)$
         Res=solve(SolveList,Vars)$          Res=getgcd(Res,Rea)$
   
         if(nonposdegchk(Res)){          if(nonposdegchk(Res)){
                 Res=getgcd(Res,Rea)$                  TMP1=makeret(Res,Vars,1)$
                 TMP1=makeret1(Res,Vars);                  if(TMP1[0]==0){
                 if(car(TMP1)==0){                                TMP=roundret(TMP1[1])$
                         TMP2=roundret(cdr(TMP1));                          if(TMP!=[])
                         TMP3=map(drint,cdr(TMP1))$                                  RET=append(RET,wsort(TMP1[1],Vars,TMP,FLAG))$
                         RET=cons([cdr(TMP1),newvect(length(TMP3),TMP3),TMP2],RET)$  
                 }                          RET=append(RET,wsort(TMP1[1],Vars,
                 else                                  map(drint,TMP1[1]*1.0),FLAG))$
                         RET=cons([cdr(TMP1),[],[]],RET)$  
         }                          return RET$
                   }
 /* third */                  else{
                           RET=append(RET,[[Vars,vtol(TMP1[1]*1.0)]])$
         ExpMat=qsort(ExpMat,junban2)$                          return RET$
         ExpMat2=[]$                  }
         for(I=0;I<size(ExpMat)[0];I++)          }
                 if(car(ExpMat2)!=ExpMat[I])          else
                         ExpMat2=cons(ExpMat[I],ExpMat2)$                  return RET$
   
         ExpMat=newvect(length(ExpMat2),ExpMat2)$  }
         ExpMatRowNum=size(ExpMat)[0]$  
         ExpMatColNum=size(ExpMat[0])[0]$  def weightr(ExpMat,Vars,PolyListNum,OneMat,FLAG){
   
         NormMat=newmat(ExpMatColNum,ExpMatColNum+1)$          RET=[]$
   
         for(I=0;I<ExpMatColNum;I++)          ExpMatRowNum=size(ExpMat)[0]$
                 for(J=0;J<ExpMatColNum;J++)          ExpMatColNum=size(ExpMat[0])[0]$
                         for(K=0;K<ExpMatRowNum;K++)          ExtMatColNum=ExpMatColNum+PolyListNum$
                                 NormMat[I][J]+=ExpMat[K][I]*ExpMat[K][J]$  
           ExtVars=reverse(Vars)$
         for(I=0;I<ExpMatColNum;I++)          for(I=0;I<PolyListNum;I++)
                 for(J=0;J<ExpMatRowNum;J++)                  ExtVars=cons(uc(),ExtVars)$
                         NormMat[I][ExpMatColNum]+=ExpMat[J][I]$  
           ExtVars=reverse(ExtVars)$
         SolveList=[]$  
         for(I=0;I<ExpMatColNum;I++){          NormMat=newmat(ExpMatColNum,ExtMatColNum)$
                 TMP=0$  
                 for(J=0;J<ExpMatColNum;J++)          for(I=0;I<ExpMatColNum;I++)
                         TMP+=NormMat[I][J]*Vars[J]$                  for(J=I;J<ExpMatColNum;J++)
                           for(K=0;K<ExpMatRowNum;K++)
                 TMP-=NormMat[I][ExpMatColNum]$                                  NormMat[I][J]+=
                 SolveList=cons(TMP,SolveList)$                                          ExpMat[K][I]*
         }                                          ExpMat[K][J]$
   
         Rea=vars(SolveList)$          for(I=0;I<ExpMatColNum;I++)
         Res=solve(SolveList,Vars)$                  for(J=0;J<PolyListNum;J++)
                           for(K=OneMat[J];K<OneMat[J+1];K++)
         if(nonposdegchk(Res)){                                  NormMat[I][J+ExpMatColNum]-=
                 Res=getgcd(Res,Rea)$                                          ExpMat[K][I]$
                 TMP1=makeret1(Res,Vars);  
                 if(car(TMP1)==0){                WVect=newvect(PolyListNum)$
                         TMP2=roundret(cdr(TMP1));          for(I=0;I<PolyListNum;I++)
                         TMP3=map(drint,cdr(TMP1))$                  WVect[I]=OneMat[I+1]-OneMat[I]$
                         RET=cons([cdr(TMP1),newvect(length(TMP3),TMP3),TMP2],RET)$  
                 }          for(F=0;F<ExtMatColNum;F++){
                 else                  SolveList=[]$
                         RET=cons([cdr(TMP1),[],[]],RET)$                  for(I=0;I<ExpMatColNum;I++){
         }                          if (F==I)
                                   continue$
         RET=cons(Vars,reverse(RET))$  
         RET=cons(0,RET)$                          TMP=0$
         return RET$  
 }                          for(J=0;J<I;J++)
                                   if(J!=F)
 def average(PolyList,Vars){                                          TMP+=NormMat[J][I]*ExtVars[J]$
   
         RET=[]$                          for(J=I;J<ExtMatColNum;J++)
         dp_ord(2)$                                  if(J!=F)
                                           TMP+=NormMat[I][J]*ExtVars[J]$
         PolyListNum=length(PolyList)$  
                           if(F<I)
         ExpMat=[]$                                  TMP+=NormMat[F][I]$
         for(I=0;I<PolyListNum;I++)                          else
                 for(Poly=dp_ptod(PolyList[I],Vars);Poly!=0;Poly=dp_rest(Poly))                                  TMP+=NormMat[I][F]$
                         ExpMat=cons(dp_etov(dp_ht(Poly)),ExpMat)$  
                           SolveList=cons(TMP,SolveList)$
         ExpMat=reverse(ExpMat)$                  }
         ExpMat=newvect(length(ExpMat),ExpMat)$  
                   for(I=0;I<PolyListNum;I++){
         ExpMat=qsort(ExpMat,junban2)$                          if(F==(I+ExpMatColNum))
         ExpMat2=[]$                                  continue$
         for(I=0;I<size(ExpMat)[0];I++)  
                 if(car(ExpMat2)!=ExpMat[I])                          TMP=0$
                         ExpMat2=cons(ExpMat[I],ExpMat2)$                          for(J=0;J<ExpMatColNum;J++)
                                   if(J!=F)
         ExpMat=newvect(length(ExpMat2),ExpMat2)$                                          TMP+=NormMat[J][I+ExpMatColNum]
         ExpMatRowNum=size(ExpMat)[0]$                                                  *ExtVars[J]$
         ExpMatColNum=size(ExpMat[0])[0]$  
                           TMP+=WVect[I]*ExtVars[I+ExpMatColNum]$
         Res=newvect(ExpMatColNum);  
         for(I=0;I<ExpMatColNum;I++)                          if(F<ExpMatColNum)
                 Res[I]=newvect(2,[Vars[I]])$                                  TMP+=NormMat[F][I+ExpMatColNum]$
   
         for(I=0;I<ExpMatRowNum;I++)                          SolveList=cons(TMP,SolveList)$
                 for(J=0;J<ExpMatColNum;J++)                  }
                         Res[J][1]+=ExpMat[I][J]$  
                   Rea=vars(SolveList)$
         for(I=0;I<ExpMatColNum;I++)  
                 if(Res[I][1]==0)                  SolVars=[]$
                         Res[I][1]=1$                  for(I=0;I<ExtMatColNum;I++)
                 else                          if(I!=F && member(ExtVars[I],Rea))
                         Res[I][1]=1/Res[I][1]$                                  SolVars=cons(ExtVars[I],SolVars)$
   
         RET=cons(makeret(vtol(Res),Vars,1),RET)$                  Res=solve(SolveList,SolVars)$
         RET=cons(Vars,RET)$                  Res=cons([ExtVars[F],1],Res)$
   
         return RET$                  TMP=[]$
 }                  for(I=0;I<length(Rea);I++)
                           if(member(Rea[I],Vars))
 end$                                  TMP=cons(Rea[I],TMP)$
   
                   if(member(ExtVars[F],Vars))
                           TMP=cons(ExtVars[F],TMP)$
   
                   Res=getgcd(Res,TMP)$
   
                   if(nonposdegchk(Res)){
   
                           TMP1=makeret(Res,Vars,1)$
                           if(TMP1[0]==0){
                                   TMP=roundret(TMP1[1])$
                                   if(TMP!=[])
                                           RET=append(RET,wsort(TMP1[1],Vars,
                                                   TMP,FLAG))$
   
                                   RET=append(RET,wsort(TMP1[1],Vars,
                                           map(drint,TMP1[1]*1.0),FLAG))$
                           }
                           else{
                                   RET=append(RET,[[Vars,vtol(TMP1[1]*1.0)]])$
                           }
                   }
   
           }
   
           return [NormMat,RET]$
   }
   
   def weight(PolyList,Vars,FLAG1,FLAG2){
   
           Vars0=vars(PolyList)$
           Vars1=[]$
           for(I=0;I<length(Vars);I++)
                   if(member(Vars[I],Vars0))
                           Vars1=cons(Vars[I],Vars1)$
   
           Vars=reverse(Vars1)$
   
           RET=[]$
   
           TMP=qcheck(PolyList,Vars,FLAG2)$
   
           if(TMP!=[]){
                   RET=append(RET,TMP)$
                   return cons(1,RET)$
           }
   
           dp_ord(2)$
   
           PolyListNum=length(PolyList)$
   
           if(FLAG1){
   
                   OneMat=newvect(PolyListNum+1,[0])$
                   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)$
                           }
                           OneMat[I+1]=length(ExpMat)$
                   }
   
                   ExpMat=reverse(ExpMat)$
                   ExpMat=newvect(length(ExpMat),ExpMat)$
   
                   TMP=weightr(ExpMat,Vars,PolyListNum,OneMat,FLAG2)$
                   RET=append(RET,TMP[1])$
                   RET=append(RET,leastsq(TMP[0],ExpMat,Vars,FLAG2))$
           }
           else{
                   ExpMat=[]$
                   for(I=0;I<PolyListNum;I++){
                           for(Poly=dp_ptod(PolyList[I],Vars);
                                   Poly!=0;Poly=dp_rest(Poly)){
                                   if(nonzerovec(TMP=dp_etov(dp_ht(Poly))))
                                           ExpMat=cons(TMP,ExpMat)$
                           }
                   }
   
                   ExpMat=reverse(ExpMat)$
                   ExpMat=newvect(length(ExpMat),ExpMat)$
   
                   RET=append(RET,leastsq(0,ExpMat,Vars,FLAG2))$
           }
   
           ExpMat=qsort(ExpMat,junban)$
   
           ExpMat2=[]$
           for(I=0;I<size(ExpMat)[0];I++)
                   if(car(ExpMat2)!=ExpMat[I])
                           ExpMat2=cons(ExpMat[I],ExpMat2)$
   
           if(size(ExpMat)[0]!=length(ExpMat2)){
                   ExpMat=newvect(length(ExpMat2),ExpMat2)$
                   RET=append(RET,leastsq(0,ExpMat,Vars,FLAG2))$
           }
   
           RET=derase(RET)$
           return cons(0,RET)$
   }
   
   end$

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

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