1 | /* |
---|
2 | Compute the Groebner fan of an ideal |
---|
3 | Author: $Author: Singular $ |
---|
4 | Date: $Date: 2009-02-12 08:35:05 $ |
---|
5 | Header: $Header: /exports/cvsroot-2/cvsroot/kernel/gfan.cc,v 1.11 2009-02-12 08:35:05 Singular Exp $ |
---|
6 | Id: $Id: gfan.cc,v 1.11 2009-02-12 08:35:05 Singular Exp $ |
---|
7 | */ |
---|
8 | |
---|
9 | #include "mod2.h" |
---|
10 | |
---|
11 | #ifdef HAVE_GFAN |
---|
12 | |
---|
13 | #include "kstd1.h" |
---|
14 | #include "intvec.h" |
---|
15 | #include "polys.h" |
---|
16 | #include "ideals.h" |
---|
17 | #include "kmatrix.h" |
---|
18 | #include "/users/urmel/alggeom/monerjan/cddlib/include/setoper.h" //Support for cddlib. Dirty hack |
---|
19 | #include "/users/urmel/alggeom/monerjan/cddlib/include/cdd.h" |
---|
20 | |
---|
21 | #ifndef gfan_DEBUG |
---|
22 | #define gfan_DEBUG |
---|
23 | #endif |
---|
24 | |
---|
25 | ideal getGB(ideal inputIdeal) |
---|
26 | { |
---|
27 | #ifdef gfan_DEBUG |
---|
28 | printf("Now in getGB\n"); |
---|
29 | #endif |
---|
30 | |
---|
31 | ideal gb; |
---|
32 | gb=kStd(inputIdeal,NULL,testHomog,NULL); //Possible to call without testHomog/isHomog? |
---|
33 | idSkipZeroes(gb); //Get rid of zero entries |
---|
34 | |
---|
35 | return gb; |
---|
36 | } |
---|
37 | |
---|
38 | /****** getWallIneq computes the inequalities ***/ |
---|
39 | /*INPUT_TYPE: ideal */ |
---|
40 | /*RETURN_TYPE: matrix */ |
---|
41 | /************************************************/ |
---|
42 | void getWallIneq(ideal I) |
---|
43 | { |
---|
44 | #ifdef gfan_DEBUG |
---|
45 | printf("*** Computing Inequalities... ***\n"); |
---|
46 | #endif |
---|
47 | |
---|
48 | //All variables go here - except ineq matrix and *v, see below |
---|
49 | int lengthGB=IDELEMS(I); // # of polys in the groebner basis |
---|
50 | int pCompCount; // # of terms in a poly |
---|
51 | poly aktpoly; |
---|
52 | int numvar = pVariables; // # of variables in a polynomial (or ring?) |
---|
53 | int leadexp[numvar]; // dirty hack of exp.vects |
---|
54 | int aktexp[numvar]; |
---|
55 | int cols,rows; // will contain the dimensions of the ineq matrix - deprecated by |
---|
56 | dd_rowrange ddrows; |
---|
57 | dd_colrange ddcols; |
---|
58 | dd_rowset ddredrows; // # of redundant rows in ddineq |
---|
59 | dd_NumberType ddnumb=dd_Real; //Number type |
---|
60 | dd_ErrorType dderr=dd_NoError; // |
---|
61 | // End of var declaration |
---|
62 | |
---|
63 | printf("The Groebner basis has %i elements\n",lengthGB); |
---|
64 | printf("The current ring has %i variables\n",numvar); |
---|
65 | cols = numvar; |
---|
66 | |
---|
67 | //Compute the # inequalities i.e. rows of the matrix |
---|
68 | rows=0; //Initialization |
---|
69 | for (int ii=0;ii<IDELEMS(I);ii++) |
---|
70 | { |
---|
71 | aktpoly=(poly)I->m[ii]; |
---|
72 | rows=rows+pLength(aktpoly)-1; |
---|
73 | } |
---|
74 | printf("rows=%i\n",rows); |
---|
75 | printf("Will create a %i x %i - matrix to store inequalities\n",rows,cols); |
---|
76 | |
---|
77 | dd_rowrange aktmatrixrow=0; // needed to store the diffs of the expvects in the rows of ddineq |
---|
78 | dd_set_global_constants(); |
---|
79 | ddrows=rows; |
---|
80 | ddcols=cols; |
---|
81 | dd_MatrixPtr ddineq; //Matrix to store the inequalities |
---|
82 | ddineq=dd_CreateMatrix(ddrows,ddcols); |
---|
83 | |
---|
84 | // We loop through each g\in GB and compute the resulting inequalities |
---|
85 | for (int i=0; i<IDELEMS(I); i++) |
---|
86 | { |
---|
87 | aktpoly=(poly)I->m[i]; //get aktpoly as i-th component of I |
---|
88 | pCompCount=pLength(aktpoly); //How many terms does aktpoly consist of? |
---|
89 | printf("Poly No. %i has %i components\n",i,pCompCount); |
---|
90 | |
---|
91 | int *v=(int *)omAlloc((numvar+1)*sizeof(int)); |
---|
92 | pGetExpV(aktpoly,v); //find the exp.vect in v[1],...,v[n], use pNext(p) |
---|
93 | |
---|
94 | //Store leadexp for aktpoly |
---|
95 | for (int kk=0;kk<numvar;kk++) |
---|
96 | { |
---|
97 | leadexp[kk]=v[kk+1]; |
---|
98 | //printf("Leadexpcomp=%i\n",leadexp[kk]); |
---|
99 | //Since we need to know the difference of leadexp with the other expvects we do nothing here |
---|
100 | //but compute the diff below |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | while (pNext(aktpoly)!=NULL) //move to next term until NULL |
---|
105 | { |
---|
106 | aktpoly=pNext(aktpoly); |
---|
107 | pSetm(aktpoly); //doesn't seem to help anything |
---|
108 | pGetExpV(aktpoly,v); |
---|
109 | for (int kk=0;kk<numvar;kk++) |
---|
110 | { |
---|
111 | //The ordering somehow gets lost here but this is acceptable, since we are only interested in the inequalities |
---|
112 | aktexp[kk]=v[kk+1]; |
---|
113 | //printf("aktexpcomp=%i\n",aktexp[kk]); |
---|
114 | //ineq[aktmatrixrow][kk]=leadexp[kk]-aktexp[kk]; //dito |
---|
115 | dd_set_si(ddineq->matrix[(dd_rowrange)aktmatrixrow][kk],leadexp[kk]-aktexp[kk]); |
---|
116 | } |
---|
117 | aktmatrixrow=aktmatrixrow+1; |
---|
118 | }//while |
---|
119 | |
---|
120 | } //for |
---|
121 | |
---|
122 | // The inequalities are now stored in ddineq |
---|
123 | // Next we check for superflous rows |
---|
124 | ddredrows = dd_RedundantRows(ddineq, &dderr); |
---|
125 | if (dderr!=dd_NoError) // did an error occur? |
---|
126 | { |
---|
127 | dd_WriteErrorMessages(stderr,dderr); //if so tell us |
---|
128 | } else |
---|
129 | { |
---|
130 | printf("Redundant rows: "); |
---|
131 | set_fwrite(stdout, ddredrows); //otherwise print the redundant rows |
---|
132 | }//if dd_Error |
---|
133 | |
---|
134 | #ifdef gfan_DEBUGs |
---|
135 | printf("Inequalitiy matrix\n"); |
---|
136 | for (int i=0;i<rows;i++) |
---|
137 | { |
---|
138 | for (int j=0;j<cols;j++) |
---|
139 | { |
---|
140 | printf("%i ",ineq[i][j]); |
---|
141 | } |
---|
142 | printf("\n"); |
---|
143 | } |
---|
144 | #endif |
---|
145 | //res=(ideal)aktpoly; |
---|
146 | //return res; |
---|
147 | } |
---|
148 | |
---|
149 | ideal gfan(ideal inputIdeal) |
---|
150 | { |
---|
151 | #ifdef gfan_DEBUG |
---|
152 | printf("Now in subroutine gfan\n"); |
---|
153 | #endif |
---|
154 | ideal res; |
---|
155 | matrix ineq; //Matrix containing the boundary inequalities |
---|
156 | |
---|
157 | res=getGB(inputIdeal); |
---|
158 | getWallIneq(res); |
---|
159 | return res; |
---|
160 | } |
---|
161 | #endif |
---|