myNF.cc
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 /*****************************************************************************\
3  * Computer Algebra System SINGULAR
4 \*****************************************************************************/
5 /** @file DebugPrint.cc
6  *
7  * Here we implement dPrint-s.
8  *
9  * ABSTRACT: debug-detailed-printing
10  *
11  * @author Oleksandr Motsak
12  *
13  *
14  **/
15 /*****************************************************************************/
16 
17 
18 
19 
20 
21 // include header file
22 #include <kernel/mod2.h>
23 
24 
25 #include <omalloc/omalloc.h>
26 
27 #include <misc/intvec.h>
28 
29 #include <misc/options.h>
30 
32 #include <polys/kbuckets.h>
33 
34 
35 #include <kernel/structs.h>
36 
37 
38 
39 #include <kernel/ideals.h>
40 
41 #include <kernel/GBEngine/syz.h>
42 // #include <kernel/longrat.h>
43 #include <kernel/GBEngine/kutil.h>
44 #include <kernel/GBEngine/kstd1.h>
45 
46 
47 
48 #include <kernel/polys.h>
49 // #include <kernel/pInline2.h>
50 
51 #include "myNF.h"
52 
53 
54 #ifdef HAVE_PLURAL
55 #define PLURAL_INTERNAL_DECLARATIONS 1
56 #endif
57 
58 #include <polys/nc/sca.h>
59 #include <polys/nc/nc.h>
60 #include <kernel/GBEngine/nc.h>
61 
62 
63 
65 
66 /// reduction procedure for the normal form, which uses pLength instead of pSize!
67 static poly redNFLength (poly h,int &max_ind,int nonorm,kStrategy strat)
68 {
69  if (h==NULL) return NULL;
70  int j;
71  max_ind=strat->sl;
72 
73  if (0 > strat->sl)
74  {
75  return h;
76  }
77  LObject P(h);
78  P.SetShortExpVector();
79  P.bucket = kBucketCreate(currRing);
80  kBucketInit(P.bucket,P.p,pLength(P.p));
81  kbTest(P.bucket);
82 #ifdef HAVE_RINGS
84 #endif
85 #ifdef KDEBUG
87  {
88  PrintS("redNF: starting S: ");
89  for( j = 0; j <= max_ind; j++ )
90  {
91  Print("S[%d] (of size: %d): ", j, pLength(strat->S[j]));
92  wrp(strat->S[j]);
93  }
94  };
95 #endif
96 
97  loop
98  {
99  j=kFindDivisibleByInS(strat,&max_ind,&P);
100  if (j>=0)
101  {
102 #ifdef HAVE_RINGS
103  if (!is_ring)
104  {
105 #endif
106  int sl=pLength(strat->S[j]);
107  int jj=j;
108  loop
109  {
110  int sll;
111  jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P);
112  if (jj<0) break;
113  sll=pLength(strat->S[jj]);
114  if (sll<sl)
115  {
116 #ifdef KDEBUG
117  if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll);
118 #endif
119  //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); }
120  j=jj;
121  sl=sll;
122  }
123  }
124  if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j]))))
125  {
126  pNorm(strat->S[j]);
127  //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
128  }
129 #ifdef HAVE_RINGS
130  }
131 #endif
132  nNormalize(pGetCoeff(P.p));
133 #ifdef KDEBUG
134  if (TEST_OPT_DEBUG)
135  {
136  PrintS("red:");
137  wrp(h);
138  PrintS(" with ");
139  wrp(strat->S[j]);
140  }
141 #endif
142 #ifdef HAVE_PLURAL
143  if (rIsPluralRing(currRing))
144  {
145  number coef;
146  nc_kBucketPolyRed(P.bucket,strat->S[j],&coef);
147  nDelete(&coef);
148  }
149  else
150 #endif
151  {
152  number coef;
153  coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether);
154  nDelete(&coef);
155  }
156  h = kBucketGetLm(P.bucket); // FRAGE OLIVER
157  if (h==NULL)
158  {
159  kBucketDestroy(&P.bucket);
160 
161 #ifdef KDEBUG
162  if (TEST_OPT_DEBUG)
163  {
164  PrintS("redNF: starting S: ");
165  for( j = 0; j <= max_ind; j++ )
166  {
167  Print("S[%d] (of size: %d): ", j, pLength(strat->S[j]));
168  wrp(strat->S[j]);
169  }
170  };
171 #endif
172 
173  return NULL;
174  }
175  kbTest(P.bucket);
176  P.p=h;
177  P.t_p=NULL;
178  P.SetShortExpVector();
179 #ifdef KDEBUG
180  if (TEST_OPT_DEBUG)
181  {
182  PrintS("\nto:");
183  wrp(h);
184  PrintLn();
185  }
186 #endif
187  }
188  else
189  {
190  P.p=kBucketClear(P.bucket);
191  kBucketDestroy(&P.bucket);
192  pNormalize(P.p);
193 
194 #ifdef KDEBUG
195  if (TEST_OPT_DEBUG)
196  {
197  PrintS("redNF: starting S: ");
198  for( j = 0; j <= max_ind; j++ )
199  {
200  Print("S[%d] (of size: %d): ", j, pLength(strat->S[j]));
201  wrp(strat->S[j]);
202  }
203  };
204 #endif
205 
206  return P.p;
207  }
208  }
209 }
210 
211 
212 poly kNF2Length (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce)
213 {
214  assume(q!=NULL);
215  assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring?
216 
217 // lazy_reduce flags: can be combined by |
218 //#define KSTD_NF_LAZY 1
219  // do only a reduction of the leading term
220 //#define KSTD_NF_NONORM 4
221  // only global: avoid normalization, return a multiply of NF
222  poly p;
223  // int i;
224 
225  //if ((idIs0(F))&&(Q==NULL))
226  // return pCopy(q); /*F=0*/
227  //strat->ak = id_RankFreeModule(F, RING!);
228  /*- creating temp data structures------------------- -*/
229  BITSET save1;
230  SI_SAVE_OPT1(save1);
232  initBuchMoraCrit(strat);
233  strat->initEcart = initEcartBBA;
234  strat->enterS = enterSBba;
235 #ifndef NO_BUCKETS
237 #endif
238  /*- set S -*/
239  strat->sl = -1;
240  /*- init local data struct.---------------------------------------- -*/
241  /*Shdl=*/initS(F,Q,strat);
242  /*- compute------------------------------------------------------- -*/
243  //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
244  //{
245  // for (i=strat->sl;i>=0;i--)
246  // pNorm(strat->S[i]);
247  //}
248  kTest(strat);
249  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
250 
251  if (BVERBOSE(23)) kDebugPrint(strat);
252 
253  int max_ind;
254  p = redNFLength(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat);
255  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
256  {
257  if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
258 #ifdef HAVE_RINGS
260  {
261  p = redtailBba_Z(p,max_ind,strat);
262  }
263  else
264 #endif
265  {
267  p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0);
268  }
269  }
270  /*- release temp data------------------------------- -*/
271  omfree(strat->sevS);
272  omfree(strat->ecartS);
273  omfree(strat->T);
274  omfree(strat->sevT);
275  omfree(strat->R);
276  omfree(strat->S_2_R);
277  omfree(strat->L);
278  omfree(strat->B);
279  omfree(strat->fromQ);
280  idDelete(&strat->Shdl);
281  SI_RESTORE_OPT1(save1);
282  if (TEST_OPT_PROT) PrintLn();
283  return p;
284 }
285 
287 
288 
290 
291 poly kNFLength(ideal F, ideal Q, poly p,int syzComp, int lazyReduce)
292 {
293  if (p==NULL)
294  return NULL;
295 
296  poly pp = p;
297 
298 #ifdef HAVE_PLURAL
300  {
301  const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
302  const unsigned int m_iLastAltVar = scaLastAltVar(currRing);
303  pp = p_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing);
304 
305  if(Q == currRing->qideal)
306  Q = SCAQuotient(currRing);
307  }
308 #endif
309 
310  if ((idIs0(F))&&(Q==NULL))
311  {
312 #ifdef HAVE_PLURAL
313  if(p != pp)
314  return pp;
315 #endif
316  return pCopy(p); /*F+Q=0*/
317  }
318 
319  kStrategy strat=new skStrategy;
320  strat->syzComp = syzComp;
323 
325  res=kNF1(F,Q,pp,strat,lazyReduce);
326  else
327  res=kNF2Length(F,Q,pp,strat,lazyReduce);
328  delete(strat);
329 
330 #ifdef HAVE_PLURAL
331  if(pp != p)
333 #endif
334  return res;
335 }
336 
338 
339 // Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:750
kbTest(P.bucket)
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:495
int kFindNextDivisibleByInS(const kStrategy strat, int start, int max_ind, LObject *L)
Definition: kstd2.cc:259
ideal SCAQuotient(const ring r)
Definition: sca.h:10
unsigned si_opt_1
Definition: options.c:5
static void nc_kBucketPolyRed(kBucket_pt b, poly p, number *c)
Definition: nc.h:292
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:83
int syzComp
Definition: kutil.h:350
KINLINE poly redtailBba_Z(poly p, int pos, kStrategy strat)
Definition: kInline.h:1104
#define idDelete(H)
delete an ideal
Definition: ideals.h:29
class sLObject LObject
Definition: kutil.h:60
#define nNormalize(n)
Definition: numbers.h:30
#define TEST_OPT_PROT
Definition: options.h:98
#define pMaxComp(p)
Definition: polys.h:281
loop
Definition: myNF.cc:98
Compatiblity layer for legacy polynomial operations (over currRing)
int * S_2_R
Definition: kutil.h:338
return P p
Definition: myNF.cc:203
number kBucketPolyRed(kBucket_pt bucket, poly p1, int l1, poly spNoether)
Definition: kbuckets.cc:1053
poly kNF2Length(ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce)
Definition: myNF.cc:212
const poly kBucketGetLm(kBucket_pt bucket)
Definition: kbuckets.cc:480
kBucketInit(P.bucket, P.p, pLength(P.p))
int & max_ind
Definition: myNF.cc:67
#define nIsOne(n)
Definition: numbers.h:25
#define kTest(A)
Definition: kutil.h:653
unsigned long * sevT
Definition: kutil.h:319
#define SI_SAVE_OPT1(A)
Definition: options.h:20
int ak
Definition: kutil.h:349
#define TEST_OPT_DEBUG
Definition: options.h:103
NF which uses pLength instead of pSize!
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
#define BITSET
Definition: structs.h:18
KINLINE poly redtailBba(poly p, int pos, kStrategy strat, BOOLEAN normalize)
Definition: kInline.h:1091
poly p_KillSquares(const poly p, const short iFirstAltVar, const short iLastAltVar, const ring r)
Definition: sca.cc:1478
#define BEGIN_NAMESPACE_SINGULARXX
#define Sy_bit(x)
Definition: options.h:30
END_NAMESPACE BEGIN_NAMESPACE_SINGULARXX ideal Q
Definition: myNF.cc:291
poly pp
Definition: myNF.cc:296
#define TEST_OPT_NOT_BUCKETS
Definition: options.h:100
#define mflush()
Definition: reporter.h:57
BOOLEAN is_ring
Definition: myNF.cc:83
poly res
Definition: myNF.cc:322
void(* initEcart)(TObject *L)
Definition: kutil.h:274
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:8042
#define KSTD_NF_LAZY
Definition: kstd1.h:17
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:200
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
#define OPT_REDTAIL
Definition: options.h:86
int j
Definition: myNF.cc:70
END_NAMESPACE BEGIN_NAMESPACE_SINGULARXX ideal poly int syzComp
Definition: myNF.cc:291
#define assume(x)
Definition: mod2.h:394
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:404
intset fromQ
Definition: kutil.h:315
poly kNF1(ideal F, ideal Q, poly q, kStrategy strat, int lazyReduce)
Definition: kstd1.cc:1909
#define END_NAMESPACE_SINGULARXX
void initEcartBBA(TObject *h)
Definition: kutil.cc:1242
pNormalize(P.p)
void(* enterS)(LObject &h, int pos, kStrategy strat, int atR)
Definition: kutil.h:280
#define omfree(addr)
Definition: omAllocDecl.h:237
int kFindDivisibleByInS(const kStrategy strat, int *max_ind, LObject *L)
return -1 if no divisor is found number of first divisor in S, otherwise
Definition: kstd2.cc:197
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:9777
static int si_max(const int a, const int b)
Definition: auxiliary.h:120
void PrintS(const char *s)
Definition: reporter.cc:284
BEGIN_NAMESPACE() static poly redNFLength(poly h
reduction procedure for the normal form, which uses pLength instead of pSize!
TObject ** R
Definition: kutil.h:336
static unsigned pLength(poly a)
Definition: p_polys.h:189
static short scaFirstAltVar(ring r)
Definition: sca.h:18
#define nDelete(n)
Definition: numbers.h:16
#define OPT_INTSTRATEGY
Definition: options.h:87
#define BVERBOSE(a)
Definition: options.h:33
int int kStrategy strat
Definition: myNF.cc:68
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:843
#define KSTD_NF_NONORM
Definition: kstd1.h:21
intset ecartS
Definition: kutil.h:303
LSet L
Definition: kutil.h:321
static BOOLEAN rField_is_Ring(const ring r)
Definition: ring.h:477
#define NULL
Definition: omList.c:10
LSet B
Definition: kutil.h:322
currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: myNF.cc:332
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:345
static short scaLastAltVar(ring r)
Definition: sca.h:25
#define END_NAMESPACE
unsigned long * sevS
Definition: kutil.h:316
static bool rIsSCA(const ring r)
Definition: nc.h:206
int sl
Definition: kutil.h:344
TSet T
Definition: kutil.h:320
BOOLEAN use_buckets
Definition: kutil.h:380
void wrp(poly p)
Definition: polys.h:292
kBucketDestroy & P
Definition: myNF.cc:191
polyrec * poly
Definition: hilb.h:10
ideal Shdl
Definition: kutil.h:297
kBucket_pt kBucketCreate(const ring bucket_ring)
Creation/Destruction of buckets.
Definition: kbuckets.cc:193
static Poly * h
Definition: janet.cc:978
int int nonorm
Definition: myNF.cc:67
int BOOLEAN
Definition: auxiliary.h:85
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
#define SI_RESTORE_OPT1(A)
Definition: options.h:23
void kDebugPrint(kStrategy strat)
Definition: kutil.cc:11806
END_NAMESPACE BEGIN_NAMESPACE_SINGULARXX ideal poly int int lazyReduce
Definition: myNF.cc:292
void enterSBba(LObject &p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:9238
#define pCopy(p)
return a copy of the poly
Definition: polys.h:168