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

Annotation of OpenXM_contrib2/asir2000/lib/bfct, Revision 1.23

1.2       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.23    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/lib/bfct,v 1.22 2003/04/20 08:54:28 noro Exp $
1.10      noro       49:  */
1.1       noro       50: /* requires 'primdec' */
1.22      noro       51:
1.23    ! noro       52: #define TMP_S ssssssss
        !            53: #define TMP_T tttttttt
        !            54: #define TMP_Y1 yyyyyyyy1
        !            55: #define TMP_Y2 yyyyyyyy2
        !            56:
1.22      noro       57: extern LIBRARY_GR_LOADED$
                     58: extern LIBRARY_PRIMDEC_LOADED$
                     59:
                     60: if(!LIBRARY_GR_LOADED) load("gr"); else ; LIBRARY_GR_LOADED = 1$
                     61: if(!LIBRARY_PRIMDEC_LOADED) load("primdec"); else ; LIBRARY_PRIMDEC_LOADED = 1$
                     62:
                     63: /* toplevel */
                     64:
                     65: def bfunction(F)
                     66: {
1.23    ! noro       67:        /* XXX */
        !            68:        F = replace_vars_f(F);
        !            69:
1.22      noro       70:        V = vars(F);
                     71:        N = length(V);
                     72:        D = newvect(N);
                     73:
                     74:        for ( I = 0; I < N; I++ )
                     75:                D[I] = [deg(F,V[I]),V[I]];
                     76:        qsort(D,compare_first);
                     77:        for ( V = [], I = 0; I < N; I++ )
                     78:                V = cons(D[I][1],V);
                     79:        return bfct_via_gbfct_weight(F,V);
                     80: }
1.1       noro       81:
1.6       noro       82: /* annihilating ideal of F^s */
1.1       noro       83:
                     84: def ann(F)
                     85: {
1.23    ! noro       86:        /* XXX */
        !            87:        F = replace_vars_f(F);
        !            88:
1.1       noro       89:        V = vars(F);
                     90:        N = length(V);
1.8       noro       91:        D = newvect(N);
                     92:
                     93:        for ( I = 0; I < N; I++ )
                     94:                D[I] = [deg(F,V[I]),V[I]];
                     95:        qsort(D,compare_first);
                     96:        for ( V = [], I = N-1; I >= 0; I-- )
                     97:                V = cons(D[I][1],V);
                     98:
1.1       noro       99:        for ( I = N-1, DV = []; I >= 0; I-- )
                    100:                DV = cons(strtov("d"+rtostr(V[I])),DV);
1.8       noro      101:
                    102:        W = append([y1,y2,t],V);
1.1       noro      103:        DW = append([dy1,dy2,dt],DV);
1.8       noro      104:
                    105:        B = [1-y1*y2,t-y1*F];
1.1       noro      106:        for ( I = 0; I < N; I++ ) {
                    107:                B = cons(DV[I]+y1*diff(F,V[I])*dt,B);
                    108:        }
1.10      noro      109:
                    110:        /* homogenized (heuristics) */
1.1       noro      111:        dp_nelim(2);
1.10      noro      112:        G0 = dp_weyl_gr_main(B,append(W,DW),1,0,6);
1.1       noro      113:        G1 = [];
                    114:        for ( T = G0; T != []; T = cdr(T) ) {
                    115:                E = car(T); VL = vars(E);
                    116:                if ( !member(y1,VL) && !member(y2,VL) )
                    117:                        G1 = cons(E,G1);
                    118:        }
1.12      noro      119:        G2 = map(psi,G1,t,dt);
                    120:        G3 = map(subst,G2,t,-1-s);
                    121:        return G3;
1.1       noro      122: }
                    123:
