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

Diff for /OpenXM/src/kan96xx/Kan/gradedset.c between version 1.1 and 1.9

version 1.1, 1999/10/08 02:12:02 version 1.9, 2005/07/03 11:08:53
Line 1 
Line 1 
   /* $OpenXM: OpenXM/src/kan96xx/Kan/gradedset.c,v 1.8 2005/06/30 08:35:07 takayama Exp $ */
 #include <stdio.h>  #include <stdio.h>
   #include <stdlib.h>
 #include "datatype.h"  #include "datatype.h"
 #include "extern2.h"  #include "extern2.h"
 #include "gradedset.h"  #include "gradedset.h"
Line 7 
Line 9 
 static int Debug=0;  static int Debug=0;
   
 struct polySet *newPolySet(n)  struct polySet *newPolySet(n)
 int n;       int n;
 {  {
   struct polySet *g;    struct polySet *g;
   int i;    int i;
   g = (struct polySet *)sGC_malloc(sizeof(struct polySet));    g = (struct polySet *)sGC_malloc(sizeof(struct polySet));
   g->g = (POLY *)sGC_malloc(sizeof(POLY)*(n+1));    g->g = (POLY *)sGC_malloc(sizeof(POLY)*(n+1));
     g->gh = (POLY *)sGC_malloc(sizeof(POLY)*(n+1));
     g->gmod = (POLY *)sGC_malloc(sizeof(POLY)*(n+1));
     g->gen = (int *)sGC_malloc(sizeof(int)*(n+1));
   g->del = (int *)sGC_malloc(sizeof(int)*(n+1));    g->del = (int *)sGC_malloc(sizeof(int)*(n+1));
   g->syz = (struct syz0 **)sGC_malloc(sizeof(struct syz0 *)*(n+1));    g->syz = (struct syz0 **)sGC_malloc(sizeof(struct syz0 *)*(n+1));
   g->mark = (int *)sGC_malloc(sizeof(int)*(n+1));    g->mark = (int *)sGC_malloc(sizeof(int)*(n+1));
   g->serial = (int *)sGC_malloc(sizeof(int)*(n+1));    g->serial = (int *)sGC_malloc(sizeof(int)*(n+1));
   if (g->g == (POLY *)NULL || g->del == (int *)NULL ||    if (g->g == (POLY *)NULL || g->del == (int *)NULL ||
         g->gh == (POLY *)NULL || g->gen == (int *)NULL ||
         g->gmod == (POLY *)NULL ||
       g->syz == (struct syz0 **)NULL || g->mark == (int *)NULL ||        g->syz == (struct syz0 **)NULL || g->mark == (int *)NULL ||
       g->serial == (int *)NULL) {        g->serial == (int *)NULL) {
     errorGradedSet("No more memory.");      errorGradedSet("No more memory.");
Line 30  int n;
Line 37  int n;
 }  }
   
 struct pair *newPair(prev)  struct pair *newPair(prev)
 struct pair *prev;       struct pair *prev;
 {  {
   struct pair *g;    struct pair *g;
   int i;    int i;
Line 46  struct pair *prev;
Line 53  struct pair *prev;
 }  }
   
 struct gradedPolySet *newGradedPolySet(n)  struct gradedPolySet *newGradedPolySet(n)
 int n;       int n;
 {  {
   struct gradedPolySet *g;    struct gradedPolySet *g;
   g = (struct gradedPolySet *)sGC_malloc(sizeof(struct gradedPolySet));    g = (struct gradedPolySet *)sGC_malloc(sizeof(struct gradedPolySet));
Line 56  int n;
Line 63  int n;
     errorGradedSet("No more memory.");      errorGradedSet("No more memory.");
   g->maxGrade = 0;    g->maxGrade = 0;
   g->lim = n;    g->lim = n;
     g->gb = 0;
     g->reduced = 0;
   return(g);    return(g);
 }  }
   
 struct gradedPairs *newGradedPairs(n)  struct gradedPairs *newGradedPairs(n)
 int n;       int n;
 {  {
   struct gradedPairs *g;    struct gradedPairs *g;
   int i;    int i;
Line 85  struct syz0 *newSyz0() {
Line 94  struct syz0 *newSyz0() {
 }  }
   
 struct pair *pairCopy(node)  struct pair *pairCopy(node)
 struct pair *node;       struct pair *node;
 {  {
   struct pair *r;    struct pair *r;
   r = newPair(node->prev);    r = newPair(node->prev);
Line 94  struct pair *node;
Line 103  struct pair *node;
 }  }
   
 struct gradedPairs *enlargeGradedPairs(size,grD)  struct gradedPairs *enlargeGradedPairs(size,grD)
 int size;       int size;
 struct gradedPairs *grD;       struct gradedPairs *grD;
 {  {
   struct gradedPairs *new;    struct gradedPairs *new;
   int i;    int i;
Line 107  struct gradedPairs *grD;
Line 116  struct gradedPairs *grD;
 }  }
   
 void insertPair(inode,before)  void insertPair(inode,before)
 struct pair *inode;       struct pair *inode;
 struct pair *before;       struct pair *before;
 {  {
   struct pair *q;    struct pair *q;
   inode = pairCopy(inode);    inode = pairCopy(inode);
Line 124  struct pair *before;
Line 133  struct pair *before;
 }  }
   
 struct pair *deletePair(p)  struct pair *deletePair(p)
 struct pair *p;       struct pair *p;
 {  {
   struct pair *q;    struct pair *q;
   struct pair *r;    struct pair *r;
Line 141  struct pair *p;
Line 150  struct pair *p;
 }  }
   
 struct pair *getPair_org(grD)  struct pair *getPair_org(grD)
 struct gradedPairs *grD;       struct gradedPairs *grD;
 {  {
   int gmax,i;    int gmax,i;
   struct pair *pair;    struct pair *pair;
Line 156  struct gradedPairs *grD;
Line 165  struct gradedPairs *grD;
 }  }
   
 struct pair *getPair(grD)  struct pair *getPair(grD)
 struct gradedPairs *grD;       struct gradedPairs *grD;
 {  {
   int gmax,i;    int gmax,i;
   struct pair *pair;    struct pair *pair;
Line 170  struct gradedPairs *grD;
Line 179  struct gradedPairs *grD;
       minnode = node;        minnode = node;
       node = node->next;        node = node->next;
       while (node != (struct pair *)NULL) {        while (node != (struct pair *)NULL) {
         if ((*mmLarger)(minp,node->lcm) >= 1) {          if ((*mmLarger)(minp,node->lcm) >= 1) {
           minnode = node;            minnode = node;
           minp = minnode->lcm;            minp = minnode->lcm;
         }          }
         node = node->next;          node = node->next;
       }        }
       pair = deletePair(minnode->prev);        pair = deletePair(minnode->prev);
       return(pair);        return(pair);
Line 183  struct gradedPairs *grD;
Line 192  struct gradedPairs *grD;
   return((struct pair *)NULL);    return((struct pair *)NULL);
 }  }
   
   
 void whereInG(g,fi,gradep,indexp,sugar)  void whereInG(g,fi,gradep,indexp,sugar)
 struct gradedPolySet *g;       struct gradedPolySet *g;
 POLY fi;       POLY fi;
 int *gradep;       int *gradep;
 int *indexp;       int *indexp;
 int sugar;       int sugar;
 {  {
   if (sugar) {    if (sugar) {
     if (*gradep < 0 ) {      if (*gradep < 0 ) {
       /* if sugar and *gradep < 0, then compute the grade.        /* if sugar and *gradep < 0, then compute the grade.
          Otherwise, grade is given by the caller. */           Otherwise, grade is given by the caller. */
       *gradep = grade_sugar(fi);        *gradep = grade_sugar(fi);
     }      }
   }else{    }else{
Line 213  int sugar;
Line 223  int sugar;
 }  }
   
 struct gradedPolySet *putPolyInG(g,fi,grade,index,syz,mark,serial)  struct gradedPolySet *putPolyInG(g,fi,grade,index,syz,mark,serial)
 struct gradedPolySet *g;       struct gradedPolySet *g;
 POLY fi;       POLY fi;
 int grade;       int grade;
 int index;       int index;
 struct syz0 *syz;       struct syz0 *syz;
 int mark;       int mark;
 int serial;       int serial;
 {  {
   int i,j;    int i,j;
   struct polySet *polysNew;    struct polySet *polysNew;
Line 227  int serial;
Line 237  int serial;
   struct polySet *ps;    struct polySet *ps;
   
   /*printf("--------------------\n");    /*printf("--------------------\n");
   outputGradedPolySet(g,0);*/      outputGradedPolySet(g,0);*/
   
   if (grade < 0) {    if (grade < 0) {
     warningGradedSet("putPolyInG(): the grade is -1. The element is ignored.");      warningGradedSet("putPolyInG(): the grade is -1. The element is ignored.");
Line 244  int serial;
Line 254  int serial;
       gnew->polys[i] = newPolySet(INITSIZE);        gnew->polys[i] = newPolySet(INITSIZE);
     }      }
     gnew->maxGrade = g->maxGrade;      gnew->maxGrade = g->maxGrade;
       gnew->gb = g->gb; gnew->reduced = g->reduced;
     g = gnew;      g = gnew;
   }    }
   
Line 253  int serial;
Line 264  int serial;
     polysNew = newPolySet(index*2+1);      polysNew = newPolySet(index*2+1);
     for (i=0; i<g->polys[grade]->lim; i++) {      for (i=0; i<g->polys[grade]->lim; i++) {
       polysNew->g[i] = g->polys[grade]->g[i];        polysNew->g[i] = g->polys[grade]->g[i];
         polysNew->gh[i] = g->polys[grade]->gh[i];
         polysNew->gmod[i] = g->polys[grade]->gmod[i];
         polysNew->gen[i] = g->polys[grade]->gen[i];
       polysNew->del[i] = g->polys[grade]->del[i];        polysNew->del[i] = g->polys[grade]->del[i];
       polysNew->syz[i] = g->polys[grade]->syz[i];        polysNew->syz[i] = g->polys[grade]->syz[i];
       polysNew->mark[i] = g->polys[grade]->mark[i];        polysNew->mark[i] = g->polys[grade]->mark[i];
Line 264  int serial;
Line 278  int serial;
   
   g->polys[grade]->size = index+1;    g->polys[grade]->size = index+1;
   g->polys[grade]->g[index] = fi;    g->polys[grade]->g[index] = fi;
     g->polys[grade]->gh[index] = POLYNULL;
     g->polys[grade]->gmod[index] = POLYNULL;
     g->polys[grade]->gen[index] = 0;
   g->polys[grade]->del[index] = 0;    g->polys[grade]->del[index] = 0;
   g->polys[grade]->syz[index] = syz;    g->polys[grade]->syz[index] = syz;
   g->polys[grade]->mark[index] = mark;    g->polys[grade]->mark[index] = mark;
Line 271  int serial;
Line 288  int serial;
   if (g->maxGrade < grade+1) g->maxGrade = grade+1;    if (g->maxGrade < grade+1) g->maxGrade = grade+1;
   
   /*printf("grade=%d, index=%d\n",grade,index);    /*printf("grade=%d, index=%d\n",grade,index);
   outputGradedPolySet(g,0);*/      outputGradedPolySet(g,0);*/
   return(g);    return(g);
 }  }
   
 void markRedundant(g,fi,grade,index,sugar)  void markRedundant(g,fi,grade,index,sugar)
 struct gradedPolySet *g;       struct gradedPolySet *g;
 POLY fi;       POLY fi;
 int grade,index;       int grade,index;
 int sugar;       int sugar;
 {  {
   int i,j;    int i,j;
   struct polySet *ps;    struct polySet *ps;
Line 292  int sugar;
Line 309  int sugar;
     for (j=0; j<ps->size; j++) {      for (j=0; j<ps->size; j++) {
       if (i == grade && j == index) {        if (i == grade && j == index) {
       }else if ((*isReducible)(ps->g[j],fi)) {        }else if ((*isReducible)(ps->g[j],fi)) {
         ps->del[j] = 1;                  if (! ps->gen[j]) ps->del[j] = 1; /*?*/
       }        }
     }      }
   }    }
 }  }
   
 void markRedundant0(g,grade,index)  void markRedundant0(g,grade,index)
 struct gradedPolySet *g;       struct gradedPolySet *g;
 int grade,index;       int grade,index;
 {  {
   int i,j;    int i,j;
   struct polySet *ps;    struct polySet *ps;
Line 313  int grade,index;
Line 330  int grade,index;
     for (j=0; j<ps->size; j++) {      for (j=0; j<ps->size; j++) {
       if (i == grade && j == index) {        if (i == grade && j == index) {
       }else if ((*isReducible)(ps->g[j],fi)) {        }else if ((*isReducible)(ps->g[j],fi)) {
         ps->del[j] = 1;          if (! ps->gen[j] ) ps->del[j] = 1; /*?*/
       }else if ((*isReducible)(fi,ps->g[j])) {        }else if ((*isReducible)(fi,ps->g[j])) {
         g->polys[grade]->del[index] = 1;          if (! g->polys[grade]->gen[index] ) g->polys[grade]->del[index] = 1; /*?*/
         return;          return;
       }        }
     }      }
   }    }
 }  }
   
 struct gradedPairs *putPairInGradedPairs(struct gradedPairs *grP,  struct gradedPairs *putPairInGradedPairs(struct gradedPairs *grP,
                                          struct pair *top)                                           struct pair *top)
 {  {
   if (grP == (struct gradedPairs *)NULL) {    if (grP == (struct gradedPairs *)NULL) {
     grP = newGradedPairs(top->grade +1);      grP = newGradedPairs(top->grade +1);
Line 337  struct gradedPairs *putPairInGradedPairs(struct graded
Line 354  struct gradedPairs *putPairInGradedPairs(struct graded
 }  }
   
 void errorGradedSet(s)  void errorGradedSet(s)
 char *s;       char *s;
 {  {
   fprintf(stderr,"Error in gradedset.c, red.c, gb.c: %s\n",s);    fprintf(stderr,"Error in gradedset.c, red.c, gb.c: %s\n",s);
   exit(23);    exit(23);
 }  }
   
 void warningGradedSet(s)  void warningGradedSet(s)
 char *s;       char *s;
 {  {
   fprintf(stderr,"Warning in gradedset.c, red.c, gb.c: %s\n",s);    fprintf(stderr,"Warning in gradedset.c, red.c, gb.c: %s\n",s);
 }  }
   
   
 void outputGradedPolySet(grG,needSyz)  void outputGradedPolySet(grG,needSyz)
 struct gradedPolySet *grG;       struct gradedPolySet *grG;
 int needSyz;       int needSyz;
 {  {
   int i,j;    int i,j;
   struct polySet *set;    struct polySet *set;
     extern Ecart;
   printf("======== gradedPolySet ==========\n");    printf("======== gradedPolySet ==========\n");
   printf("maxGrade=%d\n",grG->maxGrade);    printf("maxGrade=%d\n",grG->maxGrade);
   for (i=0; i<grG->maxGrade; i++) {    for (i=0; i<grG->maxGrade; i++) {
Line 363  int needSyz;
Line 381  int needSyz;
     printf("grade=%d, size=%d\n",i,set->size);      printf("grade=%d, size=%d\n",i,set->size);
     for (j=0; j<set->size; j++) {      for (j=0; j<set->size; j++) {
       printf("j=%d, del=%d, g=%s\n",j,set->del[j],POLYToString(set->g[j],'*',1));        printf("j=%d, del=%d, g=%s\n",j,set->del[j],POLYToString(set->g[j],'*',1));
             if (Ecart) printf("     gh=%s\n",POLYToString(set->gh[j],'*',1));
       if (needSyz) {        if (needSyz) {
         printf("mark=%d,serial=%d, syz.cf=%s, syz.syz=%s\n",set->mark[j],          printf("mark=%d,serial=%d, syz.cf=%s, syz.syz=%s\n",set->mark[j],
                set->serial[j],POLYToString(set->syz[j]->cf,'*',1),                 set->serial[j],POLYToString(set->syz[j]->cf,'*',1),
                POLYToString(set->syz[j]->syz,'*',1));                 POLYToString(set->syz[j]->syz,'*',1));
       }else{        }else{
         printf("mark=%d,serial=%d\n",set->mark[j],          printf("mark=%d,serial=%d\n",set->mark[j],
                set->serial[j]);                 set->serial[j]);
       }        }
     }      }
   }    }
Line 377  int needSyz;
Line 396  int needSyz;
 }  }
   
 int countGradedPolySet(grG)  int countGradedPolySet(grG)
 struct gradedPolySet *grG;       struct gradedPolySet *grG;
 {  {
   int i,j;    int i,j;
   struct polySet *set;    struct polySet *set;
Line 391  struct gradedPolySet *grG;
Line 410  struct gradedPolySet *grG;
   
   
 void outputGradedPairs(grP)  void outputGradedPairs(grP)
 struct gradedPairs *grP;       struct gradedPairs *grP;
 {  {
   int i,j;    int i,j;
   struct pair *pair;    struct pair *pair;
Line 411  struct gradedPairs *grP;
Line 430  struct gradedPairs *grP;
 }  }
   
 void outputNode(pair)  void outputNode(pair)
 struct pair *pair;       struct pair *pair;
 {  {
   int i = 0;    int i = 0;
   printf("=== list === \n");    printf("=== list === \n");
Line 431  struct pair *pair;
Line 450  struct pair *pair;
   
   
 int countPairs(grD)  int countPairs(grD)
 struct gradedPairs *grD;       struct gradedPairs *grD;
 {  {
   int i;    int i;
   int c;    int c;
Line 449  struct gradedPairs *grD;
Line 468  struct gradedPairs *grD;
 }  }
   
 struct gradedPolySet *gradedPolySetCopy(grG)  struct gradedPolySet *gradedPolySetCopy(grG)
 struct gradedPolySet *grG;       struct gradedPolySet *grG;
 {  {
   int i,j;    int i,j;
   struct polySet *ps,*psOld;    struct polySet *ps,*psOld;
Line 473  struct gradedPolySet *grG;
Line 492  struct gradedPolySet *grG;
 }  }
   
 int deletePairByCriterion2B(struct gradedPairs *grD,POLY gt,  int deletePairByCriterion2B(struct gradedPairs *grD,POLY gt,
                             struct gradedPolySet *grG)                              struct gradedPolySet *grG)
 {  {
   int gmax,i;    int gmax,i;
   struct pair *node;    struct pair *node;
Line 488  int deletePairByCriterion2B(struct gradedPairs *grD,PO
Line 507  int deletePairByCriterion2B(struct gradedPairs *grD,PO
     if ((grD->pairs[i])->next != (struct pair *)NULL) {      if ((grD->pairs[i])->next != (struct pair *)NULL) {
       node = grD->pairs[i]->next;        node = grD->pairs[i]->next;
       while (node != (struct pair *)NULL) {        while (node != (struct pair *)NULL) {
         ig = node->ig; ii = node->ii;          ig = node->ig; ii = node->ii;
         jg = node->jg; ji = node->ji;          jg = node->jg; ji = node->ji;
         if ((*isReducible)(node->lcm,gt)) {          if ((*isReducible)(node->lcm,gt)) {
           ig = node->ig; ii = node->ii;            ig = node->ig; ii = node->ii;
           jg = node->jg; ji = node->ji;            jg = node->jg; ji = node->ji;
           it = (*lcm)(grG->polys[ig]->g[ii],gt);            it = (*lcm)(grG->polys[ig]->g[ii],gt);
           ij = (*lcm)(grG->polys[ig]->g[ii],grG->polys[jg]->g[ji]);            ij = (*lcm)(grG->polys[ig]->g[ii],grG->polys[jg]->g[ji]);
           jt = (*lcm)(grG->polys[jg]->g[ji],gt);            jt = (*lcm)(grG->polys[jg]->g[ji],gt);
           if ((*mmLarger)(it,ij) != 2 &&            if ((*mmLarger)(it,ij) != 2 &&
               (*mmLarger)(it,jt) != 2 &&                (*mmLarger)(it,jt) != 2 &&
               (*mmLarger)(ij,jt) != 2) {                (*mmLarger)(ij,jt) != 2) {
             node = deletePair(node->prev);              node = deletePair(node->prev);
             count++;              count++;
           }            }
         }          }
         node = node->next;          node = node->next;
       }        }
     }      }
   }    }
   return(count);    return(count);
   }
   
   int markGeneratorInG(struct gradedPolySet *g,int grade,int index)
   {
     g->polys[grade]->gen[index] = 1;
     return 1;
   }
   
   int clearGmod(struct gradedPolySet *gset) {
     int grd,i;
     struct polySet *set;
     for (grd=0; grd < gset->maxGrade; grd++) {
           set = gset->polys[grd];
           for (i = 0; i<set->size; i++) {
             set->gmod[i] = POLYNULL;
           }
     }
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.9

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