source: git/kernel/nc.cc @ a82c308

spielwiese
Last change on this file since a82c308 was 762407, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
config.h is for sources files only FIX: config.h should only be used by source (not from inside kernel/mod2.h!) NOTE: each source file should better include mod2.h right after config.h, while headers should better not include mod2.h.
  • Property mode set to 100644
File size: 8.9 KB
Line 
1#define PLURAL_INTERNAL_DECLARATIONS
2   
3#include "config.h"
4#include "mod2.h"
5#include <misc/auxiliary.h>
6
7#include <misc/options.h>
8
9#include <polys/simpleideals.h>
10#include <polys/prCopy.h>
11#include <polys/nc/gb_hack.h>
12
13#include <kernel/polys.h>
14
15#include <kernel/ideals.h>
16#include <kernel/kstd1.h>
17
18#include <kernel/nc.h>
19
20ideal twostd(ideal I) // works in currRing only!
21{
22  ideal J = kStd(I, currQuotient, testHomog, NULL, NULL, 0, 0, NULL); // in currRing!!!
23  idSkipZeroes(J); // ring independent!
24
25  const int rN = currRing->N;
26
27  loop
28  {
29    ideal     K    = NULL;
30    const int s    = idElem(J); // ring independent
31
32    for(int i = 0; i < s; i++)
33    {
34      const poly p = J->m[i];
35
36#ifdef PDEBUG
37      p_Test(p, currRing);
38#if 0
39      Print("p: "); // !
40      p_Write(p, currRing);
41#endif
42#endif
43
44      for (int j = 1; j <= rN; j++) // for all j = 1..N
45      {
46        poly varj = p_One( currRing);
47        p_SetExp(varj, j, 1, currRing);
48        p_Setm(varj, currRing);
49
50        poly q = pp_Mult_mm(p, varj, currRing); // q = J[i] * var(j),
51
52#ifdef PDEBUG
53        p_Test(varj, currRing);
54        p_Test(p, currRing);
55        p_Test(q, currRing);
56#if 0
57        Print("Reducing p: "); // !
58        p_Write(p, currRing);
59        Print("With q: "); // !
60        p_Write(q, currRing);
61#endif
62#endif
63
64        p_Delete(&varj, currRing);
65
66        if (q != NULL)
67        {
68#ifdef PDEBUG
69#if 0
70          Print("Reducing q[j = %d]: ", j); // !
71          p_Write(q, currRing);
72
73          Print("With p:");
74          p_Write(p, currRing);
75
76#endif
77#endif
78
79          // bug: lm(p) may not divide lm(p * var(i)) in a SCA!
80          if( p_LmDivisibleBy(p, q, currRing) )
81            q = nc_ReduceSpoly(p, q, currRing);
82
83
84#ifdef PDEBUG
85          p_Test(q, currRing);
86#if 0
87          Print("reductum q/p: ");
88          p_Write(q, currRing);
89
90          // Print("With J!\n");
91#endif
92#endif
93
94//          if( q != NULL)
95          q = kNF(J, currQuotient, q, 0, KSTD_NF_NONORM); // in currRing!!!
96
97#ifdef PDEBUG
98          p_Test(q, currRing);
99#if 0
100          Print("NF(J/currQuotient)=> q: "); // !
101          p_Write(q, currRing);
102#endif
103#endif
104          if (q!=NULL)
105          {
106            if (p_IsConstant(q, currRing)) // => return (1)!
107            {
108              p_Delete(&q, currRing);
109              id_Delete(&J, currRing);
110
111              if (K != NULL)
112                id_Delete(&K, currRing);
113
114              ideal Q = idInit(1,1); // ring independent!
115              Q->m[0] = p_One(currRing);
116
117              return(Q);
118            }
119
120//            flag = false;
121
122            // K += q:
123
124            ideal Q = idInit(1,1); // ring independent
125            Q->m[0]=q;
126
127            if( K == NULL )
128              K = Q;
129            else
130            {
131              ideal id_tmp = idSimpleAdd(K, Q); // in currRing
132              id_Delete(&K, currRing);
133              id_Delete(&Q, currRing);
134              K = id_tmp; // K += Q
135            }
136          }
137
138
139        } // if q != NULL
140      } // for all variables
141
142    }
143
144    if (K == NULL) // nothing new: i.e. all elements are two-sided
145      return(J);
146    // now we update GrBasis J with K
147    //    iSize=IDELEMS(J);
148#ifdef PDEBUG
149    idTest(J); // in currRing!
150#if 0
151    Print("J:");
152    idPrint(J);
153    PrintLn();
154#endif // debug
155#endif
156
157
158
159#ifdef PDEBUG
160    idTest(K); // in currRing!
161#if 0
162    Print("+K:");
163    idPrint(K);
164    PrintLn();
165#endif // debug
166#endif
167
168
169    int iSize = idElem(J); // ring independent
170
171    // J += K:
172    ideal id_tmp = idSimpleAdd(J,K); // in currRing
173    id_Delete(&K, currRing); id_Delete(&J, currRing);
174
175#if 1
176    BITSET save_test=test;
177    test|=Sy_bit(OPT_SB_1); // ring independent
178    J = kStd(id_tmp, currQuotient, testHomog, NULL, NULL, 0, iSize); // J = J + K, J - std // in currRing!
179    test = save_test;
180#else
181    J=kStd(id_tmp, currQuotient,testHomog,NULL,NULL,0,0,NULL);
182#endif
183
184    id_Delete(&id_tmp, currRing);
185    idSkipZeroes(J); // ring independent
186
187#ifdef PDEBUG
188    idTest(J); // in currRing!
189#if 0
190    Print("J:");
191    idPrint(J);
192    PrintLn();
193#endif // debug
194#endif
195  } // loop
196}
197
198
199
200
201static ideal idPrepareStd(ideal T, ideal s,  int k)
202{
203  // T is a left SB, without zeros, s is a list with zeros
204#ifdef PDEBUG
205  if (IDELEMS(s)!=IDELEMS(T))
206  {
207    Print("ideals of diff. size!!!");
208  }
209#endif
210  ideal t = idCopy(T);
211  int j,rs=id_RankFreeModule(s, currRing);
212  poly p,q;
213
214  ideal res = idInit(2*idElem(t),1+idElem(t));
215  if (rs == 0)
216  {
217    for (j=0; j<IDELEMS(t); j++)
218    {
219      if (s->m[j]!=NULL) pSetCompP(s->m[j],1);
220      if (t->m[j]!=NULL) pSetCompP(t->m[j],1);
221    }
222    k = si_max(k,1);
223  }
224  for (j=0; j<IDELEMS(t); j++)
225  {
226    if (s->m[j]!=NULL)
227    {
228      p = s->m[j];
229      q = pOne();
230      pSetComp(q,k+1+j);
231      pSetmComp(q);
232#if 0
233      while (pNext(p)) pIter(p);
234      pNext(p) = q;
235#else
236      p = pAdd(p,q);
237      s->m[j] = p;
238#ifdef PDEBUG
239    pTest(p);
240#endif
241#endif
242    }
243  }
244  res = idSimpleAdd(t,s);
245  idDelete(&t);
246  res->rank = 1+idElem(T);
247  return(res);
248}
249
250
251ideal Approx_Step(ideal L)
252{
253  int N=currRing->N;
254  int i,j; // k=syzcomp
255  int flag, flagcnt=0, syzcnt=0;
256  int syzcomp = 0;
257  int k=1; // for ideals not modules
258  ideal I = kStd(L, currQuotient,testHomog,NULL,NULL,0,0,NULL);
259  idSkipZeroes(I);
260  ideal s_I;
261  int idI = idElem(I);
262  ideal trickyQuotient;
263  if (currQuotient !=NULL)
264  {
265    trickyQuotient = idSimpleAdd(currQuotient,I);
266  }
267  else
268    trickyQuotient = I;
269  idSkipZeroes(trickyQuotient);
270  poly *var = (poly *)omAlloc0((N+1)*sizeof(poly));
271  //  poly *W = (poly *)omAlloc0((2*N+1)*sizeof(poly));
272  resolvente S = (resolvente)omAlloc0((N+1)*sizeof(ideal));
273  ideal SI, res;
274  matrix MI;
275  poly x=pOne();
276  var[0]=x;
277  ideal   h2, h3, s_h2, s_h3;
278  poly    p,q,qq;
279  // init vars
280  for (i=1; i<=N; i++ )
281  {
282    x = pOne();
283    pSetExp(x,i,1);
284    pSetm(x);
285    var[i]=pCopy(x);
286  }
287  // init NF's
288  for (i=1; i<=N; i++ )
289  {
290    h2 = idInit(idI,1);
291    flag = 0;
292    for (j=0; j< idI; j++ )
293    {
294      q = pp_Mult_mm(I->m[j],var[i],currRing);
295      q = kNF(I,currQuotient,q,0,0);
296      if (q!=0)
297      {
298    h2->m[j]=pCopy(q);
299    //  p_Shift(&(h2->m[flag]),1, currRing);
300    flag++;
301    pDelete(&q);
302      }
303      else
304    h2->m[j]=0;
305    }
306    // W[1..idElems(I)]
307    if (flag >0)
308    {
309      // compute syzygies with values in I
310      //      idSkipZeroes(h2);
311      //      h2 = idSimpleAdd(h2,I);
312      //      h2->rank=flag+idI+1;
313      idTest(h2);
314      //idShow(h2);
315      ring orig_ring = currRing;
316      ring syz_ring = rAssure_SyzComp(orig_ring, TRUE);
317      syzcomp = 1;
318      rSetSyzComp(syzcomp, syz_ring);
319      if (orig_ring != syz_ring)
320      {
321        rChangeCurrRing(syz_ring);
322        s_h2=idrCopyR_NoSort(h2,orig_ring, syz_ring);
323        //  s_trickyQuotient=idrCopyR_NoSort(trickyQuotient,orig_ring);
324        //  rDebugPrint(syz_ring);
325        s_I=idrCopyR_NoSort(I,orig_ring, syz_ring);
326      }
327      else
328      {
329        s_h2 = h2;
330        s_I  = I;
331        //  s_trickyQuotient=trickyQuotient;
332      }
333      idTest(s_h2);
334      //      idTest(s_trickyQuotient);
335      Print(".proceeding with the variable %d\n",i);
336      s_h3 = idPrepareStd(s_I, s_h2, 1);
337      BITSET save_test=test;
338      test|=Sy_bit(OPT_SB_1);
339      idTest(s_h3);
340      idDelete(&s_h2);
341      s_h2=idCopy(s_h3);
342      idDelete(&s_h3);
343      Print("...computing Syz");
344      s_h3 = kStd(s_h2, currQuotient,(tHomog)FALSE,NULL,NULL,syzcomp,idI);
345      test=save_test;
346      //idShow(s_h3);
347      if (orig_ring != syz_ring)
348      {
349        idDelete(&s_h2);
350        for (j=0; j<IDELEMS(s_h3); j++)
351        {
352          if (s_h3->m[j] != NULL)
353          {
354            if (p_MinComp(s_h3->m[j],syz_ring) > syzcomp) // i.e. it is a syzygy
355              p_Shift(&s_h3->m[j], -syzcomp, currRing);
356            else
357              pDelete(&s_h3->m[j]);
358          }
359        }
360        idSkipZeroes(s_h3);
361        s_h3->rank -= syzcomp;
362        rChangeCurrRing(orig_ring);
363        //  s_h3 = idrMoveR_NoSort(s_h3, syz_ring, orig_ring);
364        s_h3 = idrMoveR_NoSort(s_h3, syz_ring, orig_ring);
365        rDelete(syz_ring);
366      }
367      idTest(s_h3);
368      S[syzcnt]=kStd(s_h3,currQuotient,(tHomog)FALSE,NULL,NULL);
369      syzcnt++;
370      idDelete(&s_h3);
371    } // end if flag >0
372    else
373    {
374      flagcnt++;
375    }
376  }
377  if (flagcnt == N)
378  {
379    Print("the input is a two--sided ideal");
380    return(I);
381  }
382  if (syzcnt >0)
383  {
384    Print("..computing Intersect of %d modules\n",syzcnt);
385    if (syzcnt == 1)
386      SI = S[0];
387    else
388      SI = idMultSect(S, syzcnt);
389    //idShow(SI);
390    MI = id_Module2Matrix(SI,currRing);
391    res= idInit(MATCOLS(MI),1);
392    for (i=1; i<= MATCOLS(MI); i++)
393    {
394      p = NULL;
395      for (j=0; j< idElem(I); j++)
396      {
397        q = pCopy(MATELEM(MI,j+1,i));
398        if (q!=NULL)
399        {
400          q = pMult(q,pCopy(I->m[j]));
401          p = pAdd(p,q);
402        }
403      }
404      res->m[i-1]=p;
405    }
406    Print("final std");
407    res = kStd(res, currQuotient,testHomog,NULL,NULL,0,0,NULL);
408    idSkipZeroes(res);
409    return(res);
410  }
411  else
412  {
413    Print("No syzygies");
414    return(I);
415  }
416}
Note: See TracBrowser for help on using the repository browser.