[b3e45f] | 1 | /* |
---|
[6623f3] | 2 | Compute the Groebner fan of an ideal |
---|
[361be1f] | 3 | Author: $Author: monerjan $ |
---|
[198a339] | 4 | Date: $Date: 2009-02-10 17:04:17 $ |
---|
| 5 | Header: $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.9 2009-02-10 17:04:17 monerjan Exp $ |
---|
| 6 | Id: $Id: gfan.cc,v 1.9 2009-02-10 17:04:17 monerjan Exp $ |
---|
[b3e45f] | 7 | */ |
---|
| 8 | |
---|
[d3398c] | 9 | #include "mod2.h" |
---|
| 10 | #include "kstd1.h" |
---|
[50ab25a] | 11 | #include "intvec.h" |
---|
[2c6535] | 12 | #include "polys.h" |
---|
| 13 | #include "ideals.h" |
---|
[198a339] | 14 | #include "kmatrix.h" |
---|
[d3398c] | 15 | |
---|
[b3e45f] | 16 | #ifndef gfan_DEBUG |
---|
| 17 | #define gfan_DEBUG |
---|
| 18 | #endif |
---|
| 19 | |
---|
[2c6535] | 20 | ideal getGB(ideal inputIdeal) |
---|
| 21 | { |
---|
[b3e45f] | 22 | #ifdef gfan_DEBUG |
---|
| 23 | printf("Now in getGB\n"); |
---|
| 24 | #endif |
---|
[2c6535] | 25 | |
---|
| 26 | ideal gb; |
---|
| 27 | gb=kStd(inputIdeal,NULL,testHomog,NULL); //Possible to call without testHomog/isHomog? |
---|
| 28 | idSkipZeroes(gb); //Get rid of zero entries |
---|
| 29 | |
---|
[b3e45f] | 30 | return gb; |
---|
| 31 | } |
---|
| 32 | |
---|
[2c6535] | 33 | /****** getWallIneq computes the inequalities ***/ |
---|
| 34 | /*INPUT_TYPE: ideal */ |
---|
| 35 | /*RETURN_TYPE: matrix */ |
---|
| 36 | /************************************************/ |
---|
| 37 | void getWallIneq(ideal I) |
---|
| 38 | { |
---|
| 39 | #ifdef gfan_DEBUG |
---|
[03de21] | 40 | printf("*** Computing Inequalities... ***\n"); |
---|
[2c6535] | 41 | #endif |
---|
| 42 | |
---|
[03de21] | 43 | //All variables go here - except ineq matrix |
---|
| 44 | int lengthGB=IDELEMS(I); // # of polys in the groebner basis |
---|
| 45 | int pCompCount; // # of terms in a poly |
---|
[2c6535] | 46 | poly aktpoly; |
---|
[03de21] | 47 | int numvar = pVariables; // # of variables in a polynomial (or ring?) |
---|
| 48 | int leadexp[numvar]; // dirty hack of exp.vects |
---|
| 49 | int aktexp[numvar]; |
---|
| 50 | int cols,rows; // will contain the dimensions of the ineq matrix |
---|
| 51 | // End of var declaration |
---|
[2c6535] | 52 | |
---|
[198a339] | 53 | printf("The Groebner basis has %i elements\n",lengthGB); |
---|
[03de21] | 54 | printf("The current ring has %i variables\n",numvar); |
---|
| 55 | cols = numvar; |
---|
| 56 | |
---|
| 57 | //Compute the # inequalities i.e. rows of the matrix |
---|
| 58 | rows=0; //Initialization |
---|
| 59 | for (int ii=0;ii<IDELEMS(I);ii++) |
---|
| 60 | { |
---|
| 61 | aktpoly=(poly)I->m[ii]; |
---|
| 62 | rows=rows+pLength(aktpoly)-1; |
---|
| 63 | } |
---|
| 64 | printf("rows=%i\n",rows); |
---|
| 65 | printf("Will create a %i x %i - matrix to store inequalities\n",rows,cols); |
---|
[198a339] | 66 | int ineq[rows][cols]; // array of int vs matrix vs KMatrix ??? What's to use? |
---|
| 67 | int aktmatrixrow=0; // needed to store the diffs of the expvects in the rows of ineq |
---|
[2c6535] | 68 | |
---|
| 69 | // We loop through each g\in GB |
---|
| 70 | for (int i=0; i<IDELEMS(I); i++) |
---|
| 71 | { |
---|
[198a339] | 72 | aktpoly=(poly)I->m[i]; //get aktpoly as i-th component of I |
---|
| 73 | pCompCount=pLength(aktpoly); //How many terms does aktpoly consist of? |
---|
[2c6535] | 74 | printf("Poly No. %i has %i components\n",i,pCompCount); |
---|
[03de21] | 75 | |
---|
| 76 | int *v=(int *)omAlloc((numvar+1)*sizeof(int)); |
---|
| 77 | pGetExpV(aktpoly,v); //find the exp.vect in v[1],...,v[n], use pNext(p) |
---|
[198a339] | 78 | |
---|
[03de21] | 79 | //Store leadexp for aktpoly |
---|
| 80 | for (int kk=0;kk<numvar;kk++) |
---|
| 81 | { |
---|
| 82 | leadexp[kk]=v[kk+1]; |
---|
| 83 | printf("Leadexpcomp=%i\n",leadexp[kk]); |
---|
[198a339] | 84 | //Since we need to know the difference of leadexp with the other expvects we do nothing here |
---|
| 85 | //but compute the diff below |
---|
[03de21] | 86 | } |
---|
| 87 | |
---|
[198a339] | 88 | |
---|
| 89 | while (pNext(aktpoly)!=NULL) //move to next term until NULL |
---|
[03de21] | 90 | { |
---|
| 91 | aktpoly=pNext(aktpoly); |
---|
[198a339] | 92 | pSetm(aktpoly); //doesn't seem to help anything |
---|
[03de21] | 93 | pGetExpV(aktpoly,v); |
---|
| 94 | for (int kk=0;kk<numvar;kk++) |
---|
| 95 | { |
---|
| 96 | //The ordering somehow gets lost here but this is acceptable, since we are only interested in the inequalities |
---|
| 97 | aktexp[kk]=v[kk+1]; |
---|
| 98 | printf("aktexpcomp=%i\n",aktexp[kk]); |
---|
[198a339] | 99 | ineq[aktmatrixrow][kk]=leadexp[kk]-aktexp[kk]; //dito |
---|
[03de21] | 100 | } |
---|
[198a339] | 101 | aktmatrixrow=aktmatrixrow+1; |
---|
[03de21] | 102 | }//while |
---|
[2c6535] | 103 | } //for |
---|
[198a339] | 104 | #ifdef gfan_DEBUG |
---|
| 105 | printf("Inequalitiy matrix\n"); |
---|
| 106 | for (int i=0;i<rows;i++) |
---|
| 107 | { |
---|
| 108 | for (int j=0;j<cols;j++) |
---|
| 109 | { |
---|
| 110 | printf("%i ",ineq[i][j]); |
---|
| 111 | } |
---|
| 112 | printf("\n"); |
---|
| 113 | } |
---|
| 114 | #endif |
---|
[2c6535] | 115 | //res=(ideal)aktpoly; |
---|
| 116 | //return res; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | ideal gfan(ideal inputIdeal) |
---|
| 120 | { |
---|
[b3e45f] | 121 | #ifdef gfan_DEBUG |
---|
| 122 | printf("Now in subroutine gfan\n"); |
---|
| 123 | #endif |
---|
| 124 | ideal res; |
---|
[2c6535] | 125 | matrix ineq; //Matrix containing the boundary inequalities |
---|
| 126 | |
---|
[b3e45f] | 127 | res=getGB(inputIdeal); |
---|
[2c6535] | 128 | getWallIneq(res); |
---|
[b3e45f] | 129 | return res; |
---|
[d3398c] | 130 | } |
---|