[BACK]Return to poly4.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / Kan

Annotation of OpenXM/src/kan96xx/Kan/poly4.c, Revision 1.6

1.6     ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/poly4.c,v 1.5 2003/07/10 08:20:04 takayama Exp $ */
1.1       maekawa     2: #include <stdio.h>
                      3: #include "datatype.h"
                      4: #include "stackm.h"
                      5: #include "extern.h"
                      6: #include "extern2.h"
                      7: #include "matrix.h"
                      8: static void shell(int v[],int n);
                      9: static int degreeOfPrincipalPart(POLY f);
                     10: static int degreeOfInitW(POLY f,int w[]);
                     11:
                     12:
                     13: static void shell(v,n)
1.3       takayama   14:      int v[];
                     15:      int n;
1.1       maekawa    16: {
                     17:   int gap,i,j,temp;
                     18:
                     19:   for (gap = n/2; gap > 0; gap /= 2) {
                     20:     for (i = gap; i<n; i++) {
                     21:       for (j=i-gap ; j>=0 && v[j]<v[j+gap]; j -= gap) {
1.3       takayama   22:         temp = v[j];
                     23:         v[j] = v[j+gap];
                     24:         v[j+gap] = temp;
1.1       maekawa    25:       }
                     26:     }
                     27:   }
                     28: }
                     29:
                     30:
                     31: struct matrixOfPOLY *parts(f,v)
1.3       takayama   32:      POLY f;
                     33:      POLY v;  /* v must be a single variable, e.g. x */
1.1       maekawa    34: {
                     35:   struct matrixOfPOLY *evPoly;
                     36:   int vi = 0;  /* index of v */
                     37:   int vx = 1;  /* x --> 1, D--> 0 */
                     38:   int n,evSize,i,k,e;
                     39:   int *ev;
                     40:   struct object *evList;
                     41:   struct object *list;
                     42:   struct object ob;
                     43:   POLY ans;
                     44:   POLY h;
                     45:   extern struct ring *CurrentRingp;
                     46:   POLY ft;
                     47:
                     48:
                     49:   if (f ISZERO || v ISZERO) {
                     50:     evPoly = newMatrixOfPOLY(2,1);
                     51:     getMatrixOfPOLY(evPoly,0,0) = ZERO;
                     52:     getMatrixOfPOLY(evPoly,1,0) = ZERO;
                     53:     return(evPoly);
                     54:   }
                     55:   n = v->m->ringp->n;
                     56:   /* get the index of the variable v */
                     57:   for (i=0; i<n; i++) {
                     58:     if (v->m->e[i].x) {
                     59:       vx = 1; vi = i; break;
                     60:     }else if (v->m->e[i].D) {
                     61:       vx = 0; vi = i; break;
                     62:     }
                     63:   }
                     64:   ft = f;
                     65:   /* get the vector of exponents */
                     66:   evList = NULLLIST;
                     67:   while (ft != POLYNULL) {
                     68:     if (vx) {
                     69:       e = ft->m->e[vi].x;
                     70:     }else{
                     71:       e = ft->m->e[vi].D;
                     72:     }
                     73:     ft = ft->next;
                     74:     ob = KpoInteger(e);
                     75:     if (!memberQ(evList,ob)) {
                     76:       list = newList(&ob);
                     77:       evList = vJoin(evList,list);
                     78:     }
                     79:   }
                     80:   /*printf("evList = "); printObjectList(evList);*/
                     81:   evSize = klength(evList);
                     82:   ev = (int *)sGC_malloc(sizeof(int)*(evSize+1));
                     83:   if (ev == (int *)NULL) errorPoly("No more memory.");
                     84:   for (i=0; i<evSize; i++) {
                     85:     ev[i] = KopInteger(car(evList));
                     86:     evList = cdr(evList);
                     87:   }
                     88:   /* sort ev */
                     89:   shell(ev,evSize);
                     90:
                     91:   /* get coefficients */
                     92:   evPoly = newMatrixOfPOLY(2,evSize);
                     93:   for (i=0; i<evSize; i++) {
                     94:     ans = ZERO;
                     95:     getMatrixOfPOLY(evPoly,0,i) = cxx(ev[i],0,0,CurrentRingp);
                     96:     ft = f;
                     97:     while (ft != POLYNULL) {
                     98:       if (vx) {
1.3       takayama   99:         if (ft->m->e[vi].x == ev[i]) {
                    100:           h = newCell(ft->coeffp,monomialCopy(ft->m));
                    101:           xset0(h,vi); /* touch monomial part, so you need to copy it above. */
                    102:           ans = ppAdd(ans,h);
                    103:         }
1.1       maekawa   104:       }else{
1.3       takayama  105:         if (ft->m->e[vi].D == ev[i]) {
                    106:           h = newCell(ft->coeffp,monomialCopy(ft->m));
                    107:           dset0(h,vi);
                    108:           ans = ppAdd(ans,h);
                    109:         }
1.1       maekawa   110:       }
                    111:       ft = ft->next;
                    112:     }
                    113:     getMatrixOfPOLY(evPoly,1,i) = ans;
                    114:   }
                    115:   return(evPoly);
                    116: }
