source: git/Singular/LIB/fpadim.lib @ a34c05

spielwiese
Last change on this file since a34c05 was a34c05, checked in by Viktor Levandovskyy <levandov@…>, 13 years ago
*levandov: fpadim lib by G Studzinski, dimension computations in associative algebras git-svn-id: file:///usr/local/Singular/svn/trunk@13290 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100755
File size: 71.1 KB
Line 
1///////////////////////////////////////////////////////
2version="$Id: fpadim.lib,v beta 2010/09/27 13:14:51 studzins Exp $";
3category="Noncommutative";
4info="
5LIBRARY: fpadim.lib     Algorithms for quotient algebras
6AUTHORS: Grischa Studzinski,       grischa.studzinski@rwth-aachen.de
7
8SUPPORT: Projects LE 2697/2-1; KR 1907/3-1 of the Priority Programme SPP 1489:
9@* 'Algorithmische und Experimentelle Methoden in Algebra, Geometrie und Zahlentheorie'
10@* of the German DFG
11
12THEORY: Given the free algebra A = K<x_1,...,x_n> and a (finite) Groebner basis
13@*      GB = {g_1,..,g_w}, one is interested in the K-dimension and in the
14@*      explicit K-basis of A/<GB>.
15@*      Therefore one is interested in the following data:
16@*      - the Ufnarovskij graph induced by GB
17@*      - the mistletoes of A/<GB>
18@*      - the K-dimension of A/<GB>
19@*      - the Hilbert series of A/<GB>
20@*
21@*      The Ufnarovskij graph is used to determine whether A/<GB> has finite
22@*      K-dimension. One has to check if the graph contains cycles.
23@*      For the whole theory we refer to [ufna]. Given a
24@*      reduced set of monomials GB one can define the basis tree, which vertex
25@*      set V consists of all normal monomials w.r.t. GB. For every two
26@*      monomials m_1, m_2 in V there is a direct edge from m_1 to m_2, if and
27@*      only if there exists x_k in {x_1,..,x_n}, such that m_1*x_k = m_2. The
28@*      set M = {m in V | there is no edge from m to another monomial in V} is
29@*      called the set of mistletoes. As one can easily see it consists of
30@*      the endpoints of the graph. Since there is a unique path to every
31@*      monomial in V the whole graph can be described only from the knowledge
32@*      of the mistletoes. Note that V corresponds to a basis of A/<GB>, so
33@*      knowing the mistletoes we know a K-basis. For more details see
34@*      [studzins]. This package uses the Letterplace format introduced by
35@*      [lls]. The algebra can either be represented as a Letterplace ring or
36@*      via integer vectors: Every variable will only be represented by its
37@*      number, so variable one is represented as 1, variable two as 2 and so
38@*      on. The monomial x_1*x_3*x_2 for example will be stored as (1,3,2).
39@*      Multiplication is concatenation. Note that there is no algorithm for
40@*      computing the normalform yet, but for our case it is not needed.
41@*
42
43REFERENCES:
44
45@*   [ufna]     Ufnarovskij: Combinatorical and asymptotic methods in algebra,
46@*                           1990
47@*   [lls]      Levandovskyy, La Scala: Letterplace ideals and non-commutative
48@*                                      Groebner bases, 2009
49@*   [studzins] Studzinski: Dimension computations in non-commutative,
50@*                          associative algebras, Diploma thesis, RWTH Aachen, 2010
51
52ASSUMPTIONS:
53@* - basering is always a Letterplace ring
54@* - all intvecs correspond to Letterplace monomials
55@* - if you specify a different degree bound d,
56@*  d <= attrib(basering,uptodeg) holds
57@*
58@* In the procedures below, 'iv' stands for intvec representation
59@* and 'lp' for the letterplace representation of monomials
60
61MAIN PROCEDURES:
62
63ivDHilbert(L,n[,d]);       computes the K-dimension and the Hilbert series
64ivDHilbertSickle(L,n[,d]); computes mistletoes, K-dimension and Hilbert series
65ivDimCheck(L,n);           checks if the K-dimension of A/<L> is infinite
66ivHilbert(L,n[,d]);        computes the Hilbert series of A/<L> in intvec format
67ivKDim(L,n[,d]);           computes the K-dimension of A/<L> in intvec format
68ivMis2Dim(M);              computes the K-dimension of the factor algebra
69ivOrdMisLex(M);            orders a list of intvecs lexicographically
70ivSickle(L,n[,d]);         computes the mistletoes of A/<L> in intvec format
71ivSickleHil(L,n[,d]);      computes the mistletoes and Hilbert series of A/<L>
72ivSickleDim(L,n[,d]);      computes the mistletoes and the K-dimension of A/<L>
73lpDHilbert(G[,d,n]);       computes the K-dimension and Hilbert series of A/<G>
74lpDHilbertSickle(G[,d,n]); computes mistletoes, K-dimension and Hilbert series
75lpHilbert(G[,d,n]);        computes the Hilbert series of A/<G> in lp format
76lpDimCheck(G);             checks if the K-dimension of A/<G> is infinite
77lpKDim(G[,d,n]);           computes the K-dimension of A/<G> in lp format
78lpMis2Dim(M);              computes the K-dimension of the factor algebra
79lpOrdMisLex(M);            orders an ideal of lp-monomials lexicographically
80lpSickle(G[,d,n]);         computes the mistletoes of A/<G> in lp format
81lpSickleHil(G[,d,n]);      computes the mistletoes and Hilbert series of A/<G>
82lpSickleDim(G[,d,n]);      computes the mistletoes and the K-dimension of A/<G>
83sickle(G[,m,d,h]);         can be used to access all lp main procedures
84
85
86AUXILIARY PROCEDURES:
87
88ivL2lpI(L);           transforms a list of intvecs into an ideal of lp monomials
89iv2lp(I);             transforms an intvec into the corresponding monomial
90iv2lpList(L);         transforms a list of intmats into an ideal of lp monomials
91iv2lpMat(M);          transforms an intmat into an ideal of lp monomials
92lp2iv(p);             transforms a polynomial into the corresponding intvec
93lp2ivId(G);           transforms an ideal into the corresponding list of intmats
94lpId2ivLi(G);         transforms a lp-ideal into the corresponding list of intvecs
95
96SEE ALSO: freegb_lib
97";
98
99LIB "freegb.lib"; //for letterplace rings
100LIB "general.lib";//for sorting mistletoes
101
102/////////////////////////////////////////////////////////
103
104
105//--------------- auxiliary procedures ------------------
106
107static proc allVars(list L, intvec P, int n)
108"USAGE: allVars(L,P,n); L a list of intmats, P an intvec, n an integer
109RETURN: 0, if all variables are contained in the quotient algebra, 1 otherwise
110"
111{int i,j,r;
112 intvec V;
113 for (i = 1; i <= size(P); i++) {if (P[i] == 1){ j = i; break;}}
114 V = L[j][1..nrows(L[j]),1];
115 for (i = 1; i <= n; i++) {if (isInVec(i,V) == 0) {r = 1; break;}}
116 if (r == 0) {return(1);}
117 else {return(0);}
118}
119
120static proc checkAssumptions(int d, list L)
121"PURPOSE: Checks, if all the Assumptions are holding
122"
123{if (typeof(attrib(basering,"isLetterplaceRing"))=="string") {ERROR("Basering is not a Letterplace ring!");}
124 if (d > attrib(basering,"uptodeg")) {ERROR("Specified degree bound exceeds ring parameter!");}
125 int i;
126 for (i = 1; i <= size(L); i++)
127 {if (entryViolation(L[i], attrib(basering,"lV")))
128  {ERROR("Not allowed monomial/intvec found!");}
129 }
130 return();
131}
132
133static proc createStartMat(int d, int n)
134"USAGE: createStartMat(d,n); d, n integers
135RETURN: An intmat
136PURPOSE:Creating the intmat with all normal monomials in n variables and of degree d to start with
137NOTE:   d has to be > 0
138"
139{intmat M[(n^d)][d];
140 int i1,i2,i3,i4;
141 for (i1 = 1; i1 <= d; i1++)  //Spalten
142 {i2 = 1; //durchlaeuft Zeilen
143  while (i2 <= (n^d))
144  {for (i3 = 1; i3 <= n; i3++)
145   {for (i4 = 1; i4 <= (n^(i1-1)); i4++)
146    {M[i2,i1] = i3;
147     i2 = i2 + 1;
148    }
149   }
150  }
151 }
152 return(M);
153}
154
155static proc createStartMat1(int n, intmat M)
156"USAGE: createStartMat1(n,M); n an integer, M an intmat
157RETURN: An intmat with all variables except those in M
158"
159{int i;
160 intvec V,Vt;
161 V = M[(1..nrows(M)),1];
162 for (i = 1; i <= size(V); i++) {if (isInVec(i,V) == 0) {Vt = Vt,i;}}
163 if (Vt == 0) {intmat S; return(S);}
164 else {Vt = Vt[2..size(Vt)]; intmat S [size(Vt)][1]; S[1..size(Vt),1] = Vt; return(S);}
165}
166
167static proc entryViolation(intmat M, int n)
168"PURPOSE:checks, if all entries in M are variable-related
169"
170{int i,j;
171 for (i = 1; i <= nrows(M); i++)
172 {for (j = 1; j <= ncols(M); j++)
173  {if(!((1<=M[i,j])&&(M[i,j]<=n))) {return(1);}}
174 }
175 return(0);
176}
177
178static proc findDimen(intvec V, int n, list L, intvec P, list #)
179"USAGE: findDimen(V,n,L,P,degbound); V,P intvecs, n, an integer, L a list,
180@*      degbound an optional integer
181RETURN: An integer
182PURPOSE:Computing the K-dimension of the quotient algebra
183"
184{int degbound = 0;
185 if (size(#) > 0) {if (#[1] > 0) {degbound = #[1];}}
186 int dimen,i,j,w,it;
187 intvec Vt,Vt2;
188 module M;
189 if (degbound == 0)
190 {for (i = 1; i <= n; i++)
191  {Vt = V, i; w = 0;
192   for (j = 1; j<= size(P); j++)
193   {if (P[j] <= size(Vt))
194    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
195     if (isInMat(Vt2,L[j]) > 0) {w = 1; break;}
196    }
197   }
198    if (w == 0)
199    {vector Vtt;
200     for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
201     M = M,Vtt;
202     kill Vtt;
203    }
204  }
205  if (size(M) == 0) {return(0);}
206  else
207  {M = simplify(M,2);
208   for (i = 1; i <= size(M); i++)
209   {kill Vt; intvec Vt;
210    for (j =1; j <= size(M[i]); j++){Vt[j] =  int(leadcoef(M[i][j]));}
211    dimen = dimen + 1 + findDimen(Vt,n,L,P);
212   }
213   return(dimen);
214  }
215 }
216 else
217 {if (size(V) > degbound) {ERROR("monomial exceeds degreebound");}
218  if (size(V) == degbound) {return(0);}
219  for (i = 1; i <= n; i++)
220  {Vt = V, i; w = 0;
221   for (j = 1; j<= size(P); j++)
222   {if (P[j] <= size(Vt))
223    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
224     if (isInMat(Vt2,L[j]) > 0) {w = 1; break;}
225    }
226   }
227    if (w == 0) {vector Vtt;
228     for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
229     M = M,Vtt;
230     kill Vtt;
231    }
232  }
233  if (size(M) == 0) {return(0);}
234  else
235  {M = simplify(M,2);
236   for (i = 1; i <= size(M); i++)
237   {kill Vt; intvec Vt;
238    for (j =1; j <= size(M[i]); j++){Vt[j] =  int(leadcoef(M[i][j]));}
239    dimen = dimen + 1 + findDimen(Vt,n,L,P,degbound);
240   }
241   return(dimen);
242  }
243 }
244}
245
246static proc findCycle(intvec V, list L, intvec P, int n, int ld, module M)
247"USAGE:
248RETURN: 1, if Ufn-graph contains a cycle, or 0 otherwise
249PURPOSE:Searching the Ufnarovskij graph for cycles
250"
251{int i,j,w,r;intvec Vt,Vt2;
252 int it, it2;
253 if (size(V) < ld)
254 {for (i = 1; i <= n; i++)
255  {Vt = V,i; w = 0;
256   for (j = 1; j <= size(P); j++)
257   {if (P[j] <= size(Vt))
258    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
259     if (isInMat(Vt2,L[j]) > 0)
260     {w = 1; break;}
261    }
262   }
263   if (w == 0) {r = findCycle(Vt,L,P,n,ld,M);}
264   if (r == 1) {break;}
265  }
266  return(r);
267 }
268 else
269 {j = size(M);
270  if (j > 0)
271  {
272   intmat Mt[j][nrows(M)];
273   for (it = 1; it <= j; it++)
274   { for(it2 = 1; it2 <= nrows(M);it2++)
275     {Mt[it,it2] = int(leadcoef(M[it2,it]));}
276   }
277   Vt = V[(size(V)-ld+1)..size(V)];
278   //Mt; type(Mt);Vt;type(Vt);
279   if (isInMat(Vt,Mt) > 0) {return(1);}
280   else
281   {vector Vtt;
282    for (it =1; it <= size(Vt); it++)
283     {Vtt = Vtt + Vt[it]*gen(it);}
284    M = M,Vtt;
285    kill Vtt;
286    for (i = 1; i <= n; i++)
287    {Vt = V,i; w = 0;
288     for (j = 1; j <= size(P); j++)
289     {if (P[j] <= size(Vt))
290      {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
291      //L[j]; type(L[j]);Vt2;type(Vt2);
292       if (isInMat(Vt2,L[j]) > 0)
293       {w = 1; break;}
294      }
295     }
296     if (w == 0) {r = findCycle(Vt,L,P,n,ld,M);}
297     if (r == 1) {break;}
298    }
299    return(r);
300   }
301  }
302  else
303  { Vt = V[(size(V)-ld+1)..size(V)];
304    vector Vtt;
305    for (it = 1; it <= size(Vt); it++)
306     {Vtt = Vtt + Vt[it]*gen(it);}
307    M = Vtt;
308    kill Vtt;
309    for (i = 1; i <= n; i++)
310    {Vt = V,i; w = 0;
311     for (j = 1; j <= size(P); j++)
312     {if (P[j] <= size(Vt))
313      {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
314      //L[j]; type(L[j]);Vt2;type(Vt2);
315       if (isInMat(Vt2,L[j]) > 0)
316       {w = 1; break;}
317      }
318     }
319     if (w == 0) {r = findCycle(Vt,L,P,n,ld,M);}
320     if (r == 1) {break;}
321    }
322    return(r);
323  }
324 }
325}
326
327static proc findHCoeff(intvec V,int n,list L,intvec P,intvec H,list #)
328"USAGE: findHCoeff(V,n,L,P,H,degbound); L a list of intmats, degbound an integer
329RETURN: An intvec
330PURPOSE:Computing the coefficient of the Hilbert series (upto degree degbound)
331NOTE:   Starting with a part of the Hilbert series we change the coefficient
332@*      depending on how many baseelements we found on the actual branch
333"       
334{int degbound = 0;
335 if (size(#) > 0){if (#[1] > 0){degbound = #[1];}}
336 int i,w,j,it;
337 int h1 = 0;
338 intvec Vt,Vt2,H1;
339 module M;
340 if (degbound == 0)
341 {for (i = 1; i <= n; i++)
342  {Vt = V, i; w = 0;
343   for (j = 1; j<= size(P); j++)
344   {if (P[j] <= size(Vt))
345    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
346     if (isInMat(Vt2,L[j]) > 0) {w = 1; break;}
347    }
348   }
349    if (w == 0)
350    {vector Vtt;
351     for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
352     M = M,Vtt;
353     kill Vtt;
354    }
355  }
356  if (size(M) == 0) {return(H);}
357  else
358  {M = simplify(M,2);
359   for (i = 1; i <= size(M); i++)
360   {kill Vt; intvec Vt;
361    for (j =1; j <= size(M[i]); j++) {Vt[j] =  int(leadcoef(M[i][j]));}
362    h1 = h1 + 1; H1 = findHCoeff(Vt,n,L,P,H1);
363   }
364   if (size(H1) < (size(V)+2)) {H1[(size(V)+2)] = h1;}
365   else {H1[(size(V)+2)] = H1[(size(V)+2)] + h1;}
366   H1 = H1 + H;
367   return(H1);
368  }
369 }
370 else
371 {if (size(V) > degbound) {ERROR("monomial exceeds degreebound");}
372  if (size(V) == degbound) {return(H);}
373  for (i = 1; i <= n; i++)
374  {Vt = V, i; w = 0;
375   for (j = 1; j<= size(P); j++)
376   {if (P[j] <= size(Vt))
377    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
378     if (isInMat(Vt2,L[j]) > 0) {w = 1; break;}
379    }
380   }
381    if (w == 0)
382    {vector Vtt;
383     for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
384     M = M,Vtt;
385     kill Vtt;
386    }
387  }
388  if (size(M) == 0) {return(H);}
389  else
390  {M = simplify(M,2);
391   for (i = 1; i <= size(M); i++)
392   {kill Vt; intvec Vt;
393    for (j =1; j <= size(M[i]); j++)
394     {Vt[j] =  int(leadcoef(M[i][j]));}
395    h1 = h1 + 1; H1 = findHCoeff(Vt,n,L,P,H1,degbound);
396   }
397   if (size(H1) < (size(V)+2)) { H1[(size(V)+2)] = h1;}
398   else {H1[(size(V)+2)] = H1[(size(V)+2)] + h1;}
399   H1 = H1 + H;
400   return(H1);
401  }
402 }
403}
404
405static proc findHCoeffMis(intvec V, int n, list L, intvec P, list R,list #)
406"USAGE: findHCoeffMis(V,n,L,P,R,degbound); degbound an optional integer, L a
407@*      list of Intmats, R
408RETURN: A list
409PURPOSE:Computing the coefficients of the Hilbert series and the Mistletoes all
410@*      at once
411"
412{int degbound = 0;
413 if (size(#) > 0) {if (#[1] > 0) {degbound = #[1];}}
414 int i,w,j,h1;
415 intvec Vt,Vt2,H1; int it;
416 module M;
417 if (degbound == 0)
418 {for (i = 1; i <= n; i++)
419  {Vt = V, i; w = 0;
420   for (j = 1; j<= size(P); j++)
421   {if (P[j] <= size(Vt))
422    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
423     if (isInMat(Vt2,L[j]) > 0) {w = 1; break;}
424    }
425   }
426    if (w == 0)
427    {vector Vtt;
428    for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
429    M = M,Vtt;
430    kill Vtt;
431    }
432  }
433  if (size(M) == 0) {if (size(R) < 2){R[2] = list(V);} else {R[2] = R[2] + list(V);} return(R);}
434  else
435  {M = simplify(M,2);
436   for (i = 1; i <= size(M); i++)
437   {kill Vt; intvec Vt;
438    for (j =1; j <= size(M[i]); j++)
439     {Vt[j] =  int(leadcoef(M[i][j]));}
440    if (size(R[1]) < (size(V)+2)) { R[1][(size(V)+2)] = 1;}
441    else
442    {R[1][(size(V)+2)] = R[1][(size(V)+2)] + 1;}
443    R = findHCoeffMis(Vt,n,L,P,R);
444   }
445   return(R);
446  }
447 }
448 else
449 {if (size(V) > degbound) {ERROR("monomial exceeds degreebound");}
450  if (size(V) == degbound)
451  {if (size(R) < 2){R[2] = list (V);}
452   else{R[2] = R[2] + list (V);}
453   return(R);
454  }
455  for (i = 1; i <= n; i++)
456  {Vt = V, i; w = 0;
457   for (j = 1; j<= size(P); j++)
458   {if (P[j] <= size(Vt))
459    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
460     if (isInMat(Vt2,L[j]) > 0) {w = 1; break;}
461    }
462   }
463    if (w == 0)
464    {vector Vtt;
465    for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
466    M = M,Vtt;
467    kill Vtt;
468    }
469  }
470  if (size(M) == 0) {if (size(R) < 2){R[2] = list(V);} else {R[2] = R[2] + list(V);} return(R);}
471  else
472  {M = simplify(M,2);
473    for (i = 1; i <= ncols(M); i++)
474    {kill Vt; intvec Vt;
475     for (j =1; j <= size(M[i]); j++)
476     {Vt[j] =  int(leadcoef(M[i][j]));}
477     if (size(R[1]) < (size(V)+2)) { R[1][(size(V)+2)] = 1;}
478     else
479     {R[1][(size(V)+2)] = R[1][(size(V)+2)] + 1;}
480     R = findHCoeffMis(Vt,n,L,P,R,degbound);
481    }
482   return(R);
483  }
484 }
485}
486
487
488static proc findMisDim(intvec V,int n,list L,intvec P,list R,list #)
489"USAGE:
490RETURN: A list
491PURPOSE:Computing the K-dimension and the Mistletoes all at once
492"
493{int degbound = 0;
494 if (size(#) > 0) {if (#[1] > 0) {degbound = #[1];}}
495 int dimen,i,j,w;
496 intvec Vt,Vt2; int it;
497 module M;
498 if (degbound == 0)
499 {for (i = 1; i <= n; i++)
500  {Vt = V, i; w = 0;
501   for (j = 1; j<= size(P); j++)
502   {if (P[j] <= size(Vt))
503    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
504     if (isInMat(Vt2,L[j]) > 0) {w = 1; break;}
505    }
506   }
507    if (w == 0)
508    {vector Vtt;
509     for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
510     M = M,Vtt;
511     kill Vtt;
512    }
513  }
514  if (size(M) == 0)
515  {if (size(R) < 2){R[2] = list (V);}
516   else{R[2] = R[2] + list(V);}
517   return(R);
518  }
519  else
520  {M = simplify(M,2);
521   for (i = 1; i <= size(M); i++)
522   {kill Vt; intvec Vt;
523    for (j =1; j <= size(M[i]); j++){Vt[j] =  int(leadcoef(M[i][j]));}
524     R[1] = R[1] + 1; R = findMisDim(Vt,n,L,P,R);
525   }
526   return(R);
527  }
528 }
529 else
530 {if (size(V) > degbound) {ERROR("monomial exceeds degreebound");}
531  if (size(V) == degbound)
532  {if (size(R) < 2){R[2] = list (V);}
533   else{R[2] = R[2] + list (V);}
534   return(R);
535  }
536  for (i = 1; i <= n; i++)
537  {Vt = V, i; w = 0;
538   for (j = 1; j<= size(P); j++)
539   {if (P[j] <= size(Vt))
540    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
541     if (isInMat(Vt2,L[j]) > 0) {w = 1; break;}
542    }
543   }
544    if (w == 0)
545    {vector Vtt;
546     for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
547     M = M,Vtt;
548     kill Vtt;
549    }
550  }
551  if (size(M) == 0)
552  {if (size(R) < 2){R[2] = list (V);}
553   else{R[2] = R[2] + list(V);}
554   return(R);
555  }
556  else
557  {M = simplify(M,2);
558   for (i = 1; i <= size(M); i++)
559   {kill Vt; intvec Vt;
560    for (j =1; j <= size(M[i]); j++){Vt[j] =  int(leadcoef(M[i][j]));}
561     R[1] = R[1] + 1; R = findMisDim(Vt,n,L,P,R,degbound);
562   }
563   return(R);
564
565  }
566 }
567}
568
569
570static proc findmistletoes(intvec V, int n, list L, intvec P, list #)
571"USAGE: findmistletoes(V,n,L,P,degbound); V a normal word, n the number of
572@*      variables, L the GB, P the occuring degrees,
573@*      and degbound the (optional) degreebound
574RETURN: A list
575PURPOSE:Computing mistletoes starting in V
576NOTE:   V has to be normal w.r.t. L, it will not be checked for being so
577"
578{int degbound = 0;
579 if (size(#) > 0) {if (#[1] > 0) {degbound = #[1];}}
580 list R; intvec Vt,Vt2; int it;
581 int i,j;
582 module M;
583 if (degbound == 0)
584 {int w;
585  for (i = 1; i <= n; i++)
586  {Vt = V,i; w = 0;
587   for (j = 1; j <= size(P); j++)
588   {if (P[j] <= size(Vt))
589    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
590     if (isInMat(Vt2,L[j]) > 0)
591     {w = 1; break;}
592    }
593   }
594   if (w == 0)
595   {vector Vtt;
596    for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
597    M = M,Vtt;
598    kill Vtt;
599   }
600  }
601  if (size(M)==0) {R = V; return(R);}
602  else
603  {M = simplify(M,2);
604   for (i = 1; i <= size(M); i++)
605   {kill Vt; intvec Vt;
606    for (j =1; j <= size(M[i]); j++){Vt[j] =  int(leadcoef(M[i][j]));}
607    R = R + findmistletoes(Vt,n,L,P);
608   }
609   return(R);
610  }
611 }
612 else
613 {if (size(V) > degbound) {ERROR("monomial exceeds degreebound");}
614  if (size(V) == degbound) {R = V; return(R);}
615  int w;
616  for (i = 1; i <= n; i++)
617  {Vt = V,i; w = 0;
618   for (j = 1; j <= size(P); j++)
619   {if (P[j] <= size(Vt))
620    {Vt2 = Vt[(size(Vt)-P[j]+1)..size(Vt)];
621     if (isInMat(Vt2,L[j]) > 0){w = 1; break;}
622    }
623   }
624   if (w == 0)
625   {vector Vtt;
626    for (it = 1; it <= size(Vt); it++){Vtt = Vtt + Vt[it]*gen(it);}
627    M = M,Vtt;
628    kill Vtt;
629   }
630  }
631  if (size(M) == 0) {R = V; return(R);}
632  else
633  {M = simplify(M,2);
634   for (i = 1; i <= ncols(M); i++)
635   {kill Vt; intvec Vt;
636    for (j =1; j <= size(M[i]); j++)
637     {Vt[j] =  int(leadcoef(M[i][j]));}
638      //Vt; typeof(Vt); size(Vt);
639      R = R + findmistletoes(Vt,n,L,P,degbound);
640   }
641   return(R);
642  }
643 }
644}
645
646static proc isInList(intvec V, list L)
647"USAGE: isInList(V,L); V an intvec, L a list of intvecs
648RETURN: An integer
649PURPOSE:Finding the position of V in L, returns 0, if V is not in M
650"
651{int i,n;
652 n = 0;
653 for (i = 1; i <= size(L); i++) {if (L[i] == V) {n = i; break;}}
654 return(n);
655}
656
657static proc isInMat(intvec V, intmat M)
658"USAGE: isInMat(V,M);V an intvec, M an intmat
659RETURN: An integer
660PURPOSE:Finding the position of V in M, returns 0, if V is not in M
661"
662{if (size(V) <> ncols(M)) {return(0);}
663 int i;
664 intvec Vt;
665 for (i = 1; i <= nrows(M); i++)
666 {Vt = M[i,1..ncols(M)];
667  if ((V-Vt) == 0){return(i);}
668 }
669 return(0);
670}
671
672static proc isInVec(int v,intvec V)
673"USAGE: isInVec(v,V); v an integer,V an intvec
674RETURN: An integer
675PURPOSE:Finding the position of v in V, returns 0, if v is not in V
676"
677{int i,n;
678 n = 0;
679 for (i = 1; i <= size(V); i++) {if (V[i] == v) {n = i; break;}}
680 return(n);
681}
682
683proc ivL2lpI(list L)
684"USAGE: ivL2lpI(L); L a list of intvecs
685RETURN: ideal
686PURPOSE:Transforming a list of intvecs into an ideal of Letterplace monomials
687ASSUME: - Intvec corresponds to a Letterplace monomial
688@*      - basering has to be a Letterplace ring
689EXAMPLE: example ivL2lpI; shows examples
690"
691{checkAssumptions(0,L);
692 int i; ideal G;
693 poly p;
694 for (i = 1; i <= size(L); i++)
695 {p = iv2lp(L[i]);
696  G[(size(G) + 1)] = p;
697 }
698 return(G);
699}
700example
701{
702  "EXAMPLE:"; echo = 2;
703  ring r = 0,(x,y,z),dp;
704  def R = makeLetterplaceRing(5);// constructs a Letterplace ring
705  setring R; //sets basering to Letterplace ring
706  intvec u = 1,1,2; intvec v = 2,1,3; intvec w = 3,1,1;
707  // u = x^2y, v = yxz, w = zx^2 in intvec representation
708  list L = u,v,w;
709  ivL2lpI(L);// invokes the procedure, returns the ideal containing u,v,w
710}
711
712proc iv2lp(intvec I)
713"USAGE: iv2lp(I); I an intvec
714RETURN: poly
715PURPOSE:Transforming an intvec into the corresponding Letterplace polynomial
716ASSUME: - Intvec corresponds to a Letterplace monomial
717@*      - basering has to be a Letterplace ring
718NOTE:   - Assumptions will not be checked!
719EXAMPLE: example iv2lp; shows examples
720"
721{if (I[1] == 0) {return(1);}
722 int i = size(I);
723 if (i > attrib(basering,"uptodeg")) {ERROR("polynomial exceeds degreebound");}
724 int j; poly p = 1;
725 for (j = 1; j <= i; j++) {if (I[j] > 0) { p = lpMult(p,var(I[j]));}} //ignore zeroes, because they correspond to 1
726 return(p);
727}
728example
729{
730  "EXAMPLE:"; echo = 2;
731  ring r = 0,(x,y,z),dp;
732  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
733  setring R; //sets basering to Letterplace ring
734  intvec u = 1,1,2; intvec v = 2,1,3; intvec w = 3,1,1;
735  // u = x^2y, v = yxz, w = zx^2 in intvec representation
736  iv2lp(u); // invokes the procedure and returns the corresponding poly
737  iv2lp(v);
738  iv2lp(w);
739}
740
741proc iv2lpList(list L)
742"USAGE: iv2lpList(L); L a list of intmats
743RETURN: ideal
744PURPOSE:Converting a list of intmats into an ideal of corresponding monomials
745ASSUME: - The rows of each intmat in L must correspond to a Letterplace monomial
746@*      - basering has to be a Letterplace ring
747EXAMPLE: example iv2lpList; shows examples
748"
749{checkAssumptions(0,L);
750 ideal G;
751 int i;
752 for (i = 1; i <= size(L); i++){G = G + iv2lpMat(L[i]);}
753 return(G);
754}
755example
756{
757  "EXAMPLE:"; echo = 2;
758  ring r = 0,(x,y,z),dp;
759  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
760  setring R; // sets basering to Letterplace ring
761  intmat u[3][1] = 1,1,2; intmat v[1][3] = 2,1,3; intmat w[2][3] = 3,1,1,2,3,1;
762  // defines intmats of different size containing intvec representations of
763  // monomials as rows
764  list L = u,v,w;
765  print(u); print(v); print(w); // shows the intmats contained in L
766  iv2lpList(L); // returns the corresponding monomials as an ideal
767}
768
769
770proc iv2lpMat(intmat M)
771"USAGE: iv2lpMat(M); M an intmat
772RETURN: ideal
773PURPOSE:Converting an intmat into an ideal of the corresponding monomials
774ASSUME: - The rows of M must correspond to Letterplace monomials
775@*      - basering has to be a Letterplace ring
776EXAMPLE: example iv2lpMat; shows examples
777"
778{list L = M;
779 checkAssumptions(0,L);
780 kill L;
781 ideal G; poly p;
782 int i; intvec I;
783 for (i = 1; i <= nrows(M); i++)
784  { I = M[i,1..ncols(M)];
785    p = iv2lp(I);
786    G[size(G)+1] = p;
787  }
788 return(G);
789}
790example
791{
792  "EXAMPLE:"; echo = 2;
793  ring r = 0,(x,y,z),dp;
794  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
795  setring R; // sets basering to Letterplace ring
796  intmat u[3][1] = 1,1,2; intmat v[1][3] = 2,1,3; intmat w[2][3] = 3,1,1,2,3,1;
797  // defines intmats of different size containing intvec representations of
798  // monomials as rows
799  iv2lpMat(u); // returns the monomials contained in u
800  iv2lpMat(v); // returns the monomials contained in v
801  iv2lpMat(w); // returns the monomials contained in w
802}
803
804proc lpId2ivLi(ideal G)
805"USAGE: lpId2ivLi(G); G an ideal
806RETURN: list
807PURPOSE:Transforming an ideal into the corresponding list of intvecs
808ASSUME: - basering has to be a Letterplace ring
809EXAMPLE: example lpId2ivLi; shows examples
810"
811{int i,j,k;
812 list M;
813 checkAssumptions(0,M);
814 for (i = 1; i <= size(G); i++) {M[i] = lp2iv(G[i]);}
815 return(M);
816}
817example
818{
819  "EXAMPLE:"; echo = 2;
820   ring r = 0,(x,y),dp;
821   def R = makeLetterplaceRing(5); // constructs a Letterplace ring
822   setring R; // sets basering to Letterplace ring
823   ideal L = x(1)*x(2),y(1)*y(2),x(1)*y(2)*x(3);
824   lpId2ivLi(L); // returns the corresponding intvecs as a list
825
826
827proc lp2iv(poly p)
828"USAGE: lp2iv(p); p a poly
829RETURN: intvec
830PURPOSE:Transforming a monomial into the corresponding intvec
831ASSUME: - basering has to be a Letterplace ring
832NOTE:   - Assumptions will not be checked!
833EXAMPLE: example lp2iv; shows examples
834"
835{p = normalize(lead(p));
836 intvec I;
837 int i,j;
838 if (deg(p) > attrib(basering,"uptodeg")) {ERROR("Monomial exceeds degreebound");}
839 if (p == 1) {return(I);}
840 if (p == 0) {ERROR("Monomial is not allowed to equal zero");}
841 intvec lep = leadexp(p);
842 for ( i = 1; i <= attrib(basering,"lV"); i++) {if (lep[i] == 1) {I = i; break;}}
843 for (i = (attrib(basering,"lV")+1); i <= size(lep); i++)
844   {if (lep[i] == 1)
845    { j = (i mod attrib(basering,"lV"));
846      if (j == 0) {I = I,attrib(basering,"lV");}
847      else {I = I,j;}
848    }
849    else { if (lep[i] > 1) {ERROR("monomial has a not allowed multidegree");}}
850   }
851 if (I[1] == 0) {ERROR("monomial has a not allowed multidegree");}
852
853 return(I);
854}
855example
856{
857  "EXAMPLE:"; echo = 2;
858  ring r = 0,(x,y,z),dp;
859  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
860  setring R; // sets basering to Letterplace ring
861  poly p = x(1)*x(2)*z(3); poly q = y(1)*y(2)*x(3)*x(4);
862  poly w= z(1)*y(2)*x(3)*z(4)*z(5);
863  // p,q,w are some polynomials we want to transform into their
864  // intvec representation
865  lp2iv(p); lp2iv(q); lp2iv(w);
866}
867
868proc lp2ivId(ideal G)
869"USAGE: lp2ivId(G); G an ideal
870RETURN: list
871PURPOSE:Converting an ideal into an list of intmats,
872@*      the corresponding intvecs forming the rows
873ASSUME: - basering has to be a Letterplace ring
874EXAMPLE: example lp2ivId; shows examples
875"
876{G = normalize(lead(G));
877 intvec I; list L;
878 checkAssumptions(0,L);
879 int i,md;
880 for (i = 1; i <= size(G); i++) { if (md <= deg(G[i])) {md = deg(G[i]);}}
881 while (size(G) > 0)
882 {ideal Gt;
883  for (i = 1; i <= ncols(G); i++) {if (md == deg(G[i])) {Gt = Gt + G[i]; G[i] = 0;}}
884  if (size(Gt) > 0)
885  {G = simplify(G,2); 
886   intmat M [size(Gt)][md];
887   for (i = 1; i <= size(Gt); i++) {M[i,1..md] = lp2iv(Gt[i]);}
888   L = insert(L,M);
889   kill M; kill Gt;
890   md = md - 1; 
891  }
892  else {kill Gt; md = md - 1;}
893 }
894 return(L);
895}
896example
897{
898  "EXAMPLE:"; echo = 2;
899  ring r = 0,(x,y,z),dp;
900  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
901  setring R; // sets basering to Letterplace ring
902  poly p = x(1)*x(2)*z(3); poly q = y(1)*y(2)*x(3)*x(4);
903  poly w = z(1)*y(2)*x(3)*z(4);
904  // p,q,w are some polynomials we want to transform into their
905  // intvec representation
906  ideal G = p,q,w;
907  // define the ideal containing p,q and w
908  lp2ivId(G); // and return the list of intmats for this ideal
909}
910
911// -----------------main procedures----------------------
912
913proc ivDHilbert(list L, int n, list #)
914"USAGE: ivDHilbert(L,n[,degbound]); L a list of intmats, n an integer,
915@*      degbound an optional integer
916RETURN: list
917PURPOSE:Computing the K-dimension and the Hilbert series
918ASSUME: - basering is a Letterplace ring
919@*      - all rows of each intmat correspond to a Letterplace monomial
920@*      - if you specify a different degree bound degbound,
921@*        degbound <= attrib(basering,uptodeg) holds
922NOTE: - If L is the list returned, then L[1] is an integer corresponding to the
923@*      dimension, L[2] is an intvec which contains the coefficients of the
924@*      Hilbert series
925@*    - If degbound is set, there will be a degree bound added. By default there
926@*      is no degree bound
927@*    - n is the number of variables
928@*    - If I = L[2] is the intvec returned, then I[k] is the (k-1)-th coefficient of
929@*      the Hilbert series.
930@*    - If the K-dimension is known to be infinite, a degree bound is needed
931EXAMPLE: example ivDHilbert; shows examples
932"
933{int degbound = 0;
934 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] > 0){degbound = #[1];}}}
935 checkAssumptions(degbound,L);
936 intvec H; int i,dimen;
937 H = ivHilbert(L,n,degbound);
938 for (i = 1; i <= size(H); i++){dimen = dimen + H[i];}
939 L = dimen,H;
940 return(L);
941}
942example
943{
944  "EXAMPLE:"; echo = 2;
945  ring r = 0,(x,y),dp;
946  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
947    R;
948  setring R; // sets basering to Letterplace ring
949  //some intmats, which contain monomials in intvec representation as rows
950  intmat I1 [2][2] = 1,1,2,2; intmat I2 [1][3]  = 1,2,1;
951  intmat J1 [1][2] =  1,1; intmat J2 [2][3] = 2,1,2,1,2,1;
952  print(I1);
953  print(I2);
954  print(J1);
955  print(J2);
956  list G = I1,I2; // ideal, which is already a Groebner basis
957  list I = J1,J2; // ideal, which is already a Groebner basis
958  //the procedure without a degree bound
959  ivDHilbert(G,2);
960  // the procedure with degree bound 5
961  ivDHilbert(I,2,5);
962}
963
964proc ivDHilbertSickle(list L, int n, list #)
965"USAGE: ivDHilbertSickle(L,n[,degbound]); L a list of intmats, n an integer,
966@*      degbound an optional integer
967RETURN: list
968PURPOSE:Computing K-dimension, Hilbert series and mistletoes
969ASSUME: - basering is a Letterplace ring.
970@*      - All rows of each intmat correspond to a Letterplace monomial.
971@*      - If you specify a different degree bound degbound,
972@*        degbound <= attrib(basering,uptodeg) holds.
973NOTE: - If L is the list returned, then L[1] is an intvec which contains the
974@*      coefficients of the Hilbert series, L[2] is an integer and L[3]
975@*      is a list, containing the mistletoes as intvecs.
976@*    - If degbound is set, a degree bound will be added. By default there
977@*      is no degree bound.
978@*    - n is the number of variables.
979@*    - If I = L[1] is the intvec returned, then I[k] is the (k-1)-th
980@*      coefficient of the Hilbert series.
981@*    - If the K-dimension is known to be infinite, a degree bound is needed
982EXAMPLE: example ivDHilbertSickle; shows examples
983"
984{int degbound = 0;
985 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] > 0){degbound = #[1];}}}
986 checkAssumptions(degbound,L);
987 int i,dimen; list R;
988 R = ivSickleHil(L,n,degbound);
989 for (i = 1; i <= size(R[1]); i++){dimen = dimen + R[1][i];}
990 R[3] = R[2]; R[2] = dimen;
991 return(R);
992}
993example
994{
995  "EXAMPLE:"; echo = 2;
996  ring r = 0,(x,y),dp;
997  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
998  R;
999  setring R; // sets basering to Letterplace ring
1000  //some intmats, which contain monomials in intvec representation as rows
1001  intmat I1 [2][2] = 1,1,2,2; intmat I2 [1][3]  = 1,2,1;
1002  intmat J1 [1][2] =  1,1; intmat J2 [2][3] = 2,1,2,1,2,1;
1003  print(I1);
1004  print(I2);
1005  print(J1);
1006  print(J2);
1007  list G = I1,I2;// ideal, which is already a Groebner basis
1008  list I = J1,J2; // ideal, which is already a Groebner basis
1009  ivDHilbertSickle(G,2); // invokes the procedure without a degree bound
1010  ivDHilbertSickle(I,2,3); // invokes the procedure with degree bound 3
1011}
1012
1013proc ivDimCheck(list L, int n)
1014"USAGE: ivDimCheck(L,n); L a list of intmats, n an integer
1015RETURN: int, 0 if the dimension is finite, or 1 otherwise
1016PURPOSE:Decides, whether the K-dimension is finite or not
1017ASSUME: - basering is a Letterplace ring.
1018@*      - All rows of each intmat correspond to a Letterplace monomial.
1019NOTE:   - n is the number of variables.
1020EXAMPLE: example ivDimCheck; shows examples
1021"
1022{checkAssumptions(0,L);
1023 int i,r;
1024 intvec P,H;
1025 for (i = 1; i <= size(L); i++)
1026 {P[i] = ncols(L[i]);
1027  if (P[i] == 1) {if (isInMat(H,L[i]) > 0) {ERROR("Quotient algebra is trivial");}}
1028 }
1029 if (size(L) == 0) {ERROR("GB is empty, quotient algebra corresponds to free algebra");}
1030 kill H;
1031 intmat S; int sd,ld; intvec V;
1032 sd = P[1]; ld = P[1];
1033 for (i = 2; i <= size(P); i++)
1034 {if (P[i] < sd) {sd = P[i];}
1035  if (P[i] > ld) {ld = P[i];}
1036 }
1037 sd = (sd - 1); ld = ld - 1;
1038 if (ld == 0) { return(allVars(L,P,n));}
1039 if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1040 else {S = createStartMat(sd,n);}
1041 module M;
1042 for (i = 1; i <= nrows(S); i++)
1043 {V = S[i,1..ncols(S)];
1044  if (findCycle(V,L,P,n,ld,M)) {r = 1; break;}
1045 }
1046 return(r);
1047}
1048example
1049{
1050  "EXAMPLE:"; echo = 2;
1051  ring r = 0,(x,y),dp;
1052  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1053  R;
1054  setring R; // sets basering to Letterplace ring
1055  //some intmats, which contain monomials in intvec representation as rows
1056  intmat I1 [2][2] = 1,1,2,2; intmat I2 [1][3]  = 1,2,1;
1057  intmat J1 [1][2] =  1,1; intmat J2 [2][3] = 2,1,2,1,2,1;
1058  print(I1);
1059  print(I2);
1060  print(J1);
1061  print(J2);
1062  list G = I1,I2;// ideal, which is already a Groebner basis
1063  list I = J1,J2; // ideal, which is already a Groebner basis and which
1064  ivDimCheck(G,2); // invokes the procedure, factor is of finite K-dimension
1065  ivDimCheck(I,2); // invokes the procedure, factor is not of finite K-dimension
1066}
1067
1068proc ivHilbert(list L, int n, list #)
1069"USAGE: ivHilbert(L,n[,degbound]); L a list of intmats, n an integer,
1070@*      degbound an optional integer
1071RETURN: An intvec, containing the coefficients of the Hilbert series
1072PURPOSE:Computing the Hilbert series
1073ASSUME: - basering is a Letterplace ring.
1074@*      - all rows of each intmat correspond to a Letterplace monomial
1075@*      - if you specify a different degree bound degbound,
1076@*       degbound <= attrib(basering,uptodeg) holds.
1077NOTE: - If degbound is set, a degree bound  will be added. By default there
1078@*      is no degree bound.
1079@*    - n is the number of variables.
1080@*    - If I is returned, then I[k] is the (k-1)-th coefficient of the Hilbert
1081@*      series.
1082@*    - If the K-dimension is known to be infinite, a degree bound is needed
1083EXAMPLE: example ivHilbert; shows examples
1084"
1085{int degbound = 0;
1086 if (size(#) > 0) {if (typeof(#[1])=="int"){if (#[1] > 0) {degbound = #[1];}}}
1087 intvec P,H; int i;
1088 for (i = 1; i <= size(L); i++)
1089 {P[i] = ncols(L[i]);
1090  if (P[i] == 1) {if ( isInMat(H,L[i]) > 0) {ERROR("Quotient algebra is trivial");}}
1091 }
1092 if (size(L) == 0) {ERROR("GB is empty, quotient algebra corresponds to free algebra");}
1093 H[1] = 1;
1094 checkAssumptions(degbound,L);
1095 if (degbound == 0)
1096 {int sd; 
1097  intmat S;
1098  sd = P[1];
1099  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1100  sd = (sd - 1);
1101  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1102  else {S = createStartMat(sd,n);}
1103  if (intvec(S) == 0) {return(H);}
1104  for (i = 1; i <= sd; i++) {H = H,(n^i);}
1105  for (i = 1; i <= nrows(S); i++)
1106  {intvec St = S[i,1..ncols(S)];
1107   H = findHCoeff(St,n,L,P,H);
1108   kill St;
1109  }
1110  return(H);
1111 }
1112 else
1113 {for (i = 1; i <= size(P); i++)
1114  {if (P[i] > degbound) {ERROR("degreebound is too small, GB contains elements of higher degree");}}
1115  int sd; 
1116  intmat S;
1117  sd = P[1];
1118  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1119  sd = (sd - 1);
1120  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1121  else {S = createStartMat(sd,n);}
1122  if (intvec(S) == 0) {return(H);}
1123  for (i = 1; i <= sd; i++) {H = H,(n^i);}
1124  for (i = 1; i <= nrows(S); i++)
1125  {intvec St = S[i,1..ncols(S)];
1126   H = findHCoeff(St,n,L,P,H,degbound);
1127   kill St;
1128  }
1129  return(H);   
1130 }
1131}
1132example
1133{
1134  "EXAMPLE:"; echo = 2;
1135  ring r = 0,(x,y),dp;
1136  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1137  R;
1138  setring R; // sets basering to Letterplace ring
1139  //some intmats, which contain monomials in intvec representation as rows
1140  intmat I1 [2][2] = 1,1,2,2; intmat I2 [1][3]  = 1,2,1;
1141  intmat J1 [1][2] =  1,1; intmat J2 [2][3] = 2,1,2,1,2,1;
1142  print(I1);
1143  print(I2);
1144  print(J1);
1145  print(J2);
1146  list G = I1,I2; // ideal, which is already a Groebner basis
1147  list I = J1,J2; // ideal, which is already a Groebner basis
1148  ivHilbert(G,2); // invokes the procedure without any degree bound
1149  ivHilbert(I,2,5); // invokes the procedure with degree bound 5
1150}
1151
1152
1153proc ivKDim(list L, int n, list #)
1154"USAGE: ivKDim(L,n[,degbound]); L a list of intmats,
1155@*      n an integer, degbound an optional integer
1156RETURN: An integer, the K-dimension of A/<L>
1157PURPOSE:Computing the K-dimension of A/<L>
1158ASSUME: - basering is a Letterplace ring.
1159@*      - all rows of each intmat correspond to a Letterplace monomial
1160@*      - if you specify a different degree bound degbound,
1161@*        degbound <= attrib(basering,uptodeg) holds.
1162NOTE: - If degbound is set, a degree bound will be added. By default there
1163@*      is no degree bound.
1164@*    - n is the number of variables.
1165@*    - If the K-dimension is known to be infinite, a degree bound is needed
1166EXAMPLE: example ivKDim; shows examples
1167"
1168{int degbound = 0;
1169 if (size(#) > 0) {if (typeof(#[1])=="int"){if (#[1] > 0) {degbound = #[1];}}}
1170 intvec P,H; int i;
1171 for (i = 1; i <= size(L); i++)
1172 {P[i] = ncols(L[i]);
1173  if (P[i] == 1) {if ( isInMat(H,L[i]) > 0) {ERROR("Quotient algebra is trivial");}}
1174 }
1175 if (size(L) == 0) {ERROR("GB is empty, quotient algebra corresponds to free algebra");}
1176 kill H;
1177 checkAssumptions(degbound,L);
1178 if (degbound == 0)
1179 {int sd; int dimen = 1;
1180  intmat S;
1181  sd = P[1];
1182  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1183  sd = (sd - 1);
1184  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1185  else {S = createStartMat(sd,n);}
1186  if (intvec(S) == 0) {return(dimen);}
1187  for (i = 1; i <= sd; i++) {dimen = dimen +(n^i);}
1188  for (i = 1; i <= nrows(S); i++)
1189  {intvec St = S[i,1..ncols(S)];
1190   dimen = dimen + findDimen(St,n,L,P);
1191   kill St;
1192  }
1193  return(dimen);
1194 }
1195 else
1196 {for (i = 1; i <= size(P); i++)
1197  {if (P[i] > degbound) {ERROR("degreebound is too small, GB contains elements of higher degree");}}
1198  int sd; int dimen = 1;
1199  intmat S;
1200  sd = P[1];
1201  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1202  sd = (sd - 1);
1203  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1204  else {S = createStartMat(sd,n);}
1205  if (intvec(S) == 0) {return(dimen);}
1206  for (i = 1; i <= sd; i++) {dimen = dimen +(n^i);}
1207  for (i = 1; i <= nrows(S); i++)
1208  {intvec St = S[i,1..ncols(S)];
1209   dimen = dimen + findDimen(St,n,L,P, degbound);
1210   kill St;
1211  }
1212  return(dimen);
1213 }
1214}
1215example
1216{
1217  "EXAMPLE:"; echo = 2;
1218  ring r = 0,(x,y),dp;
1219  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1220  R;
1221  setring R; // sets basering to Letterplace ring
1222  //some intmats, which contain monomials in intvec representation as rows
1223  intmat I1 [2][2] = 1,1,2,2; intmat I2 [1][3]  = 1,2,1;
1224  intmat J1 [1][2] =  1,1; intmat J2 [2][3] = 2,1,2,1,2,1;
1225  print(I1);
1226  print(I2);
1227  print(J1);
1228  print(J2);
1229  list G = I1,I2; // ideal, which is already a Groebner basis
1230  list I = J1,J2; // ideal, which is already a Groebner basis
1231  ivKDim(G,2); // invokes the procedure without any degree bound
1232  ivKDim(I,2,5); // invokes the procedure with degree bound 5
1233}
1234
1235proc ivMis2Dim(list M)
1236"USAGE: ivMis2Dim(M); M a list of intvecs
1237RETURN: An integer, the K-dimension of the given algebra
1238PURPOSE:Computing the K-dimension out of given mistletoes
1239ASSUME: - The mistletoes have to be ordered lexicographically -> OrdMisLex.
1240@*        Otherwise the returned value may differ from the K-dimension.
1241@*      - basering is a Letterplace ring.
1242EXAMPLE: example ivMis2Dim; shows examples
1243"
1244{checkAssumptions(0,M);
1245 intvec L;
1246 if (size(M) == 0){ERROR("There are no mistletoes, so it appears your dimension is infinite!");}
1247 if (isInList(L,M) > 0) {print("1 is a mistletoe, therefore dim = 1"); return(1);}
1248 int i,j,d,s;
1249 j = 1;
1250 d = 1 + size(M[1]);
1251 for (i = 1; i < size(M); i++)
1252  {s = size(M[i]); if (s > size(M[i+1])){s = size(M[i+1]);}
1253   while ((M[i][j] == M[i+1][j]) && (j <= s)){j = j + 1;}
1254   d = d + size(M[i+1])- j + 1;
1255  }
1256 return(d);
1257}
1258example
1259{
1260  "EXAMPLE:"; echo = 2;
1261   ring r = 0,(x,y),dp;
1262   def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1263   R;
1264   setring R; // sets basering to Letterplace ring
1265   intvec i1 = 1,2; intvec i2 = 2,1,2;
1266   // the mistletoes are xy and yxy, which are already ordered lexicographically
1267   list L = i1,i2;
1268   ivMis2Dim(L); // returns the dimension of the factor algebra
1269}
1270
1271proc ivOrdMisLex(list M)
1272"USAGE: ivOrdMisLex(M); M a list of intvecs
1273RETURN: A list, containing the ordered intvecs of M
1274PURPOSE:Orders a given set of mistletoes lexicographically
1275ASSUME: - basering is a Letterplace ring.
1276        - intvecs correspond to monomials
1277NOTE:   - This is preprocessing, it's not needed if the mistletoes are returned
1278@*        from the sickle algorithm.
1279@*      - Each entry of the list returned is an intvec.
1280EXAMPLE: example ivOrdMisLex; shows examples
1281"
1282{checkAssumptions(0,M);
1283 return(sort(M)[1]);
1284}
1285example
1286{
1287  "EXAMPLE:"; echo = 2;
1288   ring r = 0,(x,y),dp;
1289   def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1290   setring R; // sets basering to Letterplace ring
1291   intvec i1 = 1,2,1; intvec i2 = 2,2,1; intvec i3 = 1,1; intvec i4 = 2,1,1,1;
1292   // the corresponding monomials are xyx,y^2x,x^2,yx^3
1293   list M = i1,i2,i3,i4;
1294   M;
1295   ivOrdMisLex(M);// orders the list of monomials
1296}
1297
1298proc ivSickle(list L, int n, list #)
1299"USAGE: ivSickle(L,n,[degbound]); L a list of intmats, n an int, degbound an
1300@*      optional integer
1301RETURN: A list, containing intvecs, the mistletoes of A/<L>
1302PURPOSE:Computing the mistletoes for a given Groebner basis L
1303ASSUME: - basering is a Letterplace ring.
1304@*      - all rows of each intmat correspond to a Letterplace monomial
1305@*      - if you specify a different degree bound degbound,
1306@*        degbound <= attrib(basering,uptodeg) holds.
1307NOTE: - If degbound is set, a degree bound will be added. By default there
1308@*      is no degree bound.
1309@*    - n is the number of variables.
1310@*    - If the K-dimension is known to be infinite, a degree bound is needed
1311EXAMPLE: example ivSickle; shows examples
1312"
1313{list M;
1314 int degbound = 0;
1315 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] > 0){degbound = #[1];}}}
1316 int i;
1317 intvec P,H;
1318 for (i = 1; i <= size(L); i++)
1319 {P[i] = ncols(L[i]);
1320  if (P[i] == 1) {if (isInMat(H,L[i]) > 0) {ERROR("Quotient algebra is trivial");}}
1321 }
1322 if (size(L) == 0) {ERROR("GB is empty, quotient algebra corresponds to free algebra");}
1323 kill H;
1324 checkAssumptions(degbound,L);
1325 if (degbound == 0)
1326 {intmat S; int sd;
1327  sd = P[1];
1328  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1329  sd = (sd - 1);
1330  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1331  else {S = createStartMat(sd,n);}
1332  if (intvec(S) == 0) {return(list (intvec(0)));}
1333  for (i = 1; i <= nrows(S); i++)
1334  {intvec St = S[i,1..ncols(S)];
1335   M = M + findmistletoes(St,n,L,P);
1336   kill St;
1337  }
1338  return(M);
1339 }
1340 else
1341 {for (i = 1; i <= size(P); i++)
1342  {if (P[i] > degbound) {ERROR("degreebound is too small, GB contains elements of higher degree");}}
1343  intmat S; int sd;
1344  sd = P[1];
1345  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1346  sd = (sd - 1);
1347  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1348  else {S = createStartMat(sd,n);}
1349  if (intvec(S) == 0) {return(list (intvec(0)));}
1350  for (i = 1; i <= nrows(S); i++)
1351  {intvec St = S[i,1..ncols(S)];
1352   M = M + findmistletoes(St,n,L,P,degbound);
1353   kill St;
1354  }
1355  return(M);
1356 }
1357}
1358example
1359{
1360  "EXAMPLE:"; echo = 2;
1361  ring r = 0,(x,y),dp;
1362  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1363  setring R; // sets basering to Letterplace ring
1364  //some intmats, which contain monomials in intvec representation as rows
1365  intmat I1 [2][2] = 1,1,2,2; intmat I2 [1][3]  = 1,2,1;
1366  intmat J1 [1][2] =  1,1; intmat J2 [2][3] = 2,1,2,1,2,1;
1367  print(I1);
1368  print(I2);
1369  print(J1);
1370  print(J2);
1371  list G = I1,I2; // ideal, which is already a Groebner basis
1372  list I =  J1,J2; // ideal, which is already a Groebner basis
1373  ivSickle(G,2); // invokes the procedure without any degree bound
1374  ivSickle(I,2,5); // invokes the procedure with degree bound 5
1375}
1376
1377proc ivSickleDim(list L, int n, list #)
1378"USAGE: ivSickleDim(L,n[,degbound]); L a list of intmats, n an integer, degbound
1379@*      an optional integer
1380RETURN: A list
1381PURPOSE:Computing mistletoes and the K-dimension
1382ASSUME: - basering is a Letterplace ring.
1383@*      - all rows of each intmat correspond to a Letterplace monomial
1384@*      - if you specify a different degree bound degbound,
1385@*        degbound <= attrib(basering,uptodeg) holds.
1386NOTE: - If L is the list returned, then L[1] is an integer, L[2] is a list,
1387@*      containing the mistletoes as intvecs.
1388@*    - If degbound is set, a degree bound will be added. By default there
1389@*      is no degree bound.
1390@*    - n is the number of variables.
1391@*    - If the K-dimension is known to be infinite, a degree bound is needed
1392EXAMPLE: example ivSickleDim; shows examples
1393"
1394{list M;
1395 int degbound = 0;
1396 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] > 0){degbound = #[1];}}}
1397 int i,dimen; list R;
1398 intvec P,H;
1399 for (i = 1; i <= size(L); i++)
1400 {P[i] = ncols(L[i]);
1401  if (P[i] == 1) {if (isInMat(H,L[i]) > 0) {ERROR("Quotient algebra is trivial, dimension equals zero");}}
1402 }
1403 if (size(L) == 0) {ERROR("GB is empty, quotient algebra corresponds to free algebra");}
1404 kill H;
1405 checkAssumptions(degbound,L);
1406 if (degbound == 0)
1407 {int sd; dimen = 1;
1408  intmat S;
1409  sd = P[1];
1410  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1411  sd = (sd - 1);
1412  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1413  else {S = createStartMat(sd,n);}
1414  if (intvec(S) == 0) {return(list(dimen,list(intvec(0))));}
1415  for (i = 1; i <= sd; i++) {dimen = dimen +(n^i);}
1416  R[1] = dimen;
1417  for (i = 1; i <= nrows(S); i++)
1418  {intvec St = S[i,1..ncols(S)];
1419   R = findMisDim(St,n,L,P,R);
1420   kill St;
1421  }
1422  return(R);
1423 }
1424 else
1425 {for (i = 1; i <= size(P); i++)
1426  {if (P[i] > degbound) {ERROR("degreebound is too small, GB contains elements of higher degree");}}
1427  int sd; dimen = 1;
1428  intmat S;
1429  sd = P[1];
1430  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1431  sd = (sd - 1);
1432  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1433  else {S = createStartMat(sd,n);}
1434  if (intvec(S) == 0) {return(list(dimen,list(intvec(0))));}
1435  for (i = 1; i <= sd; i++) {dimen = dimen +(n^i);}
1436  R[1] = dimen;
1437  for (i = 1; i <= nrows(S); i++)
1438  {intvec St = S[i,1..ncols(S)];
1439   R = findMisDim(St,n,L,P,R,degbound);
1440   kill St;
1441  }
1442  return(R);
1443 }
1444}
1445example
1446{
1447  "EXAMPLE:"; echo = 2;
1448  ring r = 0,(x,y),dp;
1449  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1450  setring R; // sets basering to Letterplace ring
1451  //some intmats, which contain monomials in intvec representation as rows
1452  intmat I1 [2][2] = 1,1,2,2; intmat I2 [1][3]  = 1,2,1;
1453  intmat J1 [1][2] =  1,1; intmat J2 [2][3] = 2,1,2,1,2,1;
1454  print(I1);
1455  print(I2);
1456  print(J1);
1457  print(J2);
1458  list G = I1,I2;// ideal, which is already a Groebner basis
1459  list I =  J1,J2; // ideal, which is already a Groebner basis
1460  ivSickleDim(G,2); // invokes the procedure without any degree bound
1461  ivSickleDim(I,2,5); // invokes the procedure with degree bound 5
1462}
1463
1464proc ivSickleHil(list L, int n, list #)
1465"USAGE:ivSickleHil(L,n[,degbound]); L a list of intmats, n an integer,
1466@*     degbound an optional integer
1467RETURN: A list
1468PURPOSE:Computing the mistletoes and the Hilbert series
1469ASSUME: - basering is a Letterplace ring.
1470@*      - all rows of each intmat correspond to a Letterplace monomial
1471@*      - if you specify a different degree bound degbound,
1472@*        degbound <= attrib(basering,uptodeg) holds.
1473NOTE: - If L is the list returned, then L[1] is an intvec, L[2] is a list,
1474@*      containing the mistletoes as intvecs.
1475@*    - If degbound is set, a degree bound will be added. By default there
1476@*      is no degree bound.
1477@*    - n is the number of variables.
1478@*    - If I = L[1] is the intvec returned, then I[k] is the (k-1)-th
1479@*      coefficient of the Hilbert series.
1480@*    - If the K-dimension is known to be infinite, a degree bound is needed
1481EXAMPLE: example ivSickleHil; shows examples
1482"
1483{int degbound = 0;
1484 if (size(#) > 0) {if (typeof(#[1])=="int"){if (#[1] > 0) {degbound = #[1];}}}
1485 intvec P,H; int i; list R;
1486 for (i = 1; i <= size(L); i++)
1487 {P[i] = ncols(L[i]);
1488  if (P[i] == 1) {if ( isInMat(H,L[i]) > 0) {ERROR("Quotient algebra is trivial");}}
1489 }
1490 if (size(L) == 0) {ERROR("GB is empty, quotient algebra corresponds to free algebra");}
1491 H[1] = 1;
1492 checkAssumptions(degbound,L);
1493 if (degbound == 0)
1494 {int sd; 
1495  intmat S;
1496  sd = P[1];
1497  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1498  sd = (sd - 1);
1499  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1500  else {S = createStartMat(sd,n);}
1501  if (intvec(S) == 0) {return(list(H,list(intvec (0))));}
1502  for (i = 1; i <= sd; i++) {H = H,(n^i);}
1503  R[1] = H; kill H;
1504  for (i = 1; i <= nrows(S); i++)
1505  {intvec St = S[i,1..ncols(S)];
1506   R = findHCoeffMis(St,n,L,P,R);
1507   kill St;
1508  }
1509  return(R);
1510 }
1511 else
1512 {for (i = 1; i <= size(P); i++)
1513  {if (P[i] > degbound) {ERROR("degreebound is too small, GB contains elements of higher degree");}}
1514  int sd; 
1515  intmat S;
1516  sd = P[1];
1517  for (i = 2; i <= size(P); i++) {if (P[i] < sd) {sd = P[i];}}
1518  sd = (sd - 1);
1519  if (sd == 0) { for (i = 1; i <= size(L); i++){if (ncols(L[i]) == 1){S = createStartMat1(n,L[i]); break;}}}
1520  else {S = createStartMat(sd,n);}
1521  if (intvec(S) == 0) {return(list(H,list(intvec(0))));}
1522  for (i = 1; i <= sd; i++) {H = H,(n^i);}
1523  R[1] = H; kill H;
1524  for (i = 1; i <= nrows(S); i++)
1525  {intvec St = S[i,1..ncols(S)];
1526   R = findHCoeffMis(St,n,L,P,R,degbound);
1527   kill St;
1528  }
1529  return(R);
1530 }
1531}
1532example
1533{
1534  "EXAMPLE:"; echo = 2;
1535  ring r = 0,(x,y),dp;
1536  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1537  setring R; // sets basering to Letterplace ring
1538  //some intmats, which contain monomials in intvec representation as rows
1539  intmat I1[2][2] = 1,1,2,2; intmat I2[1][3]  = 1,2,1;
1540  intmat J1[1][2] =  1,1; intmat J2[2][3] = 2,1,2,1,2,1;
1541  print(I1);
1542  print(I2);
1543  print(J1);
1544  print(J2);
1545  list G = I1,I2;// ideal, which is already a Groebner basis
1546  list I =  J1,J2; // ideal, which is already a Groebner basis
1547  ivSickleHil(G,2); // invokes the procedure without any degree bound
1548  ivSickleHil(I,2,5); // invokes the procedure with degree bound 5
1549}
1550
1551proc lpDHilbert(ideal G, list #)
1552"USAGE: lpDHilbert(G[,degbound,n]); G an ideal, degbound, n optional integers
1553RETURN: A list
1554PURPOSE:Computing K-dimension and Hilbert series, starting with a lp-ideal
1555ASSUME: - basering is a Letterplace ring.
1556@*      - if you specify a different degree bound degbound,
1557@*        degbound <= attrib(basering,uptodeg) holds.
1558NOTE: - If L is the list returned, then L[1] is an integer, L[2] is an intvec.
1559@*    - If degbound is set, there will be a degree bound added. 0 means no
1560@*      degree bound. Default: attrib(basering,uptodeg).
1561@*    - n can be set to a different number of variables.
1562@*      Default: n = attrib(basering, lV).
1563@*    - If I = L[2] is the intvec returned, then I[k] is the (k-1)-th
1564@*      coefficient of the Hilbert series.
1565@*    - If the K-dimension is known to be infinite, a degree bound is needed
1566EXAMPLE: example lpDHilbert; shows examples
1567"
1568{int degbound = attrib(basering,"uptodeg");int n = attrib(basering, "lV");
1569 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] >= 0){degbound = #[1];}}}
1570 if (size(#) > 1){if (typeof(#[1])=="int"){if (#[2] > 0){n = #[2];}}}
1571 list L;
1572 L = lp2ivId(normalize(lead(G)));
1573 return(ivDHilbert(L,n,degbound));
1574}
1575example
1576{
1577  "EXAMPLE:"; echo = 2;
1578  ring r = 0,(x,y),dp;
1579  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1580  setring R; // sets basering to Letterplace ring
1581  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3); // ideal G contains a
1582  //Groebner basis
1583  lpDHilbert(G,5,2); // invokes procedure with degree bound 5 and 2 variables
1584  // note that the optional parameters are not necessary, due to the finiteness
1585  // of the K-dimension of the factor algebra
1586  lpDHilbert(G); // procedure with ring parameters
1587  lpDHilbert(G,0); // procedure without degreebound
1588}
1589
1590proc lpDHilbertSickle(ideal G, list #)
1591"USAGE: lpDHilbertSickle(G[,degbound,n]); G an ideal, degbound, n optional
1592@*      integers
1593RETURN: A list
1594PURPOSE:Computing K-dimension, Hilbert series and mistletoes at once
1595ASSUME: - basering is a Letterplace ring.
1596@*      - if you specify a different degree bound degbound,
1597@*        degbound <= attrib(basering,uptodeg) holds.
1598NOTE: - If L is the list returned, then L[1] is an intvec, the Hilbert series,
1599@*      L[2] is an integer, the K-dimension and L[3] is an ideal, the mistletoes
1600@*    - If degbound is set, there will be a degree bound added. 0 means no
1601@*      degree bound. Default: attrib(basering,uptodeg).
1602@*    - n can be set to a different number of variables.
1603@*      Default: n = attrib(basering, lV).
1604@*    - If I = L[1] is the intvec returned, then I[k] is the (k-1)-th
1605@*      coefficient of the Hilbert series.
1606@*    - If the K-dimension is known to be infinite, a degree bound is needed
1607EXAMPLE: example lpDHilbertSickle; shows examples
1608"
1609{int degbound = attrib(basering,"uptodeg");int n = attrib(basering, "lV");
1610 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] >= 0){degbound = #[1];}}}
1611 if (size(#) > 1){if (typeof(#[1])=="int"){if (#[2] > 0){n = #[2];}}}
1612 list L;
1613 L = lp2ivId(normalize(lead(G)));
1614 L = ivDHilbertSickle(L,n,degbound);
1615 L[3] =  ivL2lpI(L[3]);
1616 return(L);
1617}
1618example
1619{
1620  "EXAMPLE:"; echo = 2;
1621  ring r = 0,(x,y),dp;
1622  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1623  setring R; // sets basering to Letterplace ring
1624  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3); // ideal G contains a
1625  //Groebner basis
1626  lpDHilbertSickle(G,5,2); //invokes procedure with degree bound 5 and 2 variables
1627  // note that the optional parameters are not necessary, due to the finiteness
1628  // of the K-dimension of the factor algebra
1629  lpDHilbert(G); // procedure with ring parameters
1630  lpDHilbert(G,0); // procedure without degreebound
1631}
1632
1633proc lpHilbert(ideal G, list #)
1634"USAGE: lpHilbert(G[,degbound,n]); G an ideal, degbound, n optional integers
1635RETURN: An intvec, containing the coefficients of the Hilbert series
1636PURPOSE:Computing the Hilbert series
1637ASSUME: - basering is a Letterplace ring.
1638@*      - if you specify a different degree bound degbound,
1639@*        degbound <= attrib(basering,uptodeg) holds.
1640NOTE: - If degbound is set, there will be a degree bound added. 0 means no
1641@*      degree bound. Default: attrib(basering,uptodeg).
1642@*    - n is the number of variables, which can be set to a different number.
1643@*      Default: attrib(basering, lV).
1644@*    - If I is returned, then I[k] is the (k-1)-th coefficient of the Hilbert
1645@*      series.
1646@*    - If the K-dimension is known to be infinite, a degree bound is needed
1647EXAMPLE: example lpHilbert; shows examples
1648"
1649{int degbound = attrib(basering,"uptodeg");int n = attrib(basering, "lV");
1650 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] >= 0){degbound = #[1];}}}
1651 if (size(#) > 1){if (typeof(#[1])=="int"){if (#[2] > 0){n = #[2];}}}
1652 list L;
1653 L = lp2ivId(normalize(lead(G)));
1654 return(ivHilbert(L,n,degbound));
1655}
1656example
1657{
1658  "EXAMPLE:"; echo = 2;
1659  ring r = 0,(x,y),dp;
1660  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1661  setring R; // sets basering to Letterplace ring
1662  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3); // ideal G contains a
1663  //Groebner basis
1664  lpHilbert(G,5,2); // invokes procedure with degree bound 5 and 2 variables
1665  // note that the optional parameters are not necessary, due to the finiteness
1666  // of the K-dimension of the factor algebra
1667  lpDHilbert(G); // procedure with ring parameters
1668  lpDHilbert(G,0); // procedure without degreebound
1669}
1670
1671proc lpDimCheck(ideal G)
1672"USAGE: lpDimCheck(G);
1673RETURN: 1, if K-dimension of the factor algebra is infinite, 0 otherwise
1674PURPOSE:Checking a factor algebra for finiteness of the K-dimension
1675ASSUME: - basering is a Letterplace ring.
1676EXAMPLE: example lpDimCheck; shows examples
1677"
1678{int n = attrib(basering,"lV");
1679 list L;
1680 ideal R;
1681 R = normalize(lead(G));
1682 L = lp2ivId(R);
1683 return(ivDimCheck(L,n));
1684}
1685example
1686{
1687  "EXAMPLE:"; echo = 2;
1688  ring r = 0,(x,y),dp;
1689  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1690  setring R; // sets basering to Letterplace ring
1691  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3);
1692  // Groebner basis
1693  ideal I = x(1)*x(2), y(1)*x(2)*y(3), x(1)*y(2)*x(3);
1694  // Groebner basis
1695  lpDimCheck(G); // invokes procedure, factor algebra is of finite K-dimension
1696  lpDimCheck(I); // invokes procedure, factor algebra is of infinite Kdimension
1697}
1698
1699proc lpKDim(ideal G, list #)
1700"USAGE: lpKDim(G[,degbound, n]); G an ideal, degbound, n optional integers
1701RETURN: An integer, the K-dimension of the factor algebra
1702PURPOSE:Computing the K-dimension of a factor algebra, given via an ideal
1703ASSUME: - basering is a Letterplace ring
1704@*      - if you specify a different degree bound degbound,
1705@*        degbound <= attrib(basering,uptodeg) holds.
1706NOTE: - If degbound is set, there will be a degree bound added. 0 means no
1707@*      degree bound. Default: attrib(basering, uptodeg).
1708@*    - n is the number of variables, which can be set to a different number.
1709@*      Default: attrib(basering, lV).
1710@*    - If the K-dimension is known to be infinite, a degree bound is needed
1711EXAMPLE: example lpKDim; shows examples
1712"
1713{int degbound = attrib(basering, "uptodeg");int n = attrib(basering, "lV");
1714 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] >= 0){degbound = #[1];}}}
1715 if (size(#) > 1){if (typeof(#[1])=="int"){if (#[2] > 0){n = #[2];}}}
1716 list L;
1717 L = lp2ivId(normalize(lead(G)));
1718 return(ivKDim(L,n,degbound));
1719}
1720example
1721{
1722  "EXAMPLE:"; echo = 2;
1723  ring r = 0,(x,y),dp;
1724  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1725  setring R; // sets basering to Letterplace ring
1726  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3);
1727  // ideal G contains a Groebner basis
1728  lpKDim(G); //procedure invoked with ring parameters
1729  // the factor algebra is finite, so the degree bound given by the Letterplace
1730  // ring is not necessary
1731  lpKDim(G,0); // procedure without any degree bound
1732}
1733
1734proc lpMis2Dim(ideal M)
1735"USAGE: lpMis2Dim(M); M an ideal
1736RETURN: An integer, the K-dimension of the factor algebra
1737PURPOSE:Computing the K-dimension out of given mistletoes
1738ASSUME: - basering is a Letterplace ring.
1739@*      - M contains only monomials
1740NOTE:   - The mistletoes have to be ordered lexicographically -> OrdMisLex.
1741EXAMPLE: example lpMis2Dim; shows examples
1742"
1743{list L;
1744 L = lpId2ivLi(M);
1745 return(ivMis2Dim(L));
1746}
1747example
1748{
1749  "EXAMPLE:"; echo = 2;
1750   ring r = 0,(x,y),dp;
1751   def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1752  setring R; // sets basering to Letterplace ring
1753   ideal L = x(1)*y(2),y(1)*x(2)*y(3);
1754   // ideal containing the mistletoes
1755   lpMis2Dim(L); // returns the K-dimension of the factor algebra
1756}
1757
1758proc lpOrdMisLex(ideal M)
1759"USAGE: lpOrdMisLex(M); M an ideal of mistletoes
1760RETURN: An ideal, containing the mistletoes, ordered lexicographically
1761PURPOSE:A given set of mistletoes is ordered lexicographically
1762ASSUME: - basering is a Letterplace ring.
1763NOTE:   This is preprocessing, it is not needed if the mistletoes are returned
1764@*      from the sickle algorithm.
1765EXAMPLE: example lpOrdMisLex; shows examples
1766"
1767{return(ivL2lpI(sort(lpId2ivLi(M))[1]));}
1768example
1769{
1770  "EXAMPLE:"; echo = 2;
1771   ring r = 0,(x,y),dp;
1772   def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1773   setring R; // sets basering to Letterplace ring
1774   ideal M = x(1)*y(2)*x(3), y(1)*y(2)*x(3), x(1)*x(2), y(1)*x(2)*x(3)*x(4);
1775   // some monomials
1776   lpOrdMisLex(M); // orders the monomials lexicographically
1777}
1778
1779proc lpSickle(ideal G,  list #)
1780"USAGE: lpSickle(G[,degbound,n]); G an ideal, degbound, n optional integers
1781RETURN: An ideal
1782PURPOSE:Computing the mistletoes of K[X]/<G>
1783ASSUME: - basering is a Letterplace ring.
1784@*      - if you specify a different degree bound degbound,
1785@*        degbound <= attrib(basering,uptodeg) holds.
1786NOTE: - If degbound is set, there will be a degree bound added. 0 means no
1787@*      degree bound. Default: attrib(basering,uptodeg).
1788@*    - n is the number of variables, which can be set to a different number.
1789@*      Default: attrib(basering, lV).
1790@*    - If the K-dimension is known to be infinite, a degree bound is needed
1791EXAMPLE: example lpSickle; shows examples
1792"
1793{int degbound = attrib(basering,"uptodeg"); int n = attrib(basering, "lV");
1794 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] >= 0){degbound = #[1];}}}
1795 if (size(#) > 1){if (typeof(#[1])=="int"){if (#[2] > 0){n = #[2];}}}
1796 list L; ideal R;
1797 R = normalize(lead(G));
1798 L = lp2ivId(R);
1799 L = ivSickle(L,n,degbound);
1800 R = ivL2lpI(L);
1801 return(R);
1802}
1803example
1804{
1805  "EXAMPLE:"; echo = 2;
1806  ring r = 0,(x,y),dp;
1807  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1808  setring R; // sets basering to Letterplace ring
1809  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3); // ideal G contains a
1810  //Groebner basis
1811  lpSickle(G); //invokes the procedure with ring parameters
1812  // the factor algebra is finite, so the degree bound given by the Letterplace
1813  // ring is not necessary
1814  lpSickle(G,0); // procedure without any degree bound
1815}
1816
1817proc lpSickleDim(ideal G, list #)
1818"USAGE: lpSickleDim(G[,degbound,n]); G an ideal, degbound, n optional integers
1819RETURN: A list
1820PURPOSE:Computing the K-dimension and the mistletoes
1821ASSUME: - basering is a Letterplace ring.
1822@*      - if you specify a different degree bound degbound,
1823@*        degbound <= attrib(basering,uptodeg) holds.
1824NOTE: - If L is the list returned, then L[1] is an integer, the K-dimension,
1825@*      L[2] is an ideal, the mistletoes.
1826@*    - If degbound is set, there will be a degree bound added. 0 means no
1827@*      degree bound. Default: attrib(basering,uptodeg).
1828@*    - n is the number of variables, which can be set to a different number.
1829@*      Default: attrib(basering, lV).
1830@*    - If the K-dimension is known to be infinite, a degree bound is needed
1831EXAMPLE: example lpSickleDim; shows examples
1832"
1833{int degbound = attrib(basering,"uptodeg");int n = attrib(basering, "lV");
1834 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] >= 0){degbound = #[1];}}}
1835 if (size(#) > 1){if (typeof(#[1])=="int"){if (#[2] > 0){n = #[2];}}}
1836 list L;
1837 L = lp2ivId(normalize(lead(G)));
1838 L = ivSickleDim(L,n,degbound);
1839 L[2] = ivL2lpI(L[2]);
1840 return(L);
1841}
1842example
1843{
1844  "EXAMPLE:"; echo = 2;
1845  ring r = 0,(x,y),dp;
1846  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1847  setring R; // sets basering to Letterplace ring
1848  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3); // ideal G contains a
1849  //Groebner basis
1850  lpSickleDim(G); // invokes the procedure with ring parameters
1851  // the factor algebra is finite, so the degree bound given by the Letterplace
1852  // ring is not necessary
1853  lpSickleDim(G,0); // procedure without any degree bound
1854}
1855
1856proc lpSickleHil(ideal G, list #)
1857"USAGE: lpSickleHil(G);
1858RETURN: A list
1859PURPOSE:Computing the Hilbert series and the mistletoes
1860ASSUME: - basering is a Letterplace ring.
1861@*      - if you specify a different degree bound degbound,
1862@*        degbound <= attrib(basering,uptodeg) holds.
1863NOTE: - If L is the list returned, then L[1] is an intvec, corresponding to the
1864@*      Hilbert series, L[2] is an ideal, the mistletoes.
1865@*    - If degbound is set, there will be a degree bound added. 0 means no
1866@*      degree bound. Default: attrib(basering,uptodeg).
1867@*    - n is the number of variables, which can be set to a different number.
1868@*      Default: attrib(basering, lV).
1869@*    - If I = L[1] is the intvec returned, then I[k] is the (k-1)-th
1870@*      coefficient of the Hilbert series.
1871@*    - If the K-dimension is known to be infinite, a degree bound is needed
1872EXAMPLE: example lpSickleHil; shows examples
1873"
1874{int degbound = attrib(basering,"uptodeg");int n = attrib(basering, "lV");
1875 if (size(#) > 0){if (typeof(#[1])=="int"){if (#[1] >= 0){degbound = #[1];}}}
1876 if (size(#) > 1){if (typeof(#[1])=="int"){if (#[2] > 0){n = #[2];}}}
1877 list L;
1878 L = lp2ivId(normalize(lead(G)));
1879 L = ivSickleHil(L,n,degbound);
1880 L[2] =  ivL2lpI(L[2]);
1881 return(L);
1882}
1883example
1884{
1885  "EXAMPLE:"; echo = 2;
1886  ring r = 0,(x,y),dp;
1887  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1888  setring R; // sets basering to Letterplace ring
1889  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3); // ideal G contains a
1890  //Groebner basis
1891  lpSickleHil(G); // invokes the procedure with ring parameters
1892  // the factor algebra is finite, so the degree bound given by the Letterplace
1893  // ring is not necessary
1894  lpSickleHil(G,0); // procedure without any degree bound
1895}
1896
1897proc sickle(ideal G, list #)
1898"USAGE: sickle(G[,m, d, h, degbound]); G an ideal; m,d,h,degbound optional
1899@*      integers
1900RETURN: A list
1901PURPOSE:Allowing the user to access all procs with one command
1902ASSUME: - basering is a Letterplace ring.
1903@*      - if you specify a different degree bound degbound,
1904@*        degbound <= attrib(basering,uptodeg) holds.
1905NOTE:   The returned object will always be a list, but the entries of the
1906@*      returned list may be very different
1907@* case m=1,d=1,h=1: see lpDHilbertSickle
1908@* case m=1,d=1,h=0: see lpSickleDim
1909@* case m=1,d=0,h=1: see lpSickleHil
1910@* case m=1,d=0,h=0: see lpSickle (this is the default case)
1911@* case m=0,d=1,h=1: see lpDHilbert
1912@* case m=0,d=1,h=0: see lpKDim
1913@* case m=0,d=0,h=1: see lpHilbert
1914@* case m=0,d=0,h=0: returns an error
1915@*    - If degbound is set, there will be a degree bound added. 0 means no
1916@*      degree bound. Default: attrib(basering,uptodeg).
1917@*    - If the K-dimension is known to be infinite, a degree bound is needed
1918EXAMPLE: example sickle; shows examples
1919"
1920{int m,d,h,degbound;
1921 m = 1; d = 0; h = 0; degbound = attrib(basering,"uptodeg");
1922 if (size(#) > 0) {if (typeof(#[1])=="int"){if (#[1] < 1) {m = 0;}}}
1923 if (size(#) > 1) {if (typeof(#[1])=="int"){if (#[2] > 0) {d = 1;}}}
1924 if (size(#) > 2) {if (typeof(#[1])=="int"){if (#[3] > 0) {h = 1;}}}
1925 if (size(#) > 3) {if (typeof(#[1])=="int"){if (#[4] >= 0) {degbound = #[4];}}}
1926 if (m == 1)
1927 {if (d == 0)
1928  {if (h == 0) {return(lpSickle(G,degbound,attrib(basering,"lV")));}
1929   else        {return(lpSickleHil(G,degbound,attrib(basering,"lV")));}
1930  }
1931  else
1932  {if (h == 0) {return(lpSickleDim(G,degbound,attrib(basering,"lV")));}
1933   else {return(lpDHilbertSickle(G,degbound,attrib(basering,"lV")));}
1934  }
1935 }
1936 else
1937 {if (d == 0)
1938  {if (h == 0) {ERROR("You request to do nothing, so relax and do so");}
1939   else        {return(lpHilbert(G,degbound,attrib(basering,"lV")));}
1940  }
1941  else
1942  {if (h == 0) {return(lpKDim(G,degbound,attrib(basering,"lV")));}
1943   else {return(lpDHilbert(G,degbound,attrib(basering,"lV")));}
1944  }
1945 }
1946}
1947example
1948{
1949  "EXAMPLE:"; echo = 2;
1950  ring r = 0,(x,y),dp;
1951  def R = makeLetterplaceRing(5); // constructs a Letterplace ring
1952  setring R; // sets basering to Letterplace ring
1953  ideal G = x(1)*x(2), y(1)*y(2),x(1)*y(2)*x(3);
1954  // G contains a Groebner basis
1955  sickle(G,1,1,1); // computes mistletoes, K-dimension and the Hilbert series
1956  sickle(G,1,0,0); // computes mistletoes only
1957  sickle(G,0,1,0); // computes K-dimension only
1958  sickle(G,0,0,1); // computes Hilbert series only
1959}
1960
1961///////////////////////////////////////////////////////////////////////////////
1962
1963
1964proc tst_fpadim()
1965{
1966 example ivDHilbert;
1967 example ivDHilbertSickle;
1968 example ivDimCheck;
1969 example ivHilbert;
1970 example ivKDim;
1971 example ivMis2Dim;
1972 example ivOrdMisLex;
1973 example ivSickle;
1974 example ivSickleHil;
1975 example ivSickleDim;
1976 example lpDHilbert;
1977 example lpDHilbertSickle;
1978 example lpHilbert;
1979 example lpDimCheck;
1980 example lpKDim;
1981 example lpMis2Dim;
1982 example lpOrdMisLex;
1983 example lpSickle;
1984 example lpSickleHil;
1985 example lpSickleDim;
1986 example sickle;
1987 example ivL2lpI;
1988 example iv2lp;
1989 example iv2lpList;
1990 example iv2lpMat;
1991 example lp2iv;
1992 example lp2ivId;
1993 example lpId2ivLi;
1994}
1995
1996
1997
1998
1999
2000/*
2001Here are some examples one may try. Just copy them into your console.
2002These are relations for braid groups, up to degree d:
2003
2004
2005LIB "fpadim.lib";
2006ring r = 0,(x,y,z),dp;
2007int d =10; // degree
2008def R = makeLetterplaceRing(d);
2009setring R;
2010ideal I = y(1)*x(2)*y(3) - z(1)*y(2)*z(3), x(1)*y(2)*x(3) - z(1)*x(2)*y(3),
2011z(1)*x(2)*z(3) - y(1)*z(2)*x(3), x(1)*x(2)*x(3) + y(1)*y(2)*y(3) +
2012z(1)*z(2)*z(3) + x(1)*y(2)*z(3);
2013option(prot);
2014option(redSB);option(redTail);option(mem);
2015ideal J = system("freegb",I,d,3);
2016lpDimCheck(J);
2017sickle(J,1,1,1,d);//Computes mistletoes, K-dimension and the Hilbert series
2018
2019
2020
2021LIB "fpadim.lib";
2022ring r = 0,(x,y,z),dp;
2023int d =11; // degree
2024def R = makeLetterplaceRing(d);
2025setring R;
2026ideal I = y(1)*x(2)*y(3) - z(1)*y(2)*z(3), x(1)*y(2)*z(3) - z(1)*x(2)*y(3),
2027z(1)*x(2)*z(3) - y(1)*z(2)*x(3), x(1)*x(2)*x(3) + y(1)*y(2)*y(3) +
2028z(1)*z(2)*z(3) + x(1)*y(2)*z(3);
2029option(prot);
2030option(redSB);option(redTail);option(mem);
2031ideal J = system("freegb",I,d,3);
2032lpDimCheck(J);
2033sickle(J,1,1,1,d);
2034
2035
2036
2037LIB "fpadim.lib";
2038ring r = 0,(x,y,z),dp;
2039int d  = 6; // degree
2040def R  = makeLetterplaceRing(d);
2041setring R;
2042ideal I = y(1)*x(2)*y(3) - z(1)*y(2)*z(3), x(1)*y(2)*x(3) - z(1)*x(2)*y(3),
2043z(1)*x(2)*z(3) - y(1)*z(2)*x(3), x(1)*x(2)*x(3) -2*y(1)*y(2)*y(3) + 3*z(1)*z(2)*z(3) -4*x(1)*y(2)*z(3) + 5*x(1)*z(2)*z(3)- 6*x(1)*y(2)*y(3) +7*x(1)*x(2)*z(3) - 8*x(1)*x(2)*y(3);
2044option(prot);
2045option(redSB);option(redTail);option(mem);
2046ideal J = system("freegb",I,d,3);
2047lpDimCheck(J);
2048sickle(J,1,1,1,d);
2049*/
2050
2051/*
2052Here are some examples, which can also be found in [studzins]:
2053
2054// takes up to 880Mb of memory
2055LIB "fpadim.lib";
2056ring r = 0,(x,y,z),dp;
2057int d =10; // degree
2058def R = makeLetterplaceRing(d);
2059setring R;
2060ideal I =
2061z(1)*z(2)*z(3)*z(4) + y(1)*x(2)*y(3)*x(4) - x(1)*y(2)*y(3)*x(4) - 3*z(1)*y(2)*x(3)*z(4), x(1)*x(2)*x(3) + y(1)*x(2)*y(3) - x(1)*y(2)*x(3), z(1)*y(2)*x(3)-x(1)*y(2)*z(3) + z(1)*x(2)*z(3);
2062option(prot);
2063option(redSB);option(redTail);option(mem);
2064ideal J = system("freegb",I,d,nvars(r));
2065lpDimCheck(J);
2066sickle(J,1,1,1,d); // dimension is 24872
2067
2068
2069LIB "fpadim.lib";
2070ring r = 0,(x,y,z),dp;
2071int d =10; // degree
2072def R = makeLetterplaceRing(d);
2073setring R;
2074ideal I = x(1)*y(2) + y(1)*z(2), x(1)*x(2) + x(1)*y(2) - y(1)*x(2) - y(1)*y(2);
2075option(prot);
2076option(redSB);option(redTail);option(mem);
2077ideal J = system("freegb",I,d,3);
2078lpDimCheck(J);
2079sickle(J,1,1,1,d);
2080*/
Note: See TracBrowser for help on using the repository browser.