source: git/Singular/hilb.cc @ 0e1846

spielwiese
Last change on this file since 0e1846 was 0e1846, checked in by Olaf Bachmann <obachman@…>, 27 years ago
This commit was generated by cvs2svn to compensate for changes in r59, which included commits to RCS files with non-trunk default branches. git-svn-id: file:///usr/local/Singular/svn/trunk@60 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 10.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4static char  rcsid[] = "$Header: /exports/cvsroot-2/cvsroot/Singular/hilb.cc,v 1.1.1.1 1997-03-19 13:18:45 obachman Exp $";
5/* $Log: not supported by cvs2svn $*/
6/*
7*  ABSTRACT -  Hilbert series
8*/
9
10#include "mod2.h"
11#include "tok.h"
12#include "febase.h"
13#include "mmemory.h"
14#include "polys.h"
15#include "intvec.h"
16#include "hutil.h"
17#include "stairc.h"
18
19static int  **Qpol;
20static int  *Q0, *Ql;
21static int  hLength;
22
23static void hHilbEst(scfmon stc, int Nstc, varset var, int Nvar)
24{
25  int  i, j;
26  int  x, y, z = 1;
27  int  *p;
28  for (i = Nvar; i>0; i--)
29  {
30    x = 0;
31    for (j = 0; j < Nstc; j++)
32    {
33      y = stc[j][var[i]];
34      if (y > x)
35        x = y;
36    }
37    z += x;
38    j = i - 1;
39    if (z > Ql[j])
40    {
41      p = (int *)Alloc(z * sizeof(int));
42      if (Ql[j]!=0)
43      {
44        if (j==0)
45          memcpy(p, Qpol[j], Ql[j] * sizeof(int));
46        Free((ADDRESS)Qpol[j], Ql[j] * sizeof(int));
47      }
48      if (j==0)
49      {
50        for (x = Ql[j]; x < z; x++)
51          p[x] = 0;
52      }
53      Ql[j] = z;
54      Qpol[j] = p;
55    }
56  }
57}
58
59static int  *hAddHilb(int Nv, int x, int *pol, int *lp)
60{
61  int  l = *lp, ln, i;
62  int  *pon;
63  *lp = ln = l + x;
64  pon = Qpol[Nv];
65  memcpy(pon, pol, l * sizeof(int));
66  if (l > x)
67  {
68    for (i = x; i < l; i++)
69      pon[i] -= pol[i - x];
70    for (i = l; i < ln; i++)
71      pon[i] = -pol[i - x];
72  }
73  else
74  {
75    for (i = l; i < x; i++)
76      pon[i] = 0;
77    for (i = x; i < ln; i++)
78      pon[i] = -pol[i - x];
79  }
80  return pon;
81}
82
83static void hLastHilb(scmon pure, int Nv, varset var, int *pol, int lp)
84{
85  int  l = lp, x, i, j;
86  int  *p, *pl;
87  p = pol;
88  for (i = Nv; i>0; i--)
89  {
90    x = pure[var[i + 1]];
91    if (x!=0)
92      p = hAddHilb(i, x, p, &l);
93  }
94  pl = *Qpol;
95  j = Q0[Nv + 1];
96  for (i = 0; i < l; i++)
97    pl[i + j] += p[i];
98  x = pure[var[1]];
99  if (x!=0)
100  {
101    j += x;
102    for (i = 0; i < l; i++)
103      pl[i + j] -= p[i];
104  }
105  j += l;
106  if (j > hLength)
107    hLength = j;
108}
109
110static void hHilbStep(scmon pure, scfmon stc, int Nstc, varset var,
111 int Nvar, int *pol, int Lpol)
112{
113  int  iv = Nvar -1, ln, a, a0, a1, b, i;
114  short  x, x0;
115  scmon pn;
116  scfmon sn;
117  int  *pon;
118  if (Nstc==0)
119  {
120    hLastHilb(pure, iv, var, pol, Lpol);
121    return;
122  }
123  x = a = 0;
124  pn = hGetpure(pure);
125  sn = hGetmem(Nstc, stc, stcmem[iv]);
126  hStepS(sn, Nstc, var, Nvar, &a, &x);
127  Q0[iv] = Q0[Nvar];
128  ln = Lpol;
129  pon = pol;
130  if (a == Nstc)
131  {
132    x = pure[var[Nvar]];
133    if (x!=0)
134      pon = hAddHilb(iv, x, pon, &ln);
135    hHilbStep(pn, sn, a, var, iv, pon, ln);
136    return;
137  }
138  else
139  {
140    pon = hAddHilb(iv, x, pon, &ln);
141    hHilbStep(pn, sn, a, var, iv, pon, ln);
142  }
143  b = a;
144  x0 = 0;
145  loop
146  {
147    Q0[iv] += (x - x0);
148    a0 = a;
149    x0 = x;
150    hStepS(sn, Nstc, var, Nvar, &a, &x);
151    hElimS(sn, &b, a0, a, var, iv);
152    a1 = a;
153    hPure(sn, a0, &a1, var, iv, pn, &i);
154    hLex2S(sn, b, a0, a1, var, iv, hwork);
155    b += (a1 - a0);
156    ln = Lpol;
157    if (a < Nstc)
158    {
159      pon = hAddHilb(iv, x - x0, pol, &ln);
160      hHilbStep(pn, sn, b, var, iv, pon, ln);
161    }
162    else
163    {
164      x = pure[var[Nvar]];
165      if (x!=0)
166        pon = hAddHilb(iv, x - x0, pol, &ln);
167      else
168        pon = pol;
169      hHilbStep(pn, sn, b, var, iv, pon, ln);
170      return;
171    }
172  }
173}
174
175/*
176*basic routines
177*/
178
179intvec * hSeries(ideal S, intvec *modulweight, ideal Q, int notstc)
180{
181  intvec *work, *hseries1=NULL;
182  short  mc;
183  int  *p0;
184  int  i, j, k, l, ii;
185  hexist = hInit(S, Q, &hNexist);
186  if (hNexist==0)
187  {
188    hseries1=new intvec(1);
189    (*hseries1)[0]=1;
190    return hseries1;
191  }
192  p0 = (int *)Alloc(sizeof(int));
193  *p0 = 1;
194  hwork = (scfmon)Alloc(hNexist * sizeof(scmon));
195  hvar = (varset)Alloc((pVariables + 1) * sizeof(int));
196  hpure = (scmon)Alloc((1 + (pVariables * pVariables)) * sizeof(short));
197  stcmem = hCreate(pVariables - 1);
198  Qpol = (int **)Alloc((pVariables + 1) * sizeof(int *));
199  Ql = (int *)Alloc0((pVariables + 1) * sizeof(int));
200  Q0 = (int *)Alloc((pVariables + 1) * sizeof(int));
201  *Qpol = NULL;
202  hLength = k = j = 0;
203  mc = hisModule;
204  if (mc!=0)
205    hstc = (scfmon)Alloc(hNexist * sizeof(scmon));
206  else
207  {
208    hstc = hexist;
209    hNstc = hNexist;
210  }
211  loop
212  {
213    if (mc!=0)
214    {
215      hComp(hexist, hNexist, mc, hstc, &hNstc);
216      if (modulweight != NULL)
217        j = (*modulweight)[mc-1];
218    }
219    if (hNstc!=0)
220    {
221      hNvar = pVariables;
222      for (i = hNvar; i; i--)
223        hvar[i] = i;
224      if (notstc)
225        hStaircase(hstc, &hNstc, hvar, hNvar);
226      hSupp(hstc, hNstc, hvar, &hNvar);
227      if (hNvar!=0)
228      {
229        if ((hNvar > 2) && (hNstc > 10))
230          hOrdSupp(hstc, hNstc, hvar, hNvar);
231        hHilbEst(hstc, hNstc, hvar, hNvar);
232        memset(hpure, 0, (pVariables + 1) * sizeof(short));
233        hPure(hstc, 0, &hNstc, hvar, hNvar, hpure, &hNpure);
234        hLexS(hstc, hNstc, hvar, hNvar);
235        Q0[hNvar] = 0;
236        hHilbStep(hpure, hstc, hNstc, hvar, hNvar, p0, 1);
237      }
238    }
239    else
240    {
241      if(*Qpol!=NULL)
242        (**Qpol)++;
243      else
244      {
245        *Qpol = (int *)Alloc(sizeof(int));
246        hLength = *Ql = **Qpol = 1;
247      }
248    }
249    if (*Qpol!=NULL)
250    {
251      i = hLength;
252      while ((i > 0) && ((*Qpol)[i - 1] == 0))
253        i--;
254      if (i > 0)
255      {
256        l = i + j;
257        if (l > k)
258        {
259          work = new intvec(l);
260          for (ii=0; ii<k; ii++)
261            (*work)[ii] = (*hseries1)[ii];
262          if (hseries1 != NULL)
263            delete hseries1;
264          hseries1 = work;
265          k = l;
266        }
267        while (i > 0)
268        {
269          (*hseries1)[i + j - 1] += (*Qpol)[i - 1];
270          (*Qpol)[i - 1] = 0;
271          i--;
272        }
273      }
274    }
275    mc--;
276    if (mc <= 0)
277      break;
278  }
279  if (k==0)
280  {
281    hseries1=new intvec(1);
282    (*hseries1)[0]=0;
283  }
284  else
285  {
286    l = k;
287    while ((*hseries1)[l-1]==0) l--;
288    if (l<k)
289    {
290      work = new intvec(l);
291      for (ii=0; ii<l; ii++)
292        (*work)[ii] = (*hseries1)[ii];
293      delete hseries1;
294      hseries1 = work;
295    }
296  }
297  for (i = 0; i <= pVariables; i++)
298    if (Ql[i]!=0)
299      Free((ADDRESS)Qpol[i], Ql[i] * sizeof(int));
300  Free((ADDRESS)Q0, (pVariables + 1) * sizeof(int));
301  Free((ADDRESS)Ql, (pVariables + 1) * sizeof(int));
302  Free((ADDRESS)Qpol, (pVariables + 1) * sizeof(int *));
303  hKill(stcmem, pVariables - 1);
304  Free((ADDRESS)hpure, (1 + (pVariables * pVariables)) * sizeof(short));
305  Free((ADDRESS)hvar, (pVariables + 1) * sizeof(int));
306  Free((ADDRESS)hwork, hNexist * sizeof(scmon));
307  Free((ADDRESS)hexist, hNexist * sizeof(scmon));
308  Free((ADDRESS)p0, sizeof(int));
309  if (hisModule!=0)
310    Free((ADDRESS)hstc, hNexist * sizeof(scmon));
311  return hseries1;
312}
313
314
315intvec * hHstdSeries(ideal S, intvec *modulweight, ideal Q)
316{
317  return hSeries(S, modulweight, Q, 0);
318}
319
320intvec * hFirstSeries(ideal S, intvec *modulweight, ideal Q)
321{
322  return hSeries(S, modulweight, Q, 1);
323}
324
325intvec * hSecondSeries(intvec *hseries1)
326{
327  intvec *work, *hseries2;
328  int i, j, k, s, t, l;
329  if (hseries1 == NULL)
330    return NULL;
331  hseries2 = new intvec(hseries1);
332  k = l = hseries2->length();
333  s = 0;
334  for (i = k-1; i >= 0; i--)
335    s += (*hseries2)[i];
336  loop
337  {
338    if ((s != 0) || (k == 1))
339      break;
340    s = 0;
341    t = (*hseries2)[k-1];
342    k--;
343    for (i = k-1; i >= 0; i--)
344    {
345      j = (*hseries2)[i];
346      (*hseries2)[i] = -t;
347      s += t;
348      t += j;
349    }
350  }
351  if (k < l)
352  {
353    work = new intvec(k);
354    for (i = k-1; i >= 0; i--)
355      (*work)[i] = (*hseries2)[i];
356    delete hseries2;
357    hseries2 = work;
358  }
359  return hseries2;
360}
361
362intvec * hThirdSeries(intvec *hseries, int dim)
363{
364  intvec *hseries3;
365  int i, j, k,  t, l;
366  if (hseries == NULL)
367    return NULL;
368  l = hseries->length();
369  t = 0;
370  for (i = l-1; i >= 0; i--)
371    t += (*hseries)[i];
372  if (t == 0)
373  {
374    hseries3 = hSecondSeries(hseries);
375    k = hseries3->length();
376    dim = pVariables+k-l;
377    l = k;
378  }
379  else
380    hseries3 = new intvec(hseries);
381  k = dim;
382  loop
383  {
384    if ((k == 0) || (l == 1))
385      break;
386    t = (*hseries3)[l-1];
387    k--;
388    l--;
389    for (i = l-1; i >= 0; i--)
390    {
391      j = (*hseries3)[i];
392      (*hseries3)[i] = -t;
393      t += j;
394    }
395    (*hseries3)[l] = t;
396  }
397  return hseries3;
398}
399
400void hDegreeSeries(intvec *s1, intvec *s2, int *co, int *mu)
401{
402  int m, i, j, k;
403  *co = *mu = 0;
404  if ((s1 == NULL) || (s2 == NULL))
405    return;
406  i = s1->length();
407  j = s2->length();
408  if (j > i)
409    return;
410  m = 0;
411  for(k=0; k<j; k++)
412    m += (*s2)[k];
413  *mu = m;
414  *co = i - j;
415}
416
417void hPrintHilb(intvec *hseries, int dim)
418{
419  int  i, j, l, k;
420  if (hseries == NULL)
421    return;
422  l = hseries->length();
423  k = l-dim;
424  for (i = 0; i < k; i++)
425  {
426    j = (*hseries)[i];
427    if (j != 0)
428    {
429      Print("//  %8d t^%d\n", j, i);
430    }
431  }
432  if (k < 0)
433  {
434    k--;
435    for (i = 0; i < l; i++)
436    {
437      j = (*hseries)[i];
438      if (j != 0)
439      {
440        Print("//  %8d (1-t)^-%d\n", j, i-k);
441      }
442    }
443  }
444  else
445  {
446    i = k;
447    k--;
448    for (; i < l; i++)
449    {
450      j = (*hseries)[i];
451      if (j != 0)
452      {
453        Print("//  %8d (1-t)^-%d\n", j, i-k);
454      }
455    }
456  }
457}
458
459/*
460*caller
461*/
462
463static void hPrintDegree(int co, int mu)
464{
465  if (pOrdSgn == 1)
466    Print("// codimension = %d\n// dimension   = %d\n// degree      = %d\n",
467      co, pVariables - co, mu);
468  else
469    Print("// codimension  = %d\n// dimension    = %d\n// multiplicity = %d\n",
470      co, pVariables - co, mu);
471}
472
473void hLookSeries(ideal S, intvec *modulweight, ideal Q)
474{
475  int co, mu, l;
476  intvec *hseries2;
477//  intvec *hseries3;
478  intvec *hseries1 = hFirstSeries(S, modulweight, Q);
479  hPrintHilb(hseries1, 0);
480  l = hseries1->length();
481  if (l > 1)
482    hseries2 = hSecondSeries(hseries1);
483  else
484    hseries2 = hseries1;
485  hDegreeSeries(hseries1, hseries2, &co, &mu);
486//  if (co > 0)
487//  {
488    PrintLn();
489    hPrintHilb(hseries2, 0);
490//  }
491  if ((l == 1) &&(mu == 0))
492    hPrintDegree(pVariables+1, 0);
493  else
494    hPrintDegree(co, mu);
495//  if (co < pVariables)
496//  {
497//    hseries3 = hThirdSeries(hseries2,pVariables-co);
498//    PrintLn();
499//    hPrintHilb(hseries3, pVariables-co);
500//    delete hseries3;
501//  }
502  if (l>1)
503    delete hseries1;
504  delete hseries2;
505}
506
Note: See TracBrowser for help on using the repository browser.