[BACK]Return to module_syz.rr CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-contrib / testing / noro

Annotation of OpenXM/src/asir-contrib/testing/noro/module_syz.rr, Revision 1.3

1.1       noro        1: module newsyz;
                      2:
1.3     ! noro        3: localf module_syz;
        !             4: localf simplify_syz, icont, mod, remove_cont,ordcheck;
        !             5: localf complsb, complsb_sd, sortlsb, find_pos, find_pos, reduce, lres_setup, dpm_sort1, comp_pos;
        !             6: localf fres,minres,sres,minsres,lres, create_base_ord, simplify_k, simplify_by_k, remove_k, remove_k1, extract_nonzero;
        !             7: localf nonzero, phi, syz_check, renumber_pos, compress, compress_h;
        !             8: localf syz_check0,phi0,todpmlist,dpmlisttollist;
1.1       noro        9:
                     10: /* F : a list of (lists or polynomials),
                     11:    V : a variable list, H >1=> over GF(H), H=0,1=> over Q
                     12:    O : term order
                     13:    return: [GS,G]
                     14:    GS : a GB of syz(F) wrt [1,O] (POT), G: a GB of F wrt [1,O]
                     15: */
                     16:
1.3     ! noro       17: // return [dpmlist F,rank N]
        !            18: def todpmlist(F,V)