1.3       takayama  117:
1.1       maekawa   118: struct object parts2(f,v)
1.3       takayama  119:      POLY f;
                    120:      POLY v;  /* v must be a single variable, e.g. x */
1.1       maekawa   121: {
                    122:   struct matrixOfPOLY *evPoly;
                    123:   int vi = 0;  /* index of v */
                    124:   int vx = 1;  /* x --> 1, D--> 0 */
                    125:   int n,evSize,i,k,e;
                    126:   int *ev;
                    127:   struct object *evList;
                    128:   struct object *list;
                    129:   struct object ob;
                    130:   POLY ans;
                    131:   POLY h;
                    132:   POLY ft;
                    133:   struct object ob1,ob2,rob;
                    134:
                    135:
                    136:   if (f ISZERO || v ISZERO) {
                    137:     evPoly = newMatrixOfPOLY(2,1);
                    138:     getMatrixOfPOLY(evPoly,0,0) = ZERO;
                    139:     getMatrixOfPOLY(evPoly,1,0) = ZERO;
                    140:     rob = newObjectArray(2);
                    141:     ob1 = newObjectArray(1);
                    142:     ob2 = newObjectArray(1);
                    143:     putoa(ob1,0,KpoInteger(0));
                    144:     putoa(ob2,0,KpoPOLY(POLYNULL));
                    145:     putoa(rob,0,ob1); putoa(rob,1,ob2);
                    146:     return(rob);
                    147:   }
                    148:   n = v->m->ringp->n;
                    149:   /* get the index of the variable v */
                    150:   for (i=0; i<n; i++) {
                    151:     if (v->m->e[i].x) {
                    152:       vx = 1; vi = i; break;
                    153:     }else if (v->m->e[i].D) {
                    154:       vx = 0; vi = i; break;
                    155:     }
                    156:   }
                    157:   ft = f;
                    158:   /* get the vector of exponents */
                    159:   evList = NULLLIST;
                    160:   while (ft != POLYNULL) {
                    161:     if (vx) {
                    162:       e = ft->m->e[vi].x;
                    163:     }else{
                    164:       e = ft->m->e[vi].D;
                    165:     }
                    166:     ft = ft->next;
                    167:     ob = KpoInteger(e);
                    168:     if (!memberQ(evList,ob)) {
                    169:       list = newList(&ob);
                    170:       evList = vJoin(evList,list);
                    171:     }
                    172:   }
                    173:   /*printf("evList = "); printObjectList(evList);*/
                    174:   evSize = klength(evList);
                    175:   ev = (int *)sGC_malloc(sizeof(int)*(evSize+1));
                    176:   if (ev == (int *)NULL) errorPoly("No more memory.");
                    177:   for (i=0; i<evSize; i++) {
                    178:     ev[i] = KopInteger(car(evList));
                    179:     evList = cdr(evList);
                    180:   }
                    181:   /* sort ev */
                    182:   shell(ev,evSize);
                    183:
                    184:   /* get coefficients */
                    185:   evPoly = newMatrixOfPOLY(2,evSize);
                    186:   for (i=0; i<evSize; i++) {
                    187:     ans = ZERO;
                    188:     /* getMatrixOfPOLY(evPoly,0,i) = cxx(ev[i],0,0,CurrentRingp); */
                    189:     getMatrixOfPOLY(evPoly,0,i) = POLYNULL;
                    190:     ft = f;
                    191:     while (ft != POLYNULL) {
                    192:       if (vx) {
1.3       takayama  193:         if (ft->m->e[vi].x == ev[i]) {
                    194:           h = newCell(ft->coeffp,monomialCopy(ft->m));
                    195:           xset0(h,vi); /* touch monomial part, so you need to copy it above. */
                    196:           ans = ppAdd(ans,h);
                    197:         }
1.1       maekawa   198:       }else{
1.3       takayama  199:         if (ft->m->e[vi].D == ev[i]) {
                    200:           h = newCell(ft->coeffp,monomialCopy(ft->m));
                    201:           dset0(h,vi);
                    202:           ans = ppAdd(ans,h);
                    203:         }
1.1       maekawa   204:       }
                    205:       ft = ft->next;
                    206:     }
                    207:     getMatrixOfPOLY(evPoly,1,i) = ans;
                    208:   }
                    209:   rob = newObjectArray(2);
                    210:   ob1 = newObjectArray(evSize);
                    211:   ob2 = newObjectArray(evSize);
                    212:   for (i=0; i<evSize; i++) {
                    213:     putoa(ob2,i,KpoPOLY(getMatrixOfPOLY(evPoly,1,i)));
                    214:     putoa(ob1,i,KpoInteger(ev[i]));
                    215:   }
                    216:   putoa(rob,0,ob1); putoa(rob,1,ob2);
                    217:   return(rob);
                    218: }
