source: git/kernel/shiftgb.cc @ 8c35ba

spielwiese
Last change on this file since 8c35ba was 37a4c3, checked in by Viktor Levandovskyy <levandov@…>, 16 years ago
*levandov: major changes in shift free gb git-svn-id: file:///usr/local/Singular/svn/trunk@10580 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: shiftgb.cc,v 1.4 2008-02-15 17:14:23 levandov Exp $ */
5/*
6* ABSTRACT: kernel: utils for shift GB and free GB
7*/
8
9#include "mod2.h"
10
11#ifdef HAVE_PLURAL
12#include "febase.h"
13#include "ring.h"
14#include "polys.h"
15#include "numbers.h"
16#include "ideals.h"
17#include "matpol.h"
18#include "kbuckets.h"
19#include "kstd1.h"
20#include "sbuckets.h"
21#include "p_Mult_q.h"
22#include "kutil.h"
23#include "structs.h"
24#include "omalloc.h"
25#include "khstd.h"
26#include "kbuckets.h"
27#include "weight.h"
28#include "intvec.h"
29#include "structs.h"
30#include "kInline.cc"
31#include "stairc.h"
32#include "weight.h"
33#include "intvec.h"
34#include "timer.h"
35#include "shiftgb.h"
36#include "sca.h"
37
38
39#define freeT(A,v) omFreeSize((ADDRESS)A,(v+1)*sizeof(int))
40
41poly pLPshift(poly p, int sh, int uptodeg, int lV)
42{
43  /* assume shift takes place */
44  /* shifts the poly p by sh */
45  /* deletes p */
46
47  /* assume sh and uptodeg agree */
48
49  if (sh == 0) return(p); /* the zero shift */
50
51  poly q  = NULL;
52  poly pp = p; // pCopy(p);
53  while (pp!=NULL)
54  {
55    q = p_Add_q(q, pmLPshift(pp,sh,uptodeg,lV),currRing);
56    pIter(pp);
57  }
58  /* delete pp? */
59  /* int version: returns TRUE if it was successful */
60  return(q);
61}
62
63poly pmLPshift(poly p, int sh, int uptodeg, int lV)
64{
65  /* pm is a monomial */
66
67  if (sh == 0) return(p); /* the zero shift */
68
69  if (sh < 0 )
70  {
71#ifdef PDEBUG
72    Print("pmLPshift: negative shift requested");
73#endif
74    return(NULL); /* violation, 2check */
75  }
76
77  int L = pmLastVblock(p,lV);
78  if (L+sh-1 > uptodeg)
79  {
80#ifdef PDEBUG
81    Print("pmLPshift: too big shift requested");
82#endif
83    return(NULL); /* violation, 2check */
84  }
85  int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int));
86  int *s=(int *)omAlloc0((currRing->N+1)*sizeof(int));
87  pGetExpV(p,e);
88  number c = pGetCoeff(p);
89  int j;
90  for (j=1; j<=currRing->N; j++)
91  {
92    if (e[j])
93    {
94      s[j + (sh*lV)] = e[j]; /* actually 1 */
95    }
96  }
97  poly m = pOne();
98  pSetExpV(m,s);
99  /*  pSetm(m); */ /* done in the pSetExpV */
100  /* think on the component */
101  pSetCoeff0(m,c);
102  freeT(e, currRing->N);
103  freeT(s, currRing->N);
104  return(m);
105}
106
107int pLastVblock(poly p, int lV)
108{
109  /* returns the number of maximal block */
110  /* appearing among the monomials of p */
111  /* the 0th block is the 1st one */
112  poly q = p_Copy(p,currRing); /* need it ? */
113  int ans = 0; 
114  int ansnew = 0;
115  while (q!=NULL)
116  {
117    ansnew = pmLastVblock(q,lV);
118    ans    = si_max(ans,ansnew);
119    pIter(q);
120  }
121  /* do not need to delete q */
122  return(ans);
123}
124
125int pmLastVblock(poly p, int lV)
126{
127  /* for a monomial p, returns the number of the last block */
128  /* where a nonzero exponent is sitting */
129  int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int));
130  pGetExpV(p,e);
131  int j,b;
132  j = currRing->N;
133  while ( (!e[j]) && (j>=1) ) j--;
134  if (j==0) 
135  {
136#ifdef PDEBUG
137    Print("pmLastVblock: unexpected zero exponent vector");
138    PrintLn();
139#endif   
140    return(j);
141  }
142  b = (int)(j/lV) + 1; /* the number of the block, >=1 */
143  return (b);
144}
145
146int isInV(poly p, int lV)
147{
148  if (lV <= 0) return(0);
149  /* returns 1 iff p is in V */
150  /* that is in each block up to a certain one there is only one nonzero exponent */
151  /* lV = the length of V = the number of orig vars */
152  int *e = (int *)omAlloc0((currRing->N+1)*sizeof(int));
153  int  b = (int)(currRing->N)/lV; /* the number of blocks */
154  int *B = (int *)omAlloc0((b+1)*sizeof(int)); /* the num of elements in a block */
155  pGetExpV(p,e);
156  int i,j;
157  for (j=1; j<=b; j++)
158  {
159    /* we go through all the vars */
160    /* by blocks in lV vars */
161    for (i=(j-1)*lV + 1; i<= j*lV; i++)
162    {
163      if (!e[i]) B[j] = B[j]+1;
164    }
165  }
166  j = b;
167  //  while ( (!B[j]) && (j>=1)) j--;
168  for (j=b; j>=1; j--)
169  {
170    if (B[j]!=0) break;
171  }
172
173  if (j==0)
174  {
175    /* it is a zero exp vector, which is in V */
176    return(1);
177  }
178  /* now B[j] != 0 */
179  for (j; j>=1; j--)
180  {
181    if (B[j]!=1)
182    {
183      return(0);
184    }
185  }
186  return(1);
187}
188
189/* shiftgb stuff */
190
191
192/* remarks: cleanT : just deletion
193enlargeT: just reallocation */
194
195#endif
Note: See TracBrowser for help on using the repository browser.