1.10      noro      124: /*
                    125:  * compute J_f|s=r, where r = the minimal integral root of global b_f(s)
                    126:  * ann0(F) returns [MinRoot,Ideal]
                    127:  */
                    128:
                    129: def ann0(F)
                    130: {
1.23    ! noro      131:        /* XXX */
        !           132:        F = replace_vars_f(F);
        !           133:
1.10      noro      134:        V = vars(F);
                    135:        N = length(V);
                    136:        D = newvect(N);
                    137:
                    138:        for ( I = 0; I < N; I++ )
                    139:                D[I] = [deg(F,V[I]),V[I]];
                    140:        qsort(D,compare_first);
                    141:        for ( V = [], I = 0; I < N; I++ )
                    142:                V = cons(D[I][1],V);
                    143:
                    144:        for ( I = N-1, DV = []; I >= 0; I-- )
                    145:                DV = cons(strtov("d"+rtostr(V[I])),DV);
                    146:
                    147:        /* XXX : heuristics */
                    148:        W = append([y1,y2,t],reverse(V));
                    149:        DW = append([dy1,dy2,dt],reverse(DV));
                    150:        WDW = append(W,DW);
                    151:
                    152:        B = [1-y1*y2,t-y1*F];
                    153:        for ( I = 0; I < N; I++ ) {
                    154:                B = cons(DV[I]+y1*diff(F,V[I])*dt,B);
                    155:        }
                    156:
                    157:        /* homogenized (heuristics) */
                    158:        dp_nelim(2);
                    159:        G0 = dp_weyl_gr_main(B,WDW,1,0,6);
                    160:        G1 = [];
                    161:        for ( T = G0; T != []; T = cdr(T) ) {
                    162:                E = car(T); VL = vars(E);
                    163:                if ( !member(y1,VL) && !member(y2,VL) )
                    164:                        G1 = cons(E,G1);
                    165:        }
1.12      noro      166:        G2 = map(psi,G1,t,dt);
                    167:        G3 = map(subst,G2,t,-1-s);
1.10      noro      168:
1.12      noro      169:        /* G3 = J_f(s) */
1.10      noro      170:
                    171:        V1 = cons(s,V); DV1 = cons(ds,DV); V1DV1 = append(V1,DV1);
1.12      noro      172:        G4 = dp_weyl_gr_main(cons(F,G3),V1DV1,0,1,0);
                    173:        Bf = weyl_minipoly(G4,V1DV1,0,s);
1.10      noro      174:
                    175:        FList = cdr(fctr(Bf));
                    176:        for ( T = FList, Min = 0; T != []; T = cdr(T) ) {
                    177:                LF = car(car(T));
                    178:                Root = -coef(LF,0)/coef(LF,1);
                    179:                if ( dn(Root) == 1 && Root < Min )
                    180:                        Min = Root;
                    181:        }
1.12      noro      182:        return [Min,map(subst,G3,s,Min)];
1.10      noro      183: }
                    184:
1.7       noro      185: def indicial1(F,V)
1.6       noro      186: {
                    187:        W = append([y1,t],V);
                    188:        N = length(V);
                    189:        B = [t-y1*F];
                    190:        for ( I = N-1, DV = []; I >= 0; I-- )
                    191:                DV = cons(strtov("d"+rtostr(V[I])),DV);
                    192:        DW = append([dy1,dt],DV);
                    193:        for ( I = 0; I < N; I++ ) {
                    194:                B = cons(DV[I]+y1*diff(F,V[I])*dt,B);
                    195:        }
                    196:        dp_nelim(1);
1.10      noro      197:
                    198:        /* homogenized (heuristics) */
1.7       noro      199:        G0 = dp_weyl_gr_main(B,append(W,DW),1,0,6);
1.6       noro      200:        G1 = map(subst,G0,y1,1);
                    201:        G2 = map(psi,G1,t,dt);
                    202:        G3 = map(subst,G2,t,-s-1);
                    203:        return G3;
                    204: }
                    205:
                    206: def psi(F,T,DT)
                    207: {
                    208:        D = dp_ptod(F,[T,DT]);
                    209:        Wmax = weight(D);
                    210:        D1 = dp_rest(D);
                    211:        for ( ; D1; D1 = dp_rest(D1) )
                    212:                if ( weight(D1) > Wmax )
                    213:                        Wmax = weight(D1);
                    214:        for ( D1 = D, Dmax = 0; D1; D1 = dp_rest(D1) )
                    215:                if ( weight(D1) == Wmax )
                    216:                        Dmax += dp_hm(D1);
                    217:        if ( Wmax >= 0 )
                    218:                Dmax = dp_weyl_mul(<<Wmax,0>>,Dmax);
                    219:        else
                    220:                Dmax = dp_weyl_mul(<<0,-Wmax>>,Dmax);
                    221:        Rmax = dp_dtop(Dmax,[T,DT]);
                    222:        R = b_subst(subst(Rmax,DT,1),T);
                    223:        return R;
                    224: }
                    225:
                    226: def weight(D)
                    227: {
                    228:        V = dp_etov(D);
                    229:        return V[1]-V[0];
                    230: }
                    231:
                    232: def compare_first(A,B)
                    233: {
                    234:        A0 = car(A);
                    235:        B0 = car(B);
                    236:        if ( A0 > B0 )
                    237:                return 1;
                    238:        else if ( A0 < B0 )
                    239:                return -1;
                    240:        else
                    241:                return 0;
                    242: }
                    243:
1.13      noro      244: /* generic b-function w.r.t. weight vector W */
                    245:
                    246: def generic_bfct(F,V,DV,W)
                    247: {
                    248:        N = length(V);
                    249:        N2 = N*2;
                    250:
1.16      noro      251:        /* If W is a list, convert it to a vector */
                    252:        if ( type(W) == 4 )
                    253:                W = newvect(length(W),W);
1.15      noro      254:        dp_weyl_set_weight(W);
                    255:
1.14      noro      256:        /* create a term order M in D<x,d> (DRL) */
1.13      noro      257:        M = newmat(N2,N2);
                    258:        for ( J = 0; J < N2; J++ )
                    259:                M[0][J] = 1;
                    260:        for ( I = 1; I < N2; I++ )
                    261:                M[I][N2-I] = -1;
                    262:
                    263:        VDV = append(V,DV);
                    264:
                    265:        /* create a non-term order MW in D<x,d> */
                    266:        MW = newmat(N2+1,N2);
                    267:        for ( J = 0; J < N; J++ )
                    268:                MW[0][J] = -W[J];
                    269:        for ( ; J < N2; J++ )
                    270:                MW[0][J] = W[J-N];
                    271:        for ( I = 1; I <= N2; I++ )
                    272:                for ( J = 0; J < N2; J++ )
                    273:                        MW[I][J] = M[I-1][J];
                    274:
                    275:        /* create a homogenized term order MWH in D<x,d,h> */
                    276:        MWH = newmat(N2+2,N2+1);
                    277:        for ( J = 0; J <= N2; J++ )
                    278:                MWH[0][J] = 1;
                    279:        for ( I = 1; I <= N2+1; I++ )
                    280:                for ( J = 0; J < N2; J++ )
                    281:                        MWH[I][J] = MW[I-1][J];
                    282:
                    283:        /* homogenize F */
                    284:        VDVH = append(VDV,[h]);
                    285:        FH = map(dp_dtop,map(dp_homo,map(dp_ptod,F,VDV)),VDVH);
                    286:
                    287:        /* compute a groebner basis of FH w.r.t. MWH */
1.21      noro      288:        dp_gr_flags(["Top",1,"NoRA",1]);
1.15      noro      289:        GH = dp_weyl_gr_main(FH,VDVH,0,1,11);
1.21      noro      290:        dp_gr_flags(["Top",0,"NoRA",0]);
1.13      noro      291:
                    292:        /* dehomigenize GH */
                    293:        G = map(subst,GH,h,1);
                    294:
                    295:        /* G is a groebner basis w.r.t. a non term order MW */
                    296:        /* take the initial part w.r.t. (-W,W) */
                    297:        GIN = map(initial_part,G,VDV,MW,W);
                    298:
                    299:        /* GIN is a groebner basis w.r.t. a term order M */
                    300:        /* As -W+W=0, gr_(-W,W)(D<x,d>) = D<x,d> */
                    301:
                    302:        /* find b(W1*x1*d1+...+WN*xN*dN) in Id(GIN) */
                    303:        for ( I = 0, T = 0; I < N; I++ )
                    304:                T += W[I]*V[I]*DV[I];
1.14      noro      305:        B = weyl_minipoly(GIN,VDV,0,T); /* M represents DRL order */
1.13      noro      306:        return B;
                    307: }
                    308:
1.18      noro      309: /* all term reduction + interreduce */
                    310: def generic_bfct_1(F,V,DV,W)
                    311: {
                    312:        N = length(V);
                    313:        N2 = N*2;
                    314:
                    315:        /* If W is a list, convert it to a vector */
                    316:        if ( type(W) == 4 )
                    317:                W = newvect(length(W),W);
                    318:        dp_weyl_set_weight(W);
                    319:
                    320:        /* create a term order M in D<x,d> (DRL) */
                    321:        M = newmat(N2,N2);
                    322:        for ( J = 0; J < N2; J++ )
                    323:                M[0][J] = 1;
                    324:        for ( I = 1; I < N2; I++ )
                    325:                M[I][N2-I] = -1;
                    326:
                    327:        VDV = append(V,DV);
                    328:
                    329:        /* create a non-term order MW in D<x,d> */
                    330:        MW = newmat(N2+1,N2);
                    331:        for ( J = 0; J < N; J++ )
                    332:                MW[0][J] = -W[J];
                    333:        for ( ; J < N2; J++ )
                    334:                MW[0][J] = W[J-N];
                    335:        for ( I = 1; I <= N2; I++ )
                    336:                for ( J = 0; J < N2; J++ )
                    337:                        MW[I][J] = M[I-1][J];
                    338:
                    339:        /* create a homogenized term order MWH in D<x,d,h> */
                    340:        MWH = newmat(N2+2,N2+1);
                    341:        for ( J = 0; J <= N2; J++ )
                    342:                MWH[0][J] = 1;
                    343:        for ( I = 1; I <= N2+1; I++ )
                    344:                for ( J = 0; J < N2; J++ )
                    345:                        MWH[I][J] = MW[I-1][J];
                    346:
                    347:        /* homogenize F */
                    348:        VDVH = append(VDV,[h]);
                    349:        FH = map(dp_dtop,map(dp_homo,map(dp_ptod,F,VDV)),VDVH);
                    350:
                    351:        /* compute a groebner basis of FH w.r.t. MWH */
                    352: /*     dp_gr_flags(["Top",1,"NoRA",1]); */
                    353:        GH = dp_weyl_gr_main(FH,VDVH,0,1,11);
                    354: /*     dp_gr_flags(["Top",0,"NoRA",0]); */
                    355:
                    356:        /* dehomigenize GH */
                    357:        G = map(subst,GH,h,1);
                    358:
                    359:        /* G is a groebner basis w.r.t. a non term order MW */
                    360:        /* take the initial part w.r.t. (-W,W) */
                    361:        GIN = map(initial_part,G,VDV,MW,W);
                    362:
                    363:        /* GIN is a groebner basis w.r.t. a term order M */
                    364:        /* As -W+W=0, gr_(-W,W)(D<x,d>) = D<x,d> */
                    365:
                    366:        /* find b(W1*x1*d1+...+WN*xN*dN) in Id(GIN) */
                    367:        for ( I = 0, T = 0; I < N; I++ )
                    368:                T += W[I]*V[I]*DV[I];
                    369:        B = weyl_minipoly(GIN,VDV,0,T); /* M represents DRL order */
                    370:        return B;
                    371: }
                    372:
1.13      noro      373: def initial_part(F,V,MW,W)
                    374: {
                    375:        N2 = length(V);
                    376:        N = N2/2;
                    377:        dp_ord(MW);
                    378:        DF = dp_ptod(F,V);
                    379:        R = dp_hm(DF);
                    380:        DF = dp_rest(DF);
                    381:
                    382:        E = dp_etov(R);
                    383:        for ( I = 0, TW = 0; I < N; I++ )
                    384:                TW += W[I]*(-E[I]+E[N+I]);
                    385:        RW = TW;
                    386:
                    387:        for ( ; DF; DF = dp_rest(DF) ) {
                    388:                E = dp_etov(DF);
                    389:                for ( I = 0, TW = 0; I < N; I++ )
                    390:                        TW += W[I]*(-E[I]+E[N+I]);
                    391:                if ( TW == RW )
                    392:                        R += dp_hm(DF);
                    393:                else if ( TW < RW )
                    394:                        break;
                    395:                else
                    396:                        error("initial_part : cannot happen");
                    397:        }
                    398:        return dp_dtop(R,V);
                    399:
                    400: }
                    401:
1.1       noro      402: /* b-function of F ? */
                    403:
                    404: def bfct(F)
                    405: {
1.23    ! noro      406:        /* XXX */
        !           407:        F = replace_vars_f(F);
        !           408:
1.1       noro      409:        V = vars(F);
                    410:        N = length(V);
1.6       noro      411:        D = newvect(N);
1.7       noro      412:
1.6       noro      413:        for ( I = 0; I < N; I++ )
                    414:                D[I] = [deg(F,V[I]),V[I]];
                    415:        qsort(D,compare_first);
                    416:        for ( V = [], I = 0; I < N; I++ )
                    417:                V = cons(D[I][1],V);
1.1       noro      418:        for ( I = N-1, DV = []; I >= 0; I-- )
                    419:                DV = cons(strtov("d"+rtostr(V[I])),DV);
1.6       noro      420:        V1 = cons(s,V); DV1 = cons(ds,DV);
1.7       noro      421:
                    422:        G0 = indicial1(F,reverse(V));
                    423:        G1 = dp_weyl_gr_main(G0,append(V1,DV1),0,1,0);
                    424:        Minipoly = weyl_minipoly(G1,append(V1,DV1),0,s);
1.6       noro      425:        return Minipoly;
                    426: }
                    427:
1.14      noro      428: /* b-function computation via generic_bfct() (experimental) */
                    429:
                    430: def bfct_via_gbfct(F)
                    431: {
1.23    ! noro      432:        /* XXX */
        !           433:        F = replace_vars_f(F);
        !           434:
1.14      noro      435:        V = vars(F);
                    436:        N = length(V);
                    437:        D = newvect(N);
                    438:
                    439:        for ( I = 0; I < N; I++ )
                    440:                D[I] = [deg(F,V[I]),V[I]];
                    441:        qsort(D,compare_first);
                    442:        for ( V = [], I = 0; I < N; I++ )
                    443:                V = cons(D[I][1],V);
                    444:        V = reverse(V);
                    445:        for ( I = N-1, DV = []; I >= 0; I-- )
                    446:                DV = cons(strtov("d"+rtostr(V[I])),DV);
                    447:
                    448:        B = [t-F];
                    449:        for ( I = 0; I < N; I++ ) {
                    450:                B = cons(DV[I]+diff(F,V[I])*dt,B);
                    451:        }
                    452:        V1 = cons(t,V); DV1 = cons(dt,DV);
                    453:        W = newvect(N+1);
                    454:        W[0] = 1;
1.21      noro      455:        R = generic_bfct(B,V1,DV1,W);
1.14      noro      456:
                    457:        return subst(R,s,-s-1);
                    458: }
                    459:
1.17      noro      460: /* use an order s.t. [t,x,y,z,...,dt,dx,dy,dz,...,h] */
                    461:
                    462: def bfct_via_gbfct_weight(F,V)
                    463: {
1.23    ! noro      464:        /* XXX */
        !           465:        F = replace_vars_f(F);
        !           466:        V = replace_vars_v(V);
        !           467:
1.17      noro      468:        N = length(V);
                    469:        D = newvect(N);
                    470:        Wt = getopt(weight);
1.18      noro      471:        if ( type(Wt) != 4 ) {
                    472:                for ( I = 0, Wt = []; I < N; I++ )
                    473:                        Wt = cons(1,Wt);
                    474:        }
                    475:        Tdeg = w_tdeg(F,V,Wt);
                    476:        WtV = newvect(2*(N+1)+1);
                    477:        WtV[0] = Tdeg;
                    478:        WtV[N+1] = 1;
                    479:        /* wdeg(V[I])=Wt[I], wdeg(DV[I])=Tdeg-Wt[I]+1 */
                    480:        for ( I = 1; I <= N; I++ ) {
                    481:                WtV[I] = Wt[I-1];
                    482:                WtV[N+1+I] = Tdeg-Wt[I-1]+1;
1.17      noro      483:        }
1.18      noro      484:        WtV[2*(N+1)] = 1;
                    485:        dp_set_weight(WtV);
1.17      noro      486:        for ( I = N-1, DV = []; I >= 0; I-- )
                    487:                DV = cons(strtov("d"+rtostr(V[I])),DV);
                    488:
                    489:        B = [t-F];
                    490:        for ( I = 0; I < N; I++ ) {
                    491:                B = cons(DV[I]+diff(F,V[I])*dt,B);
                    492:        }
                    493:        V1 = cons(t,V); DV1 = cons(dt,DV);
                    494:        W = newvect(N+1);
                    495:        W[0] = 1;
1.18      noro      496:        R = generic_bfct_1(B,V1,DV1,W);
                    497:        dp_set_weight(0);
1.17      noro      498:        return subst(R,s,-s-1);
                    499: }
                    500:
                    501: /* use an order s.t. [x,y,z,...,t,dx,dy,dz,...,dt,h] */
                    502:
                    503: def bfct_via_gbfct_weight_1(F,V)
                    504: {
1.23    ! noro      505:        /* XXX */
        !           506:        F = replace_vars_f(F);
        !           507:        V = replace_vars_v(V);
        !           508:
1.17      noro      509:        N = length(V);
                    510:        D = newvect(N);
                    511:        Wt = getopt(weight);
1.18      noro      512:        if ( type(Wt) != 4 ) {
                    513:                for ( I = 0, Wt = []; I < N; I++ )
                    514:                        Wt = cons(1,Wt);
                    515:        }
                    516:        Tdeg = w_tdeg(F,V,Wt);
                    517:        WtV = newvect(2*(N+1)+1);
                    518:        /* wdeg(V[I])=Wt[I], wdeg(DV[I])=Tdeg-Wt[I]+1 */
                    519:        for ( I = 0; I < N; I++ ) {
                    520:                WtV[I] = Wt[I];
                    521:                WtV[N+1+I] = Tdeg-Wt[I]+1;
1.17      noro      522:        }
1.18      noro      523:        WtV[N] = Tdeg;
                    524:        WtV[2*N+1] = 1;
                    525:        WtV[2*(N+1)] = 1;
                    526:        dp_set_weight(WtV);
1.17      noro      527:        for ( I = N-1, DV = []; I >= 0; I-- )
                    528:                DV = cons(strtov("d"+rtostr(V[I])),DV);
                    529:
                    530:        B = [t-F];
                    531:        for ( I = 0; I < N; I++ ) {
                    532:                B = cons(DV[I]+diff(F,V[I])*dt,B);
                    533:        }
                    534:        V1 = append(V,[t]); DV1 = append(DV,[dt]);
                    535:        W = newvect(N+1);
                    536:        W[N] = 1;
1.21      noro      537:        R = generic_bfct_1(B,V1,DV1,W);
1.19      noro      538:        dp_set_weight(0);
                    539:        return subst(R,s,-s-1);
                    540: }
                    541:
                    542: def bfct_via_gbfct_weight_2(F,V)
                    543: {
1.23    ! noro      544:        /* XXX */
        !           545:        F = replace_vars_f(F);
        !           546:        V = replace_vars_v(V);
        !           547:
1.19      noro      548:        N = length(V);
                    549:        D = newvect(N);
                    550:        Wt = getopt(weight);
                    551:        if ( type(Wt) != 4 ) {
                    552:                for ( I = 0, Wt = []; I < N; I++ )
                    553:                        Wt = cons(1,Wt);
                    554:        }
                    555:        Tdeg = w_tdeg(F,V,Wt);
                    556:
                    557:        /* a weight for the first GB computation */
                    558:        /* [t,x1,...,xn,dt,dx1,...,dxn,h] */
                    559:        WtV = newvect(2*(N+1)+1);
                    560:        WtV[0] = Tdeg;
                    561:        WtV[N+1] = 1;
                    562:        WtV[2*(N+1)] = 1;
                    563:        /* wdeg(V[I])=Wt[I], wdeg(DV[I])=Tdeg-Wt[I]+1 */
                    564:        for ( I = 1; I <= N; I++ ) {
                    565:                WtV[I] = Wt[I-1];
                    566:                WtV[N+1+I] = Tdeg-Wt[I-1]+1;
                    567:        }
                    568:        dp_set_weight(WtV);
                    569:
                    570:        /* a weight for the second GB computation */
                    571:        /* [x1,...,xn,t,dx1,...,dxn,dt,h] */
                    572:        WtV2 = newvect(2*(N+1)+1);
                    573:        WtV2[N] = Tdeg;
                    574:        WtV2[2*N+1] = 1;
                    575:        WtV2[2*(N+1)] = 1;
                    576:        for ( I = 0; I < N; I++ ) {
                    577:                WtV2[I] = Wt[I];
                    578:                WtV2[N+1+I] = Tdeg-Wt[I]+1;
                    579:        }
                    580:
                    581:        for ( I = N-1, DV = []; I >= 0; I-- )
                    582:                DV = cons(strtov("d"+rtostr(V[I])),DV);
                    583:
                    584:        B = [t-F];
                    585:        for ( I = 0; I < N; I++ ) {
                    586:                B = cons(DV[I]+diff(F,V[I])*dt,B);
                    587:        }
                    588:        V1 = cons(t,V); DV1 = cons(dt,DV);
                    589:        V2 = append(V,[t]); DV2 = append(DV,[dt]);
                    590:        W = newvect(N+1,[1]);
                    591:        dp_weyl_set_weight(W);
                    592:
                    593:        VDV = append(V1,DV1);
                    594:        N1 = length(V1);
                    595:        N2 = N1*2;
                    596:
                    597:        /* create a non-term order MW in D<x,d> */
                    598:        MW = newmat(N2+1,N2);
                    599:        for ( J = 0; J < N1; J++ ) {
                    600:                MW[0][J] = -W[J]; MW[0][N1+J] = W[J];
                    601:        }
                    602:        for ( J = 0; J < N2; J++ ) MW[1][J] = 1;
                    603:        for ( I = 2; I <= N2; I++ ) MW[I][N2-I+1] = -1;
                    604:
                    605:        /* homogenize F */
                    606:        VDVH = append(VDV,[h]);
                    607:        FH = map(dp_dtop,map(dp_homo,map(dp_ptod,B,VDV)),VDVH);
                    608:
                    609:        /* compute a groebner basis of FH w.r.t. MWH */
                    610:        GH = dp_weyl_gr_main(FH,VDVH,0,1,11);
                    611:
                    612:        /* dehomigenize GH */
                    613:        G = map(subst,GH,h,1);
                    614:
                    615:        /* G is a groebner basis w.r.t. a non term order MW */
                    616:        /* take the initial part w.r.t. (-W,W) */
                    617:        GIN = map(initial_part,G,VDV,MW,W);
                    618:
                    619:        /* GIN is a groebner basis w.r.t. a term order M */
                    620:        /* As -W+W=0, gr_(-W,W)(D<x,d>) = D<x,d> */
                    621:
                    622:        /* find b(W1*x1*d1+...+WN*xN*dN) in Id(GIN) */
                    623:        for ( I = 0, T = 0; I < N1; I++ )
                    624:                T += W[I]*V1[I]*DV1[I];
                    625:
                    626:        /* change of ordering from VDV to VDV2 */
                    627:        VDV2 = append(V2,DV2);
                    628:        dp_set_weight(WtV2);
1.20      noro      629:        for ( Pind = 0; ; Pind++ ) {
                    630:                Prime = lprime(Pind);
                    631:                GIN2 = dp_weyl_gr_main(GIN,VDV2,0,-Prime,0);
                    632:                if ( GIN2 ) break;
                    633:        }
1.19      noro      634:
                    635:        R = weyl_minipoly(GIN2,VDV2,0,T); /* M represents DRL order */
1.18      noro      636:        dp_set_weight(0);
1.17      noro      637:        return subst(R,s,-s-1);
                    638: }
                    639:
