[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.3

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

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