[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.2 and 1.4

version 1.2, 2000/01/16 07:55:38 version 1.4, 2003/07/17 07:33:03
Line 1 
Line 1 
 /* $OpenXM$ */  /* $OpenXM: OpenXM/src/kan96xx/Kan/gradedset.c,v 1.3 2001/05/04 01:06:23 takayama Exp $ */
 #include <stdio.h>  #include <stdio.h>
 #include "datatype.h"  #include "datatype.h"
 #include "extern2.h"  #include "extern2.h"
Line 8 
Line 8 
 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->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->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 31  int n;
Line 33  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 47  struct pair *prev;
Line 49  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 61  int n;
Line 63  int n;
 }  }
   
 struct gradedPairs *newGradedPairs(n)  struct gradedPairs *newGradedPairs(n)
 int n;       int n;
 {  {
   struct gradedPairs *g;    struct gradedPairs *g;
   int i;    int i;
Line 86  struct syz0 *newSyz0() {
Line 88  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 95  struct pair *node;
Line 97  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 108  struct gradedPairs *grD;
Line 110  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 125  struct pair *before;
Line 127  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 142  struct pair *p;
Line 144  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 157  struct gradedPairs *grD;
Line 159  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 171  struct gradedPairs *grD;
Line 173  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 185  struct gradedPairs *grD;
Line 187  struct gradedPairs *grD;
 }  }
   
 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 214  int sugar;
Line 216  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 228  int serial;
Line 230  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 254  int serial;
Line 256  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->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 265  int serial;
Line 268  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]->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 272  int serial;
Line 276  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 293  int sugar;
Line 297  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;          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 314  int grade,index;
Line 318  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;          ps->del[j] = 1;
       }else if ((*isReducible)(fi,ps->g[j])) {        }else if ((*isReducible)(fi,ps->g[j])) {
         g->polys[grade]->del[index] = 1;          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 338  struct gradedPairs *putPairInGradedPairs(struct graded
Line 342  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 364  int needSyz;
Line 369  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 378  int needSyz;
Line 384  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 392  struct gradedPolySet *grG;
Line 398  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 412  struct gradedPairs *grP;
Line 418  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 432  struct pair *pair;
Line 438  struct pair *pair;
   
   
 int countPairs(grD)  int countPairs(grD)
 struct gradedPairs *grD;       struct gradedPairs *grD;
 {  {
   int i;    int i;
   int c;    int c;
Line 450  struct gradedPairs *grD;
Line 456  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 474  struct gradedPolySet *grG;
Line 480  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 489  int deletePairByCriterion2B(struct gradedPairs *grD,PO
Line 495  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;
       }        }
     }      }
   }    }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.4

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