1.6       noro      640: def weyl_minipolym(G,V,O,M,V0)
                    641: {
                    642:        N = length(V);
                    643:        Len = length(G);
                    644:        dp_ord(O);
                    645:        setmod(M);
                    646:        PS = newvect(Len);
                    647:        PS0 = newvect(Len);
                    648:
                    649:        for ( I = 0, T = G; T != []; T = cdr(T), I++ )
                    650:                PS0[I] = dp_ptod(car(T),V);
                    651:        for ( I = 0, T = G; T != []; T = cdr(T), I++ )
                    652:                PS[I] = dp_mod(dp_ptod(car(T),V),M,[]);
                    653:
                    654:        for ( I = Len - 1, GI = []; I >= 0; I-- )
                    655:                GI = cons(I,GI);
                    656:
                    657:        U = dp_mod(dp_ptod(V0,V),M,[]);
1.17      noro      658:        U = dp_weyl_nf_mod(GI,U,PS,1,M);
1.6       noro      659:
                    660:        T = dp_mod(<<0>>,M,[]);
                    661:        TT = dp_mod(dp_ptod(1,V),M,[]);
                    662:        G = H = [[TT,T]];
                    663:
                    664:        for ( I = 1; ; I++ ) {
1.14      noro      665:                if ( dp_gr_print() )
                    666:                        print(".",2);
1.6       noro      667:                T = dp_mod(<<I>>,M,[]);
                    668:
                    669:                TT = dp_weyl_nf_mod(GI,dp_weyl_mul_mod(TT,U,M),PS,1,M);
                    670:                H = cons([TT,T],H);
                    671:                L = dp_lnf_mod([TT,T],G,M);
1.14      noro      672:                if ( !L[0] ) {
                    673:                        if ( dp_gr_print() )
                    674:                                print("");
1.13      noro      675:                        return dp_dtop(L[1],[t]); /* XXX */
1.14      noro      676:                } else
1.6       noro      677:                        G = insert(G,L);
                    678:        }
                    679: }
                    680:
