source: git/Singular/LIB/schreyer.lib @ f37467

spielwiese
Last change on this file since f37467 was f37467, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
Compute the whole inter-reduced & tail-reduced Syz(lead) instead of L(Syz(lead))! add: SSCompute2LeadingSyzygyTerms chg: test the syz. property only in @DEBUG mode fix: removed no SB warning during NF
  • Property mode set to 100644
File size: 27.2 KB
Line 
1//////////////////////////////////////////////////////////////////////////////
2version="$Id$";
3category="General purpose";
4info="
5LIBRARY: schreyer.lib     Helpers for working with the Schreyer induced ordering
6AUTHOR:  Oleksandr Motsak <U@D>, where U={motsak}, D={mathematik.uni-kl.de}
7
8PROCEDURES:
9 Sres(M,l)      Schreyer resolution of module M of maximal length l
10 Ssyz(M)        Schreyer resolution of module M of length 1
11 Scontinue(l)   continue the resolution computation by most l steps
12
13KEYWORDS:  syzygy; Schreyer induced ordering; Schreyer free resolution
14NOTE:  requires the dynamic module: syzextra
15";
16
17static proc prepareSyz( module I, list # )
18{
19  int i;
20  int k = 0;
21  int r = nrows(I);
22  int c = ncols(I);
23
24
25  if( size(#) > 0 )
26  {
27    if( typeof(#[1]) == "int" || typeof(#[1]) == "bigint" )
28    {
29      k = #[1];
30    }
31  }
32
33  if( k < r )
34  {
35    "// *** Wrong k: ", k, " < nrows: ", r, " => setting k = r = ", r;
36    k = r;
37  }
38
39//   "k: ", k;  "c: ", c;   "I: ", I;
40
41  for( i = c; i > 0; i-- )
42  {
43    I[i] = I[i] + gen(k + i);
44  }
45
46//  DetailedPrint(I);
47
48  return(I);
49}
50
51static proc separateSyzGB( module J, int c )
52{
53  module II, G; vector v; int i;
54
55  J = simplify(J, 2);
56
57  for( i = ncols(J); i > 0; i-- )
58  {
59    v = J[i];
60    if( leadcomp(v) > c )
61    {
62      II[i] = v;
63    } else
64    {
65      G[i] = v; // leave only gen(i): i <= c
66    }
67  }
68
69  II = simplify(II, 2);
70  G = simplify(G, 2);
71
72  return (list(G, II));
73}
74
75static proc splitSyzGB( module J, int c )
76{
77  module JJ; vector v, vv; int i;
78
79  for( i = ncols(J); i > 0; i-- )
80  {
81    v = J[i];
82
83    vv = 0;
84   
85    while( leadcomp(v) <= c )
86    {
87      vv = vv + lead(v);
88      v  = v  - lead(v);
89    }
90
91    J[i] = vv;
92    JJ[i] = v;
93  }
94
95  J = simplify(J, 2);
96  JJ = simplify(JJ, 2);
97
98  return (list(J, JJ));
99}
100
101
102static proc Sinit(module M)
103{
104  def @save = basering;
105 
106  int @DEBUG = !system("with", "ndebug");
107  if( @DEBUG )
108  {
109    "Sinit::Input";
110    type(M);
111    DetailedPrint(M);
112    attrib(M);
113  }
114
115  int @RANK = nrows(M); int @SIZE = ncols(M);
116
117  int @IS_A_SB = attrib(M, "isSB"); // ??? only if all weights were zero?!
118
119  if( !@IS_A_SB )
120  {
121    M = std(M); // this should be faster than computing std in S (later on)
122  }
123
124  def S = MakeInducedSchreyerOrdering(1); // 1 puts history terms to the back
125  // TODO: NOTE: +1 causes trouble to Singular interpreter!!!???
126  setring S; // a new ring with a Schreyer ordering
127
128  if( @DEBUG )
129  {
130    "Sinit::StartingISRing";
131    basering;
132//    DetailedPrint(basering);
133  }
134
135  // Setup the leading syzygy^{-1} module to zero:
136  module Z = 0; Z[@RANK] = 0; attrib(Z, "isHomog", intvec(0)); 
137
138  module MRES = Z;
139 
140  list RES; RES[1] = Z;
141
142  module F = freemodule(@RANK);
143  intvec @V = deg(F[1..@RANK]);
144 
145  module M = imap(@save, M);
146 
147  attrib(M, "isHomog", @V);
148  attrib(M, "isSB", 1);
149
150 
151  if( @DEBUG )
152  {
153    "Sinit::SB_Input: ";
154    type(M);
155    attrib(M);
156    attrib(M, "isHomog");
157    DetailedPrint(M);
158  }
159
160  if( @DEBUG )
161  {
162    // 0^th syz. property
163    if( size(module(transpose( transpose(M) * transpose(MRES) ))) > 0 )
164    {
165      transpose( transpose(M) * transpose(MRES) );
166      "transpose( transpose(M) * transpose(MRES) ) != 0!!!";
167      $
168    }
169  }
170
171  RES[size(RES)+1] = M; // list of all syzygy modules
172  MRES = MRES, M;
173
174  attrib(MRES, "isHomog", @V); 
175
176  attrib(S, "InducionLeads", lead(M));
177  attrib(S, "InducionStart", @RANK); 
178 
179  if( @DEBUG )
180  {
181    "Sinit::MRES";
182    DetailedPrint(MRES);
183    attrib(MRES, "isHomog");
184    attrib(S);
185  }
186
187  export RES;
188  export MRES;
189  return (S);
190}
191
192static proc Sstep()
193{
194  int @DEBUG = !system("with", "ndebug");
195
196  if( @DEBUG )
197  {
198    "Sstep::NextInducedRing";
199    DetailedPrint(basering);
200
201    attrib(basering, "InducionLeads");
202    attrib(basering, "InducionStart");
203
204    GetInducedData();
205  }
206
207  // syzygy step:
208
209/*
210  // is initial weights are all zeroes!
211  def L =  lead(M);
212  intvec @V = deg(M[1..ncols(M)]);  @W;  @V;  @W = @V;  attrib(L, "isHomog", @W); 
213  SetInducedReferrence(L, @RANK, 0);
214*/
215
216//  def L =  lead(MRES);
217//  @W = @W, @V;
218//  attrib(L, "isHomog", @W); 
219
220
221  // General setting:
222//  SetInducedReferrence(MRES, 0, 0); // limit: 0!
223  int @l = size(RES);
224
225  module M = RES[@l];
226
227  module L = attrib(basering, "InducionLeads");
228  int limit = attrib(basering, "InducionStart");
229
230//  L;  limit;
231 
232  int @RANK = ncols(MRES) - ncols(M); // nrows(M); // what if M is zero?!
233
234/*
235  if( @RANK !=  nrows(M) )
236  {
237    type(MRES);
238    @RANK;
239    type(M);
240    pause();
241  }
242*/
243 
244  intvec @W = attrib(M, "isHomog");
245  intvec @V = deg(M[1..ncols(M)]);
246  @V = @W, @V;
247   
248  if( @DEBUG )
249  {
250    "Sstep::NextInput: ";
251    M;
252    @V;
253    @RANK;   
254    DetailedPrint(MRES);
255    attrib(MRES, "isHomog");
256  }
257
258 
259     
260  SetInducedReferrence(L, limit, 0);
261 
262  def K = prepareSyz(M, @RANK);
263//  K;
264 
265//   attrib(K, "isHomog", @V);   DetailedPrint(K, 1000);
266
267//  pause();
268 
269  K = idPrepare(K, @RANK); // std(K); // ?
270  K = simplify(K, 2);
271
272//  K;
273
274  module N = separateSyzGB(K, @RANK)[2]; // 1^st syz. module: vectors which start in lower part (comp >= @RANK)
275  attrib(N, "isHomog", @V);
276
277// "N_0: "; N; DetailedPrint(N, 10);
278 
279  N = std(N); // TODO: fix "wrong weights"!!!?
280  attrib(N, "isHomog", @V);
281
282//  N;
283 
284  if( @DEBUG )
285  {
286    if( size(N) > 0 )
287    {
288      // next syz. property
289      if( size(module(transpose( transpose(N) * transpose(MRES) ))) > 0 )
290      {
291        MRES;
292
293        "N: "; N; DetailedPrint(N, 10);
294
295        "K:"; K; DetailedPrint(K, 10);
296
297        "RANKS: ", @RANK;
298
299        "transpose( transpose(N) * transpose(MRES) ) != 0!!!";
300        transpose( transpose(N) * transpose(MRES) );
301
302        "transpose(N) * transpose(MRES): ";
303        transpose(N) * transpose(MRES);
304        DetailedPrint(module(_), 2);
305        $
306      }
307    }
308  }
309 
310  RES[@l + 1] = N; // list of all syzygy modules
311 
312  MRES = MRES, N;
313  attrib(MRES, "isHomog", @V);
314
315
316  L = L, lead(N);
317  attrib(basering, "InducionLeads", L);
318
319  if( @DEBUG )
320  {
321    "Sstep::NextSyzOutput: ";
322    DetailedPrint(N);
323    attrib(N, "isHomog");
324  }
325
326}
327
328proc Scontinue(int l)
329"USAGE:  Scontinue(l)
330RETURN:  nothing, instead it changes RES and MRES variables in the current ring
331PURPOSE: computes further (at most l) syzygies
332NOTE:    must be used within a ring returned by Sres or Ssyz. RES and MRES are
333         explained in Sres
334EXAMPLE: example Scontinue; shows an example
335"
336{
337  def data = GetInducedData();
338           
339  if( (!defined(RES)) || (!defined(MRES)) || (typeof(data) != "list") || (size(data) != 2) )
340  {
341    ERROR("Sorry, but basering does not seem to be returned by Sres or Ssyz");
342  }
343  for (;  (l != 0) && (size(RES[size(RES)]) > 0); l-- )
344  {
345    Sstep();
346  }
347}
348example
349{ "EXAMPLE:"; echo = 2;
350  ring r;
351  module M = maxideal(1); M;
352  def S = Ssyz(M); setring S; S;
353  "Only the first syzygy: ";
354  RES; MRES;
355  "More syzygies: ";
356  Scontinue(10);
357  RES; MRES;
358}
359
360proc Ssyz(module M)
361"USAGE:  Ssyz(M)
362RETURN:  ring, containing a list of modules RES and a module MRES
363PURPOSE: computes the first syzygy module of M (wrt some Schreyer ordering)
364NOTE:    The output is explained in Sres
365EXAMPLE: example Ssyz; shows an example
366"
367{
368  def S = Sinit(M); setring S;
369 
370  Sstep(); // NOTE: what if M is zero?
371
372  return (S);
373}
374example
375{ "EXAMPLE:"; echo = 2;
376  ring r;
377  module M = maxideal(1); M;
378  def S = Ssyz(M); setring S; S;
379  "Only the first syzygy: ";
380  RES;
381  MRES; // Note gen(i)
382  kill S;
383  setring r; kill M;
384
385  module M = 0;
386  def S = Ssyz(M); setring S; S;
387  "Only the first syzygy: ";
388  RES;
389  MRES;
390}
391
392proc Sres(module M, int l)
393"USAGE:  Sres(M, l)
394RETURN:  ring, containing a list of modules RES and a module MRES
395PURPOSE: computes (at most l) syzygy modules of M wrt the classical Schreyer
396         induced ordering with gen(i) > gen(j) if i > j, provided both gens
397         are from the same syzygy level.
398NOTE:    RES contains the images of maps subsituting the beginning of the
399         Schreyer free resolution of baseRing^r/M, while MRES is a sum of
400         these images in a big free sum, containing all the syzygy modules.
401         The syzygy modules are shifted so that gen(i) correspons to MRES[i].
402         The leading zero module RES[0] indicates the fact that coker of the
403         first map is zero. The number of zeroes inducates the rank of input.
404NOTE:    If l == 0 then l is set to be nvars(basering) + 1
405EXAMPLE: example Sres; shows an example
406"
407{
408  def S = Sinit(M); setring S;
409
410  if (l == 0)
411  {
412    l = nvars(basering) + 1; // not really an estimate...?!
413  }
414 
415  Sstep(); l = l - 1;
416 
417  Scontinue(l);
418 
419  return (S);
420}
421example
422{ "EXAMPLE:"; echo = 2;
423  ring r;
424  module M = maxideal(1); M;
425  def S = Sres(M, 0); setring S; S;
426  RES;
427  MRES;
428  kill S;
429  setring r; kill M;
430
431  def A = nc_algebra(-1,0); setring A;
432  ideal Q = var(1)^2, var(2)^2, var(3)^2;
433  qring SCA = twostd(Q);
434  basering;
435
436  module M = maxideal(1);
437  def S = Sres(M, 2); setring S; S;
438  RES;
439  MRES;
440}
441
442
443
444// ================================================================== //
445
446
447LIB "general.lib"; // for sort
448
449// TODO: in C++!
450static proc Tail(def M)
451{
452  int i = ncols(M); def m;
453  while (i > 0)
454  {
455    m = M[i];
456
457    m = m - lead(m); // m = tail(m)
458   
459    M[i] = m;
460   
461    i--;
462  }
463  return (M);
464}
465
466/* static */ proc SSinit(def M)
467{
468  if( (typeof(M) != "module") && (typeof(M) != "ideal") )
469  {
470    ERROR("Sorry: need an ideal or a module for input");
471  }
472
473  // TODO! DONE?
474  def @save = basering;
475 
476  int @DEBUG = !system("with", "ndebug");
477 
478  if( @DEBUG )
479  {
480    "SSinit::Input";
481    type(M);
482//    DetailedPrint(M);
483    attrib(M);
484  }
485
486  int @RANK = nrows(M); int @SIZE = ncols(M);
487
488  int @IS_A_SB = attrib(M, "isSB"); // ??? only if all weights were zero?!
489
490  if( !@IS_A_SB )
491  {
492    def opts = option(get);
493    option(redSB); option(redTail);
494    M = std(M);
495    option(set, opts);
496    kill opts;
497  } else
498  {
499    M = simplify(M, 2 + 4 + 32);
500  }
501
502  def LEAD = lead(M);
503
504  // sort wrt neg.deg.rev.lex!
505  intvec iv_ds = sort(LEAD, "ds", 1)[2]; // ,1 => reversed!
506
507  M = M[iv_ds]; // sort M wrt ds on current leading terms
508  LEAD = LEAD[iv_ds];
509 
510  def TAIL = Tail(M);
511 
512  intvec @DEGS = deg(M[1..@SIZE]); // store actuall degrees of input elements
513 
514  // TODO: what about real modules? weighted ones?
515 
516  list @l = ringlist(@save);
517
518  int @z = 0; ideal @m = maxideal(1); intvec @wdeg = deg(@m[1..ncols(@m)]);
519
520  // NOTE: @wdeg will be ignored anyway :(
521  @l[3] = list(list("C", @z), list("lp", @wdeg));
522
523  kill @z, @wdeg; // since these vars are ring independent!
524
525  def S = ring(@l); // --MakeInducedSchreyerOrdering(1);
526
527  module F = freemodule(@RANK);
528  intvec @V = deg(F[1..@RANK]);
529 
530  setring S; // ring with an easy divisibility test ("C, lex")
531
532  if( @DEBUG )
533  {
534    "SSinit::StartingISRing";
535    basering;
536//    DetailedPrint(basering);
537  }
538
539  // Setup the leading syzygy^{-1} module to zero:
540  module Z = 0; Z[@RANK] = 0; attrib(Z, "isHomog", intvec(0)); 
541
542  module MRES = Z;
543 
544  list RES;  RES[1] = Z;
545  list LRES; LRES[1] = Z;
546  list TRES; TRES[1] = Z;
547 
548  def M = imap(@save, M);
549
550  attrib(M, "isHomog", @V);
551  attrib(M, "isSB", 1);
552  attrib(M, "degrees", @DEGS); 
553 
554  def LEAD = imap(@save, LEAD);
555 
556  attrib(LEAD, "isHomog", @V);
557  attrib(LEAD, "isSB", 1); 
558 
559  def TAIL = imap(@save, TAIL);
560
561  if( @DEBUG )
562  {
563    "SSinit::(sorted) SB_Input: ";
564    type(M);
565    attrib(M);
566    attrib(M, "isHomog");
567//    DetailedPrint(M);
568  }
569
570  if( @DEBUG )
571  {
572    // 0^th syz. property
573    if( size(module(transpose( transpose(M) * transpose(MRES) ))) > 0 )
574    {
575      transpose( transpose(M) * transpose(MRES) );
576      "ERROR: transpose( transpose(M) * transpose(MRES) ) != 0!!!";
577      $
578    }
579  }
580
581  RES[size(RES)+1] = M; // list of all syzygy modules
582  LRES[size(LRES)+1] = LEAD; // list of all syzygy modules
583  TRES[size(TRES)+1] = TAIL; // list of all syzygy modules
584 
585  MRES = MRES, M; //?
586
587  attrib(MRES, "isHomog", @V);
588 
589  attrib(S, "InducionStart", @RANK);
590 
591  if( @DEBUG )
592  {
593    "SSinit::MRES";
594    MRES;
595//    DetailedPrint(MRES);
596    attrib(MRES, "isHomog");
597    attrib(S);
598  }
599
600  export RES;
601  export MRES;
602  export LRES;
603  export TRES;
604  return (S);
605}
606example
607{ "EXAMPLE:"; echo = 2;
608  ring R = 0, (w, x, y, z), dp;
609
610  def M = maxideal(1);
611  def S = SSinit(M); setring S; S;
612 
613  "Only the first initialization: ";
614  RES; LRES; TRES;
615  MRES;
616
617  kill S; setring R; kill M;
618 
619  ideal M = w^2 - x*z,  w*x - y*z,  x^2 - w*y, x*y - z^2, y^2 - w*z;
620  def S = SSinit(M); setring S; S;
621
622  "Only the first initialization: ";
623  RES; LRES; TRES;
624  MRES;
625
626  kill S; setring R; kill M;
627}
628
629
630LIB "poly.lib"; // for lcm
631
632
633
634/// Compute L(Syz(L))
635proc SSComputeLeadingSyzygyTerms(def L)
636{
637  int @DEBUG = !system("with", "ndebug");
638
639  if( @DEBUG )
640  {
641    "SSComputeLeadingSyzygyTerms::Input: ";
642    L;
643  }
644
645  int i, j, r; intvec iv_ds;
646  int N = ncols(L);
647  def a, b;
648  poly aa, bb;
649
650  bigint c;
651
652  ideal M;
653
654  module S = 0;
655 
656  for(i = 1; i <= N; i++)
657  {
658    a = L[i];
659//    "a: ", a;
660    c = leadcomp(a);
661    r = int(c);
662
663    if(r > 0)
664    {
665      aa = a[r];
666    } else
667    {
668      aa = a;
669    }
670
671    M = 0;
672   
673    for(j = i-1; j > 0; j--)
674    {
675      b = L[j];
676//      "b: ", b;
677
678      if( leadcomp(b) == c )
679      {
680        if(r > 0)
681        {
682          bb = b[r];
683        } else
684        {
685          bb = b;
686        }
687
688        M[j] = (lcm(aa, bb) / aa);
689      }
690    }
691   
692    // TODO: add quotient relations here...
693
694    M = simplify(M, 1 + 2 + 32);
695
696    iv_ds = sort(M, "ds", 1)[2]; // ,1 => reversed!
697
698    M = M[iv_ds];
699   
700    S = S, M * gen(i);
701  }
702
703  S = simplify(S, 2);
704
705  S = sort(S, "ds", 1)[1]; // ,1 => reversed! // TODO: not needed?
706 
707  if( @DEBUG )
708  {
709    "SSComputeLeadingSyzygyTerms::Output: ";
710    S;
711  } 
712
713  attrib(S, "isSB", 1);
714
715  return (S);
716}
717
718/// Compute Syz(L), where L is a monomial (leading) module
719proc SSCompute2LeadingSyzygyTerms(def L)
720{
721  int @DEBUG = !system("with", "ndebug");
722
723  if( @DEBUG )
724  {
725    "SSCompute2LeadingSyzygyTerms::Input: ";
726    L;
727  }
728
729  int i, j, r;
730  int N = ncols(L);
731  def a, b;
732
733  poly aa, bb, @lcm;
734
735  bigint c;
736
737  module M;
738
739  module S = 0;
740
741  for(i = 1; i <= N; i++)
742  {
743    a = L[i];
744//    "a: ", a;
745    c = leadcomp(a);
746    r = int(c);
747
748    aa = leadmonomial(a);
749
750    M = 0;
751
752    for(j = i-1; j > 0; j--)
753    {
754      b = L[j];
755//      "b: ", b;
756
757      if( leadcomp(b) == c )
758      {
759        bb = leadmonomial(b);
760        @lcm = lcm(aa, bb);
761
762        M[j] = (@lcm / aa)* gen(i) - (@lcm / bb)* gen(j);
763      }
764    }
765   
766    M = simplify(M, 2);
767
768    // TODO: add quotient relations here...
769    S = S, M;
770  }
771
772  // Make sure that 2nd syzygy terms are not reducible by 1st
773  def opts = option(get);
774  option(redSB); option(redTail);
775  S = std(S); // binomial module
776  option(set, opts);
777//  kill opts; 
778
779  S = sort(S, "ds", 1)[1]; // ,1 => reversed!
780
781  if( @DEBUG )
782  {
783    "SSCompute2LeadingSyzygyTerms::Syz(LEAD): "; S;
784
785    if( size(S) > 0 and size(L) > 0 )
786    {
787      if( size(module(transpose( transpose(S) * transpose(L) ))) > 0 )
788      {
789        transpose( transpose(S) * transpose(L) );
790        "ERROR: transpose( transpose(S) * transpose(L) ) != 0!!!";
791        $
792      }
793    }
794  }
795
796  module S2 = Tail(S);
797  S = lead(S); // (C,lp) on base ring!
798             
799  if( @DEBUG )
800  {
801    "SSCompute2LeadingSyzygyTerms::Output: "; S; S2;
802  } 
803 
804  attrib(S, "isSB", 1);
805
806  return (S, S2);
807}
808
809// -------------------------------------------------------- //
810
811/// TODO: save shortcut LM(m) * "t" -> ?
812proc SSReduce(poly m, def t, def L, def T, def LS)
813{
814  int @DEBUG = !system("with", "ndebug");
815
816  if( @DEBUG )
817  {
818    "SSReduce::Input: ";
819
820    "mult: ", m;
821    "term: ", t;
822    "L: ", L;
823    "T: ", T;
824    "LS: ", LS;
825//    "attrib(LS, 'isSB')", attrib(LS, "isSB");
826  }
827 
828  vector s = 0;
829
830  if( t == 0 )
831  {
832    return (s);
833  }
834
835  def product = m * t;
836
837  bigint c = leadcomp(t);
838  int r = int(c);
839
840 
841  def a, b, nf, bb;
842
843  // looking for an appropriate reducer
844  for( int k = ncols(L); k > 0; k-- )
845  {
846    a = L[k];
847    // with the same mod. component
848    if( leadcomp(a) == c )
849    {
850      b = - (leadmonomial(product) / leadmonomial(L[k]));
851     
852      // which divides the product
853      if( b != 0 )
854      {
855//        "b: ", b;
856        bb = b * gen(k);
857        nf = NF(bb, LS);
858
859//        "NF: ", nf;
860        // while the complement (the fraction) is not reducible by leading syzygies
861        if( nf != 0 )
862        {
863          s = bb + SSTraverse(b, k, L, T, LS);
864          break;
865        }
866      }
867    }
868  } 
869  if( @DEBUG )
870  {
871    "SSReduce::Output: ", s;
872  }
873  return (s);
874}
875
876/// TODO: save shortcut LM(m) * T[i] -> ?
877proc SSTraverse(poly m, int i, def L, def T, def LS)
878{
879  int @DEBUG = !system("with", "ndebug");
880
881  if( @DEBUG )
882  {
883    "SSTraverse::Input: ";
884
885    "index: ", i;
886    "mult: ", m;
887
888    "lead: ", L[i];
889    "tail: ", T[i];
890
891    "LSyz: ", LS;
892//    "attrib(LS, 'isSB')", attrib(LS, "isSB");
893  }
894
895  //  reduce the product m * ( L[i] + T[i] ):
896//  SSReduce(m, L[i], L, T, LS);
897
898  def @tail = T[i]; def @l;
899
900  vector s = 0;
901
902  while( size(@tail) > 0 )
903  {
904    @l = lead(@tail);
905    s = s + SSReduce(m, @l, L, T, LS);
906    @tail = @tail - @l;
907  }
908
909  if( @DEBUG )
910  {
911    "SSTraverse::Output: ", s;
912  }
913  return (s);
914}
915
916// -------------------------------------------------------- //
917
918// module (N, LL, TT) = SSComputeSyzygy(L, T);
919// Compute Syz(L ++ T) = N = LL ++ TT
920proc SSComputeSyzygy(/*def M, */ def L, def T)
921{
922  int @DEBUG = !system("with", "ndebug");
923
924  if( @DEBUG )
925  {
926    "SSComputeSyzygy::Input";
927    "basering: ", basering; attrib(basering);
928//    DetailedPrint(basering);
929
930//    "iCompShift: ", iCompShift;
931
932//    "M: "; M;
933    "L: "; L;
934    "T: "; T;
935  }
936
937  def a, a2; bigint c; int r, r2, k; poly aa, aa2;
938
939  /// Get the critical leading syzygy terms
940  // module LL = SSComputeLeadingSyzygyTerms(L);
941
942  module LL, LL2; (LL, LL2) = SSCompute2LeadingSyzygyTerms(L);
943
944  module TT, SYZ;
945
946  if( size(LL) > 0 )
947  { 
948    vector @tail;
949
950    for(k = ncols(LL); k > 0; k-- )
951    {
952      // leading syz. term:
953      a = LL[k]; c = leadcomp(a); r = int(c); aa = leadmonomial(a);
954
955      // 2nd syz. term:
956      a2 = LL2[k]; c = leadcomp(a2); r2 = int(c); aa2 = leadmonomial(a2);
957     
958     
959  //    "A: ", a, " --->>>> ", aa, " **** [", r, "]: ";
960      @tail = a2 + 
961             SSTraverse(aa, r, L, T, LL) +
962             SSTraverse(aa2, r2, L, T, LL)
963//                SSReduce(aa, L[r], L, T, LL) // get the 2nd syzygy term...
964             ;
965      TT[k] = @tail;
966      SYZ[k] = a + @tail;
967    }
968  }
969
970/* 
971  def opts = option(get); option(redSB); option(redTail);
972  module SYZ = std(syz(M)); // TODO: !!!!!!!!!!!
973  option(set, opts); kill opts;
974
975  "SYZ: ";  SYZ;  print(SYZ);
976
977  "shifted SYZ: ";  SYZ;  print(SYZ);
978 
979  module LL, TT;
980
981  LL = lead(SYZ); // TODO: WRONG ORDERING!!!!!!!!
982  TT = Tail(SYZ);
983*/
984 
985  if( @DEBUG )
986  {
987    "SSComputeSyzygy::Output";
988
989    "SYZ: "; SYZ;
990    "LL: "; LL;
991    "TT: "; TT;
992  }
993
994  return (SYZ, LL, TT);
995}
996
997// resolution/syzygy step:
998static proc SSstep()
999{
1000  /// TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1001  int @DEBUG = !system("with", "ndebug");
1002
1003  if( @DEBUG )
1004  {
1005    "SSstep::NextInducedRing";
1006    "basering: ", basering; attrib(basering);
1007  }
1008
1009/*
1010  // is initial weights are all zeroes!
1011  def L =  lead(M);
1012  intvec @V = deg(M[1..ncols(M)]);  @W;  @V;  @W = @V;  attrib(L, "isHomog", @W); 
1013  SetInducedReferrence(L, @RANK, 0);
1014*/
1015
1016//  def L =  lead(MRES);
1017//  @W = @W, @V;
1018//  attrib(L, "isHomog", @W); 
1019
1020
1021  // General setting:
1022//  SetInducedReferrence(MRES, 0, 0); // limit: 0!
1023  int @l = size(RES);
1024
1025  def M =  RES[@l];
1026
1027  def L = LRES[@l];
1028  def T = TRES[@l];
1029
1030
1031  //// TODO: wrong !!!!!
1032  int @RANK = ncols(MRES) - ncols(M); // nrows(M); // what if M is zero?!
1033
1034 
1035
1036/*
1037  if( @RANK !=  nrows(M) )
1038  {
1039    type(MRES);
1040    @RANK;
1041    type(M);
1042    pause();
1043  }
1044*/
1045 
1046  intvec @W = attrib(M, "isHomog"); intvec @V = attrib(M, "degrees"); @V = @W, @V;
1047   
1048  if( @DEBUG )
1049  {
1050    "Sstep::NextInput: ";
1051    M;
1052    L;
1053    @V;
1054    @RANK;
1055//    DetailedPrint(MRES);
1056    attrib(MRES, "isHomog");
1057  }
1058
1059     
1060  // TODO: N  = SYZ( M )!!!
1061  module N, LL, TT;
1062  (N, LL, TT) = SSComputeSyzygy(/*M, */L, T/*, @RANK*/);
1063
1064  // shift syz.comp by @RANK:
1065  module Z;
1066  Z = 0; Z[@RANK] = 0; Z = Z, transpose(LL);   LL = transpose(Z);
1067  Z = 0; Z[@RANK] = 0; Z = Z, transpose(TT);   TT = transpose(Z);
1068  Z = 0; Z[@RANK] = 0; Z = Z, transpose(N);     N = transpose(Z);
1069
1070
1071  if( size(N) > 0 )
1072  {
1073    if( @DEBUG )
1074    {
1075      // next syz. property
1076      if( size(module(transpose( transpose(N) * transpose(MRES) ))) > 0 )
1077      {
1078        "MRES", MRES;
1079
1080        "N: "; N; // DetailedPrint(N, 2);
1081
1082        "LL:"; LL; // DetailedPrint(LL, 1);
1083        "TT:"; TT; // DetailedPrint(TT, 10);
1084
1085        "RANKS: ", @RANK;
1086
1087        "transpose( transpose(N) * transpose(MRES) ) != 0!!!";
1088        transpose( transpose(N) * transpose(MRES) );
1089
1090        "transpose(N) * transpose(MRES): ";
1091        transpose(N) * transpose(MRES);
1092        // DetailedPrint(module(_), 2);
1093        $
1094      }
1095    }
1096  }
1097
1098  attrib(N, "isHomog", @V);
1099
1100  // TODO: correct the following:
1101  intvec @DEGS = deg(N[1..ncols(N)]); // no mod. comp. weights :(
1102
1103 
1104  attrib(N, "degrees", @DEGS);
1105 
1106   RES[@l + 1] = N; // list of all syzygy modules
1107  LRES[@l + 1] = LL; // list of all syzygy modules
1108  TRES[@l + 1] = TT; // list of all syzygy modules
1109
1110  MRES = MRES, N;
1111 
1112  attrib(MRES, "isHomog", @V);
1113
1114//  L = L, lead(N);  attrib(basering, "InducionLeads", L);
1115
1116  if( @DEBUG )
1117  {
1118    "SSstep::NextSyzOutput: ";
1119    N;
1120//    DetailedPrint(N);
1121    attrib(N);
1122  }
1123
1124}
1125
1126proc SScontinue(int l)
1127"USAGE:  SScontinue(l)
1128RETURN:  nothing, instead it changes RES and MRES variables in the current ring
1129PURPOSE: computes further (at most l) syzygies
1130NOTE:    must be used within a ring returned by Sres or Ssyz. RES and MRES are
1131         explained in Sres
1132EXAMPLE: example Scontinue; shows an example
1133"
1134{
1135
1136  /// TODO!
1137//  def data = GetInducedData();
1138
1139  if( (!defined(RES)) || (!defined(MRES)) ) /* || (typeof(data) != "list") || (size(data) != 2) */
1140  {
1141    ERROR("Sorry, but basering does not seem to be returned by Sres or Ssyz");
1142  }
1143  for (;  (l != 0) && (size(RES[size(RES)]) > 0); l-- )
1144  {
1145    SSstep();
1146  }
1147}
1148example
1149{ "EXAMPLE:"; echo = 2;
1150  ring r;
1151  module M = maxideal(1); M;
1152  def S = SSsyz(M); setring S; S;
1153  "Only the first syzygy: ";
1154  RES; MRES;
1155  "More syzygies: ";
1156  SScontinue(10);
1157  RES; MRES;
1158}
1159
1160proc SSsyz(def M)
1161"USAGE:  SSsyz(M)
1162RETURN:  ring, containing a list of modules RES and a module MRES
1163PURPOSE: computes the first syzygy module of M (wrt some Schreyer ordering)?
1164NOTE:    The output is explained in Sres
1165EXAMPLE: example Ssyz; shows an example
1166"
1167{
1168  if( (typeof(M) != "module") && (typeof(M) != "ideal") )
1169  {
1170    ERROR("Sorry: need an ideal or a module for input");
1171  }
1172
1173  def SS = SSinit(M); setring SS;
1174 
1175  SSstep(); // NOTE: what if M is zero?
1176
1177  return (SS);
1178}
1179example
1180{ "EXAMPLE:"; echo = 2;
1181  ring r;
1182
1183/*  ideal M = 0;
1184  def S = SSsyz(M); setring S; S;
1185  "Only the first syzygy: ";
1186  RES; LRES; TRES;
1187  MRES;
1188 
1189  kill S; setring r; kill M;
1190*/ 
1191
1192  module M = maxideal(1); M;
1193  def S = SSres(M, 0); setring S; S;
1194  MRES;
1195  RES;
1196  "";
1197  LRES;
1198  "";
1199  TRES;
1200
1201  kill S; setring r; kill M;
1202
1203  kill r;
1204 
1205  ring R = 0, (w, x, y, z), dp;
1206  ideal M = w^2 - x*z,  w*x - y*z,  x^2 - w*y, x*y - z^2, y^2 - w*z;
1207 
1208  def S = SSres(M, 0); setring S; S;
1209  MRES;
1210  RES;
1211  "";
1212  LRES;
1213  "";
1214  TRES;
1215}
1216
1217proc SSres(def M, int l)
1218"USAGE:  SSres(I, l)
1219RETURN:  ring, containing a list of modules RES and a module MRES
1220PURPOSE: computes (at most l) syzygy modules of M wrt the classical Schreyer
1221         induced ordering with gen(i) > gen(j) if i > j, provided both gens
1222         are from the same syzygy level.???
1223NOTE:    RES contains the images of maps subsituting the beginning of the
1224         Schreyer free resolution of baseRing^r/M, while MRES is a sum of
1225         these images in a big free sum, containing all the syzygy modules.
1226         The syzygy modules are shifted so that gen(i) correspons to MRES[i].
1227         The leading zero module RES[0] indicates the fact that coker of the
1228         first map is zero. The number of zeroes inducates the rank of input.
1229NOTE:    If l == 0 then l is set to be nvars(basering) + 1
1230EXAMPLE: example SSres; shows an example
1231"
1232{
1233  if( (typeof(M) != "module") && (typeof(M) != "ideal") )
1234  {
1235    ERROR("Sorry: need an ideal or a module for input");
1236  }
1237
1238  def SS = SSinit(M); setring SS;
1239
1240  if (l == 0)
1241  {
1242    l = nvars(basering) + 1; // not really an estimate...?!
1243  }
1244
1245  SSstep(); l = l - 1;
1246
1247  SScontinue(l);
1248
1249  return (SS);
1250}
1251example
1252{ "EXAMPLE:"; echo = 2;
1253  ring r;
1254  module M = maxideal(1); M;
1255  def S = SSres(M, 0); setring S; S;
1256  RES;
1257  MRES;
1258  kill S;
1259  setring r; kill M;
1260
1261  def A = nc_algebra(-1,0); setring A;
1262  ideal Q = var(1)^2, var(2)^2, var(3)^2;
1263  qring SCA = twostd(Q);
1264  basering;
1265
1266  module M = maxideal(1);
1267  def S = SSres(M, 2); setring S; S;
1268  RES;
1269  MRES;
1270}
1271
1272
1273
1274static proc loadme()
1275{
1276  int @DEBUG = !system("with", "ndebug");
1277
1278  if( @DEBUG )
1279  {
1280   
1281    "ndebug?: ", system("with", "ndebug");
1282    "om_ndebug?: ", system("with", "om_ndebug");
1283
1284    listvar(Top);
1285    listvar(Schreyer);
1286  }
1287//  listvar(Syzextra); listvar(Syzextra_g);
1288
1289  if( !defined(DetailedPrint) )
1290  {
1291    if( !@DEBUG )
1292    {
1293
1294      if( @DEBUG )
1295      {
1296        "Loading the Release version!";
1297      }
1298      load("syzextra.so");
1299
1300      if( @DEBUG )
1301      {
1302        listvar(Syzextra);
1303      }
1304     
1305//      export Syzextra;
1306
1307//      exportto(Schreyer, Syzextra::noop);
1308      exportto(Schreyer, Syzextra::DetailedPrint);
1309      exportto(Schreyer, Syzextra::leadmonomial);
1310      exportto(Schreyer, Syzextra::leadcomp);
1311//      exportto(Schreyer, Syzextra::leadrawexp);
1312//      exportto(Schreyer, Syzextra::ISUpdateComponents);
1313      exportto(Schreyer, Syzextra::SetInducedReferrence);
1314      exportto(Schreyer, Syzextra::GetInducedData);
1315//      exportto(Schreyer, Syzextra::GetAMData);
1316//      exportto(Schreyer, Syzextra::SetSyzComp);
1317      exportto(Schreyer, Syzextra::MakeInducedSchreyerOrdering);
1318//      exportto(Schreyer, Syzextra::MakeSyzCompOrdering);
1319      exportto(Schreyer, Syzextra::idPrepare);
1320//      exportto(Schreyer, Syzextra::reduce_syz);
1321//      exportto(Schreyer, Syzextra::p_Content);
1322
1323    }
1324    else
1325    {
1326      if( @DEBUG )
1327      {
1328        "Loading the Debug version!";
1329      }
1330
1331      load("syzextra_g.so");
1332
1333      if( @DEBUG )
1334      {     
1335        listvar(Syzextra_g);
1336      }
1337     
1338//      export Syzextra_g;
1339//      exportto(Schreyer, Syzextra_g::noop);
1340      exportto(Schreyer, Syzextra_g::DetailedPrint);
1341      exportto(Schreyer, Syzextra_g::leadmonomial);
1342      exportto(Schreyer, Syzextra_g::leadcomp);
1343//      exportto(Schreyer, Syzextra_g::leadrawexp);
1344//      exportto(Schreyer, Syzextra_g::ISUpdateComponents);
1345      exportto(Schreyer, Syzextra_g::SetInducedReferrence);
1346      exportto(Schreyer, Syzextra_g::GetInducedData);
1347//      exportto(Schreyer, Syzextra_g::GetAMData);
1348//      exportto(Schreyer, Syzextra_g::SetSyzComp);
1349      exportto(Schreyer, Syzextra_g::MakeInducedSchreyerOrdering);
1350//      exportto(Schreyer, Syzextra_g::MakeSyzCompOrdering);
1351      exportto(Schreyer, Syzextra_g::idPrepare);
1352//      exportto(Schreyer, Syzextra_g::reduce_syz);
1353//      exportto(Schreyer, Syzextra_g::p_Content);
1354
1355     
1356    }
1357
1358    exportto(Top, DetailedPrint);
1359    exportto(Top, GetInducedData);
1360
1361    if( @DEBUG )
1362    {
1363      listvar(Top);
1364      listvar(Schreyer);
1365    }
1366  }
1367 
1368  if( !defined(GetInducedData) )
1369  {
1370    ERROR("Sorry but we are missing the dynamic module (syzextra(_g)?.so)...");
1371  }
1372
1373}
1374
1375static proc mod_init()
1376{
1377  loadme();
1378}
1379
1380
1381proc testallSexamples()
1382{
1383  example Ssyz;
1384  example Scontinue;
1385  example Sres; 
1386}
1387
1388proc testallSSexamples()
1389{
1390  example SSsyz;
1391  example SScontinue;
1392  example SSres; 
1393}
1394
1395example
1396{ "EXAMPLE:"; echo = 2;
1397  testallSexamples();
1398  testallSSexamples();
1399}
Note: See TracBrowser for help on using the repository browser.