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

Annotation of OpenXM/src/kan96xx/Kan/poly.c, Revision 1.4

1.4     ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/Kan/poly.c,v 1.3 2001/05/04 01:06:24 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:
                      8:
                      9: void KinitKan(void) {
                     10:
                     11:   extern int Msize;
                     12:   extern struct ring SmallRing;
                     13:   extern struct ring *CurrentRingp;
                     14:   extern MP_INT *Mp_one;
                     15:   extern MP_INT *Mp_zero;
                     16:   extern MP_INT Mp_work_iiComb;
                     17:   extern MP_INT Mp_work_iiPoch;
                     18:   extern MP_INT Mp_work_iiPower;
                     19:
                     20:   static MP_INT Mp_One;
                     21:   static MP_INT Mp_Zero;
                     22:
                     23:   extern struct coeff *UniversalZero;
                     24:   extern struct coeff *UniversalOne;
                     25:
                     26:   int i;
                     27:   static char *smallx[] = {"x","t"};
                     28:   static char *smalld[] = {"h","T"};
1.3       takayama   29:   /* t  x  T  h */
1.1       maekawa    30:   static int smallOrder[] = { 1, 0, 0, 0,
                     31:                               0, 1, 0, 0,
                     32:                               0, 0, 1, 0,
                     33:                               0, 0, 0, 1};
                     34:
                     35:   static int outputOrderForSmallRing[] = {1,0,3,2};
                     36:   Msize = sizeof(struct monomial) - sizeof(struct monomialDummy);
                     37:   if (Msize <= 0) errorPoly("Problem of your C-compiler??!!");
                     38:
                     39:   /* Define the CurrentRingp */
                     40:   /* Define the SmallRingp */
                     41:
                     42:   SmallRing.p = 0;
                     43:   SmallRing.n = SmallRing.m = SmallRing.l = SmallRing.c = 2;
                     44:   SmallRing.nn = SmallRing.mm = SmallRing.ll = 2;
                     45:   SmallRing.cc = 1;
                     46:   SmallRing.x = smallx;
                     47:   SmallRing.D = smalld;
                     48:   SmallRing.order = smallOrder;
                     49:   SmallRing.orderMatrixSize = 4;
                     50:   setFromTo(&SmallRing);
                     51:   SmallRing.next = (struct ring *)NULL;
                     52:   SmallRing.multiplication = mpMult_poly;
                     53:   SmallRing.schreyer = 0;
                     54:   SmallRing.gbListTower = NULL;
                     55:   SmallRing.outputOrder = outputOrderForSmallRing;
                     56:   SmallRing.name = "SmallRingp";
1.4     ! takayama   57:   SmallRing.partialEcart = 0;
1.1       maekawa    58:
                     59:   CurrentRingp = &SmallRing;
                     60:   initSyzRingp();
                     61:
                     62:   switch_init();
                     63:   initT();  /* Initialize poly3.c */
                     64:
                     65:
                     66: #ifndef NOGC
                     67:   /* initialize MPZ */
1.3       takayama   68:   mp_set_memory_functions(sGC_malloc,sGC_realloc2,sGC_free2);
1.1       maekawa    69: #endif
                     70:
                     71:   /* Msize is 8 on SUN gcc */
                     72:
                     73:   /* We have defined a ring. Let's initialize Nodes */
                     74:
                     75:   Mp_one = &Mp_One;
                     76:   mpz_init(Mp_one); mpz_set_si(Mp_one,(long) 1);
                     77:   Mp_zero = &Mp_Zero;
                     78:   mpz_init(Mp_zero); mpz_set_si(Mp_zero,(long) 0);
                     79:   mpz_init(&Mp_work_iiComb); mpz_init(&Mp_work_iiPoch);
                     80:   mpz_init(&Mp_work_iiPower);
                     81:
                     82:   UniversalZero = intToCoeff(0,&SmallRing);
                     83:   UniversalOne = intToCoeff(1,&SmallRing);
                     84:
                     85:   KdefaultPolyRing(KpoInteger(0));
                     86: }
                     87:
                     88: #ifndef NOGC
                     89: void *sGC_realloc2(void *p,size_t old,size_t new)
                     90: {
                     91:   return((void *)sGC_realloc(p,(int) new));
                     92: }
                     93: void sGC_free2(void *p,size_t size)
                     94: {
                     95:   /* Do nothing. */
                     96: }
                     97: #endif
                     98:
                     99:
                    100: MONOMIAL newMonomial(ringp)