1.3       takayama  219:
1.1       maekawa   220: int pDegreeWrtV(f,v)
1.3       takayama  221:      POLY f;
                    222:      POLY v;
1.1       maekawa   223: {
                    224:   int vx = 1;
                    225:   int vi = 0;
                    226:   int i,n;
                    227:   int ans;
                    228:   if (f ISZERO || v ISZERO) return(0);
                    229:   n = f->m->ringp->n;
                    230:   for (i=0; i<n; i++) {
                    231:     if (v->m->e[i].x) {
                    232:       vx = 1; vi = i;
                    233:       break;
                    234:     }else if (v->m->e[i].D) {
                    235:       vx = 0; vi = i;
                    236:       break;
                    237:     }
                    238:   }
                    239:   if (vx) {
                    240:     ans = f->m->e[vi].x;
                    241:   }else{
                    242:     ans = f->m->e[vi].D;
                    243:   }
                    244:   f = f->next;
                    245:   while (f != POLYNULL) {
                    246:     if (vx) {
                    247:       if (f->m->e[vi].x > ans) ans = f->m->e[vi].x;
                    248:     }else{
                    249:       if (f->m->e[vi].D > ans) ans = f->m->e[vi].D;
                    250:     }
                    251:     f = f->next;
                    252:   }
                    253:   return(ans);
                    254: }
                    255:
                    256: int containVectorVariable(POLY f)
                    257: {
                    258:   MONOMIAL tf;
                    259:   static int nn,mm,ll,cc,n,m,l,c;
                    260:   static struct ring *cr = (struct ring *)NULL;
                    261:   int i;
                    262:
                    263:   if (f ISZERO) return(0);
                    264:   tf = f->m;
                    265:   if (tf->ringp != cr) {
                    266:     n = tf->ringp->n;
                    267:     m = tf->ringp->m;
                    268:     l = tf->ringp->l;
                    269:     c = tf->ringp->c;
                    270:     nn = tf->ringp->nn;
                    271:     mm = tf->ringp->mm;
                    272:     ll = tf->ringp->ll;
                    273:     cc = tf->ringp->cc;
                    274:     cr = tf->ringp;
                    275:   }
                    276:
                    277:   while (f != POLYNULL) {
                    278:     tf = f->m;
                    279:     for (i=cc; i<c; i++) {
                    280:       if ( tf->e[i].x ) return(1);
                    281:       if ( tf->e[i].D ) return(1);
                    282:     }
                    283:     for (i=ll; i<l; i++) {
                    284:       if (tf->e[i].x) return(1);
                    285:       if (tf->e[i].D) return(1);
                    286:     }
                    287:     for (i=mm; i<m; i++) {
                    288:       if (tf->e[i].x) return(1);
                    289:       if (tf->e[i].D) return(1);
                    290:     }
                    291:     for (i=nn; i<n; i++) {
                    292:       if (tf->e[i].x) return(1);
                    293:       if (tf->e[i].D) return(1);
                    294:     }
                    295:     f = f->next;
                    296:   }
                    297:   return(0);
                    298:
                    299: }
                    300:
                    301: POLY homogenize(f)
