source: git/dyn_modules/syzextra/myNF.cc @ 0838d7

spielwiese
Last change on this file since 0838d7 was 72a01e, checked in by Hans Schoenemann <hannes@…>, 10 years ago
removed unused febase.h, moved parts to ipshell.h/subexpr.h/structs.h
  • 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
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
31#include <polys/monomials/p_polys.h>
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
64BEGIN_NAMESPACE()
65
66///  reduction procedure for the normal form, which uses pLength instead of pSize!
67static 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
83  BOOLEAN is_ring = rField_is_Ring(currRing);
84#endif
85#ifdef KDEBUG
86  if (TEST_OPT_DEBUG)
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
212poly 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);
231  si_opt_1|=Sy_bit(OPT_REDTAIL);
232  initBuchMoraCrit(strat);
233  strat->initEcart = initEcartBBA;
234  strat->enterS = enterSBba;
235#ifndef NO_BUCKETS
236  strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing));
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  assume(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
259    if (rField_is_Ring(currRing))
260    {
261      p = redtailBba_Z(p,max_ind,strat);
262    }
263    else
264#endif
265    {
266      si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY);
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
286END_NAMESPACE
287
288
289BEGIN_NAMESPACE_SINGULARXX  BEGIN_NAMESPACE(NF)
290
291poly 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
299  if(rIsSCA(currRing))
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 == currQuotient)
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;
321  strat->ak = si_max(id_RankFreeModule(F, currRing),pMaxComp(p));
322  poly res;
323
324  if (rHasLocalOrMixedOrdering(currRing)==-1)
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)
332    p_Delete(&pp, currRing);
333#endif
334  return res;
335}
336
337END_NAMESPACE               END_NAMESPACE_SINGULARXX
338
339// Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab
Note: See TracBrowser for help on using the repository browser.