source: git/Singular/LIB/schreyer.lib @ 8f57c0

spielwiese
Last change on this file since 8f57c0 was 8f57c0, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
further Schreyer Syzygy impl. add: compute M_i add: starting to traverse
  • Property mode set to 100644
File size: 23.8 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  attrib(M, "isHomog", @V);
147  attrib(M, "isSB", 1);
148
149 
150  if( @DEBUG )
151  {
152    "Sinit::SB_Input: ";
153    type(M);
154    attrib(M);
155    attrib(M, "isHomog");
156    DetailedPrint(M);
157  }
158
159  // 0^th syz. property
160  if( size(module(transpose( transpose(M) * transpose(MRES) ))) > 0 )
161  {
162    transpose( transpose(M) * transpose(MRES) );
163    "transpose( transpose(M) * transpose(MRES) ) != 0!!!";
164    $
165  }
166
167  RES[size(RES)+1] = M; // list of all syzygy modules
168  MRES = MRES, M;
169
170  attrib(MRES, "isHomog", @V); 
171
172  attrib(S, "InducionLeads", lead(M));
173  attrib(S, "InducionStart", @RANK); 
174 
175  if( @DEBUG )
176  {
177    "Sinit::MRES";
178    DetailedPrint(MRES);
179    attrib(MRES, "isHomog");
180    attrib(S);
181  }
182
183  export RES;
184  export MRES;
185  return (S);
186}
187
188static proc Sstep()
189{
190  int @DEBUG = !system("with", "ndebug");
191
192  if( @DEBUG )
193  {
194    "Sstep::NextInducedRing";
195    DetailedPrint(basering);
196
197    attrib(basering, "InducionLeads");
198    attrib(basering, "InducionStart");
199
200    GetInducedData();
201  }
202
203  // syzygy step:
204
205/*
206  // is initial weights are all zeroes!
207  def L =  lead(M);
208  intvec @V = deg(M[1..ncols(M)]);  @W;  @V;  @W = @V;  attrib(L, "isHomog", @W); 
209  SetInducedReferrence(L, @RANK, 0);
210*/
211
212//  def L =  lead(MRES);
213//  @W = @W, @V;
214//  attrib(L, "isHomog", @W); 
215
216
217  // General setting:
218//  SetInducedReferrence(MRES, 0, 0); // limit: 0!
219  int @l = size(RES);
220
221  module M = RES[@l];
222
223  module L = attrib(basering, "InducionLeads");
224  int limit = attrib(basering, "InducionStart");
225
226//  L;  limit;
227 
228  int @RANK = ncols(MRES) - ncols(M); // nrows(M); // what if M is zero?!
229
230/*
231  if( @RANK !=  nrows(M) )
232  {
233    type(MRES);
234    @RANK;
235    type(M);
236    pause();
237  }
238*/
239 
240  intvec @W = attrib(M, "isHomog");
241  intvec @V = deg(M[1..ncols(M)]);
242  @V = @W, @V;
243   
244  if( @DEBUG )
245  {
246    "Sstep::NextInput: ";
247    M;
248    @V;
249    @RANK;   
250    DetailedPrint(MRES);
251    attrib(MRES, "isHomog");
252  }
253
254 
255     
256  SetInducedReferrence(L, limit, 0);
257 
258  def K = prepareSyz(M, @RANK);
259//  K;
260 
261//   attrib(K, "isHomog", @V);   DetailedPrint(K, 1000);
262
263//  pause();
264 
265  K = idPrepare(K, @RANK); // std(K); // ?
266  K = simplify(K, 2);
267
268//  K;
269
270  module N = separateSyzGB(K, @RANK)[2]; // 1^st syz. module: vectors which start in lower part (comp >= @RANK)
271  attrib(N, "isHomog", @V);
272
273// "N_0: "; N; DetailedPrint(N, 10);
274 
275  N = std(N); // TODO: fix "wrong weights"!!!?
276  attrib(N, "isHomog", @V);
277
278//  N;
279 
280  if( size(N) > 0 )
281  {
282    // next syz. property
283    if( size(module(transpose( transpose(N) * transpose(MRES) ))) > 0 )
284    {
285      MRES;
286
287      "N: "; N; DetailedPrint(N, 10);
288
289      "K:"; K; DetailedPrint(K, 10);
290
291      "RANKS: ", @RANK;
292
293      "transpose( transpose(N) * transpose(MRES) ) != 0!!!";
294      transpose( transpose(N) * transpose(MRES) );
295
296      "transpose(N) * transpose(MRES): ";
297      transpose(N) * transpose(MRES);
298      DetailedPrint(module(_), 2);
299      $
300    }
301  }
302 
303  RES[@l + 1] = N; // list of all syzygy modules
304 
305  MRES = MRES, N;
306  attrib(MRES, "isHomog", @V);
307
308
309  L = L, lead(N);
310  attrib(basering, "InducionLeads", L);
311
312  if( @DEBUG )
313  {
314    "Sstep::NextSyzOutput: ";
315    DetailedPrint(N);
316    attrib(N, "isHomog");
317  }
318
319}
320
321proc Scontinue(int l)
322"USAGE:  Scontinue(l)
323RETURN:  nothing, instead it changes RES and MRES variables in the current ring
324PURPOSE: computes further (at most l) syzygies
325NOTE:    must be used within a ring returned by Sres or Ssyz. RES and MRES are
326         explained in Sres
327EXAMPLE: example Scontinue; shows an example
328"
329{
330  def data = GetInducedData();
331           
332  if( (!defined(RES)) || (!defined(MRES)) || (typeof(data) != "list") || (size(data) != 2) )
333  {
334    ERROR("Sorry, but basering does not seem to be returned by Sres or Ssyz");
335  }
336  for (;  (l != 0) && (size(RES[size(RES)]) > 0); l-- )
337  {
338    Sstep();
339  }
340}
341example
342{ "EXAMPLE:"; echo = 2;
343  ring r;
344  module M = maxideal(1); M;
345  def S = Ssyz(M); setring S; S;
346  "Only the first syzygy: ";
347  RES; MRES;
348  "More syzygies: ";
349  Scontinue(10);
350  RES; MRES;
351}
352
353proc Ssyz(module M)
354"USAGE:  Ssyz(M)
355RETURN:  ring, containing a list of modules RES and a module MRES
356PURPOSE: computes the first syzygy module of M (wrt some Schreyer ordering)
357NOTE:    The output is explained in Sres
358EXAMPLE: example Ssyz; shows an example
359"
360{
361  def S = Sinit(M); setring S;
362 
363  Sstep(); // NOTE: what if M is zero?
364
365  return (S);
366}
367example
368{ "EXAMPLE:"; echo = 2;
369  ring r;
370  module M = maxideal(1); M;
371  def S = Ssyz(M); setring S; S;
372  "Only the first syzygy: ";
373  RES;
374  MRES; // Note gen(i)
375  kill S;
376  setring r; kill M;
377
378  module M = 0;
379  def S = Ssyz(M); setring S; S;
380  "Only the first syzygy: ";
381  RES;
382  MRES;
383}
384
385proc Sres(module M, int l)
386"USAGE:  Sres(M, l)
387RETURN:  ring, containing a list of modules RES and a module MRES
388PURPOSE: computes (at most l) syzygy modules of M wrt the classical Schreyer
389         induced ordering with gen(i) > gen(j) if i > j, provided both gens
390         are from the same syzygy level.
391NOTE:    RES contains the images of maps subsituting the beginning of the
392         Schreyer free resolution of baseRing^r/M, while MRES is a sum of
393         these images in a big free sum, containing all the syzygy modules.
394         The syzygy modules are shifted so that gen(i) correspons to MRES[i].
395         The leading zero module RES[0] indicates the fact that coker of the
396         first map is zero. The number of zeroes inducates the rank of input.
397NOTE:    If l == 0 then l is set to be nvars(basering) + 1
398EXAMPLE: example Sres; shows an example
399"
400{
401  def S = Sinit(M); setring S;
402
403  if (l == 0)
404  {
405    l = nvars(basering) + 1; // not really an estimate...?!
406  }
407 
408  Sstep(); l = l - 1;
409 
410  Scontinue(l);
411 
412  return (S);
413}
414example
415{ "EXAMPLE:"; echo = 2;
416  ring r;
417  module M = maxideal(1); M;
418  def S = Sres(M, 0); setring S; S;
419  RES;
420  MRES;
421  kill S;
422  setring r; kill M;
423
424  def A = nc_algebra(-1,0); setring A;
425  ideal Q = var(1)^2, var(2)^2, var(3)^2;
426  qring SCA = twostd(Q);
427  basering;
428
429  module M = maxideal(1);
430  def S = Sres(M, 2); setring S; S;
431  RES;
432  MRES;
433}
434
435
436
437// ================================================================== //
438
439
440LIB "general.lib"; // for sort
441
442// TODO: in C++!
443static proc Tail(def M)
444{
445  int i = ncols(M); def m;
446  while (i > 0)
447  {
448    m = M[i];
449
450    m = m - lead(m); // m = tail(m)
451   
452    M[i] = m;
453   
454    i--;
455  }
456  return (M);
457}
458
459/* static */ proc SSinit(module M)
460{
461  if( (typeof(M) != "module") && (typeof(M) != "ideal") )
462  {
463    ERROR("Sorry: need an ideal or a module for input");
464  }
465
466  // TODO! DONE?
467  def @save = basering;
468 
469  int @DEBUG = !system("with", "ndebug");
470  if( @DEBUG )
471  {
472    "SSinit::Input";
473    type(M);
474    DetailedPrint(M);
475    attrib(M);
476  }
477
478  int @RANK = nrows(M); int @SIZE = ncols(M);
479
480  int @IS_A_SB = attrib(M, "isSB"); // ??? only if all weights were zero?!
481
482  if( !@IS_A_SB )
483  {
484    def opts = option(get);
485    option(redSB); option(redTail);
486    M = std(M);
487    option(set, opts);
488    kill opts;
489  } else
490  {
491    M = simplify(M, 2 + 4 + 32);
492  }
493
494  def LEAD = lead(M);
495
496  // sort wrt neg.deg.rev.lex!
497  intvec iv_ds = sort(LEAD, "ds", 1)[2]; // ,1 => reversed!
498
499  M = M[iv_ds]; // sort M wrt ds on current leading terms
500  LEAD = LEAD[iv_ds];
501 
502  def TAIL = Tail(M);
503 
504  intvec @DEGS = deg(M[1..@SIZE]); // store actuall degrees of input elements
505 
506  // TODO: what about real modules? weighted ones?
507 
508  list @l = ringlist(@save);
509
510  int @z = 0; ideal @m = maxideal(1); intvec @wdeg = deg(@m[1..ncols(@m)]);
511
512  // NOTE: @wdeg will be ignored anyway :(
513  @l[3] = list(list("C", @z), list("lp", @wdeg));
514
515  kill @z, @wdeg; // since these vars are ring independent!
516
517  def S = ring(@l); // --MakeInducedSchreyerOrdering(1);
518
519  module F = freemodule(@RANK);
520  intvec @V = deg(F[1..@RANK]);
521 
522  setring S; // ring with an easy divisibility test ("C, lex")
523
524  if( @DEBUG )
525  {
526    "SSinit::StartingISRing";
527    basering;
528//    DetailedPrint(basering);
529  }
530
531  // Setup the leading syzygy^{-1} module to zero:
532  module Z = 0; Z[@RANK] = 0; attrib(Z, "isHomog", intvec(0)); 
533
534  module MRES = Z;
535 
536  list RES;  RES[1] = Z;
537  list LRES; LRES[1] = Z;
538  list TRES; TRES[1] = Z;
539 
540  def M = imap(@save, M);
541  attrib(M, "isHomog", @V);
542  attrib(M, "isSB", 1);
543
544  attrib(M, "degrees", @DEGS); 
545 
546  def LEAD = imap(@save, LEAD);
547  attrib(LEAD, "isHomog", @V);
548  attrib(LEAD, "isSB", 1); 
549 
550  def TAIL = imap(@save, TAIL);
551
552  if( @DEBUG )
553  {
554    "SSinit::(sorted) SB_Input: ";
555    type(M);
556    attrib(M);
557    attrib(M, "isHomog");
558    DetailedPrint(M);
559  }
560
561  // 0^th syz. property
562  if( size(module(transpose( transpose(M) * transpose(MRES) ))) > 0 )
563  {
564    transpose( transpose(M) * transpose(MRES) );
565    "ERROR: transpose( transpose(M) * transpose(MRES) ) != 0!!!";
566    $
567  }
568
569  RES[size(RES)+1] = M; // list of all syzygy modules
570  LRES[size(LRES)+1] = LEAD; // list of all syzygy modules
571  TRES[size(TRES)+1] = TAIL; // list of all syzygy modules
572 
573  MRES = MRES, M; //?
574
575  attrib(MRES, "isHomog", @V); 
576
577  attrib(S, "InducionStart", @RANK);
578 
579  if( @DEBUG )
580  {
581    "SSinit::MRES";
582    DetailedPrint(MRES);
583    attrib(MRES, "isHomog");
584    attrib(S);
585  }
586
587  export RES;
588  export MRES;
589  export LRES;
590  export TRES;
591  return (S);
592}
593example
594{ "EXAMPLE:"; echo = 2;
595  ring R = 0, (w, x, y, z), dp;
596
597  def M = maxideal(1);
598  def S = SSinit(M); setring S; S;
599 
600  "Only the first initialization: ";
601  RES; LRES; TRES;
602  MRES;
603
604  kill S; setring R; kill M;
605 
606  ideal M = w^2 - x*z,  w*x - y*z,  x^2 - w*y, x*y - z^2, y^2 - w*z;
607  def S = SSinit(M); setring S; S;
608
609  "Only the first initialization: ";
610  RES; LRES; TRES;
611  MRES;
612
613  kill S; setring R; kill M;
614}
615
616
617LIB "poly.lib"; // for lcm
618
619
620proc SSComputeLeadingSyzygyTerms(def L, int iCompShift)
621{
622  int @DEBUG = !system("with", "ndebug");
623
624  if( @DEBUG )
625  {
626    "SSComputeLeadingSyzygyTerms::Input: ";
627    L;
628    "iCompShift: ", iCompShift;
629
630  }
631
632  int i, j, r; intvec iv_ds;
633  int N = ncols(L);
634  def a, b;
635  poly aa, bb;
636
637  bigint c;
638
639  ideal M;
640
641  module S = 0;
642 
643  for(i = 1; i <= N; i++)
644  {
645    a = L[i];
646    "a: ", a;
647    c = leadcomp(a);
648    r = int(c);
649    aa = a[r];
650
651    M = 0;
652   
653    for(j = i-1; j > 0; j--)
654    {
655      b = L[j];
656      "b: ", b;
657
658      if( leadcomp(b) == c )
659      {
660        bb = b[r];
661
662        M[j] = (lcm(aa, bb) / aa);
663      }
664    }
665
666    M = simplify(M, 1 + 2 + 32);
667
668    iv_ds = sort(M, "ds", 1)[2]; // ,1 => reversed!
669
670    M = M[iv_ds];
671   
672    S = S, M * gen(i + iCompShift);
673  }
674
675  S = simplify(S, 2);
676
677 
678  if( @DEBUG )
679  {
680    "SSComputeLeadingSyzygyTerms::Output: ";
681    S;
682  }
683
684  return (S);
685
686}
687
688proc Traverse(mult, index, Leads, Tails, LSyz)
689{
690
691
692}
693
694
695
696// module (N, LL, TT) = SSComputeSyzygy(L, T, @RANK); // shift syz.comp by @RANK!
697proc SSComputeSyzygy(def M, def L, def T, int iCompShift)
698{
699  int @DEBUG = !system("with", "ndebug");
700
701  if( @DEBUG )
702  {
703    "SSComputeSyzygy::Input";
704    "basering: ", basering; attrib(basering);
705//    DetailedPrint(basering);
706
707    "iCompShift: ", iCompShift;
708
709    "M: "; M;
710    "L: "; L;
711    "T: "; T;
712  }
713
714
715  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
716  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
717  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
718  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
719  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
720  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
721  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
722
723  def a; bigint c; int r, k; poly aa;
724 
725  def LS = SSComputeLeadingSyzygyTerms(L, 0); // iCompShift // 0?
726  for(k = ncols(LS); k >= 0; k-- )
727  {
728    a = LS[k];
729    "A: ", a;
730    c = leadcomp(a);
731    r = int(c);
732    aa = a[r];
733
734    Traverse(aa, r, L, T, LS);
735  }
736
737
738  def opts = option(get); option(redSB); option(redTail);
739  module SYZ = std(syz(M)); // TODO: !!!!!!!!!!!
740  option(set, opts); kill opts;
741
742  "SYZ: ";  SYZ;  print(SYZ);
743
744  module Z; Z[iCompShift] = 0; Z = Z, transpose(SYZ); SYZ = transpose(Z);
745
746  "shifted SYZ: ";  SYZ;  print(SYZ);
747 
748  module LL, TT;
749
750  LL = lead(SYZ); // TODO: WRONG ORDERING!!!!!!!!
751  TT = Tail(SYZ);
752
753
754  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
755  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
756  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
757  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
758  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
759  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
760  // !!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!! //
761 
762  intvec iv_ds = sort(LL, "ds", 1)[2]; // ,1 => reversed!
763  LL = LL[iv_ds];
764  TT = TT[iv_ds];
765 
766  if( @DEBUG )
767  {
768    "SSComputeSyzygy::Output";
769
770    "SYZ: "; SYZ;
771    "LL: "; LL;
772    "TT: "; TT;
773  }
774
775  return (SYZ, LL, TT);
776}
777
778// resolution/syzygy step:
779static proc SSstep()
780{
781  /// TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
782  int @DEBUG = !system("with", "ndebug");
783
784  if( @DEBUG )
785  {
786    "SSstep::NextInducedRing";
787    "basering: ", basering; attrib(basering);
788//    DetailedPrint(basering);
789  }
790
791/*
792  // is initial weights are all zeroes!
793  def L =  lead(M);
794  intvec @V = deg(M[1..ncols(M)]);  @W;  @V;  @W = @V;  attrib(L, "isHomog", @W); 
795  SetInducedReferrence(L, @RANK, 0);
796*/
797
798//  def L =  lead(MRES);
799//  @W = @W, @V;
800//  attrib(L, "isHomog", @W); 
801
802
803  // General setting:
804//  SetInducedReferrence(MRES, 0, 0); // limit: 0!
805  int @l = size(RES);
806
807  def M =  RES[@l];
808
809  def L = LRES[@l];
810  def T = TRES[@l];
811
812
813  //// TODO: wrong !!!!!
814  int @RANK = ncols(MRES) - ncols(M); // nrows(M); // what if M is zero?!
815
816 
817
818/*
819  if( @RANK !=  nrows(M) )
820  {
821    type(MRES);
822    @RANK;
823    type(M);
824    pause();
825  }
826*/
827 
828  intvec @W = attrib(M, "isHomog"); intvec @V = attrib(M, "degrees"); @V = @W, @V;
829   
830  if( @DEBUG )
831  {
832    "Sstep::NextInput: ";
833    M;
834    L;
835    @V;
836    @RANK;
837    DetailedPrint(MRES);
838    attrib(MRES, "isHomog");
839  }
840
841     
842  // TODO: N  = SYZ( M )!!!
843  module N, LL, TT; (N, LL, TT) = SSComputeSyzygy(M, L, T, @RANK); // shift syz.comp by @RANK!
844
845  attrib(N, "isHomog", @V);
846
847  // TODO: correct the following:
848  intvec @DEGS = deg(N[1..ncols(N)]); // no mod. comp. weights :(
849  attrib(N, "degrees", @DEGS); 
850 
851  if( size(N) > 0 )
852  {
853    N;
854    MRES;
855    // next syz. property
856    if( size(module(transpose( transpose(N) * transpose(MRES) ))) > 0 )
857    {
858      MRES;
859
860      "N: "; N; // DetailedPrint(N, 2);
861
862      "LL:"; LL; // DetailedPrint(LL, 1);
863      "TT:"; TT; // DetailedPrint(TT, 10);
864
865      "RANKS: ", @RANK;
866
867      "transpose( transpose(N) * transpose(MRES) ) != 0!!!";
868      transpose( transpose(N) * transpose(MRES) );
869
870      "transpose(N) * transpose(MRES): ";
871      transpose(N) * transpose(MRES);
872      // DetailedPrint(module(_), 2);
873      $
874    }
875  }
876 
877   RES[@l + 1] = N; // list of all syzygy modules
878  LRES[@l + 1] = LL; // list of all syzygy modules
879  TRES[@l + 1] = TT; // list of all syzygy modules
880
881  MRES = MRES, N;
882  attrib(MRES, "isHomog", @V);
883
884//  L = L, lead(N);  attrib(basering, "InducionLeads", L);
885
886  if( @DEBUG )
887  {
888    "SSstep::NextSyzOutput: ";
889    DetailedPrint(N);
890    attrib(N);
891  }
892
893}
894
895proc SScontinue(int l)
896"USAGE:  SScontinue(l)
897RETURN:  nothing, instead it changes RES and MRES variables in the current ring
898PURPOSE: computes further (at most l) syzygies
899NOTE:    must be used within a ring returned by Sres or Ssyz. RES and MRES are
900         explained in Sres
901EXAMPLE: example Scontinue; shows an example
902"
903{
904
905  /// TODO!
906//  def data = GetInducedData();
907
908  if( (!defined(RES)) || (!defined(MRES)) ) /* || (typeof(data) != "list") || (size(data) != 2) */
909  {
910    ERROR("Sorry, but basering does not seem to be returned by Sres or Ssyz");
911  }
912  for (;  (l != 0) && (size(RES[size(RES)]) > 0); l-- )
913  {
914    SSstep();
915  }
916}
917example
918{ "EXAMPLE:"; echo = 2;
919  ring r;
920  module M = maxideal(1); M;
921  def S = SSsyz(M); setring S; S;
922  "Only the first syzygy: ";
923  RES; MRES;
924  "More syzygies: ";
925  SScontinue(10);
926  RES; MRES;
927}
928
929proc SSsyz(def M)
930"USAGE:  SSsyz(M)
931RETURN:  ring, containing a list of modules RES and a module MRES
932PURPOSE: computes the first syzygy module of M (wrt some Schreyer ordering)?
933NOTE:    The output is explained in Sres
934EXAMPLE: example Ssyz; shows an example
935"
936{
937  if( (typeof(M) != "module") && (typeof(M) != "ideal") )
938  {
939    ERROR("Sorry: need an ideal or a module for input");
940  }
941
942  def SS = SSinit(M); setring SS;
943 
944  SSstep(); // NOTE: what if M is zero?
945
946  return (SS);
947}
948example
949{ "EXAMPLE:"; echo = 2;
950  ring r;
951
952/*  ideal M = 0;
953  def S = SSsyz(M); setring S; S;
954  "Only the first syzygy: ";
955  RES; LRES; TRES;
956  MRES;
957 
958  kill S; setring r; kill M;
959*/ 
960
961  module M = maxideal(1); M;
962  def S = SSsyz(M); setring S; S;
963  "Only the first syzygy: ";
964  RES; LRES; TRES;
965  MRES;
966
967  kill S; setring r; kill M;
968
969  kill r;
970 
971  ring R = 0, (w, x, y, z), dp;
972  ideal M = w^2 - x*z,  w*x - y*z,  x^2 - w*y, x*y - z^2, y^2 - w*z;
973 
974  def S = SSsyz(M); setring S; S;
975  "Only the first syzygy: ";
976  RES; LRES; TRES;
977  MRES;
978}
979
980proc SSres(def M, int l)
981"USAGE:  SSres(I, l)
982RETURN:  ring, containing a list of modules RES and a module MRES
983PURPOSE: computes (at most l) syzygy modules of M wrt the classical Schreyer
984         induced ordering with gen(i) > gen(j) if i > j, provided both gens
985         are from the same syzygy level.???
986NOTE:    RES contains the images of maps subsituting the beginning of the
987         Schreyer free resolution of baseRing^r/M, while MRES is a sum of
988         these images in a big free sum, containing all the syzygy modules.
989         The syzygy modules are shifted so that gen(i) correspons to MRES[i].
990         The leading zero module RES[0] indicates the fact that coker of the
991         first map is zero. The number of zeroes inducates the rank of input.
992NOTE:    If l == 0 then l is set to be nvars(basering) + 1
993EXAMPLE: example SSres; shows an example
994"
995{
996  if( (typeof(M) != "module") && (typeof(M) != "ideal") )
997  {
998    ERROR("Sorry: need an ideal or a module for input");
999  }
1000
1001  def SS = SSinit(M); setring SS;
1002
1003  if (l == 0)
1004  {
1005    l = nvars(basering) + 1; // not really an estimate...?!
1006  }
1007
1008  SSstep(); l = l - 1;
1009
1010  SScontinue(l);
1011
1012  return (SS);
1013}
1014example
1015{ "EXAMPLE:"; echo = 2;
1016  ring r;
1017  module M = maxideal(1); M;
1018  def S = SSres(M, 0); setring S; S;
1019  RES;
1020  MRES;
1021  kill S;
1022  setring r; kill M;
1023
1024  def A = nc_algebra(-1,0); setring A;
1025  ideal Q = var(1)^2, var(2)^2, var(3)^2;
1026  qring SCA = twostd(Q);
1027  basering;
1028
1029  module M = maxideal(1);
1030  def S = SSres(M, 2); setring S; S;
1031  RES;
1032  MRES;
1033}
1034
1035
1036
1037static proc loadme()
1038{
1039  int @DEBUG = !system("with", "ndebug");
1040
1041  if( @DEBUG )
1042  {
1043   
1044    "ndebug?: ", system("with", "ndebug");
1045    "om_ndebug?: ", system("with", "om_ndebug");
1046
1047    listvar(Top);
1048    listvar(Schreyer);
1049  }
1050//  listvar(Syzextra); listvar(Syzextra_g);
1051
1052  if( !defined(DetailedPrint) )
1053  {
1054    if( !@DEBUG )
1055    {
1056
1057      if( @DEBUG )
1058      {
1059        "Loading the Release version!";
1060      }
1061      load("syzextra.so");
1062
1063      if( @DEBUG )
1064      {
1065        listvar(Syzextra);
1066      }
1067     
1068//      export Syzextra;
1069
1070//      exportto(Schreyer, Syzextra::noop);
1071      exportto(Schreyer, Syzextra::DetailedPrint);
1072//      exportto(Schreyer, Syzextra::leadmonom);
1073      exportto(Schreyer, Syzextra::leadcomp);
1074//      exportto(Schreyer, Syzextra::leadrawexp);
1075//      exportto(Schreyer, Syzextra::ISUpdateComponents);
1076      exportto(Schreyer, Syzextra::SetInducedReferrence);
1077      exportto(Schreyer, Syzextra::GetInducedData);
1078//      exportto(Schreyer, Syzextra::GetAMData);
1079//      exportto(Schreyer, Syzextra::SetSyzComp);
1080      exportto(Schreyer, Syzextra::MakeInducedSchreyerOrdering);
1081//      exportto(Schreyer, Syzextra::MakeSyzCompOrdering);
1082      exportto(Schreyer, Syzextra::idPrepare);
1083//      exportto(Schreyer, Syzextra::reduce_syz);
1084//      exportto(Schreyer, Syzextra::p_Content);
1085
1086    }
1087    else
1088    {
1089      if( @DEBUG )
1090      {
1091        "Loading the Debug version!";
1092      }
1093
1094      load("syzextra_g.so");
1095
1096      if( @DEBUG )
1097      {     
1098        listvar(Syzextra_g);
1099      }
1100     
1101//      export Syzextra_g;
1102//      exportto(Schreyer, Syzextra_g::noop);
1103      exportto(Schreyer, Syzextra_g::DetailedPrint);
1104//      exportto(Schreyer, Syzextra_g::leadmonom);
1105      exportto(Schreyer, Syzextra_g::leadcomp);
1106//      exportto(Schreyer, Syzextra_g::leadrawexp);
1107//      exportto(Schreyer, Syzextra_g::ISUpdateComponents);
1108      exportto(Schreyer, Syzextra_g::SetInducedReferrence);
1109      exportto(Schreyer, Syzextra_g::GetInducedData);
1110//      exportto(Schreyer, Syzextra_g::GetAMData);
1111//      exportto(Schreyer, Syzextra_g::SetSyzComp);
1112      exportto(Schreyer, Syzextra_g::MakeInducedSchreyerOrdering);
1113//      exportto(Schreyer, Syzextra_g::MakeSyzCompOrdering);
1114      exportto(Schreyer, Syzextra_g::idPrepare);
1115//      exportto(Schreyer, Syzextra_g::reduce_syz);
1116//      exportto(Schreyer, Syzextra_g::p_Content);
1117
1118     
1119    }
1120
1121    exportto(Top, DetailedPrint);
1122    exportto(Top, GetInducedData);
1123
1124    if( @DEBUG )
1125    {
1126      listvar(Top);
1127      listvar(Schreyer);
1128    }
1129  }
1130 
1131  if( !defined(GetInducedData) )
1132  {
1133    ERROR("Sorry but we are missing the dynamic module (syzextra(_g)?.so)...");
1134  }
1135
1136}
1137
1138static proc mod_init()
1139{
1140  loadme();
1141}
1142
1143
1144proc testallSexamples()
1145{
1146  example Ssyz;
1147  example Scontinue;
1148  example Sres; 
1149}
1150
1151proc testallSSexamples()
1152{
1153  example SSsyz;
1154  example SScontinue;
1155  example SSres; 
1156}
1157
1158example
1159{ "EXAMPLE:"; echo = 2;
1160  testallSexamples();
1161  testallSSexamples();
1162}
Note: See TracBrowser for help on using the repository browser.