1.3       takayama  302:      POLY f;
                    303:      /* homogenize by using (*grade)(f) */
1.1       maekawa   304: {
                    305:   POLY t;
                    306:   int maxg;
                    307:   int flag,d;
                    308:
                    309:   if (f == ZERO) return(f);
                    310:   t = f; maxg = (*grade)(f); flag = 0;
                    311:   while (t != POLYNULL) {
                    312:     d = (*grade)(t);
                    313:     if (d != maxg) flag = 1;
                    314:     if (d > maxg) {
                    315:       maxg = d;
                    316:     }
                    317:     t = t->next;
                    318:   }
                    319:   if (flag == 0) return(f);
                    320:
                    321:   f = pmCopy(f); /* You can rewrite the monomial parts */
                    322:   t = f;
                    323:   while (t != POLYNULL) {
                    324:     d = (*grade)(t);
                    325:     if (d != maxg) {
                    326:       t->m->e[0].D += maxg-d; /* Multiply h^(maxg-d) */
                    327:     }
                    328:     t = t->next;
                    329:   }
                    330:   return(f);
                    331: }
                    332:
                    333: int isHomogenized(f)
1.3       takayama  334:      POLY f;
1.1       maekawa   335: {
                    336:   POLY t;
                    337:   extern int Homogenize_vec;
                    338:   int maxg;
                    339:   if (!Homogenize_vec) return(isHomogenized_vec(f));
                    340:   if (f == ZERO) return(1);
1.4       takayama  341:   if (f->m->ringp->weightedHomogenization) {
                    342:        return 1; /* BUG: do not chech in case of one-zero homogenization */
                    343:   }
1.1       maekawa   344:   maxg = (*grade)(f);
                    345:   t = f;
                    346:   while (t != POLYNULL) {
                    347:     if (maxg != (*grade)(t)) return(0);
                    348:     t = t->next;
                    349:   }
                    350:   return(1);
                    351: }
                    352:
                    353: int isHomogenized_vec(f)
1.3       takayama  354:      POLY f;
1.1       maekawa   355: {
1.3       takayama  356:   /* This is not efficient version. *grade should be grade_module1v(). */
1.1       maekawa   357:   POLY t;
                    358:   int ggg;
                    359:   if (f == ZERO) return(1);
1.4       takayama  360:   if (f->m->ringp->weightedHomogenization) {
                    361:        return 1; /* BUG: do not chech in case of one-zero homogenization */
                    362:   }
1.1       maekawa   363:   while (f != POLYNULL) {
                    364:     t = f;
                    365:     ggg = (*grade)(f);
                    366:     while (t != POLYNULL) {
                    367:       if ((*isSameComponent)(f,t)) {
1.3       takayama  368:         if (ggg != (*grade)(t)) return(0);
1.1       maekawa   369:       }
                    370:       t = t->next;
                    371:     }
                    372:     f = f->next;
                    373:   }
                    374:   return(1);
                    375: }
                    376:
                    377:
                    378: static int degreeOfPrincipalPart(f)
1.3       takayama  379:      POLY f;
1.1       maekawa   380: {
                    381:   int n,i,dd;
                    382:   if (f ISZERO) return(0);
                    383:   n = f->m->ringp->n; dd = 0;
                    384:   /* D[0] is homogenization var */
                    385:   for (i=1; i<n; i++) {
                    386:     dd += f->m->e[i].D;
                    387:   }
                    388:   return(dd);
                    389: }
                    390:
                    391: POLY POLYToPrincipalPart(f)
1.3       takayama  392:      POLY f;
1.1       maekawa   393: {
                    394:   POLY node;
                    395:   struct listPoly nod;
                    396:   POLY h;
                    397:   POLY g;
                    398:   int maxd = -20000; /* very big negative number */
                    399:   int dd;
                    400:   node = &nod; node->next = POLYNULL; h = node;
                    401:
                    402:   g = pCopy(f); /* shallow copy */
                    403:   while (!(f ISZERO)) {
                    404:     dd = degreeOfPrincipalPart(f);
                    405:     if (dd > maxd) maxd = dd;
                    406:     f = f->next;
                    407:   }
                    408:   while (!(g ISZERO)) {
                    409:     dd = degreeOfPrincipalPart(g);
                    410:     if (dd == maxd) {
                    411:       h->next = g;
                    412:       h = h->next;
                    413:     }
                    414:     g = g->next;
                    415:   }
                    416:   h->next = POLYNULL;
                    417:   return(node->next);
                    418: }
                    419:
                    420: static int degreeOfInitW(f,w)
