1 | /* |
---|
2 | Compute the Groebner fan of an ideal |
---|
3 | Author: $Author: monerjan $ |
---|
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 $ |
---|
7 | */ |
---|
8 | |
---|
9 | #include "mod2.h" |
---|
10 | #include "kstd1.h" |
---|
11 | #include "intvec.h" |
---|
12 | #include "polys.h" |
---|
13 | #include "ideals.h" |
---|
14 | #include "kmatrix.h" |
---|
15 | |
---|
16 | #ifndef gfan_DEBUG |
---|
17 | #define gfan_DEBUG |
---|
18 | #endif |
---|
19 | |
---|
20 | ideal getGB(ideal inputIdeal) |
---|
21 | { |
---|
22 | #ifdef gfan_DEBUG |
---|
23 | printf("Now in getGB\n"); |
---|
24 | #endif |
---|
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 | |
---|
30 | return gb; |
---|
31 | } |
---|
32 | |
---|
33 | /****** getWallIneq computes the inequalities ***/ |
---|
34 | /*INPUT_TYPE: ideal */ |
---|
35 | /*RETURN_TYPE: matrix */ |
---|
36 | /************************************************/ |
---|
37 | void getWallIneq(ideal I) |
---|
38 | { |
---|
39 | #ifdef gfan_DEBUG |
---|
40 | printf("*** Computing Inequalities... ***\n"); |
---|
41 | #endif |
---|
42 | |
---|
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 |
---|
46 | poly aktpoly; |
---|
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 |
---|
52 | |
---|
53 | printf("The Groebner basis has %i elements\n",lengthGB); |
---|
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); |
---|
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 |
---|
68 | |
---|
69 | // We loop through each g\in GB |
---|
70 | for (int i=0; i<IDELEMS(I); i++) |
---|
71 | { |
---|
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? |
---|
74 | printf("Poly No. %i has %i components\n",i,pCompCount); |
---|
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) |
---|
78 | |
---|
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]); |
---|
84 | //Since we need to know the difference of leadexp with the other expvects we do nothing here |
---|
85 | //but compute the diff below |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | while (pNext(aktpoly)!=NULL) //move to next term until NULL |
---|
90 | { |
---|
91 | aktpoly=pNext(aktpoly); |
---|
92 | pSetm(aktpoly); //doesn't seem to help anything |
---|
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]); |
---|
99 | ineq[aktmatrixrow][kk]=leadexp[kk]-aktexp[kk]; //dito |
---|
100 | } |
---|
101 | aktmatrixrow=aktmatrixrow+1; |
---|
102 | }//while |
---|
103 | } //for |
---|
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 |
---|
115 | //res=(ideal)aktpoly; |
---|
116 | //return res; |
---|
117 | } |
---|
118 | |
---|
119 | ideal gfan(ideal inputIdeal) |
---|
120 | { |
---|
121 | #ifdef gfan_DEBUG |
---|
122 | printf("Now in subroutine gfan\n"); |
---|
123 | #endif |
---|
124 | ideal res; |
---|
125 | matrix ineq; //Matrix containing the boundary inequalities |
---|
126 | |
---|
127 | res=getGB(inputIdeal); |
---|
128 | getWallIneq(res); |
---|
129 | return res; |
---|
130 | } |
---|