source: git/dyn_modules/syzextra/myNF.cc @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 7.3 KB
Line 
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// include header file
18#include <kernel/mod2.h>
19
20
21#include <omalloc/omalloc.h>
22
23#include <misc/intvec.h>
24
25#include <misc/options.h>
26
27#include <polys/monomials/p_polys.h>
28#include <polys/kbuckets.h>
29
30
31#include <kernel/structs.h>
32#include <kernel/febase.h>
33
34
35
36#include <kernel/ideals.h>
37
38#include <kernel/syz.h>
39// #include <kernel/longrat.h>
40#include <kernel/kutil.h>
41#include <kernel/kstd1.h>
42
43
44
45#include <kernel/polys.h>
46// #include <kernel/pInline2.h>
47
48#include "myNF.h"
49
50
51#ifdef HAVE_PLURAL
52#define PLURAL_INTERNAL_DECLARATIONS 1
53#endif
54
55#include <polys/nc/sca.h>
56#include <polys/nc/nc.h>
57#include <kernel/nc.h>
58
59
60
61BEGIN_NAMESPACE()
62
63///  reduction procedure for the normal form, which uses pLength instead of pSize!
64static poly redNFLength (poly h,int &max_ind,int nonorm,kStrategy strat)
65{
66  if (h==NULL) return NULL;
67  int j;
68  max_ind=strat->sl;
69
70  if (0 > strat->sl)
71  {
72    return h;
73  }
74  LObject P(h);
75  P.SetShortExpVector();
76  P.bucket = kBucketCreate(currRing);
77  kBucketInit(P.bucket,P.p,pLength(P.p));
78  kbTest(P.bucket);
79#ifdef HAVE_RINGS
80  BOOLEAN is_ring = rField_is_Ring(currRing);
81#endif
82#ifdef KDEBUG
83  if (TEST_OPT_DEBUG)
84  {
85    PrintS("redNF: starting S: ");
86    for( j = 0; j <= max_ind; j++ )
87    {
88      Print("S[%d] (of size: %d): ", j, pLength(strat->S[j]));
89      wrp(strat->S[j]);
90    }
91  };
92#endif
93
94  loop
95  {
96    j=kFindDivisibleByInS(strat,&max_ind,&P);
97    if (j>=0)
98    {
99#ifdef HAVE_RINGS
100      if (!is_ring)
101      {
102#endif
103        int sl=pLength(strat->S[j]);
104        int jj=j;
105        loop
106        {
107          int sll;
108          jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P);
109          if (jj<0) break;
110          sll=pLength(strat->S[jj]);
111          if (sll<sl)
112          {
113#ifdef KDEBUG
114            if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll);
115#endif
116            //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); }
117            j=jj;
118            sl=sll;
119          }
120        }
121        if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j]))))
122        {
123          pNorm(strat->S[j]);
124          //if (TEST_OPT_PROT) { PrintS("n"); mflush(); }
125        }
126#ifdef HAVE_RINGS
127      }
128#endif
129      nNormalize(pGetCoeff(P.p));
130#ifdef KDEBUG
131      if (TEST_OPT_DEBUG)
132      {
133        PrintS("red:");
134        wrp(h);
135        PrintS(" with ");
136        wrp(strat->S[j]);
137      }
138#endif
139#ifdef HAVE_PLURAL
140      if (rIsPluralRing(currRing))
141      {
142        number coef;
143        nc_kBucketPolyRed(P.bucket,strat->S[j],&coef);
144        nDelete(&coef);
145      }
146      else
147#endif
148      {
149        number coef;
150        coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether);
151        nDelete(&coef);
152      }
153      h = kBucketGetLm(P.bucket);   // FRAGE OLIVER
154      if (h==NULL)
155      {
156        kBucketDestroy(&P.bucket);
157
158#ifdef KDEBUG
159        if (TEST_OPT_DEBUG)
160        {
161          PrintS("redNF: starting S: ");
162          for( j = 0; j <= max_ind; j++ )
163          {
164            Print("S[%d] (of size: %d): ", j, pLength(strat->S[j]));
165            wrp(strat->S[j]);
166          }
167        };
168#endif
169
170        return NULL;
171      }
172      kbTest(P.bucket);
173      P.p=h;
174      P.t_p=NULL;
175      P.SetShortExpVector();
176#ifdef KDEBUG
177      if (TEST_OPT_DEBUG)
178      {
179        PrintS("\nto:");
180        wrp(h);
181        PrintLn();
182      }
183#endif
184    }
185    else
186    {
187      P.p=kBucketClear(P.bucket);
188      kBucketDestroy(&P.bucket);
189      pNormalize(P.p);
190
191#ifdef KDEBUG
192      if (TEST_OPT_DEBUG)
193      {
194        PrintS("redNF: starting S: ");
195        for( j = 0; j <= max_ind; j++ )
196        {
197          Print("S[%d] (of size: %d): ", j, pLength(strat->S[j]));
198          wrp(strat->S[j]);
199        }
200      };
201#endif
202
203      return P.p;
204    }
205  }
206}
207
208
209poly kNF2Length (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce)
210{
211  assume(q!=NULL);
212  assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring?
213
214// lazy_reduce flags: can be combined by |
215//#define KSTD_NF_LAZY   1
216  // do only a reduction of the leading term
217//#define KSTD_NF_NONORM 4
218  // only global: avoid normalization, return a multiply of NF
219  poly   p;
220  int   i;
221
222  //if ((idIs0(F))&&(Q==NULL))
223  //  return pCopy(q); /*F=0*/
224  //strat->ak = id_RankFreeModule(F, RING!);
225  /*- creating temp data structures------------------- -*/
226  BITSET save_test=test;
227  test|=Sy_bit(OPT_REDTAIL);
228  initBuchMoraCrit(strat);
229  strat->initEcart = initEcartBBA;
230  strat->enterS = enterSBba;
231#ifndef NO_BUCKETS
232  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
233#endif
234  /*- set S -*/
235  strat->sl = -1;
236  /*- init local data struct.---------------------------------------- -*/
237  /*Shdl=*/initS(F,Q,strat);
238  /*- compute------------------------------------------------------- -*/
239  //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
240  //{
241  //  for (i=strat->sl;i>=0;i--)
242  //    pNorm(strat->S[i]);
243  //}
244  kTest(strat);
245  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
246
247  if (BVERBOSE(23)) kDebugPrint(strat);
248
249  int max_ind;
250  p = redNFLength(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat);
251  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
252  {
253    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
254#ifdef HAVE_RINGS
255    if (rField_is_Ring(currRing))
256    {
257      p = redtailBba_Z(p,max_ind,strat);
258    }
259    else
260#endif
261    {
262      BITSET save=test;
263      test &= ~Sy_bit(OPT_INTSTRATEGY);
264      p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0);
265      test=save;
266    }
267  }
268  /*- release temp data------------------------------- -*/
269  omfree(strat->sevS);
270  omfree(strat->ecartS);
271  omfree(strat->T);
272  omfree(strat->sevT);
273  omfree(strat->R);
274  omfree(strat->S_2_R);
275  omfree(strat->L);
276  omfree(strat->B);
277  omfree(strat->fromQ);
278  idDelete(&strat->Shdl);
279  test=save_test;
280  if (TEST_OPT_PROT) PrintLn();
281  return p;
282}
283
284END_NAMESPACE
285
286
287BEGIN_NAMESPACE_SINGULARXX  BEGIN_NAMESPACE(NF)
288
289poly kNFLength(ideal F, ideal Q, poly p,int syzComp, int lazyReduce)
290{
291  if (p==NULL)
292    return NULL;
293
294  poly pp = p;
295
296#ifdef HAVE_PLURAL
297  if(rIsSCA(currRing))
298  {
299    const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
300    const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
301    pp = p_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing);
302
303    if(Q == currQuotient)
304      Q = SCAQuotient(currRing);
305  }
306#endif
307
308  if ((idIs0(F))&&(Q==NULL))
309  {
310#ifdef HAVE_PLURAL
311    if(p != pp)
312      return pp;
313#endif
314    return pCopy(p); /*F+Q=0*/
315  }
316
317  kStrategy strat=new skStrategy;
318  strat->syzComp = syzComp;
319  strat->ak = si_max(id_RankFreeModule(F, currRing),pMaxComp(p));
320  poly res;
321
322  if (rHasLocalOrMixedOrdering(currRing)==-1)
323    res=kNF1(F,Q,pp,strat,lazyReduce);
324  else
325    res=kNF2Length(F,Q,pp,strat,lazyReduce);
326  delete(strat);
327
328#ifdef HAVE_PLURAL
329  if(pp != p)
330    p_Delete(&pp, currRing);
331#endif
332  return res;
333}
334
335END_NAMESPACE               END_NAMESPACE_SINGULARXX
336
337// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
Note: See TracBrowser for help on using the repository browser.