1.3       takayama  101:      struct ring *ringp;
1.1       maekawa   102: {
                    103:   MONOMIAL f;
                    104:   extern int Msize;
                    105:   int i;
                    106:   int n;
                    107:   n = ringp->n;
                    108:   f = (MONOMIAL) sGC_malloc(sizeof(struct smallMonomial)+n*Msize);
                    109:   if (f == (MONOMIAL) NULL) errorPoly("No more memory.");
                    110:   f->ringp = ringp;
                    111:   for (i=0; i<n; i++) {
                    112:     (f->e)[i].x = 0;
                    113:     (f->e)[i].D = 0;  /* necessary?->Yes. */
                    114:   }
                    115:   return(f);
                    116: }
                    117:
                    118:
                    119: MONOMIAL monomialCopy(m)
1.3       takayama  120:      MONOMIAL m;
1.1       maekawa   121: {
                    122:   extern int Msize;
                    123:   MONOMIAL f;
                    124:   int i;
                    125:   int n;
                    126:   n = m->ringp->n;
                    127:   f = (MONOMIAL) sGC_malloc(sizeof(struct smallMonomial)+n*Msize);
                    128:
                    129:   if (f == (MONOMIAL) NULL) errorPoly("No more memory.");
                    130:   f->ringp = m->ringp;
                    131:   for (i=0; i<n; i++) {
                    132:     (f->e)[i].x = (m->e)[i].x;
                    133:     (f->e)[i].D = (m->e)[i].D;
                    134:   }
                    135:   return(f);
                    136: }
                    137:
                    138:
                    139: struct coeff *newCoeff() {
                    140:   struct coeff *cp;
                    141:   cp = (struct coeff *)sGC_malloc(sizeof (struct coeff));
                    142:   if (cp == (struct coeff *)NULL) errorPoly("No more memory.");
                    143:   cp->tag = UNKNOWN;
                    144:   cp->p = -123; /* stupid value */
                    145:   return(cp);
                    146: }
                    147:
                    148: MP_INT *newMP_INT() {
                    149:   MP_INT *ip;
                    150:   ip = (MP_INT *)sGC_malloc(sizeof(MP_INT));
                    151:   if (ip == (MP_INT *)NULL) errorPoly("No more memory.");
                    152:   mpz_init(ip);
                    153:   return(ip);
                    154: }
                    155:
                    156: POLY newCell(c,mon)
1.3       takayama  157:      struct coeff *c;
                    158:      MONOMIAL mon;
1.1       maekawa   159: {
                    160:   POLY ff;
                    161:   ff = (POLY) sGC_malloc(sizeof(struct listPoly));
                    162:   if (ff == POLYNULL) errorPoly("No more memory.");
                    163:   ff->next = POLYNULL;
                    164:   ff->coeffp = c;
                    165:   ff->m = mon;
                    166:   return(ff);
                    167: }
                    168:
                    169: /* constructors */
                    170: POLY cxx(c,i,k,ringp)
1.3       takayama  171:      int c,i,k;
                    172:      struct ring *ringp;
                    173:      /*  c x_i^k where p is the characteristic. */
                    174:      /* New cell, monomial and coeff. */
