source: git/kernel/nc.cc @ 80ca3c

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