source: git/dyn_modules/syzextra/myNF.cc @ d30a399

spielwiese
Last change on this file since d30a399 was d30a399, checked in by Hans Schoenemann <hannes@…>, 11 years ago
chg: option handling: test,verbose renamed to si_opt_1,si_opt_2
  • Property mode set to 100644
File size: 7.2 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 save1;
227  SI_SAVE_OPT1(save1);
228  si_opt_1|=Sy_bit(OPT_REDTAIL);
229  initBuchMoraCrit(strat);
230  strat->initEcart = initEcartBBA;
231  strat->enterS = enterSBba;
232#ifndef NO_BUCKETS
233  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
234#endif
235  /*- set S -*/
236  strat->sl = -1;
237  /*- init local data struct.---------------------------------------- -*/
238  /*Shdl=*/initS(F,Q,strat);
239  /*- compute------------------------------------------------------- -*/
240  //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
241  //{
242  //  for (i=strat->sl;i>=0;i--)
243  //    pNorm(strat->S[i]);
244  //}
245  kTest(strat);
246  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
247
248  if (BVERBOSE(23)) kDebugPrint(strat);
249
250  int max_ind;
251  p = redNFLength(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat);
252  if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0))
253  {
254    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
255#ifdef HAVE_RINGS
256    if (rField_is_Ring(currRing))
257    {
258      p = redtailBba_Z(p,max_ind,strat);
259    }
260    else
261#endif
262    {
263      si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY);
264      p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0);
265    }
266  }
267  /*- release temp data------------------------------- -*/
268  omfree(strat->sevS);
269  omfree(strat->ecartS);
270  omfree(strat->T);
271  omfree(strat->sevT);
272  omfree(strat->R);
273  omfree(strat->S_2_R);
274  omfree(strat->L);
275  omfree(strat->B);
276  omfree(strat->fromQ);
277  idDelete(&strat->Shdl);
278  SI_RESTORE_OPT1(save1);
279  if (TEST_OPT_PROT) PrintLn();
280  return p;
281}
282
283END_NAMESPACE
284
285
286BEGIN_NAMESPACE_SINGULARXX  BEGIN_NAMESPACE(NF)
287
288poly kNFLength(ideal F, ideal Q, poly p,int syzComp, int lazyReduce)
289{
290  if (p==NULL)
291    return NULL;
292
293  poly pp = p;
294
295#ifdef HAVE_PLURAL
296  if(rIsSCA(currRing))
297  {
298    const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing);
299    const unsigned int m_iLastAltVar  = scaLastAltVar(currRing);
300    pp = p_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing);
301
302    if(Q == currQuotient)
303      Q = SCAQuotient(currRing);
304  }
305#endif
306
307  if ((idIs0(F))&&(Q==NULL))
308  {
309#ifdef HAVE_PLURAL
310    if(p != pp)
311      return pp;
312#endif
313    return pCopy(p); /*F+Q=0*/
314  }
315
316  kStrategy strat=new skStrategy;
317  strat->syzComp = syzComp;
318  strat->ak = si_max(id_RankFreeModule(F, currRing),pMaxComp(p));
319  poly res;
320
321  if (rHasLocalOrMixedOrdering(currRing)==-1)
322    res=kNF1(F,Q,pp,strat,lazyReduce);
323  else
324    res=kNF2Length(F,Q,pp,strat,lazyReduce);
325  delete(strat);
326
327#ifdef HAVE_PLURAL
328  if(pp != p)
329    p_Delete(&pp, currRing);
330#endif
331  return res;
332}
333
334END_NAMESPACE               END_NAMESPACE_SINGULARXX
335
336// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
Note: See TracBrowser for help on using the repository browser.