1.1       maekawa   175: {
                    176:   POLY f;
                    177:   int p;
                    178:   p = ringp->p;
                    179:   if (c == 0) return(POLYNULL);
                    180:   f = pMalloc(ringp);
                    181:   if (ringp->next == (struct ring *)NULL) {
                    182:     if (p) {
                    183:       f->coeffp->tag = INTEGER; f->coeffp->p = p;
                    184:       f->coeffp->val.i = c % p;
                    185:       if (f->coeffp->val.i == 0) return(POLYNULL);
                    186:     }else{
                    187:       f->coeffp->tag = MP_INTEGER; f->coeffp->p = 0;
                    188:       f->coeffp->val.bigp = newMP_INT();
                    189:       mpz_set_si(f->coeffp->val.bigp,(long) c);
                    190:     }
                    191:     f->m->e[i].x = k;
                    192:     return(f);
                    193:   }else{
                    194:     f->coeffp->tag = POLY_COEFF; f->coeffp->p = p;
                    195:     f->coeffp->val.f = cxx(c,0,0,ringp->next);
                    196:     if (f->coeffp->val.f == POLYNULL) return(POLYNULL);
                    197:     f->m->e[i].x = k;
                    198:     return(f);
                    199:   }
                    200: }
                    201:
                    202: POLY bxx(c,i,k,ringp)
1.3       takayama  203:      MP_INT *c;
                    204:      int i,k;
                    205:      struct ring *ringp;
                    206:      /*  c x_i^k.  c is not copied. */
1.1       maekawa   207: {
1.3       takayama  208:   /* new cell, monomial, coeff. MP_INT c is not copied. */
1.1       maekawa   209:   POLY f;
                    210:   int p;
                    211:   p = ringp->p;
                    212:   if (mpz_cmp_si(c,(long)0) == 0) return(POLYNULL);
                    213:   f = pMalloc(ringp);
                    214:   if (ringp->next == (struct ring *)NULL) {
                    215:     if (p) {
                    216:       f->coeffp->tag = INTEGER; f->coeffp->p = p;
                    217:       f->coeffp->val.i = (int) mpz_get_si(c);
                    218:       f->coeffp->val.i %= p;
                    219:       if (f->coeffp->val.i == 0) return(POLYNULL);
                    220:     }else{
                    221:       f->coeffp->tag = MP_INTEGER; f->coeffp->p = 0;
                    222:       f->coeffp->val.bigp = c;
                    223:     }
                    224:     f->m->e[i].x = k;
                    225:     return(f);
                    226:   }else{
                    227:     warningPoly("cbb(): ringp->next is not NULL. Returns 0.");
                    228:     return(POLYNULL);
                    229:   }
                    230: }
                    231:
                    232: POLY cdd(c,i,k,ringp)
1.3       takayama  233:      int c,i,k;
                    234:      struct ring *ringp;
                    235:      /*  c D_i^k where p is the characteristic. */
                    236:      /* New cell, monomial and coeff. */
1.1       maekawa   237: {
                    238:   POLY f;
                    239:   int p;
                    240:   p = ringp->p;
                    241:   if (c == 0) return(POLYNULL);
                    242:   f = pMalloc(ringp);
                    243:   if (ringp->next == (struct ring *)NULL) {
                    244:     if (p) {
                    245:       f->coeffp->tag = INTEGER; f->coeffp->p = p;
                    246:       f->coeffp->val.i = c % p;
                    247:       if (f->coeffp->val.i == 0) return(POLYNULL);
                    248:     }else{
                    249:       f->coeffp->tag = MP_INTEGER; f->coeffp->p = 0;
                    250:       f->coeffp->val.bigp = newMP_INT();
                    251:       mpz_set_si(f->coeffp->val.bigp,(long) c);
                    252:     }
                    253:     f->m->e[i].D = k;
                    254:     return(f);
                    255:   }else{
                    256:     f->coeffp->tag = POLY_COEFF; f->coeffp->p = p;
                    257:     f->coeffp->val.f = cdd(c,0,0,ringp->next);
                    258:     if (f->coeffp->val.f == POLYNULL) return(POLYNULL);
                    259:     f->m->e[i].D = k;
                    260:     return(f);
                    261:   }
                    262:
                    263: }
                    264:
                    265:
                    266: POLY pCopy(f)