1.3       takayama  421:      POLY f;
                    422:      int w[];
1.1       maekawa   423: {
                    424:   int n,i,dd;
                    425:   if (f ISZERO) {
                    426:     errorPoly("degreeOfInitW(0,w) ");
                    427:   }
                    428:   n = f->m->ringp->n; dd = 0;
                    429:   for (i=0; i<n; i++) {
                    430:     dd += (f->m->e[i].D)*w[n+i];
                    431:     dd += (f->m->e[i].x)*w[i];
                    432:   }
                    433:   return(dd);
                    434: }
                    435:
                    436: POLY POLYToInitW(f,w)
1.3       takayama  437:      POLY f;
                    438:      int w[]; /* weight vector */
1.1       maekawa   439: {
                    440:   POLY node;
                    441:   struct listPoly nod;
                    442:   POLY h;
                    443:   POLY g;
                    444:   int maxd;
                    445:   int dd;
                    446:   node = &nod; node->next = POLYNULL; h = node;
                    447:
                    448:   if (f ISZERO) return(f);
                    449:   maxd = degreeOfInitW(f,w);
                    450:   g = pCopy(f); /* shallow copy */
                    451:   while (!(f ISZERO)) {
                    452:     dd = degreeOfInitW(f,w);
                    453:     if (dd > maxd) maxd = dd;
                    454:     f = f->next;
                    455:   }
                    456:   while (!(g ISZERO)) {
                    457:     dd = degreeOfInitW(g,w);
                    458:     if (dd == maxd) {
                    459:       h->next = g;
                    460:       h = h->next;
                    461:     }
                    462:     g = g->next;
                    463:   }
                    464:   h->next = POLYNULL;
                    465:   return(node->next);
                    466: }
                    467:
                    468:
                    469: /*
                    470: 1.The substitution  "ringp->multiplication = ...." is allowed only in
                    471:   KsetUpRing(), so the check in KswitchFunction is not necessary.
                    472: 2.mmLarger != matrix and AvoidTheSameRing==1, then error
                    473: 3.If Schreyer = 1, then the system always generates a new ring.
                    474: 4.The execution of set_order_by_matrix is not allowed when Avoid... == 1.
                    475: 5.When mmLarger == tower  (in tower.sm1, tower-sugar.sm1), we do
                    476:   as follows with our own risk.
                    477: [(AvoidTheSameRing)] pushEnv [ [(AvoidTheSameRing) 0] system_variable (mmLarger) (tower) switch_function ] pop popEnv
                    478: */
                    479: int isTheSameRing(struct ring *rstack[],int rp, struct ring *newRingp)
                    480: {
                    481:   struct ring *rrr;
                    482:   int i,j,k;
                    483:   int a=0;
                    484:   for (k=0; k<rp; k++) {
                    485:     rrr = rstack[k];
                    486:     if (rrr->p != newRingp->p) { a=1; goto bbb ; }
                    487:     if (rrr->n != newRingp->n) { a=2; goto bbb ; }
                    488:     if (rrr->nn != newRingp->nn) { a=3; goto bbb ; }
                    489:     if (rrr->m != newRingp->m) { a=4; goto bbb ; }
                    490:     if (rrr->mm != newRingp->mm) { a=5; goto bbb ; }
                    491:     if (rrr->l != newRingp->l) { a=6; goto bbb ; }
                    492:     if (rrr->ll != newRingp->ll) { a=7; goto bbb ; }
                    493:     if (rrr->c != newRingp->c) { a=8; goto bbb ; }
                    494:     if (rrr->cc != newRingp->cc) { a=9; goto bbb ; }
                    495:     for (i=0; i<rrr->n; i++) {
                    496:       if (strcmp(rrr->x[i],newRingp->x[i])!=0) { a=10; goto bbb ; }
                    497:       if (strcmp(rrr->D[i],newRingp->D[i])!=0) { a=11; goto bbb ; }
                    498:     }
                    499:     if (rrr->orderMatrixSize != newRingp->orderMatrixSize) { a=12; goto bbb ; }
                    500:     for (i=0; i<rrr->orderMatrixSize; i++) {
                    501:       for (j=0; j<2*(rrr->n); j++) {
1.3       takayama  502:         if (rrr->order[i*2*(rrr->n)+j] != newRingp->order[i*2*(rrr->n)+j])
                    503:           { a=13; goto bbb ; }
1.1       maekawa   504:       }
                    505:     }
                    506:     if (rrr->next != newRingp->next) { a=14; goto bbb ; }
                    507:     if (rrr->multiplication != newRingp->multiplication) { a=15; goto bbb ; }
                    508:     /* if (rrr->schreyer != newRingp->schreyer) { a=16; goto bbb ; }*/
                    509:     if (newRingp->schreyer == 1) { a=16; goto bbb; }
1.4       takayama  510:     if (rrr->weightedHomogenization != newRingp->weightedHomogenization) { a=16; goto bbb; }
1.1       maekawa   511:     /* The following fields are ignored.
                    512:        void *gbListTower;
                    513:        int *outputOrder;
                    514:        char *name;
                    515:     */
                    516:     /* All tests are passed. */
                    517:     return(k);
                    518:   bbb: ;
                    519:     /* for debugging. */
                    520:     /* fprintf(stderr," reason=%d, ",a); */
                    521:   }
                    522:   return(-1);
                    523: }