1.13      noro      681: def weyl_minipoly(G0,V0,O0,P)
1.6       noro      682: {
1.11      noro      683:        HM = hmlist(G0,V0,O0);
1.13      noro      684:
                    685:        N = length(V0);
                    686:        Len = length(G0);
                    687:        dp_ord(O0);
                    688:        PS = newvect(Len);
                    689:        for ( I = 0, T = G0, HL = []; T != []; T = cdr(T), I++ )
                    690:                PS[I] = dp_ptod(car(T),V0);
                    691:        for ( I = Len - 1, GI = []; I >= 0; I-- )
                    692:                GI = cons(I,GI);
1.20      noro      693:        PSM = newvect(Len);
1.13      noro      694:        DP = dp_ptod(P,V0);
                    695:
1.20      noro      696:        for ( Pind = 0; ; Pind++ ) {
                    697:                Prime = lprime(Pind);
1.11      noro      698:                if ( !valid_modulus(HM,Prime) )
                    699:                        continue;
1.20      noro      700:                setmod(Prime);
                    701:                for ( I = 0, T = G0, HL = []; T != []; T = cdr(T), I++ )
                    702:                        PSM[I] = dp_mod(dp_ptod(car(T),V0),Prime,[]);
1.13      noro      703:
                    704:                NFP = weyl_nf(GI,DP,1,PS);
1.20      noro      705:                NFPM = dp_mod(NFP[0],Prime,[])/ptomp(NFP[1],Prime);
                    706:
1.13      noro      707:                NF = [[dp_ptod(1,V0),1]];
                    708:                LCM = 1;
                    709:
1.20      noro      710:                TM = dp_mod(<<0>>,Prime,[]);
                    711:                TTM = dp_mod(dp_ptod(1,V0),Prime,[]);
                    712:                GM = NFM = [[TTM,TM]];
                    713:
                    714:                for ( D = 1; ; D++ ) {
1.14      noro      715:                        if ( dp_gr_print() )
                    716:                                print(".",2);
1.13      noro      717:                        NFPrev = car(NF);
                    718:                        NFJ = weyl_nf(GI,
                    719:                                dp_weyl_mul(NFP[0],NFPrev[0]),NFP[1]*NFPrev[1],PS);
                    720:                        NFJ = remove_cont(NFJ);
                    721:                        NF = cons(NFJ,NF);
                    722:                        LCM = ilcm(LCM,NFJ[1]);
1.20      noro      723:
                    724:                        /* modular computation */
                    725:                        TM = dp_mod(<<D>>,Prime,[]);
                    726:                        TTM = dp_mod(NFJ[0],Prime,[])/ptomp(NFJ[1],Prime);
                    727:                        NFM = cons([TTM,TM],NFM);
                    728:                        LM = dp_lnf_mod([TTM,TM],GM,Prime);
                    729:                        if ( !LM[0] )
                    730:                                break;
                    731:                        else
                    732:                                GM = insert(GM,LM);
1.13      noro      733:                }
1.20      noro      734:
1.14      noro      735:                if ( dp_gr_print() )
                    736:                        print("");
1.13      noro      737:                U = NF[0][0]*idiv(LCM,NF[0][1]);
                    738:                Coef = [];
                    739:                for ( J = D-1; J >= 0; J-- ) {
                    740:                        Coef = cons(strtov("u"+rtostr(J)),Coef);
                    741:                        U += car(Coef)*NF[D-J][0]*idiv(LCM,NF[D-J][1]);
                    742:                }
1.6       noro      743:
1.13      noro      744:                for ( UU = U, Eq = []; UU; UU = dp_rest(UU) )
                    745:                        Eq = cons(dp_hc(UU),Eq);
                    746:                M = etom([Eq,Coef]);
                    747:                B = henleq(M,Prime);
                    748:                if ( dp_gr_print() )
                    749:                        print("");
1.6       noro      750:                if ( B ) {
1.13      noro      751:                        R = 0;
                    752:                        for ( I = 0; I < D; I++ )
                    753:                                R += B[0][I]*s^I;
                    754:                        R += B[1]*s^D;
1.6       noro      755:                        return R;
                    756:                }
                    757:        }
                    758: }
                    759:
                    760: def weyl_nf(B,G,M,PS)
                    761: {
                    762:        for ( D = 0; G; ) {
                    763:                for ( U = 0, L = B; L != []; L = cdr(L) ) {
                    764:                        if ( dp_redble(G,R=PS[car(L)]) > 0 ) {
                    765:                                GCD = igcd(dp_hc(G),dp_hc(R));
                    766:                                CG = idiv(dp_hc(R),GCD); CR = idiv(dp_hc(G),GCD);
                    767:                                U = CG*G-dp_weyl_mul(CR*dp_subd(G,R),R);
                    768:                                if ( !U )
                    769:                                        return [D,M];
                    770:                                D *= CG; M *= CG;
                    771:                                break;
                    772:                        }
                    773:                }
                    774:                if ( U )
                    775:                        G = U;
                    776:                else {
                    777:                        D += dp_hm(G); G = dp_rest(G);
                    778:                }
                    779:        }
                    780:        return [D,M];
                    781: }
                    782:
                    783: def weyl_nf_mod(B,G,PS,Mod)
                    784: {
                    785:        for ( D = 0; G; ) {
                    786:                for ( U = 0, L = B; L != []; L = cdr(L) ) {
                    787:                        if ( dp_redble(G,R=PS[car(L)]) > 0 ) {
                    788:                                CR = dp_hc(G)/dp_hc(R);
                    789:                                U = G-dp_weyl_mul_mod(CR*dp_mod(dp_subd(G,R),Mod,[]),R,Mod);
                    790:                                if ( !U )
                    791:                                        return D;
1.1       noro      792:                                break;
1.6       noro      793:                        }
                    794:                }
                    795:                if ( U )
                    796:                        G = U;
                    797:                else {
                    798:                        D += dp_hm(G); G = dp_rest(G);
1.1       noro      799:                }
                    800:        }
1.6       noro      801:        return D;
1.1       noro      802: }
                    803:
                    804: def remove_zero(L)
                    805: {
                    806:        for ( R = []; L != []; L = cdr(L) )
                    807:                if ( car(L) )
                    808:                        R = cons(car(L),R);
                    809:        return R;
                    810: }
                    811:
                    812: def z_subst(F,V)
                    813: {
                    814:        for ( ; V != []; V = cdr(V) )
                    815:                F = subst(F,car(V),0);
                    816:        return F;
                    817: }
                    818:
                    819: def flatmf(L) {
                    820:     for ( S = []; L != []; L = cdr(L) )
                    821:                if ( type(F=car(car(L))) != NUM )
                    822:                        S = append(S,[F]);
                    823:        return S;
                    824: }
                    825:
                    826: def member(A,L) {
                    827:     for ( ; L != []; L = cdr(L) )
                    828:                if ( A == car(L) )
                    829:                        return 1;
                    830:        return 0;
                    831: }
                    832:
                    833: def intersection(A,B)
                    834: {
                    835:        for ( L = []; A != []; A = cdr(A) )
                    836:        if ( member(car(A),B) )
                    837:                L = cons(car(A),L);
                    838:        return L;
                    839: }
                    840:
                    841: def b_subst(F,V)
                    842: {
                    843:        D = deg(F,V);
                    844:        C = newvect(D+1);
                    845:        for ( I = D; I >= 0; I-- )
                    846:                C[I] = coef(F,I,V);
                    847:        for ( I = 0, R = 0; I <= D; I++ )
                    848:                if ( C[I] )
                    849:                        R += C[I]*v_factorial(V,I);
                    850:        return R;
                    851: }
                    852:
                    853: def v_factorial(V,N)
                    854: {
                    855:        for ( J = N-1, R = 1; J >= 0; J-- )
                    856:                R *= V-J;
1.17      noro      857:        return R;
                    858: }
                    859:
                    860: def w_tdeg(F,V,W)
                    861: {
                    862:        dp_set_weight(newvect(length(W),W));
                    863:        T = dp_ptod(F,V);
                    864:        for ( R = 0; T; T = cdr(T) ) {
                    865:                D = dp_td(T);
                    866:                if ( D > R ) R = D;
1.23    ! noro      867:        }
        !           868:        return R;
        !           869: }
        !           870:
        !           871: def replace_vars_f(F)
        !           872: {
        !           873:        return subst(F,s,TMP_S,t,TMP_T,y1,TMP_Y1,y2,TMP_Y2);
        !           874: }
        !           875:
        !           876: def replace_vars_v(V)
        !           877: {
        !           878:        V = replace_var(V,s,TMP_S);
        !           879:        V = replace_var(V,t,TMP_T);
        !           880:        V = replace_var(V,y1,TMP_Y1);
        !           881:        V = replace_var(V,y2,TMP_Y2);
        !           882:        return V;
        !           883: }
        !           884:
        !           885: def replace_var(V,X,Y)
        !           886: {
        !           887:        V = reverse(V);
        !           888:        for ( R = []; V != []; V = cdr(V) ) {
        !           889:                Z = car(V);
        !           890:                if ( Z == X )
        !           891:                        R = cons(Y,R);
        !           892:                else
        !           893:                        R = cons(Z,R);
1.17      noro      894:        }
1.1       noro      895:        return R;
                    896: }
                    897: end$
                    898:

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