source: git/kernel/shiftgb.cc @ cb0fbe

fieker-DuValspielwiese
Last change on this file since cb0fbe was cb0fbe, checked in by Viktor Levandovskyy <levandov@…>, 17 years ago
*levandov: shiftg related changes git-svn-id: file:///usr/local/Singular/svn/trunk@10146 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: shiftgb.cc,v 1.2 2007-06-24 16:44:41 levandov Exp $ */
5/*
6* ABSTRACT: kernel: utils for shift GB and free GB
7*/
8
9#include "mod2.h"
10#include "febase.h"
11#include "ring.h"
12#include "polys.h"
13#include "numbers.h"
14#include "ideals.h"
15#include "matpol.h"
16#include "kbuckets.h"
17#include "kstd1.h"
18#include "sbuckets.h"
19#include "p_Mult_q.h"
20#include "kutil.h"
21#include "structs.h"
22#include "omalloc.h"
23#include "khstd.h"
24#include "kbuckets.h"
25#include "weight.h"
26#include "intvec.h"
27#include "structs.h"
28#include "kInline.cc"
29#include "stairc.h"
30#include "weight.h"
31#include "intvec.h"
32#include "timer.h"
33#include "shiftgb.h"
34#include "sca.h"
35
36
37#define freeT(A,v) omFreeSize((ADDRESS)A,(v+1)*sizeof(int))
38
39poly pLPshift(poly p, int sh, int uptodeg, int lV)
40{
41  /* assume shift takes place */
42  /* shifts the poly p by sh */
43
44  /* assume sh and uptodeg agree */
45
46  if (sh == 0) return(p); /* the zero shift */
47
48  poly q  = NULL;
49  poly pp = pCopy(p);
50  while (pp!=NULL)
51  {
52    q = p_Add_q(q, pmLPshift(pp,sh,uptodeg,lV),currRing);
53    pIter(pp);
54  }
55  /* delete pp? */
56  /* int version: returns TRUE if it was successful */
57  return(q);
58}
59
60poly pmLPshift(poly p, int sh, int uptodeg, int lV)
61{
62  /* pm is a monomial */
63
64  if (sh == 0) return(p); /* the zero shift */
65
66  if (sh < 0 )
67  {
68#ifdef PDEBUG
69    Print("pmLPshift: negative shift requested");
70#endif
71    return(NULL); /* violation, 2check */
72  }
73
74  int L = pmLastVblock(p,lV);
75  if (L+sh-1 > uptodeg)
76  {
77#ifdef PDEBUG
78    Print("pmLPshift: too big shift requested");
79#endif
80    return(NULL); /* violation, 2check */
81  }
82  int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int));
83  int *s=(int *)omAlloc0((currRing->N+1)*sizeof(int));
84  pGetExpV(p,e);
85  number c = pGetCoeff(p);
86  int j;
87  for (j=1; j<=currRing->N; j++)
88  {
89    if (e[j])
90    {
91      s[j + (sh*lV)] = e[j]; /* actually 1 */
92    }
93  }
94  poly m = pOne();
95  pSetExpV(m,s);
96  /*  pSetm(m); */ /* done in the pSetExpV */
97  pSetCoeff0(m,c);
98  freeT(e, currRing->N);
99  freeT(s, currRing->N);
100  return(m);
101}
102
103int pLastVblock(poly p, int lV)
104{
105  /* returns the number of maximal block */
106  /* appearing among the monomials of p */
107  poly q = pCopy(p); /* need it ? */
108  int ans = 0; 
109  int ansnew = 0;
110  while (q!=NULL)
111  {
112    ansnew = pmLastVblock(q,lV);
113    ans    = si_max(ans,ansnew);
114    pIter(q);
115  }
116  /* do not need to delete q */
117  return(ans);
118}
119
120int pmLastVblock(poly p, int lV)
121{
122  /* for a monomial p, returns the number of the last block */
123  /* where a nonzero exponent is sitting */
124  int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int));
125  pGetExpV(p,e);
126  int j,b;
127  j = currRing->N;
128  while ( (!e[j]) && (j>=1) ) j--;
129  if (j==0) 
130  {
131#ifdef PDEBUG
132    Print("pmLastVblock: unexpected zero exponent");
133#endif   
134    return(j);
135  }
136  b = (int)(j/lV) + 1; /* the number of the block, >=1 */
137  return (b);
138}
139
140int isInV(poly p, int lV)
141{
142  if (lV <= 0) return(0);
143  /* returns 1 iff p is in V */
144  /* that is in each block up to a certain one there is only one nonzero exponent */
145  /* lV = the length of V = the number of orig vars */
146  int *e = (int *)omAlloc0((currRing->N+1)*sizeof(int));
147  int  b = (int)(currRing->N)/lV; /* the number of blocks */
148  int *B = (int *)omAlloc0((b+1)*sizeof(int)); /* the num of elements in a block */
149  pGetExpV(p,e);
150  int i,j;
151  for (j=1; j<=b; j++)
152  {
153    /* we go through all the vars */
154    /* by blocks in lV vars */
155    for (i=(j-1)*lV + 1; i<= j*lV; i++)
156    {
157      if (!e[i]) B[j] = B[j]+1;
158    }
159  }
160  j = b;
161  while ( (!B[j]) && (j>=1)) j--;
162  if (j==0)
163  {
164    /* it is a zero exp vector, which is in V */
165    return(1);
166  }
167  /* now B[j] != 0 */
168  for (j; j>=1; j--)
169  {
170    if (B[j]!=1)
171    {
172      return(0);
173    }
174  }
175  return(1);
176}
177
178/* shiftgb stuff */
179
180void initBbaShift(ideal F,kStrategy strat)
181{
182  int i;
183  idhdl h;
184 /* setting global variables ------------------- */
185  strat->enterS = enterSBba;
186
187  strat->red = redFirstShift;
188
189  /* perhaps the following?
190   *    strat->LazyPass *=4;
191   *    strat->red = redHomogShift;
192   */
193
194  /*    strat->red = redHoney;
195   *  if (strat->honey)
196   *    strat->red = redHoney;
197   *  else if (pLexOrder && !strat->homog)
198   *    strat->red = redLazy;
199   *  else
200   *  {
201   *    strat->LazyPass *=4;
202   *    strat->red = redHomog;
203   *  }
204   *#ifdef HAVE_RINGS  //TODO Oliver
205   *  if (rField_is_Ring(currRing)) {
206   *    strat->red = redRing2toM;
207   *  }
208   *#endif
209  */
210
211  if (pLexOrder && strat->honey)
212    strat->initEcart = initEcartNormal;
213  else
214    strat->initEcart = initEcartBBA;
215  if (strat->honey)
216    strat->initEcartPair = initEcartPairMora;
217  else
218    strat->initEcartPair = initEcartPairBba;
219  strat->kIdeal = NULL;
220  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
221  //else              strat->kIdeal->rtyp=MODUL_CMD;
222  //strat->kIdeal->data=(void *)strat->Shdl;
223  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
224  {
225    //interred  machen   Aenderung
226    pFDegOld=pFDeg;
227    pLDegOld=pLDeg;
228    //h=ggetid("ecart");
229    //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/)
230    //{
231    //  ecartWeights=iv2array(IDINTVEC(h));
232    //}
233    //else
234    {
235      ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short));
236      /*uses automatic computation of the ecartWeights to set them*/
237      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
238    }
239    pRestoreDegProcs(totaldegreeWecart, maxdegreeWecart);
240    if (TEST_OPT_PROT)
241    {
242      for(i=1; i<=pVariables; i++)
243        Print(" %d",ecartWeights[i]);
244      PrintLn();
245      mflush();
246    }
247  }
248}
249
Note: See TracBrowser for help on using the repository browser.