version 1.30, 2004/01/14 09:29:39 |
version 1.32, 2004/02/14 18:28:39 |
|
|
#define EPS 1E-6 |
#define EPS 1E-6 |
#define TINY 1E-20 |
#define TINY 1E-20 |
#define MAX_ITER 100 |
#define MAX_ITER 100 |
#define ROUND_THRESHOLD 0.4 |
|
|
|
def rotate(A,I,J,K,L,C,S){ |
def rotate(A,I,J,K,L,C,S){ |
|
|
Line 199 def fixedpoint(A,FLAG){ |
|
Line 198 def fixedpoint(A,FLAG){ |
|
return fixpointmain(F,Vars)$ |
return fixpointmain(F,Vars)$ |
} |
} |
|
|
def nonzerovec(A){ |
|
|
|
for(I=0;I<size(A)[0];I++) |
|
if(A[I]!=0) |
|
return 1$ |
|
|
|
return 0$ |
|
} |
|
|
|
def junban(A,B){ |
def junban(A,B){ |
return (A<B ? 1:(A>B ? -1:0))$ |
return (A<B ? 1:(A>B ? -1:0))$ |
} |
} |
|
|
def worder(A,B){ |
|
return (A[0]<B[0] ? 1:(A[0]>B[0] ? -1:0))$ |
|
} |
|
|
|
def bsort(A){ |
def bsort(A){ |
|
|
K=size(A)[0]-1$ |
K=size(A)[0]-1$ |
Line 263 def nonposdegchk(Res){ |
|
Line 249 def nonposdegchk(Res){ |
|
|
|
def getgcd(A,B){ |
def getgcd(A,B){ |
|
|
VarsNumA=length(A)$ |
Anum=length(A)$ |
VarsNumB=length(B)$ |
|
|
|
C=newvect(VarsNumB,B)$ |
TMP=[]$ |
|
for(I=0;I<length(B);I++){ |
|
|
for(I=0;I<VarsNumA;I++){ |
for(J=0;J<Anum;J++) |
|
if(B[I]==A[J][0]) |
|
break; |
|
|
for(J=0;J<VarsNumB;J++) |
if(J==Anum) |
if(B[J]==A[I][0]) |
TMP=cons([B[I],B[I]],TMP)$ |
break$ |
|
|
|
if(J<VarsNumB) |
|
C[J]=A[I][1]$ |
|
} |
} |
|
A=append(A,TMP)$ |
|
|
D=0$ |
Anum=length(A)$ |
for(I=0;I<VarsNumB;I++) |
A=map(ltov,A)$ |
D=gcd(D,C[I])$ |
|
|
|
|
for(D=0,I=0;I<Anum;I++) |
|
D=gcd(D,A[I][1])$ |
|
|
if(D!=0){ |
if(D!=0){ |
C=C/D$ |
for(I=0;I<Anum;I++) |
C=map(red,C)$ |
A[I][1]=red(A[I][1]/D)$ |
} |
} |
|
|
for(L=1,D=0,I=0;I<VarsNumB;I++){ |
for(L=1,D=0,I=0;I<Anum;I++){ |
if(type(TMP=dn(C[I]))==1) |
if(type(TMP=dn(A[I][1]))==1) |
L=ilcm(L,TMP)$ |
L=ilcm(L,TMP)$ |
|
|
if(type(TMP=nm(C[I]))==1) |
if(type(TMP=nm(A[I][1]))==1) |
D=igcd(D,TMP)$ |
D=igcd(D,TMP)$ |
} |
} |
|
|
C=C*L$ |
for(I=0;I<Anum;I++) |
if(D!=0) |
A[I][1]=A[I][1]*L$ |
C=C/D$ |
|
|
|
RET=[]$ |
if(D!=0){ |
for(I=0;I<VarsNumB;I++) |
|
RET=cons([B[I],C[I]],RET)$ |
|
|
|
return RET$ |
for(I=0;I<Anum;I++) |
|
A[I][1]=A[I][1]/D$ |
|
} |
|
|
|
return map(vtol,A)$ |
} |
} |
|
|
def makeret(Res,Vars,FLAG){ |
def makeret(Res,Vars,FLAG){ |
Line 351 def makeret(Res,Vars,FLAG){ |
|
Line 339 def makeret(Res,Vars,FLAG){ |
|
RET[J]=ResVec[I]$ |
RET[J]=ResVec[I]$ |
} |
} |
|
|
|
|
for(J=0;J<length(Vars);J++) |
|
RET=map(subst,RET,Vars[J], |
|
strtov(rtostr(Vars[J])+"_deg"))$ |
|
|
|
for(I=0;I<VarsNum;I++) |
for(I=0;I<VarsNum;I++) |
if(type(RET[I])!=1) |
if(type(RET[I])!=1) |
return [1,RET]$ |
return [1,RET]$ |
Line 367 def roundret(V){ |
|
Line 350 def roundret(V){ |
|
|
|
VN=size(V)[0]$ |
VN=size(V)[0]$ |
|
|
|
K=1$ |
RET0=V$ |
RET0=V$ |
for(I=1;I<1000;I++){ |
RET1=map(drint,RET0)$ |
RET1=I*RET0$ |
S=0$ |
for(J=0;J<VN;J++){ |
for(J=0;J<VN;J++) |
X=drint(RET1[J])$ |
S+=(RET0[J]-RET1[J])^2$ |
if(dabs(X-RET1[J])<ROUND_THRESHOLD) |
|
RET1[J]=X$ |
for(I=2;I<10;I++){ |
else |
RET0=I*V$ |
break$ |
RET1=map(drint,RET0)$ |
} |
|
if(J==VN) |
T=0$ |
break$ |
for(J=0;J<VN;J++) |
|
T+=(RET0[J]-RET1[J])^2$ |
|
|
|
if(T<S){ |
|
K=I$ |
|
S=T$ |
|
} |
} |
} |
|
|
if(I==1000) |
return map(drint,K*V)$ |
return []$ |
|
else |
|
return RET1$ |
|
} |
} |
|
|
def chkou(L,ExpMat,CHAGORD){ |
def chkou(L,ExpMat,CHAGORD){ |
Line 477 def value2(Vars,Ans){ |
|
Line 464 def value2(Vars,Ans){ |
|
Res[I][0]=Vars[I]$ |
Res[I][0]=Vars[I]$ |
Res[I][1]=Ans[I]$ |
Res[I][1]=Ans[I]$ |
} |
} |
|
Res=map(vtol,Res)$ |
|
Res=vtol(Res)$ |
|
|
Res=getgcd(Res,Vars)$ |
Res=getgcd(Res,Vars)$ |
|
|
Line 511 def qcheck(PolyList,Vars,FLAG){ |
|
Line 500 def qcheck(PolyList,Vars,FLAG){ |
|
|
|
VarsList=[]$ |
VarsList=[]$ |
for(I=0;I<VarsNum;I++) |
for(I=0;I<VarsNum;I++) |
if(member(Vars[CHAGORD[I]],Rea)) |
if(member(TMP0=Vars[CHAGORD[I]],Rea)) |
VarsList=cons(Vars[CHAGORD[I]],VarsList)$ |
VarsList=cons(Vars[CHAGORD[I]],VarsList)$ |
|
|
Res=solve(reverse(SolveList),reverse(VarsList))$ |
Res=solve(reverse(SolveList),reverse(VarsList))$ |
Line 537 def qcheck(PolyList,Vars,FLAG){ |
|
Line 526 def qcheck(PolyList,Vars,FLAG){ |
|
TMP=map(subst,TMP,TMP0[I][0],TMP0[I][1])$ |
TMP=map(subst,TMP,TMP0[I][0],TMP0[I][1])$ |
RET0=value2(Vars,TMP)$ |
RET0=value2(Vars,TMP)$ |
if(RET0!=[]) |
if(RET0!=[]) |
RET0=wsort(RET0,Vars,RET0,1/10)$ |
RET0=wsort(RET0,Vars,RET0,-1)$ |
} |
} |
|
|
TMP=vtol(TMP1[1])$ |
TMP=vtol(TMP1[1])$ |
Line 548 def qcheck(PolyList,Vars,FLAG){ |
|
Line 537 def qcheck(PolyList,Vars,FLAG){ |
|
RET0=value2(Vars,TMP)$ |
RET0=value2(Vars,TMP)$ |
|
|
if(RET0!=[]) |
if(RET0!=[]) |
RET0=wsort(RET0,Vars,RET0,1/10)$ |
RET0=wsort(RET0,Vars,RET0,-1)$ |
} |
} |
RET=append(RET,RET0)$ |
RET=append(RET,RET0)$ |
} |
} |
Line 561 def qcheck(PolyList,Vars,FLAG){ |
|
Line 550 def qcheck(PolyList,Vars,FLAG){ |
|
return RET$ |
return RET$ |
} |
} |
|
|
def leastsq(NormMat,ExpMat,Vars,FLAG,ID){ |
def unitweight2(NormMat0,ExpMat,Vars,FLAG,ID){ |
|
|
RET=[]$ |
RET=[]$ |
|
|
ExpMatRowNum=size(ExpMat)[0]$ |
ExpMatRowNum=size(ExpMat)[0]$ |
ExpMatColNum=size(ExpMat[0])[0]$ |
ExpMatColNum=size(ExpMat[0])[0]$ |
|
ExtMatColNum=ExpMatColNum+1$ |
|
|
|
ExtVars=append(Vars,[uc()])$ |
|
|
if(NormMat==0){ |
if(NormMat==0){ |
NormMat=newmat(ExpMatColNum,ExpMatColNum)$ |
|
|
|
|
NormMat0=newvect(ExtMatColNum)$ |
|
for(I=0;I<ExtMatColNum;I++) |
|
NormMat0[I]=newvect(ExtMatColNum)$ |
|
|
for(I=0;I<ExpMatColNum;I++) |
for(I=0;I<ExpMatColNum;I++) |
for(J=I;J<ExpMatColNum;J++) |
for(J=I;J<ExpMatColNum;J++) |
for(K=0;K<ExpMatRowNum;K++) |
for(K=0;K<ExpMatRowNum;K++) |
NormMat[I][J]+= |
NormMat0[I][J]+= |
ExpMat[K][I]*ExpMat[K][J]$ |
ExpMat[K][I]* |
|
ExpMat[K][J]$ |
} |
} |
|
|
BVec=newvect(ExpMatColNum)$ |
|
|
|
for(I=0;I<ExpMatColNum;I++) |
for(I=0;I<ExpMatColNum;I++) |
for(J=0;J<ExpMatRowNum;J++) |
for(K=0;K<ExpMatRowNum;K++) |
BVec[I]+=ExpMat[J][I]$ |
NormMat0[I][ExpMatColNum]-=ExpMat[K][I]$ |
|
|
SolveList=[]$ |
NormMat0[ExpMatColNum][ExpMatColNum]=ExpMatRowNum$ |
for(I=0;I<ExpMatColNum;I++){ |
|
TMP=0$ |
|
for(J=0;J<I;J++) |
|
TMP+=NormMat[J][I]*Vars[J]$ |
|
|
|
for(J=I;J<ExpMatColNum;J++) |
WorkMat=newvect(ExtMatColNum)$ |
TMP+=NormMat[I][J]*Vars[J]$ |
for(I=0;I<ExtMatColNum;I++) |
|
WorkMat[I]=newvect(ExtMatColNum)$ |
|
|
TMP-=BVec[I]$ |
if(jacobi(ExtMatColNum,NormMat0,WorkMat)){ |
SolveList=cons(TMP,SolveList)$ |
|
} |
|
|
|
Rea=vars(SolveList)$ |
Res=newvect(ExtMatColNum)$ |
|
for(I=0;I<ExtMatColNum;I++){ |
|
Res[I]=newvect(2)$ |
|
Res[I][0]=ExtVars[I]$ |
|
Res[I][1]=WorkMat[ExtMatColNum-1][I]$ |
|
} |
|
|
VarsList=[]$ |
if(nonposdegchk(Res)){ |
for(I=0;I<length(Vars);I++) |
|
if(member(Vars[I],Rea)) |
|
VarsList=cons(Vars[I],VarsList)$ |
|
|
|
Res=solve(SolveList,VarsList)$ |
TMP1=makeret(Res,Vars,1)$ |
Res=getgcd(Res,Rea)$ |
|
|
|
if(nonposdegchk(Res)){ |
if(FLAG==0){ |
|
|
TMP1=makeret(Res,Vars,1)$ |
|
|
|
if(FLAG==0){ |
|
|
|
if(TMP1[0]==0){ |
|
|
|
TMP=roundret(TMP1[1])$ |
TMP=roundret(TMP1[1])$ |
|
|
RET=append(RET,wsort(TMP1[1],Vars,map(drint,TMP1[1]*1.0),ID))$ |
RET=append(RET,wsort(TMP1[1],Vars,map(drint,TMP1[1]*1.0),ID))$ |
Line 622 def leastsq(NormMat,ExpMat,Vars,FLAG,ID){ |
|
Line 605 def leastsq(NormMat,ExpMat,Vars,FLAG,ID){ |
|
if(TMP!=[]) |
if(TMP!=[]) |
RET=append(RET,wsort(TMP1[1],Vars,TMP,ID+1))$ |
RET=append(RET,wsort(TMP1[1],Vars,TMP,ID+1))$ |
} |
} |
else{ |
else if(FLAG==1) |
|
RET=append(RET,[[ID,Vars,vtol(TMP1[1])]])$ |
TMP=vtol(TMP1[1])$ |
|
RET0=[]$ |
|
if((TMP0=fixedpoint(TMP,0))!=[]){ |
|
|
|
for(I=0;I<length(TMP0);I++) |
|
TMP=map(subst,TMP,TMP0[I][0],TMP0[I][1])$ |
|
RET0=value2(Vars,TMP)$ |
|
if(RET0!=[]) |
|
RET0=wsort(RET0,Vars,RET0,ID+1/10)$ |
|
} |
|
|
|
TMP=vtol(TMP1[1])$ |
|
if(RET0==[] && (TMP0=fixedpoint(TMP,1))!=[]){ |
|
|
|
for(I=0;I<length(TMP0);I++) |
|
TMP=map(subst,TMP,TMP0[I][0],TMP0[I][1])$ |
|
RET0=value2(Vars,TMP)$ |
|
|
|
if(RET0!=[]) |
|
RET0=wsort(RET0,Vars,RET0,ID+1/10)$ |
|
} |
|
|
|
RET=append(RET,RET0)$ |
|
} |
|
|
|
} |
} |
else if(FLAG==1) |
} |
RET=append(RET,[[ID,Vars,vtol(TMP1[1])]])$ |
|
} |
|
|
|
return RET$ |
return RET$ |
} |
} |
|
|
def unitweight(ExpMat,Vars,PolyListNum,OneMat,FLAG){ |
def unitweight1(ExpMat,Vars,PolyListNum,OneMat,FLAG){ |
|
|
RET=[]$ |
RET=[]$ |
|
|
Line 671 def unitweight(ExpMat,Vars,PolyListNum,OneMat,FLAG){ |
|
Line 627 def unitweight(ExpMat,Vars,PolyListNum,OneMat,FLAG){ |
|
|
|
ExtVars=reverse(ExtVars)$ |
ExtVars=reverse(ExtVars)$ |
|
|
NormMat0=newvect(ExpMatColNum)$ |
NormMat0=newvect(ExpMatColNum+1)$ |
for(I=0;I<ExpMatColNum;I++) |
for(I=0;I<ExpMatColNum;I++) |
NormMat0[I]=newvect(ExpMatColNum)$ |
NormMat0[I]=newvect(ExpMatColNum+1)$ |
|
|
for(I=0;I<ExpMatColNum;I++) |
for(I=0;I<ExpMatColNum;I++) |
for(J=I;J<ExpMatColNum;J++) |
for(J=I;J<ExpMatColNum;J++) |
Line 686 def unitweight(ExpMat,Vars,PolyListNum,OneMat,FLAG){ |
|
Line 642 def unitweight(ExpMat,Vars,PolyListNum,OneMat,FLAG){ |
|
for(I=0;I<ExtMatColNum;I++) |
for(I=0;I<ExtMatColNum;I++) |
NormMat1[I]=newvect(ExtMatColNum)$ |
NormMat1[I]=newvect(ExtMatColNum)$ |
|
|
|
|
WorkMat=newvect(ExtMatColNum)$ |
WorkMat=newvect(ExtMatColNum)$ |
for(I=0;I<ExtMatColNum;I++) |
for(I=0;I<ExtMatColNum;I++) |
WorkMat[I]=newvect(ExtMatColNum)$ |
WorkMat[I]=newvect(ExtMatColNum)$ |
|
|
|
|
for(I=0;I<ExpMatColNum;I++) |
for(I=0;I<ExpMatColNum;I++) |
for(J=I;J<ExpMatColNum;J++) |
for(J=I;J<ExpMatColNum;J++) |
NormMat1[I][J]=NormMat0[I][J]$ |
NormMat1[I][J]=NormMat0[I][J]$ |
Line 769 def weight(PolyList,Vars,FLAG){ |
|
Line 723 def weight(PolyList,Vars,FLAG){ |
|
ExpMat=reverse(ExpMat)$ |
ExpMat=reverse(ExpMat)$ |
ExpMat=newvect(length(ExpMat),ExpMat)$ |
ExpMat=newvect(length(ExpMat),ExpMat)$ |
|
|
TMP=unitweight(ExpMat,Vars,PolyListNum,OneMat,FLAG)$ |
TMP=unitweight1(ExpMat,Vars,PolyListNum,OneMat,FLAG)$ |
|
|
RET=append(RET,TMP[1])$ |
RET=append(RET,TMP[1])$ |
|
|
TMP0=leastsq(TMP[0],ExpMat,Vars,FLAG,3)$ |
TMP=unitweight2(TMP[0],ExpMat,Vars,FLAG,3)$ |
|
|
RET=append(RET,TMP0)$ |
RET=append(RET,TMP)$ |
|
|
ExpMat=qsort(ExpMat,junban)$ |
ExpMat=qsort(ExpMat,junban)$ |
|
|
Line 786 def weight(PolyList,Vars,FLAG){ |
|
Line 740 def weight(PolyList,Vars,FLAG){ |
|
|
|
if(size(ExpMat)[0]!=length(ExpMat2)){ |
if(size(ExpMat)[0]!=length(ExpMat2)){ |
ExpMat=newvect(length(ExpMat2),ExpMat2)$ |
ExpMat=newvect(length(ExpMat2),ExpMat2)$ |
RET=append(RET,leastsq(0,ExpMat,Vars,FLAG,5))$ |
RET=append(RET,unitweight2(0,ExpMat,Vars,FLAG,5))$ |
} |
} |
else{ |
else{ |
TMP0=map(ltov,TMP0)$ |
TMP0=map(ltov,TMP0)$ |