| version 1.1, 2003/10/15 07:06:02 |
version 1.6, 2003/11/15 06:28:21 |
|
|
| #include<defs.h> |
|
| load("solve")$ |
load("solve")$ |
| |
load("gr")$ |
| |
|
| def nonposdegchk(Res){ |
def nonposdegchk(Res){ |
| |
|
| Line 10 def nonposdegchk(Res){ |
|
| Line 10 def nonposdegchk(Res){ |
|
| return 1$ |
return 1$ |
| } |
} |
| |
|
| def extmat(Mat,OneMat,N,M,I,J){ |
|
| |
|
| if(J<N) |
def notzerovec(Vec){ |
| return Mat[I][J]$ |
|
| |
|
| if(OneMat[J][0]<=I && I<=OneMat[J][1]) |
for(I=0;I<size(Vec)[0];I++) |
| if(J==M-1) |
if(Vec[I]!=0) |
| return 1$ |
return 1$ |
| else |
|
| return -1$ |
|
| else |
|
| return 0$ |
|
| |
|
| |
return 0$ |
| } |
} |
| |
|
| def resvars(Res,Vars){ |
def resvars(Res,Vars){ |
| |
|
| ResVars=newvect(length(Vars),Vars)$ |
ResVars=newvect(length(Vars),Vars)$ |
| |
|
| for(I=0;I<length(Res);I++){ |
for(I=0;I<length(Res);I++){ |
| |
|
| for(J=0;J<size(ResVars)[0];J++) |
for(J=0;J<size(ResVars)[0];J++) |
| if(Res[I][0]==ResVars[J]) |
if(Res[I][0]==ResVars[J]) |
| break$ |
break$ |
| |
|
| ResVars[J]=Res[I][1]$ |
if(J<size(ResVars)[0]) |
| |
ResVars[J]=Res[I][1]$ |
| } |
} |
| |
|
| return(ResVars)$ |
return(ResVars)$ |
| } |
} |
| |
|
| def makeret(Res,Vars,B){ |
def makeret1(Res,Vars){ |
| |
|
| VarsNum=length(Vars)$ |
VarsNum=length(Vars)$ |
| |
|
| ResMat=newvect(VarsNum)$ |
ResVec=newvect(VarsNum,Vars)$ |
| for(I=0;I<VarsNum;I++) |
|
| ResMat[I]=newvect(2)$ |
|
| |
|
| for(I=0;I<VarsNum;I++){ |
for(F=0,I=0,M=0;I<length(Res);I++){ |
| ResMat[I][0]=Vars[I]$ |
|
| ResMat[I][1]=Vars[I]$ |
|
| } |
|
| |
|
| for(I=0;I<length(Res);I++){ |
|
| |
|
| for(J=0;J<size(ResMat)[0];J++) |
for(J=0;J<VarsNum;J++) |
| if(Res[I][0]==ResMat[J][0]) |
if(Res[I][0]==Vars[J]) |
| break$ |
break$ |
| |
|
| if(J<VarsNum) |
if(J<VarsNum){ |
| ResMat[J][1]=Res[I][1]*B$ |
ResVec[J]=Res[I][1]$ |
| |
|
| |
if(F==0 && type(ResVec[J])==1){ |
| |
if(M==0) |
| |
M=ResVec[J]$ |
| |
else |
| |
if(ResVec[J]<M) |
| |
M=ResVec[J]$ |
| |
} |
| |
else |
| |
F=1$ |
| |
} |
| |
|
| } |
} |
| |
|
| |
if(F==0) |
| |
for(I=0;I<VarsNum;I++) |
| |
ResVec[I]=ResVec[I]/M*1.0$ |
| |
|
| for(I=0;I<VarsNum;I++) |
for(I=0;I<VarsNum;I++) |
| for(J=0;J<length(Vars);J++) |
for(J=0;J<length(Vars);J++) |
| ResMat[I][1]=subst(ResMat[I][1],Vars[J], |
ResVec[I]=subst(ResVec[I],Vars[J], |
| strtov(rtostr(Vars[J])+"_deg"))$ |
strtov(rtostr(Vars[J])+"_deg"))$ |
| |
|
| ResMat=map(vtol,ResMat)$ |
ResVec=cons(F,vtol(ResVec))$ |
| return(vtol(ResMat))$ |
return ResVec$ |
| |
|
| } |
} |
| |
|
| def afo(A,B){ |
def junban(A,B){ |
| |
|
| for(I=0;I<size(A)[0];I++){ |
for(I=0;I<size(A)[0];I++){ |
| if(A[I]<B[I]) |
if(A[I]<B[I]) |
|
|
| return 0$ |
return 0$ |
| } |
} |
| |
|
| def weight(PolyList,Vars){ |
def roundret(V){ |
| |
|
| dp_ord(2)$ |
VN=length(V)$ |
| |
RET0=newvect(VN,V)$ |
| |
|
| |
for(I=1;I<1000;I++){ |
| |
RET1=I*RET0$ |
| |
for(J=0;J<VN;J++){ |
| |
X=drint(RET1[J])$ |
| |
if(dabs(X-RET1[J])<0.2) |
| |
RET1[J]=X$ |
| |
else |
| |
break$ |
| |
} |
| |
if(J==VN) |
| |
break$ |
| |
} |
| |
|
| |
if(I==1000) |
| |
return []$ |
| |
else |
| |
return RET1$ |
| |
} |
| |
|
| |
def chkou(L,ExpMat,CHAGORD){ |
| |
|
| |
P=1$ |
| |
F=ExpMat[L]$ |
| |
|
| |
for(I=0;I<L;I++){ |
| |
Q=ExpMat[L][CHAGORD[I]]$ |
| |
for(J=0;J<size(ExpMat[0])[0];J++){ |
| |
ExpMat[L][CHAGORD[J]]=red((ExpMat[I][CHAGORD[I]] |
| |
*ExpMat[L][CHAGORD[J]]- |
| |
Q*ExpMat[I][CHAGORD[J]])/P)$ |
| |
} |
| |
|
| |
P=ExpMat[I][CHAGORD[I]]$ |
| |
} |
| |
|
| |
for(J=0;J<size(ExpMat[0])[0];J++) |
| |
if(ExpMat[L][CHAGORD[J]]!=0) |
| |
break$ |
| |
|
| |
if(J==size(ExpMat[0])[0]) |
| |
return L$ |
| |
else{ |
| |
TMP=CHAGORD[L]$ |
| |
CHAGORD[L]=CHAGORD[J]$ |
| |
CHAGORD[J]=TMP$ |
| |
return (L+1)$ |
| |
} |
| |
} |
| |
|
| |
def qcheck0(PolyList,Vars){ |
| |
|
| |
RET=[]$ |
| PolyListNum=length(PolyList)$ |
PolyListNum=length(PolyList)$ |
| |
VarsNum=length(Vars)$ |
| |
|
| ExpMat=[]$ |
ExpMat=newvect(VarsNum)$ |
| for(I=0;I<PolyListNum;I++) |
CHAGORD=newvect(VarsNum)$ |
| for(Poly=dp_ptod(PolyList[I],Vars);Poly!=0;Poly=dp_rest(Poly)) |
for(I=0;I<VarsNum;I++) |
| ExpMat=cons(dp_etov(dp_ht(Poly)),ExpMat)$ |
CHAGORD[I]=I$ |
| |
|
| ExpMat=reverse(ExpMat)$ |
L=0$ |
| ExpMat=newvect(length(ExpMat),ExpMat)$ |
for(I=0;I<PolyListNum;I++){ |
| |
Poly=dp_ptod(PolyList[I],Vars)$ |
| |
BASE0=dp_etov(dp_ht(Poly))$ |
| |
Poly=dp_rest(Poly)$ |
| |
for(;Poly!=0;Poly=dp_rest(Poly)){ |
| |
ExpMat[L]=dp_etov(dp_ht(Poly))-BASE0$ |
| |
L=chkou(L,ExpMat,CHAGORD)$ |
| |
if(L==VarsNum-1){ |
| |
RET=cons(ExpMat,RET)$ |
| |
RET=cons(CHAGORD,RET)$ |
| |
RET=cons(L,RET)$ |
| |
return RET$ |
| |
} |
| |
} |
| |
} |
| |
|
| |
RET=cons(ExpMat,RET)$ |
| |
RET=cons(CHAGORD,RET)$ |
| |
RET=cons(L,RET)$ |
| |
return RET$ |
| |
} |
| |
|
| ExpMatRowNum=size(ExpMat)[0]$ |
def inner(A,B){ |
| ExpMatColNum=size(ExpMat[0])[0]$ |
|
| ExtMatRowNum=ExpMatRowNum$ |
|
| ExtMatColNum=ExpMatColNum+PolyListNum$ |
|
| |
|
| OneMat=newmat(ExtMatColNum,2)$ |
SUM=0$ |
| |
for(I=0;I<size(A)[0];I++) |
| |
SUM+=A[I]*B[I]$ |
| |
|
| for(I=0;I<ExpMatColNum;I++){ |
return SUM$ |
| OneMat[I][0]=0$ |
} |
| OneMat[I][1]=ExtMatRowNum-1$ |
|
| |
def checktd(PolyList,Vars,ResVars){ |
| |
|
| |
PolyListNum=length(PolyList)$ |
| |
VarsNum=length(Vars)$ |
| |
|
| |
L=0$ |
| |
for(I=0;I<PolyListNum;I++){ |
| |
Poly=dp_ptod(PolyList[I],Vars)$ |
| |
J0=inner(dp_etov(dp_ht(Poly)),ResVars)$ |
| |
Poly=dp_rest(Poly)$ |
| |
for(;Poly!=0;Poly=dp_rest(Poly)) |
| |
if(J0!=inner(dp_etov(dp_ht(Poly)),ResVars)) |
| |
return 0$ |
| } |
} |
| |
|
| |
return 1$ |
| |
} |
| |
|
| for(I=ExpMatColNum,SUM=0;I<ExtMatColNum;I++){ |
def getgcd(A,B){ |
| OneMat[I][0]=SUM$ |
|
| SUM=SUM+nmono(PolyList[I-ExpMatColNum])$ |
VarsNumA=length(A)$ |
| OneMat[I][1]=SUM-1$ |
VarsNumB=length(B)$ |
| |
|
| |
C=newvect(VarsNumB,B)$ |
| |
|
| |
for(I=0;I<VarsNumA;I++){ |
| |
|
| |
for(J=0;J<VarsNumB;J++) |
| |
if(C[J]==A[I][0]) |
| |
break$ |
| |
|
| |
C[J]=A[I][1]$ |
| } |
} |
| |
|
| NormMat=newmat(ExtMatColNum-1,ExtMatColNum)$ |
D=0$ |
| |
for(I=0;I<VarsNumB;I++) |
| |
D=gcd(D,C[I])$ |
| |
|
| for(I=0;I<ExtMatColNum-1;I++) |
if(D!=0){ |
| for(J=0;J<ExtMatColNum-1;J++){ |
|
| ST=MAX(OneMat[I][0],OneMat[J][0])$ |
|
| ED=MIN(OneMat[I][1],OneMat[J][1])$ |
|
| if(ST>ED) |
|
| continue$ |
|
| for(K=ST;K<=ED;K++){ |
|
| NormMat[I][J]=NormMat[I][J]+ |
|
| extmat(ExpMat,OneMat,ExpMatColNum,ExtMatColNum,K,I)* |
|
| extmat(ExpMat,OneMat,ExpMatColNum,ExtMatColNum,K,J)$ |
|
| } |
|
| } |
|
| |
|
| for(I=0;I<ExtMatColNum-1;I++){ |
for(I=0;I<VarsNumB;I++) |
| ST=MAX(OneMat[I][0],OneMat[ExtMatColNum-1][0])$ |
C[I]=red(C[I]/D)$ |
| ED=MIN(OneMat[I][1],OneMat[ExtMatColNum-1][1])$ |
|
| if(ST>ED) |
|
| continue$ |
|
| |
|
| for(K=ST;K<=ED;K++){ |
|
| NormMat[I][ExtMatColNum-1]=NormMat[I][ExtMatColNum-1]+ |
|
| extmat(ExpMat,OneMat,ExpMatColNum,ExtMatColNum,K,I)* |
|
| extmat(ExpMat,OneMat,ExpMatColNum,ExtMatColNum,K,ExtMatColNum-1)$ |
|
| } |
|
| } |
} |
| |
|
| ExtVars=Vars$ |
for(L=1,D=0,I=0;I<VarsNumB;I++){ |
| for(I=0;I<PolyListNum-1;I++) |
if(type(TMP=dn(C[I]))==1) |
| ExtVars=append(ExtVars,[uc()])$ |
L=ilcm(L,TMP)$ |
| |
|
| |
if(type(TMP=nm(C[I]))==1) |
| |
D=igcd(D,TMP)$ |
| |
} |
| |
|
| |
for(I=0;I<VarsNumB;I++) |
| |
C[I]=C[I]*L$ |
| |
|
| |
if(D!=0) |
| |
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[I][0]=B[I]$ |
| |
RET[I][1]=C[I]$ |
| |
} |
| |
|
| |
return vtol(map(vtol,RET))$ |
| |
} |
| |
|
| |
def qcheck(PolyList,Vars){ |
| |
|
| |
RET=[]$ |
| |
Res=qcheck0(PolyList,Vars)$ |
| |
VarsNum=length(Vars)$ |
| |
|
| |
IndNum=Res[0]$ |
| |
CHAGORD=Res[1]$ |
| |
ExpMat=Res[2]$ |
| |
|
| SolveList=[]$ |
SolveList=[]$ |
| for(I=0;I<ExtMatColNum-1;I++){ |
for(I=0;I<IndNum;I++){ |
| TMP=0$ |
TMP=0$ |
| for(J=0;J<ExtMatColNum-1;J++) |
for(J=0;J<VarsNum;J++) |
| TMP=TMP+NormMat[I][J]*ExtVars[J]$ |
TMP+=ExpMat[I][CHAGORD[J]]*Vars[CHAGORD[J]]$ |
| |
|
| TMP=TMP-NormMat[I][ExtMatColNum-1]$ |
|
| SolveList=cons(TMP,SolveList)$ |
SolveList=cons(TMP,SolveList)$ |
| } |
} |
| |
|
| ReaVars=vars(SolveList)$ |
VarsList=[]$ |
| Res=solve(SolveList,reverse(ExtVars))$ |
for(I=0;I<VarsNum;I++) |
| |
VarsList=cons(Vars[CHAGORD[I]],VarsList)$ |
| |
|
| |
Rea=vars(SolveList)$ |
| |
Res=solve(reverse(SolveList),reverse(VarsList))$ |
| |
|
| if(nonposdegchk(Res)){ |
if(nonposdegchk(Res)){ |
| |
|
| ResVars=resvars(Res,ExtVars)$ |
Res=getgcd(Res,Rea)$ |
| |
ResVars=resvars(Res,Vars)$ |
| |
|
| for(I=0;I<ExtMatRowNum;I++){ |
if(checktd(PolyList,Vars,ResVars)==1){ |
| TMP=0$ |
|
| for(J=0;J<ExtMatColNum-1;J++) |
|
| if((K=extmat(ExpMat,OneMat,ExpMatColNum,ExtMatColNum,I,J))!=0) |
|
| TMP=TMP+K*ResVars[J]$ |
|
| |
|
| if(TMP!=extmat(ExpMat,OneMat,ExpMatColNum,ExtMatColNum,I,ExtMatColNum-1)) |
|
| break$ |
|
| } |
|
| |
|
| if(I==ExtMatRowNum){ |
for(J=0;J<length(Vars);J++) |
| print("complitely homogenized")$ |
ResVars=map(subst,ResVars,Vars[J], |
| return(makeret(Res,Vars,1))$ |
strtov(rtostr(Vars[J])+"_deg"))$ |
| |
|
| |
RET=cons([vtol(ResVars),ResVars,[]],RET)$ |
| |
return cons(1,RET)$ |
| } |
} |
| else |
else |
| print(makeret(Res,Vars,1.0))$ |
return cons(0,RET)$ |
| } |
} |
| |
else |
| |
return cons(0,RET)$ |
| |
|
| ExpMat=qsort(ExpMat,afo)$ |
} |
| ExpMat2=[]$ |
|
| for(I=0;I<size(ExpMat)[0];I++) |
|
| if(car(ExpMat2)!=ExpMat[I]) |
|
| ExpMat2=cons(ExpMat[I],ExpMat2)$ |
|
| |
|
| ExpMat=newvect(length(ExpMat2),ExpMat2)$ |
def leastsq(ExpMat,Vars){ |
| |
|
| ExpMatRowNum=size(ExpMat)[0]$ |
ExpMatRowNum=size(ExpMat)[0]$ |
| ExpMatColNum=size(ExpMat[0])[0]$ |
ExpMatColNum=size(ExpMat[0])[0]$ |
| |
|
| Line 201 def weight(PolyList,Vars){ |
|
| Line 315 def weight(PolyList,Vars){ |
|
| for(I=0;I<ExpMatColNum;I++) |
for(I=0;I<ExpMatColNum;I++) |
| for(J=0;J<ExpMatColNum;J++) |
for(J=0;J<ExpMatColNum;J++) |
| for(K=0;K<ExpMatRowNum;K++) |
for(K=0;K<ExpMatRowNum;K++) |
| NormMat[I][J]=NormMat[I][J]+ExpMat[K][I]*ExpMat[K][J]$ |
NormMat[I][J]+=ExpMat[K][I]*ExpMat[K][J]$ |
| |
|
| for(I=0;I<ExpMatColNum;I++) |
for(I=0;I<ExpMatColNum;I++) |
| for(K=0;K<ExpMatRowNum;K++) |
for(J=0;J<ExpMatRowNum;J++) |
| NormMat[I][ExpMatColNum]=NormMat[I][ExpMatColNum]+ExpMat[K][I]$ |
NormMat[I][ExpMatColNum]+=ExpMat[J][I]$ |
| |
|
| SolveList=[]$ |
SolveList=[]$ |
| for(I=0;I<ExpMatColNum;I++){ |
for(I=0;I<ExpMatColNum;I++){ |
| TMP=0$ |
TMP=0$ |
| for(J=0;J<ExpMatColNum;J++) |
for(J=0;J<ExpMatColNum;J++) |
| TMP=TMP+NormMat[I][J]*Vars[J]$ |
TMP+=NormMat[I][J]*Vars[J]$ |
| |
|
| TMP=TMP-NormMat[I][ExpMatColNum]$ |
TMP-=NormMat[I][ExpMatColNum]$ |
| SolveList=cons(TMP,SolveList)$ |
SolveList=cons(TMP,SolveList)$ |
| } |
} |
| |
|
| |
Rea=vars(SolveList)$ |
| Res=solve(SolveList,Vars)$ |
Res=solve(SolveList,Vars)$ |
| if(nonposdegchk(Res)) |
|
| return(makeret(Res,Vars,1.0))$ |
|
| |
|
| Ret=[]$ |
if(nonposdegchk(Res)){ |
| |
Res=getgcd(Res,Rea)$ |
| |
TMP1=makeret1(Res,Vars); |
| |
if(car(TMP1)==0){ |
| |
TMP2=roundret(cdr(TMP1)); |
| |
TMP3=map(drint,cdr(TMP1))$ |
| |
return([cdr(TMP1),newvect(length(TMP3),TMP3),TMP2])$ |
| |
} |
| |
else |
| |
return([cdr(TMP1),[],[]])$ |
| |
} |
| |
|
| |
} |
| |
|
| |
def weight(PolyList,Vars){ |
| |
|
| |
Vars0=vars(PolyList)$ |
| |
Vars1=[]$ |
| for(I=0;I<length(Vars);I++) |
for(I=0;I<length(Vars);I++) |
| Ret=cons([Vars[I],1.0],Ret)$ |
if(member(Vars[I],Vars0)) |
| |
Vars1=cons(Vars[I],Vars1)$ |
| |
|
| return reverse(Ret)$ |
Vars=reverse(Vars1)$ |
| |
|
| |
RET=[]$ |
| |
|
| |
TMP=qcheck(PolyList,Vars)$ |
| |
|
| |
if(car(TMP)==1){ |
| |
RET=cdr(TMP)$ |
| |
RET=cons(Vars,RET)$ |
| |
RET=cons(1,RET)$ |
| |
return RET$ |
| |
} |
| |
|
| |
dp_ord(2)$ |
| |
|
| |
PolyListNum=length(PolyList)$ |
| |
VPolyList=newvect(PolyListNum,PolyList)$ |
| |
|
| |
ExpMat=[]$ |
| |
for(I=0;I<PolyListNum;I++) |
| |
for(Poly=dp_ptod(VPolyList[I],Vars); |
| |
Poly!=0;Poly=dp_rest(Poly)){ |
| |
Exp=dp_etov(dp_ht(Poly))$ |
| |
if(notzerovec(Exp)) |
| |
ExpMat=cons(Exp,ExpMat)$ |
| |
} |
| |
|
| |
ExpMat=reverse(ExpMat)$ |
| |
ExpMat=newvect(length(ExpMat),ExpMat)$ |
| |
|
| |
/* first */ |
| |
|
| |
RET=cons(leastsq(ExpMat,Vars),RET)$ |
| |
|
| |
/* second */ |
| |
|
| |
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=cons(leastsq(ExpMat,Vars),RET)$ |
| |
} |
| |
|
| |
RET=cons(Vars,reverse(RET))$ |
| |
RET=cons(0,RET)$ |
| |
return RET$ |
| } |
} |
| |
|
| end$ |
end$ |