1.3       takayama  267:      POLY f;
1.1       maekawa   268: {
                    269:   POLY node;
                    270:   struct listPoly nod;
                    271:   POLY h;
                    272:   node = &nod;
                    273:   if (f == POLYNULL) return(POLYNULL);
                    274:   node->next = POLYNULL;
                    275:   h = node;
                    276:   while (f != POLYNULL) {
                    277:     h->next = newCell(f->coeffp,f->m); /* shallow */
                    278:     h = h->next;
                    279:     f = f->next;
                    280:   }
                    281:   return(node->next);
                    282: }
                    283:
                    284: POLY pcCopy(f)
1.3       takayama  285:      POLY f;
1.1       maekawa   286: {
                    287:
                    288:   POLY node;
                    289:   struct listPoly nod;
                    290:   POLY h;
                    291:   struct coeff *c;
                    292:   node = &nod;
                    293:   if (f == POLYNULL) return(POLYNULL);
                    294:   node->next = POLYNULL;
                    295:   h = node;
                    296:   while (f != POLYNULL) {
                    297:     c = coeffCopy(f->coeffp);
                    298:     h->next = newCell(c,f->m); /* poly and coeff. */
                    299:     h = h->next;
                    300:     f = f->next;
                    301:   }
                    302:   return(node->next);
                    303: }
                    304:
                    305: POLY pmCopy(f)
1.3       takayama  306:      POLY f;
1.1       maekawa   307: {
                    308:   POLY node;
                    309:   struct listPoly nod;
                    310:   POLY h;
                    311:   struct coeff *c;
                    312:   node = &nod;
                    313:   if (f == POLYNULL) return(POLYNULL);
                    314:   node->next = POLYNULL;
                    315:   h = node;
                    316:   while (f != POLYNULL) {
                    317:     h->next = newCell(f->coeffp,monomialCopy(f->m));
                    318:     h = h->next;
                    319:     f = f->next;
                    320:   }
                    321:   return(node->next);
                    322: }
                    323:
                    324: POLY pcmCopy(f)
1.3       takayama  325:      POLY f;
1.1       maekawa   326: {
                    327:   POLY node;
                    328:   struct listPoly nod;
                    329:   POLY h;
                    330:   struct coeff *c;
                    331:   node = &nod;
                    332:   if (f == POLYNULL) return(POLYNULL);
                    333:   node->next = POLYNULL;
                    334:   h = node;
                    335:   while (f != POLYNULL) {
                    336:     h->next = newCell(coeffCopy(f->coeffp),monomialCopy(f->m));
                    337:     h = h->next;
                    338:     f = f->next;
                    339:   }
                    340:   return(node->next);
                    341: }
                    342:
                    343: POLY head(f)
1.3       takayama  344:      POLY f;
1.1       maekawa   345: {
                    346:   if (f == ZERO) return(f);
                    347:   else {
                    348:     return(newCell(f->coeffp,f->m));
                    349:   }
                    350: }
                    351:
                    352: void errorPoly(str)
1.3       takayama  353:      char *str;
1.1       maekawa   354: {
                    355:   fprintf(stderr,"Error(poly.c): %s\n",str);
                    356:   exit(20);
                    357: }
                    358:
                    359: void warningPoly(str)
1.3       takayama  360:      char *str;
1.1       maekawa   361: {
                    362:   fprintf(stderr,"Warning(poly.c): %s\n",str);
                    363: }
                    364:
                    365:
                    366:
                    367:
                    368:
                    369:
                    370:
                    371:
                    372:
                    373:
                    374:

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