1.1       noro       19: {
1.3     ! noro       20:   K = length(F);
        !            21:   for ( I = 0; I < K; I++ ) if ( F[I] ) break;
        !            22:   if ( I == K ) return [];
        !            23:   if ( type(F[I]) <= 2 ) {
        !            24:     // F is a polynimial list
        !            25:     F = map(dp_ptod,F,V);
        !            26:     F = map(dpm_dptodpm,F,1);
        !            27:     N = 1;
        !            28:   } else if ( type(F[I]) == 9 ) {
        !            29:     // F is a dpoly list
        !            30:     F = map(dpm_dptodpm,F,1);
        !            31:     N = 1;
        !            32:   } else if ( type(F[I]) == 4 ) {
        !            33:     // F is a list of poly lists
        !            34:     N = length(F[0]);
        !            35:     F = map(dpm_ltod,F,V);
        !            36:   } else if ( type(F[I]) == 26 ) {
        !            37:     // F is a DPM list
        !            38:     for ( N = 0, T = F; T != []; T = cdr(T) ) {
        !            39:       for ( A = car(T); A; A = dpm_rest(A) ) {
        !            40:         N1 = dpm_hp(A);
        !            41:         if ( N1 > N ) N = N1;
        !            42:       }
        !            43:     }
        !            44:   } else {
        !            45:     error("todpmlist: arugument type is invalid.");
        !            46:   }
        !            47:   return [F,N];
        !            48: }
        !            49:
        !            50: def module_syz(F,V,H,Ord)
        !            51: {
        !            52:   if ( type(Weyl=getopt(weyl)) == -1 ) Weyl = 0;
        !            53:   if ( type(DP=getopt(dp)) == -1 ) DP = 0;
        !            54:   if ( type(F4=getopt(f4)) == -1 ) F4 = 0;
        !            55:   dp_ord(Ord);
        !            56:   K = length(F);
        !            57:   for ( I = 0; I < K; I++ ) if ( F[I] ) break;
        !            58:   if ( I == K ) return [[],[],[]];
        !            59:   L = todpmlist(F,V);
        !            60:   F = L[0]; N = L[1];
        !            61:   dp_ord([1,Ord]);
        !            62:   B = [];
        !            63:   for ( I = 0; I < K; I++ ) {
        !            64:     B = cons(F[I]+dpm_dptodpm(dp_ptod(1,V),N+I+1),B);
        !            65:   }
        !            66:   B = reverse(B);
        !            67:   if ( Weyl )
        !            68:     G = nd_weyl_gr(B,V,0,[1,Ord]|dp=1,homo=H);
        !            69:   else if ( F4 ) {
        !            70: //    G = nd_f4(B,V,0,[1,Ord]|dp=1,homo=H,nora=1);
        !            71:     Ind = 0;
        !            72:     while ( 1 ) {
        !            73:       G = nd_f4_trace(B,V,H,-lprime(Ind),[1,Ord]|dp=1);
        !            74:       if ( G ) break;
        !            75:       else Ind++;
        !            76:     }
        !            77:   } else
        !            78:     G = nd_gr(B,V,0,[1,Ord]|dp=1,homo=H);
        !            79:   G0 = []; S0 = []; Gen0 = [];
        !            80:   for ( T = G; T != []; T = cdr(T) ) {
        !            81:     H = car(T);
        !            82:     if ( dpm_hp(H) > N ) {
        !            83:       S0 = cons(dpm_shift(H,N),S0);
        !            84:     } else {
        !            85:       L = dpm_split(H,N);
        !            86:       G0 = cons(L[0],G0);
        !            87:       Gen0 = cons(dpm_shift(L[1],N),Gen0);
1.1       noro       88:        }
1.3     ! noro       89:   }
        !            90: #if 0
        !            91:   S0 = reverse(S0); G0 = reverse(G0); Gen0 = reverse(Gen0);
        !            92: #endif
        !            93:   if ( !DP ) {
        !            94:     S0 = map(dpm_dtol,S0,V); G0 = map(dpm_dtol,G0,V); Gen0 = map(dpm_dtol,Gen0,V);
        !            95:   }
        !            96:   return [S0,G0,Gen0];
        !            97: }
        !            98:
        !            99: def fres(F,V,H,O)
        !           100: {
        !           101:   if ( type(Weyl=getopt(weyl)) == -1 ) Weyl = 0;
        !           102:   if ( type(F4=getopt(f4)) == -1 ) F4 = 0;
        !           103:   if ( type(DP=getopt(dp)) == -1 ) DP = 0;
        !           104:   L = todpmlist(F,V); F = L[0];
        !           105:   R = [F];
        !           106:   while ( 1 ) {
        !           107:     if ( Weyl )
        !           108:       L = module_syz(car(R),V,H,O|weyl=1,dp=1,f4=F4);
        !           109:     else
        !           110:       L = module_syz(car(R),V,H,O|dp=1,f4=F4);
        !           111:     L = L[0];
        !           112:     L = ordcheck(L,V);
        !           113:     if ( L == [] ) {
        !           114:       if ( DP ) return R;
        !           115:       else return map(dpmlisttollist,R,V);
        !           116:     }
        !           117:     R = cons(L,R);
        !           118:   }
        !           119: }
        !           120:
        !           121: def minres(F,V,H,O)
        !           122: {
        !           123:   if ( type(Weyl=getopt(weyl)) == -1 ) Weyl = 0;
        !           124:   if ( type(F4=getopt(f4)) == -1 ) F4 = 0;
        !           125:   if ( type(DP=getopt(dp)) == -1 ) DP = 0;
        !           126:   L = todpmlist(F,V); F = L[0];
        !           127:   R = [F];
        !           128:   while ( 1 ) {
        !           129:     if ( Weyl )
        !           130:       L = module_syz(car(R),V,H,O|weyl=1,dp=1,f4=F4);
        !           131:     else
        !           132:       L = module_syz(car(R),V,H,O|dp=1,f4=F4);
        !           133:     L = L[0];
        !           134:     L = ordcheck(L,V);
        !           135:     if ( L == [] ) break;
        !           136:     S = dpm_simplify_syz(L,R[0]);
        !           137:     if ( S[0] == [] && S[1] == [] ) {
        !           138:       R = cdr(R); break;
        !           139:     }
        !           140:     R = append([S[0],S[1]],cdr(R));
        !           141:     if ( R[0] == [] ) {
        !           142:       R = cdr(R); break;
        !           143:     }
        !           144:   }
        !           145:   if ( DP ) return R;
        !           146:   else return map(dpmlisttollist,R,V);
        !           147: }
        !           148:
        !           149: def dpmlisttollist(F,V)
        !           150: {
        !           151:   return map(dpm_dtol,F,V);
        !           152: }
        !           153:
        !           154: def sres(F,V,H,Ord)
        !           155: {
        !           156:   if ( type(DP=getopt(dp)) == -1 ) DP = 0;
        !           157:   dpm_set_schreyer(0);
        !           158:   dp_ord(Ord);
        !           159:   K = length(F);
        !           160:   K = length(F);
        !           161:   for ( I = 0; I < K; I++ ) if ( F[I] ) break;
        !           162:   if ( I == K ) return [[],[],[]];
        !           163:   L = todpmlist(F,V);
        !           164:   F = L[0]; N = L[1];
        !           165:   G = nd_gr(F,V,H,[0,Ord]|dp=1);
        !           166:   G = reverse(G);
        !           167:   R = [G];
        !           168:   dp_ord([0,Ord]);
        !           169:   while ( 1 ) {
        !           170:     S = dpm_schreyer_base(R[0]);
        !           171:     print(["length",length(S)]);
        !           172:     if ( S == [] ) break;
        !           173:     else R = cons(S,R);
        !           174:   }
        !           175:   dp_ord([0,0]);
        !           176:   if ( DP ) return R;
        !           177:   else return map(dpmlisttollist,R,V);
        !           178: }
        !           179:
        !           180: def minsres(F,V,H,Ord)
        !           181: {
        !           182:   if ( type(DP=getopt(dp)) == -1 ) DP = 0;
        !           183:   R = sres(F,V,H,Ord|dp=1);
        !           184:   R = ltov(R);
        !           185:   M = length(R);
        !           186:   for ( I = 0; I < M; I++ ) R[I] = map(dpm_sort,R[I]);
        !           187:   R = vtol(R);
        !           188:   for ( T = R, U = []; length(T) >= 2; ) {
        !           189:     Z = dpm_simplify_syz(T[0],T[1]);
        !           190:     U = cons(Z[0],U);
        !           191:     T = cons(Z[1],cdr(cdr(T)));
        !           192:   }
        !           193:   U = cons(T[0],U);
        !           194:   if ( DP ) return U;
        !           195:   else return map(dpmlisttollist,U,V);
        !           196: }
        !           197:
        !           198: def ordcheck(D,V)
        !           199: {
        !           200:   B=map(dpm_dtol,D,V);
        !           201:   dp_ord([1,0]);
        !           202:   D = map(dpm_sort,D);
        !           203:   D1 = map(dpm_ltod,B,V);
        !           204:   if ( D != D1 )
        !           205:     print("afo");
        !           206:   return D1;
        !           207: }
        !           208:
        !           209: def complsb(A,B)
        !           210: {
        !           211:   AL = A[3]; AD = A[4];
        !           212:   BL = B[3]; BD = B[4];
        !           213:   if ( AD > BD ) return 1;
        !           214:   else if ( AD < BD ) return -1;
        !           215:   else if ( AL < BL ) return 1;
        !           216:   else if ( AL > BL ) return -1;
        !           217:   else return 0;
        !           218: }
        !           219:
        !           220: def complsb_sd(A,B)
        !           221: {
        !           222:   AL = A[3]; AD = A[4];
        !           223:   BL = B[3]; BD = B[4];
        !           224:   if ( AD-AL > BD-BL ) return 1;
        !           225:   else if ( AD-AL < BD-BL ) return -1;
        !           226:   else if ( AL > BL ) return 1;
        !           227:   else if ( AL < BL ) return -1;
        !           228:   else return 0;
        !           229: }
        !           230:
        !           231: def sortlsb(A)
        !           232: {
        !           233:   S = [];
        !           234:   N = length(A);
        !           235:   for ( I = 0; I < N; I++ ) S = append(cdr(vtol(A[I])),S);
        !           236: //  S = qsort(S,newsyz.complsb_sd);
        !           237:   S = qsort(S,newsyz.complsb);
        !           238:   return S;
        !           239: }
        !           240: /* D=[in,sum,deg,lev,ind] */
        !           241: /* B=[0 B1 B2 ...] */
        !           242: /* C=[0 C1 C2 ...] */
        !           243: /* H=[0 H1 H2 ...] */
        !           244: /* Z=[0 Z1 Z2 ...] */
        !           245: /* Zi=[0 L1 L2 ...] */
        !           246: /* Lj=[I1,I2,...] */
        !           247: /* One=<<0,...,0>> */
        !           248:
        !           249: extern Rtime,Stime,Ptime$
        !           250:
        !           251: // B is sorted wrt positon
        !           252: def find_pos(HF,B)
        !           253: {
        !           254:   Len = length(B);
        !           255:   Pos = dpm_hp(HF);
        !           256:   First = 0; Last = Len-1;
        !           257:   if ( B[First][0] == HF ) return B[First][2];
        !           258:   if ( B[Last][0] == HF ) return B[Last][2];
        !           259:   while ( 1 ) {
        !           260:     Mid = idiv(First+Last,2);
        !           261:     PosM = dpm_hp(B[Mid][0]);
        !           262:     if ( PosM == Pos ) break;
        !           263:     else if ( PosM < Pos )
        !           264:       First = Mid;
        !           265:     else
        !           266:       Last = Mid;
        !           267:   }
        !           268:   for ( I = Mid; I < Len && dpm_hp(B[I][0]) == Pos; I++ )
        !           269:     if ( HF == B[I][0] ) return B[I][2];
        !           270:   for ( I = Mid-1; I >= 1 && dpm_hp(B[I][0]) == Pos; I-- )
        !           271:     if ( HF == B[I][0] ) return B[I][2];
        !           272:   error("find_pos : cannot happen");
        !           273: }
        !           274:
        !           275: def reduce(D,B,Bpos,C,H,Z,K,Kind,G,One,Top)
        !           276: {
        !           277:   M = D[0]; Ind = D[2]; I = D[3];
        !           278:   if ( I == 1 ) {
        !           279:     C[I][Ind] = G[Ind];
        !           280:     dpm_insert_to_zlist(Z[1],dpm_hp(G[Ind]),Ind);
        !           281:     H[I][Ind] = G[Ind];
        !           282:   } else {
        !           283:     /* M is in F(I-1) => phi(M) is in F(I-2) */
        !           284:     /* reduction in F(I-2) */
        !           285:     T0 = time()[0];
        !           286:     dpm_set_schreyer_level(I-2);
        !           287:     CI = C[I-1]; ZI = Z[I-1]; BI = B[I-1]; BposI = Bpos[I-1];
        !           288:     Len = size(CI);
        !           289:     T=dpm_hc(M); EM=dpm_hp(M);
        !           290:     XiM = T*dpm_ht(CI[EM]);
        !           291:     EXiM = dpm_hp(XiM);
        !           292:     ZIE = ZI[EXiM];
        !           293:     for ( ZIE = ZI[EXiM]; ZIE != []; ZIE = cdr(ZIE) ) {
        !           294:       J = car(ZIE);
        !           295:       if ( J > EM && dpm_redble(XiM,dpm_ht(CI[J])) ) break;
        !           296:     }
        !           297:     Ptime += time()[0]-T0;
        !           298:     T0 = time()[0];
        !           299:     QR = dpm_sp_nf(CI,ZI,EM,J|top=Top);
        !           300:     Rtime += time()[0]-T0;
        !           301:     G = QR[0]; F = QR[1];
        !           302:     if ( F ) {
        !           303:       HF = dpm_ht(F); EF = dpm_hp(HF);
        !           304:       /* find HF in B[I-1] */
        !           305:     T0 = time()[0];
        !           306:     J = find_pos(HF,BposI);
        !           307:     Stime += time()[0]-T0;
        !           308:       /* F=Ret[0]*Ret[1] */
        !           309:       Ret = dpm_remove_cont(F);
        !           310:       CI[J] = Ret[1];
        !           311:       Kind[I-1][J] = 2;
        !           312:       dpm_insert_to_zlist(ZI,EF,J);
        !           313:       dpm_set_schreyer_level(I-1);
        !           314:       Tail = -Ret[0]*dpm_dptodpm(One,J);
        !           315:       G += Tail;
        !           316:       dpm_set_schreyer_level(0);
        !           317:       Ret = dpm_remove_cont(G); G = Ret[1];
        !           318:       C[I][Ind] = G;
        !           319:       Kind[I][Ind] = 1;
        !           320:       K[I] = cons([G,Tail],K[I]);
        !           321:       dpm_insert_to_zlist(Z[I],EM,Ind);
        !           322:       /* level <- 0 */
        !           323:       BI[J][3] = 0;
        !           324:     } else {
        !           325:       Kind[I][Ind] = 0;
        !           326:       Ret = dpm_remove_cont(G); G = Ret[1];
        !           327:       H[I][Ind] = G;
        !           328:       C[I][Ind] = G;
        !           329:       dpm_insert_to_zlist(Z[I],EM,Ind);
        !           330:     }
        !           331:   }
        !           332: }
        !           333:
        !           334: def lres_setup(F,V,H,Ord)
        !           335: {
        !           336:   dpm_set_schreyer(0);
        !           337:   dp_ord(Ord);
        !           338:   K = length(F);
        !           339:   if ( type(F[0]) <= 2 ) {
        !           340:     // F is a polynimial list
        !           341:     F = map(dp_ptod,F,V);
        !           342:     F = map(dpm_dptodpm,F,1);
        !           343:     N = 1;
        !           344:   } else if ( type(F[0]) == 9 ) {
        !           345:     // F is a dpoly list
        !           346:     F = map(dpm_dptodpm,F,1);
        !           347:     N = 1;
        !           348:   } else if ( type(F[0]) == 4 ) {
        !           349:     // F is a list of poly lists
        !           350:     N = length(F[0]);
        !           351:     F = map(dpm_ltod,F,V);
        !           352:   } else if ( type(F[0]) == 26 ) {
        !           353:     // F is a DPM list
        !           354:     for ( N = 0, T = F; T != []; T = cdr(T) ) {
        !           355:       for ( A = car(T); A; A = dpm_rest(A) ) {
        !           356:         N1 = dpm_hp(A);
        !           357:         if ( N1 > N ) N = N1;
        !           358:       }
        !           359:     }
        !           360:   } else {
        !           361:     error("lres_setup: arugument type is invalid.");
        !           362:   }
        !           363:   G = nd_gr(F,V,H,[0,Ord]|dp=1);
        !           364:   G = reverse(G);
        !           365:   dp_ord([0,Ord]);
        !           366:   One = dp_ptod(1,V);
        !           367:   return [G,One];
        !           368: }
        !           369:
        !           370: def dpm_sort1(L)
        !           371: {
        !           372:   return [dpm_sort(L[0]),L[1]];
        !           373: }
        !           374:
        !           375: def comp_pos(A,B)
        !           376: {
        !           377:   PA = dpm_hp(A[0]); PB = dpm_hp(B[0]);
        !           378:   if ( PA > PB ) return 1;
        !           379:   else if ( PA < PB ) return -1;
        !           380:   else return 0;
        !           381: }
        !           382:
        !           383: def lres(F,V,H,Ord)
        !           384: {
        !           385:   T0 = time();
        !           386:   if ( type(Top=getopt(top)) == -1 ) Top = 0;
        !           387:   if ( type(NoSimpK=getopt(nosimpk)) == -1 ) NoSimpK = 0;
        !           388:   if ( type(NoPreProj=getopt(nopreproj)) == -1 ) NoPreProj = 0;
        !           389:   Rtime = Stime = Ptime = 0;
        !           390:   L = lres_setup(F,V,H,Ord);
        !           391:   G = L[0];
        !           392:   One = L[1];
        !           393:   F = dpm_schreyer_frame(G);
        !           394:   G = ltov(cons(0,L[0]));
        !           395:   F = reverse(F);
        !           396:   F = ltov(F);
        !           397:   N = length(F);
        !           398:   for ( I = 0; I < N; I++ ) {
        !           399:     FI = F[I]; FI[0] = [];
        !           400:     FI = map(ltov,FI);
        !           401:     F[I] = FI;
        !           402:   }
        !           403:   R = sortlsb(F);
        !           404:   B = vector(N+1);
        !           405:   Bpos = vector(N+1);
        !           406:   C = vector(N+1);
        !           407:   H = vector(N+1);
        !           408:   Z = vector(N+1);
        !           409:   K = vector(N+1);
        !           410:   L = vector(N+1);
        !           411:   K = vector(N+1);
        !           412:   D = vector(N+1);
        !           413:   Kind = vector(N+1);
        !           414:
        !           415:   for ( I = 1; I <= N; I++ ) {
        !           416:     FI = F[I-1]; Len = length(FI);
        !           417:     B[I] = FI;
        !           418:     T = vector(Len-1);
        !           419:     for ( J = 1; J < Len; J++ ) T[J-1] = FI[J];
        !           420:     Bpos[I] = qsort(T,newsyz.comp_pos);
        !           421:     C[I] = vector(Len);
        !           422:     H[I] = vector(Len);
        !           423:     Kind[I] = vector(Len);
        !           424:     K[I] = [];
        !           425:     Max = 0;
        !           426:     for ( J = 1; J < Len; J++ )
        !           427:       if ( (Pos = dpm_hp(FI[J][0])) > Max ) Max = Pos;
        !           428:     Z[I] = ZI = vector(Max+1);
        !           429:     for ( J = 1; J <= Max; J++ ) ZI[J] = [];
        !           430:   }
        !           431:   T1 = time(); Ftime = T1[0]-T0[0];
        !           432:   R = ltov(R); Len = length(R);
        !           433:   print(["Len",Len]);
        !           434:   for ( I = 0, NF = 0; I < Len; I++ ) {
        !           435:     if ( !((I+1)%100) ) print(".",2);
        !           436:     if ( !((I+1)%10000) ) print(I+1);
        !           437:     if ( !R[I][3] ) continue;
        !           438:     NF++;
        !           439:     reduce(R[I],B,Bpos,C,H,Z,K,Kind,G,One,Top);
        !           440:   }
        !           441:   print("");
        !           442:   print(["NF",NF]);
        !           443:   T0 = time();
        !           444:   dpm_set_schreyer_level(0);
        !           445:   D[1] = map(dpm_sort,H[1]);
        !           446:   for ( I = 2; I <= N; I++ ) {
        !           447:     // HTT = [Head,Tab,TailTop]
        !           448:     HTT = create_base_ord(K[I],length(Kind[I-1]));
        !           449:     Head = HTT[0]; Tab = HTT[1]; TailTopPos = HTT[2];
        !           450:     if ( !NoPreProj )
        !           451:       Tab = map(remove_k,map(dpm_sort,Tab),Kind[I-1]);
        !           452:     else
        !           453:       Tab = map(dpm_sort,Tab);
        !           454:     TailTop = dpm_dptodpm(One,TailTopPos);
        !           455:     if ( !NoSimpK ) {
        !           456:       print("simplify_k "+rtostr(I)+"...",2);
        !           457:       simplify_k(Head,Tab,TailTop,One);
        !           458:       print("done");
        !           459:     }
        !           460:     HI = map(remove_k,map(dpm_sort,H[I]),Kind[I-1]);
        !           461:     Len = length(HI);
        !           462:     print("simplify_by_k "+rtostr(I)+"...",2);
        !           463:     D[I] = vector(Len);
        !           464:     for ( J = 0; J < Len; J++ ) {
        !           465:       D[I][J] = simplify_by_k(HI[J],Tab,TailTop,One);
        !           466:       if ( NoPreProj )
        !           467:         D[I][J] = remove_k(D[I][J],Kind[I-1]);
        !           468:     }
        !           469:     print("done");
        !           470:   }
        !           471:   dp_ord([1,0]);
        !           472:   T1 = time();
        !           473:   print(["Frame",Ftime,"Prep",Ptime,"Reduce",Rtime,"Search",Stime,"Minimalize",T1[0]-T0[0]]);
        !           474: //  return [C,H,K,Kind,D];
        !           475:   D = compress_h(D);
        !           476:   return D;
        !           477: }
        !           478:
        !           479: def create_base_ord(K,N)
        !           480: {
        !           481:   Tab = vector(N);
        !           482:   Ks = [];
        !           483:   for ( T = K; T != []; T = cdr(T) ) {
        !           484:     Ks = cons(I=dpm_hp(car(T)[1]),Ks);
        !           485:     Tab[I] = car(T)[0];
        !           486:   }
        !           487:   Others = [];
        !           488:   for ( I = N-1; I >= 1; I-- )
        !           489:     if ( !Tab[I] ) Others = cons(I,Others);
        !           490:   Ks = reverse(Ks);
        !           491:   dp_ord([4,append(Ks,Others),0]);
        !           492:   return [ltov(Ks),Tab,car(Others)];
        !           493: }
        !           494:
        !           495: /* Head = [i1,i2,...], Tab[i1] = K[0], Tab[i2] = K[1],... */
        !           496:
        !           497: def simplify_k(Head,Tab,TailTop,One)
        !           498: {
        !           499:   N = length(Tab);
        !           500:   Len = length(Head);
        !           501:   for ( I = Len-1; I >= 0; I-- ) {
        !           502:     M = 1;
        !           503:     R = Tab[Head[I]];
        !           504:     H = dpm_hm(R); R = dpm_rest(R);
        !           505:     while ( R && dpm_dptodpm(One,dpm_hp(R)) > TailTop ) {
        !           506:       Pos = dpm_hp(R); Red = Tab[Pos];
        !           507:       CRed = dp_hc(dpm_hc(Red));
        !           508:       CR = dpm_extract(R,Pos);
        !           509:       L = dpm_remove_cont(CRed*R-CR*Red);
        !           510:       R = L[1]; M *= CRed/L[0];
        !           511:     }
        !           512:     Tab[Head[I]] = M*H+R;
        !           513:   }
        !           514: }
        !           515:
        !           516: def simplify_by_k(F,Tab,TailTop,One)
        !           517: {
        !           518:   R = F;
        !           519:   M = 1;
        !           520:   while ( R && dpm_dptodpm(One,dpm_hp(R)) > TailTop ) {
        !           521:     Pos = dpm_hp(R); Red = Tab[Pos];
        !           522:     CRed = dp_hc(dpm_hc(Red));
        !           523:     CR = dpm_extract(R,Pos);
        !           524:     L = dpm_remove_cont(CRed*R-CR*Red);
        !           525:     R = L[1]; M *= CRed/L[0];
        !           526:   }
        !           527:   return (1/M)*R;
        !           528: }
        !           529:
        !           530: /* Kind[I]=0 => phi(ei)\in H, Kind[I]=1 => phi(ei)\in K */
        !           531: def remove_k(F,Kind)
        !           532: {
        !           533:   R = [];
        !           534:   for ( T = F; T; T = dpm_rest(T) )
        !           535:     if ( Kind[dpm_hp(T)] != 1 ) R = cons(dpm_hm(T),R);
        !           536:   for ( S = 0; R != []; R = cdr(R) )
        !           537:     S += car(R);
        !           538:   return S;
        !           539: }
        !           540:
        !           541: def remove_k1(F,Kind)
        !           542: {
        !           543:   return [remove_k(F[0],Kind),F[1]];
        !           544: }
        !           545:
        !           546: def extract_nonzero(A)
        !           547: {
        !           548:   N = length(A);
        !           549:   R = [];
        !           550:   for ( C = I = 0; I < N; I++ )
        !           551:     if ( A[I] ) R=cons(A[I],R);
        !           552:   return reverse(R);;
        !           553: }
        !           554:
        !           555: def nonzero(A)
        !           556: {
        !           557:   N = length(A);
        !           558:   for ( C = I = 0; I < N; I++ )
        !           559:     if ( A[I] ) C++;
        !           560:   return C;
        !           561: }
        !           562:
        !           563: def phi(C,F)
        !           564: {
        !           565:   R = 0;
        !           566:   for ( T = F; T; T = dpm_rest(T) ) {
        !           567:     Coef = dpm_hc(T); Pos = dpm_hp(T);
        !           568:     R += Coef*C[Pos];
        !           569:   }
        !           570:   return R;
1.1       noro      571: }
                    572:
1.3     ! noro      573: def syz_check(H,I)
1.1       noro      574: {
1.3     ! noro      575:   HI = H[I];
        !           576: //  dpm_set_schreyer_level(I-1);
        !           577:   HI1 = H[I+1];
        !           578:   Len = size(HI1)[0];
        !           579:   for ( J = 1; J < Len; J++ ) {
        !           580:     F = HI1[J];
        !           581:     R = phi(HI,F);
        !           582:     if ( R ) print([J,"NG"]);
        !           583:   }
1.1       noro      584: }
                    585:
1.3     ! noro      586: // for compressed C
        !           587: def phi0(C,F)
1.1       noro      588: {
1.3     ! noro      589:   R = 0;
        !           590:   for ( T = F; T; T = dpm_rest(T) ) {
        !           591:     Coef = dpm_hc(T); Pos = dpm_hp(T);
        !           592:     R += Coef*C[Pos-1];
        !           593:   }
        !           594:   return R;
1.1       noro      595: }
                    596:
1.3     ! noro      597: // for compressed H
        !           598: def syz_check0(H,I)
1.1       noro      599: {
1.3     ! noro      600:   HI = H[I];
        !           601: //  dpm_set_schreyer_level(I-1);
        !           602:   HI1 = H[I+1];
        !           603:   Len = length(HI1);
        !           604:   for ( J = 0; J < Len; J++ ) {
        !           605:     F = HI1[J];
        !           606:     R = phi0(HI,F);
        !           607:     if ( R ) print([J,"NG"]);
        !           608:   }
1.1       noro      609: }
                    610:
1.3     ! noro      611: // renumber position
        !           612: def renumber_pos(F,Tab)
1.1       noro      613: {
1.3     ! noro      614:   L = [];
        !           615:   for ( T = F; T; T = dpm_rest(T) )
        !           616:     L = cons(dpm_hm(T),L);
        !           617:   R = 0;
        !           618:   for ( T = L; T != []; T = cdr(T) )
        !           619:     R += dpm_dptodpm(dpm_hc(car(T)),Tab[dpm_hp(car(T))]);
        !           620:   return R;
1.1       noro      621: }
                    622:
1.3     ! noro      623: // compress H1 and renumber H
        !           624: def compress(H,H1)
1.1       noro      625: {
1.3     ! noro      626:   // create index table for H1
        !           627:   L1 = length(H1);
        !           628:   Tmp = vector(L1);
        !           629:   Tab = vector(L1);
        !           630:   for ( I = 1, J = 1; I < L1; I++ )
        !           631:     if ( H1[I] ) {
        !           632:       Tab[I] = J;
        !           633:       Tmp[J++] = H1[I];
        !           634:     }
        !           635:   NH1 = vector(J);
        !           636:   for ( I = 1; I < J; I++ )
        !           637:     NH1[I] = Tmp[I];
        !           638:   if ( H )
        !           639:     H = map(renumber_pos,H,Tab);
        !           640:   return [H,NH1];
1.1       noro      641: }
                    642:
1.3     ! noro      643: def compress_h(H)
1.1       noro      644: {
1.3     ! noro      645:   // H = [0,H[1],...,H[L-1]]
        !           646:   L = length(H);
        !           647:   NH = vector(L-1);
        !           648:   H1 = H[1];
        !           649:   for ( I = 2; I < L; I++ ) {
        !           650:     R = compress(H[I],H1);
        !           651:     H1 = R[0];
        !           652:     NH[I-2] = cdr(vtol(R[1]));
        !           653:   }
        !           654:   R = compress(0,H1);
        !           655:   NH[L-2] = cdr(vtol(R[1]));
        !           656:   return NH;
1.1       noro      657: }
1.3     ! noro      658: endmodule$
1.1       noro      659: end$

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