source: git/Singular/dyn_modules/syzextra/myNF.cc @ fb1675

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