[BACK]Return to NEZ.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / engine

Annotation of OpenXM_contrib2/asir2000/engine/NEZ.c, Revision 1.4

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.4     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/engine/NEZ.c,v 1.3 2000/08/22 05:04:04 noro Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
                     51:
                     52: void nezgcdnpz(vl,ps,m,pr)
                     53: VL vl;
                     54: P *ps,*pr;
                     55: int m;
                     56: {
                     57:        P t,s,mg;
                     58:        VL tvl,svl,avl,nvl;
                     59:        int i,j,k;
                     60:        N c;
                     61:        Q cq;
                     62:        P *pl,*pm;
                     63:        DCP *ml;
                     64:        Q *cl;
                     65:        P **cp;
                     66:        int *cn;
                     67:
                     68:        pl = (P *)ALLOCA(m*sizeof(P));
                     69:        ml = (DCP *)ALLOCA(m*sizeof(DCP));
                     70:        cl = (Q *)ALLOCA(m*sizeof(Q));
                     71:        for ( i = 0; i < m; i++ )
                     72:                monomialfctr(vl,ps[i],&pl[i],&ml[i]);
                     73:        gcdmonomial(vl,ml,m,&mg);
                     74:        for ( i = 0; i < m; i++ ) {
                     75:                ptozp(pl[i],1,&cl[i],&t); pl[i] = t;
                     76:        }
                     77:        for ( i = 1, cq = cl[0]; i < m; i++ ) {
                     78:                gcdn(NM(cl[i]),NM(cq),&c); NTOQ(c,1,cq);
                     79:        }
                     80:        for ( i = 0; i < m; i++ )
                     81:                if ( NUM(pl[i]) ) {
                     82:                        mulp(vl,(P)cq,mg,pr); return;
                     83:                }
                     84:        for ( i = 0, nvl = vl, avl = 0; nvl && i < m; i++ ) {
                     85:                clctv(vl,pl[i],&tvl);
                     86:                intersectv(nvl,tvl,&svl); nvl = svl;
                     87:                mergev(vl,avl,tvl,&svl); avl = svl;
                     88:        }
                     89:        if ( !nvl ) {
                     90:                mulp(vl,(P)cq,mg,pr); return;
                     91:        }
                     92:        if ( !NEXT(avl) ) {
                     93:                nuezgcdnpzmain(vl,pl,m,&t); mulp(vl,t,(P)cq,&s); mulp(vl,s,mg,pr);
                     94:                return;
                     95:        }
                     96:        for ( tvl = nvl, i = 0; tvl; tvl = NEXT(tvl), i++ );
                     97:        for ( tvl = avl, j = 0; tvl; tvl = NEXT(tvl), j++ );
                     98:        if ( i == j ) {
                     99:                /* all the pl[i]'s have the same variables */
                    100:                sortplistbyhomdeg(pl,m); nezgcdnpzmain(nvl,pl,m,&t);
                    101: #if 0
                    102:                /* search the minimal degree poly */
                    103:                for ( i = 0; i < m; i++ ) {
                    104:                for ( tvl = nvl; tvl; tvl = NEXT(tvl) ) {
                    105:                 dt = getdeg(tvl->v,pl[i]);
                    106:                 if ( tvl == nvl || dt < d1 ) {
                    107:                         v1 = tvl->v; d1 = dt;
                    108:                 }
                    109:                }
                    110:                        if ( i == 0 || d1 < d ) {
                    111:                                v = v1; d = d1; j = i;
                    112:                        }
                    113:                }
                    114:                t = pl[0]; pl[0] = pl[j]; pl[j] = t;
                    115:                if ( v != nvl->v ) {
                    116:                        reordvar(nvl,v,&mvl);
                    117:                        for ( i = 0; i < m; i++ ) {
                    118:                                reorderp(mvl,nvl,pl[i],&t); pl[i] = t;
                    119:                        }
                    120:                        nezgcdnpzmain(mvl,pl,m,&s); reorderp(nvl,mvl,s,&t);
                    121:                } else
                    122:                        nezgcdnpzmain(nvl,pl,m,&t);
                    123: #endif
                    124:        } else {
                    125:                cp = (P **)ALLOCA(m*sizeof(P *));
                    126:                cn = (int *)ALLOCA(m*sizeof(int));
                    127:                for ( i = 0; i < m; i++ ) {
                    128:                        cp[i] = (P *)ALLOCA(lengthp(pl[i])*sizeof(P));
                    129:                        cn[i] = pcoef(vl,nvl,pl[i],cp[i]);
                    130:                }
                    131:                for ( i = j = 0; i < m; i++ )
                    132:                        j += cn[i];
                    133:                pm = (P *)ALLOCA(j*sizeof(P));
                    134:                for ( i = k = 0; i < m; i++ )
                    135:                        for ( j = 0; j < cn[i]; j++ )
                    136:                                pm[k++] = cp[i][j];
                    137:                nezgcdnpz(vl,pm,k,&t);
                    138:        }
                    139:        mulp(vl,t,(P)cq,&s); mulp(vl,s,mg,pr);
                    140: }
                    141:
                    142: void sortplistbyhomdeg(p,n)
                    143: P *p;
                    144: int n;
                    145: {
                    146:        int i,j,k;
                    147:        int *l;
                    148:        P t;
                    149:
                    150:        l = (int *)ALLOCA(n*sizeof(int));
                    151:        for ( i = 0; i < n; i++ )
                    152:                l[i] = homdeg(p[i]);
                    153:        for ( i = 0; i < n; i++ )
                    154:                for ( j = i + 1; j < n; j++ )
                    155:                        if ( l[j] < l[i] ) {
                    156:                                t = p[i]; p[i] = p[j]; p[j] = t;
                    157:                                k = l[i]; l[i] = l[j]; l[j] = k;
                    158:                        }
                    159: }
                    160:
                    161: void nuezgcdnpzmain(vl,ps,m,r)
                    162: VL vl;
                    163: P *ps;
                    164: int m;
                    165: P *r;
                    166: {
                    167:        P *tps;
                    168:        P f,t;
                    169:        int i;
                    170:
                    171:        for ( i = 0; i < m; i++ )
                    172:                if ( NUM(ps[i]) ) {
                    173:                        *r = (P)ONE; return;
                    174:                }
                    175:        tps = (P *) ALLOCA(m*sizeof(P));
                    176:        for ( i = 0; i < m; i++ )
                    177:                tps[i] = ps[i];
                    178:        sortplist(tps,m);
                    179:        for ( i = 1, f = tps[0]; i < m && !NUM(f); i++ ) {
                    180:                uezgcdpz(vl,f,tps[i],&t); f = t;
                    181:        }
                    182:        *r = f;
                    183: }
                    184:
                    185: void gcdmonomial(vl,dcl,m,r)
                    186: VL vl;
                    187: DCP *dcl;
                    188: int m;
                    189: P *r;
                    190: {
                    191:        int i,j,n;
                    192:        P g,x,s,t;
                    193:        Q d;
                    194:        DCP dc;
                    195:        VN vn;
                    196:
                    197:        for ( i = 0; i < m; i++ )
                    198:                if ( !dcl[i] ) {
                    199:                        *r = (P)ONE; return;
                    200:                }
                    201:        for ( n = 0, dc = dcl[0]; dc; dc = NEXT(dc), n++ );
                    202:        vn = (VN)ALLOCA(n*sizeof(struct oVN));
                    203:        for ( i = 0, dc = dcl[0]; i < n; dc = NEXT(dc), i++ ) {
                    204:                vn[i].v = VR(COEF(dc)); vn[i].n = QTOS(DEG(dc));
                    205:        }
                    206:        for ( i = 1; i < m; i++ ) {
                    207:                for ( j = 0; j < n; j++ ) {
                    208:                        for ( dc = dcl[i]; dc; dc = NEXT(dc) )
                    209:                                if ( VR(COEF(dc)) == vn[j].v ) {
                    210:                                        vn[j].n = MIN(vn[j].n,QTOS(DEG(dc))); break;
                    211:                                }
                    212:                        if ( !dc )
                    213:                                vn[j].n = 0;
                    214:                }
                    215:                for ( j = n-1; j >= 0 && !vn[j].n; j-- );
                    216:                if ( j < 0 ) {
                    217:                        *r = (P)ONE; return;
                    218:                } else
                    219:                        n = j+1;
                    220:        }
                    221:        for ( j = 0, g = (P)ONE; j < n; j++ )
                    222:                if ( vn[j].n ) {
                    223:                        MKV(vn[j].v,x); STOQ(vn[j].n,d);
                    224:                        pwrp(vl,x,d,&t); mulp(vl,t,g,&s); g = s;
                    225:                }
                    226:        *r = g;
                    227: }
                    228:
                    229: void nezgcdnpzmain(vl,pl,m,pr)
                    230: VL vl;
                    231: P *pl,*pr;
                    232: int m;
                    233: {
                    234:        P *ppl,*pcl;
                    235:        int i;
                    236:        P cont,gcd,t,s;
                    237:        DCP dc;
                    238:
                    239:        ppl = (P *)ALLOCA(m*sizeof(P));
                    240:        pcl = (P *)ALLOCA(m*sizeof(P));
                    241:        for ( i = 0; i < m; i++ )
                    242:                pcp(vl,pl[i],&ppl[i],&pcl[i]);
                    243:        nezgcdnpz(vl,pcl,m,&cont);
                    244:        sqfrp(vl,ppl[0],&dc);
                    245:        for ( dc = NEXT(dc), gcd = (P)ONE; dc; dc = NEXT(dc) ) {
                    246:                if ( NUM(COEF(dc)) )
                    247:                        continue;
                    248:                nezgcdnpp(vl,dc,ppl+1,m-1,&t);
                    249:                if ( NUM(t) )
                    250:                        continue;
                    251:                mulp(vl,gcd,t,&s); gcd = s;
                    252:        }
                    253:        mulp(vl,gcd,cont,pr);
                    254: }
                    255:
                    256: void nezgcdnpp(vl,dc,pl,m,r)
                    257: VL vl;
                    258: DCP dc;
                    259: P *pl;
                    260: int m;
                    261: P *r;
                    262: {
                    263:        int i,k;
                    264:        P g,t,s,gcd;
                    265:        P *pm;
                    266:
                    267:        nezgcdnp_sqfr_primitive(vl,COEF(dc),pl,m,&gcd);
                    268:        if ( NUM(gcd) ) {
                    269:                *r = (P)ONE; return;
                    270:        }
                    271:        pm = (P *) ALLOCA(m*sizeof(P));
                    272:        for ( i = 0; i < m; i++ ) {
                    273:                divsp(vl,pl[i],gcd,&pm[i]);
                    274:                if ( NUM(pm[i]) ) {
                    275:                        *r = gcd; return;
                    276:                }
                    277:        }
                    278:        for ( g = gcd, k = QTOS(DEG(dc))-1; k > 0; k-- ) {
                    279:                nezgcdnp_sqfr_primitive(vl,g,pm,m,&t);
                    280:                if ( NUM(t) )
                    281:                        break;
                    282:                mulp(vl,gcd,t,&s); gcd = s;
                    283:                for ( i = 0; i < m; i++ ) {
                    284:                        divsp(vl,pm[i],t,&s);
                    285:                        if ( NUM(s) ) {
                    286:                                *r = gcd; return;
                    287:                        }
                    288:                        pm[i] = s;
                    289:                }
                    290:        }
                    291:        *r = gcd;
                    292: }
                    293:
                    294: /*
                    295:  * pr = gcd(p0,ps[0],...,ps[m-1])
                    296:  *
                    297:  * p0 is already square-free and primitive.
                    298:  * ps[i] is at least primitive.
                    299:  *
                    300:  */
                    301:
                    302: void nezgcdnp_sqfr_primitive(vl,p0,ps,m,pr)
                    303: VL vl;
                    304: int m;
                    305: P p0,*ps,*pr;
                    306: {
                    307:        /* variables */
                    308:        P p00,g,h,g0,h0,a0,b0;
                    309:        P lp0,lgp0,lp00,lg,lg0,cbd,tq,t;
                    310:        P *lc;
                    311:        P *tps;
                    312:        VL nvl1,nvl2,nvl,tvl;
                    313:        V v;
                    314:        int i,j,k,d0,dg,dg0,dmin;
                    315:        VN vn0,vn1,vnt;
                    316:        int nv,flag;
                    317:
                    318:        /* set-up */
                    319:        if ( NUM(p0) ) {
                    320:                *pr = (P) ONE; return;
                    321:        }
                    322:        for ( v = VR(p0), i = 0; i < m; i++ )
                    323:                if ( NUM(ps[i]) || (v != VR(ps[i])) ) {
                    324:                        *pr = (P)ONE; return;
                    325:                }
                    326:        tps = (P *) ALLOCA(m*sizeof(P));
                    327:        for ( i = 0; i < m; i++ )
                    328:                tps[i] = ps[i];
                    329:        sortplist(tps,m);
                    330:        /* deg(tps[0]) <= deg(tps[1]) <= ... */
                    331:
                    332:        if ( !cmpq(DEG(DC(p0)),ONE) ) {
                    333:                if ( divcheck(vl,tps,m,(P)ONE,p0) )
                    334:                        *pr = p0;
                    335:                else
                    336:                        *pr = (P)ONE;
                    337:                return;
                    338:        }
                    339:
                    340:        lp0 = LC(p0); dmin = d0 = deg(v,p0); lc = (P *)ALLOCA((m+1)*sizeof(P));
                    341:        for ( lc[0] = lp0, i = 0; i < m; i++ )
                    342:                lc[i+1] = LC(tps[i]);
                    343:        clctv(vl,p0,&nvl);
                    344:        for ( i = 0; i < m; i++ ) {
                    345:                clctv(vl,tps[i],&nvl1); mergev(vl,nvl,nvl1,&nvl2); nvl = nvl2;
                    346:        }
                    347:        nezgcdnpz(nvl,lc,m+1,&lg);
                    348:
                    349:        mulp(nvl,p0,lg,&lgp0); k = dbound(v,lgp0)+1; cbound(nvl,lgp0,(Q *)&cbd);
                    350:        for ( nv = 0, tvl = nvl; tvl; tvl = NEXT(tvl), nv++ );
                    351:        W_CALLOC(nv,struct oVN,vn0); W_CALLOC(nv,struct oVN,vnt);
                    352:        W_CALLOC(nv,struct oVN,vn1);
                    353:        for ( i = 0, tvl = NEXT(nvl); tvl; tvl = NEXT(tvl), i++ )
                    354:                vn1[i].v = vn0[i].v = tvl->v;
1.4     ! noro      355:        if ( !nonzero_const_term(p0) ) {
        !           356:                for ( i = 0; i < nv; i++ )
        !           357:                        vn0[i].n = ((unsigned int)random())%256+1;
        !           358:        }
1.1       noro      359:
                    360:        /* main loop */
                    361:        for ( dg = deg(v,tps[0]) + 1; ; next(vn0) )
                    362:                do {
                    363:                        for ( i = 0, j = 0; vn0[i].v; i++ )
                    364:                                if ( vn0[i].n ) vnt[j++].v = (V)i;
                    365:                        vnt[j].n = 0;
                    366:
                    367:                        /* find b s.t. LC(p0)(b), LC(tps[i])(b) != 0 */
                    368:                        mulsgn(vn0,vnt,j,vn1); substvp(nvl,p0,vn1,&p00);
                    369:                        flag = (!zerovpchk(nvl,lp0,vn1) && sqfrchk(p00));
                    370:                        for ( i = 0; flag && (i < m); i++ )
                    371:                                flag &= (!zerovpchk(nvl,LC(tps[i]),vn1));
                    372:                        if ( !flag )
                    373:                                continue;
                    374:
                    375:                        /* substitute y -> b */
                    376:                        substvp(nvl,lg,vn1,&lg0); lp00 = LC(p00);
                    377:                        /* extended-gcd in 1-variable */
                    378:                        uexgcdnp(nvl,p00,tps,m,vn1,(Q)cbd,&g0,&h0,&a0,&b0,(Q *)&tq);
                    379:                        if ( NUM(g0) ) {
                    380:                                *pr = (P)ONE; return;
                    381:                        } else if ( dg > ( dg0 = deg(v,g0) ) ) {
                    382:                                dg = dg0;
                    383:                                if ( dg == d0 ) {
                    384:                                        if ( divcheck(nvl,tps,m,lp0,p0) ) {
                    385:                                                *pr = p0; return;
                    386:                                        }
                    387:                                } else if ( dg == deg(v,tps[0]) ) {
                    388:                                        if ( divtpz(nvl,p0,tps[0],&t) &&
                    389:                                                divcheck(nvl,tps+1,m-1,LC(tps[0]),tps[0]) ) {
                    390:                                                *pr = tps[0]; return;
                    391:                                        } else
                    392:                                                break;
                    393:                                } else {
                    394:                                        henmv(nvl,vn1,lgp0,g0,h0,a0,b0,lg,lp0,lg0,lp00,(Q)tq,k,&g,&h);
                    395:                                        if ( divtpz(nvl,lgp0,g,&t) &&
                    396:                                                divcheck(nvl,tps,m,lg,g) ) {
                    397:                                                pcp(nvl,g,pr,&t); return;
                    398:                                        }
                    399:                                }
                    400:                        }
                    401:                } while ( !nextbin(vnt,j) );
                    402: }
                    403:
                    404: void intersectv(vl1,vl2,vlp)
                    405: VL vl1,vl2,*vlp;
                    406: {
                    407:        int i,n;
                    408:        VL tvl;
                    409:        VN tvn;
                    410:
                    411:        if ( !vl1 || !vl2 ) {
                    412:                *vlp = 0; return;
                    413:        }
                    414:        for ( n = 0, tvl = vl1; tvl; tvl = NEXT(tvl), n++ );
                    415:        tvn = (VN) ALLOCA(n*sizeof(struct oVN));
                    416:        for ( i = 0, tvl = vl1; i < n; tvl = NEXT(tvl), i++ ) {
                    417:                tvn[i].v = tvl->v; tvn[i].n = 0;
                    418:        }
                    419:        for ( tvl = vl2; tvl; tvl = NEXT(tvl) )
                    420:                for ( i = 0; i < n; i++ )
                    421:                        if ( tvn[i].v == tvl->v ) {
                    422:                                tvn[i].n = 1; break;
                    423:                        }
                    424:        vntovl(tvn,n,vlp);
                    425: }
                    426:
                    427: int pcoef(vl,ivl,p,cp)
                    428: VL vl,ivl;
                    429: P p;
                    430: P *cp;
                    431: {
                    432:        VL nvl,tvl,svl,mvl,mvl0;
                    433:        P t;
                    434:
                    435:        if ( NUM(p) ) {
                    436:                cp[0] = p; return 1;
                    437:        } else {
                    438:                clctv(vl,p,&nvl);
                    439:                for ( tvl = nvl, mvl0 = 0; tvl; tvl = NEXT(tvl) ) {
                    440:                        for ( svl = ivl; svl; svl = NEXT(svl) )
                    441:                                if ( tvl->v == svl->v )
                    442:                                        break;
                    443:                        if ( !svl ) {
                    444:                                if ( !mvl0 ) {
                    445:                                        NEWVL(mvl0); mvl = mvl0;
                    446:                                } else {
                    447:                                        NEWVL(NEXT(mvl)); mvl = NEXT(mvl);
                    448:                                }
                    449:                                mvl->v = tvl->v;
                    450:                        }
                    451:                }
                    452:                if ( mvl0 )
                    453:                        NEXT(mvl) = ivl;
                    454:                else
                    455:                        mvl0 = ivl;
                    456:                reorderp(mvl0,nvl,p,&t);
                    457:                return pcoef0(mvl0,ivl,t,cp);
                    458:        }
                    459: }
                    460:
                    461: int pcoef0(vl,ivl,p,cp)
                    462: VL vl,ivl;
                    463: P p;
                    464: P *cp;
                    465: {
                    466:        int cn,n;
                    467:        DCP dc;
                    468:        V v;
                    469:        VL tvl;
                    470:
                    471:        if ( NUM(p) ) {
                    472:                cp[0] = p; return 1;
                    473:        } else {
                    474:                for ( v = VR(p), tvl = ivl; tvl; tvl = NEXT(tvl) )
                    475:                        if ( v == tvl->v )
                    476:                                break;
                    477:                if ( tvl ) {
                    478:                        cp[0] = p; return 1;
                    479:                } else {
                    480:                        for ( dc = DC(p), n = 0; dc; dc = NEXT(dc) ) {
                    481:                                cn = pcoef0(vl,ivl,COEF(dc),cp); cp += cn; n += cn;
                    482:                        }
                    483:                        return n;
                    484:                }
                    485:        }
                    486: }
                    487:
                    488: int lengthp(p)
                    489: P p;
                    490: {
                    491:        int n;
                    492:        DCP dc;
                    493:
                    494:        if ( NUM(p) )
                    495:                return 1;
                    496:        else {
                    497:                for ( dc = DC(p), n = 0; dc; dc = NEXT(dc) )
                    498:                        n += lengthp(COEF(dc));
                    499:                return n;
1.4     ! noro      500:        }
        !           501: }
        !           502:
        !           503: int nonzero_const_term(P p)
        !           504: {
        !           505:        DCP dc;
        !           506:
        !           507:        if ( !p )
        !           508:                return 0;
        !           509:        else if ( NUM(p) )
        !           510:                return 1;
        !           511:        else {
        !           512:                dc = DC(p);
        !           513:                for ( ; NEXT(dc); dc = NEXT(dc) );
        !           514:                if ( DEG(dc) )
        !           515:                        return 0;
        !           516:                else
        !           517:                        return nonzero_const_term(COEF(dc));
1.1       noro      518:        }
                    519: }

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