1.6     ! takayama  524:
        !           525: /* s->1 */
        !           526: POLY goDeHomogenizeS(POLY f) {
        !           527:   POLY node;
        !           528:   POLY lastf;
        !           529:   struct listPoly nod;
        !           530:   POLY h;
        !           531:   POLY tf;
        !           532:   int gt,first;
        !           533:
        !           534:   if (f == POLYNULL) return(POLYNULL);
        !           535:   node = &nod;
        !           536:   node->next = POLYNULL;
        !           537:   lastf = POLYNULL;
        !           538:   first = 1;
        !           539:   while (f != POLYNULL) {
        !           540:     tf = newCell(f->coeffp,monomialCopy(f->m));
        !           541:     tf->m->e[0].x = 0;  /* H, s variable in the G-O paper. */
        !           542:     if (first) {
        !           543:       node->next = tf;
        !           544:       lastf = tf;
        !           545:       first = 0;
        !           546:     }else{
        !           547:       gt = (*mmLarger)(lastf,tf);
        !           548:       if (gt == 1) {
        !           549:         lastf->next = tf;
        !           550:         lastf = tf;
        !           551:       }else{
        !           552:         h = node->next;
        !           553:         h = ppAddv(h,tf);
        !           554:         node->next = h;
        !           555:         lastf = h;
        !           556:         while (lastf->next != POLYNULL) {
        !           557:           lastf = lastf->next;
        !           558:         }
        !           559:       }
        !           560:     }
        !           561:     f = f->next;
        !           562:   }
        !           563:   return (node->next);
        !           564: }
        !           565:
1.5       takayama  566: /* Granger-Oaku's homogenization for the ecart tangent cone.
                    567:    Note: 2003.07.10.
                    568:    ds[] is the degree shift.
                    569:    ei ( element index ). If it is < 0, then e[n-1]->x will be used,
                    570:                          else ei is used.
1.6     ! takayama  571:    if onlyS is set to 1, then input is assumed to be (u,v)-h-homogeneous.
1.5       takayama  572: */
1.6     ! takayama  573: POLY goHomogenize(POLY f,int u[],int v[],int ds[],int dssize,int ei,int onlyS)
1.5       takayama  574: {
                    575:   POLY node;
                    576:   POLY lastf;
                    577:   struct listPoly nod;
                    578:   POLY h;
                    579:   POLY tf;
                    580:   int gt,first,m,mp,t,tp,dsIdx,message;
                    581:
                    582:   message = 1;
                    583:   if (f == POLYNULL) return(POLYNULL);
                    584:   node = &nod;
                    585:   node->next = POLYNULL;
                    586:   lastf = POLYNULL;
                    587:   first = 1;
                    588:   while (f != POLYNULL) {
                    589:     if (first) {
                    590:       t = m = dGrade1(f);
                    591:       tp = mp = uvGrade1(f,u,v,ds,dssize,ei);
                    592:     }else{
                    593:       t =  dGrade1(f);
                    594:       tp = uvGrade1(f,u,v,ds,dssize,ei);
                    595:       if (t > m) m = t;
                    596:       if (tp < mp) mp = tp;
                    597:     }
                    598:
                    599:     tf = newCell(f->coeffp,monomialCopy(f->m));
                    600:        /* Automatic dehomogenize. Not +=  */
                    601:        if (message && ((tf->m->e[0].D != 0) || (tf->m->e[0].x != 0))) {
                    602:       /*go-debug fprintf(stderr,"Automatic dehomogenize and homogenize.\n"); */
                    603:          message = 0;
                    604:        }
1.6     ! takayama  605:        if (!onlyS) {
        !           606:          tf->m->e[0].D = -t;  /* h */
        !           607:        }
1.5       takayama  608:     tf->m->e[0].x = tp;  /* H, s variable in the G-O paper. */
                    609:        /*go-debug printf("t(h)=%d, tp(uv+ds)=%d\n",t,tp); */
                    610:     if (first) {
                    611:       node->next = tf;
                    612:       lastf = tf;
                    613:       first = 0;
                    614:     }else{
                    615:       gt = (*mmLarger)(lastf,tf);
                    616:       if (gt == 1) {
                    617:         lastf->next = tf;
                    618:         lastf = tf;
                    619:       }else{
                    620:         /*go-debug printf("?\n"); */
                    621:         h = node->next;
                    622:         h = ppAddv(h,tf);
                    623:         node->next = h;
                    624:         lastf = h;
                    625:         while (lastf->next != POLYNULL) {
                    626:           lastf = lastf->next;
                    627:         }
                    628:       }
                    629:        }
                    630:        f = f->next;
                    631:   }
                    632:   h = node->next;
                    633:   /*go-debug printf("m=%d, mp=%d\n",m,mp); */
                    634:   while (h != POLYNULL) {
                    635:     /*go-debug printf("Old: h=%d, s=%d\n",h->m->e[0].D,h->m->e[0].x); */
1.6     ! takayama  636:     if (!onlyS) h->m->e[0].D += m;   /* h */
1.5       takayama  637:     h->m->e[0].x += -mp; /* H, s*/
                    638:     /*go-debug printf("New: h=%d, s=%d\n",h->m->e[0].D,h->m->e[0].x); */
                    639:     h = h->next;
                    640:   }
                    641:   return (node->next);
                    642: }
                    643:
                    644: /* u[] = -1, v[] = 1 */
1.6     ! takayama  645: POLY goHomogenize11(POLY f,int ds[],int dssize,int ei,int onlyS)
1.5       takayama  646: {
                    647:   int r;
                    648:   int i,t,n,m,nn;
                    649:   MONOMIAL tf;
                    650:   static int *u;
                    651:   static int *v;
                    652:   static struct ring *cr = (struct ring *)NULL;
                    653:
                    654:   if (f == POLYNULL) return POLYNULL;
                    655:
                    656:   tf = f->m;
                    657:   if (tf->ringp != cr) {
                    658:     n = tf->ringp->n;
                    659:     m = tf->ringp->m;
                    660:     nn = tf->ringp->nn;
                    661:     cr = tf->ringp;
                    662:        u = (int *)sGC_malloc(sizeof(int)*n);
                    663:        v = (int *)sGC_malloc(sizeof(int)*n);
                    664:        for (i=0; i<n; i++) u[i]=v[i]=0;
                    665:        for (i=m; i<nn; i++) {
                    666:          u[i] = -1; v[i] = 1;
                    667:        }
                    668:   }
1.6     ! takayama  669:   return(goHomogenize(f,u,v,ds,dssize,ei,onlyS));
1.5       takayama  670: }
                    671:
1.6     ! takayama  672: POLY goHomogenize_dsIdx(POLY f,int u[],int v[],int dsIdx,int ei,int onlyS)
1.5       takayama  673: {
                    674:   if (f == POLYNULL) return POLYNULL;
                    675: }
1.6     ! takayama  676: POLY goHomogenize11_dsIdx(POLY f,int ds[],int dsIdx,int ei,int onlyS)
1.5       takayama  677: {
                    678:   if (f == POLYNULL) return POLYNULL;
                    679: }

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