source: git/Singular/LIB/nctools.lib @ b85b62

spielwiese
Last change on this file since b85b62 was c4002e, checked in by Viktor Levandovskyy <levandov@…>, 17 years ago
*levandov: right-sided std,syz, nf and modulo added git-svn-id: file:///usr/local/Singular/svn/trunk@10038 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 31.5 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2version="$Id: nctools.lib,v 1.25 2007-05-13 18:29:43 levandov Exp $";
3category="Noncommutative";
4info="
5LIBRARY: nctools.lib     General tools for noncommutative algebras
6AUTHORS:   Levandovskyy V.,     levandov@mathematik.uni-kl.de,
7@*         Lobillo, F.J.,       jlobillo@ugr.es,
8@*         Rabelo, C.,          crabelo@ugr.es.
9
10SUPPORT: DFG (Deutsche Forschungsgesellschaft) and Metodos algebraicos y efectivos en grupos cuanticos, BFM2001-3141, MCYT, Jose Gomez-Torrecillas (Main researcher).
11
12MAIN PROCEDURES:
13Gweights(r);              compute weights for a compatible ordering in a G-algebra,
14weightedRing(r);          change the ordering of a ring to a weighted one,
15ndcond();                 the ideal of non-degeneracy conditions in G-algebra,
16Weyl([p]);                create Weyl algebra structure in a basering (two different realizations),
17makeWeyl(n, [p]);         return n-th Weyl algebra in (x(i),D(i)) presentation,
18makeHeisenberg(N, [p,d]); return n-th Heisenberg algebra in (x(i),y(i),h) realization,
19Exterior();               return qring, the exterior algebra of a basering,
20findimAlgebra(M,[r]);     create finite dimensional algebra structure from the basering and the multiplication matrix M,
21SuperCommutative([b,e, Q]);  return qring, the super-commutative algebra over a basering,
22rightStd(I);              compute a right Groebner basis of an ideal,
23
24AUXILIARY PROCEDURES:
25ncRelations(r);         recover the non-commutative relations of a G-algebra,
26isCentral(p);           check for the commutativity of a polynomial in the G-algebra,
27isNC();                 check whether basering is noncommutative,
28UpOneMatrix(N);         return NxN matrix with 1's in the whole upper triagle,
29AltVarStart()           return first alternating variable of a super-commutative algebra,
30AltVarEnd()             return last alternating variable of a super-commutative algebra,
31IsSCA()                 checks whether current ring is a super-commutative algebra
32";
33
34
35LIB "ring.lib"; // for rootofUnity
36LIB "poly.lib"; // for newtonDiag
37LIB "general.lib"; // for sort
38// LIB "ncalg.lib";
39
40///////////////////////////////////////////////////////////////////////////////
41
42// This procedure computes a weights vector for a G-algebra r
43
44proc Gweights(def r)
45"USAGE:   Gweights(r); r a ring or a square matrix
46RETURN:   intvec
47PURPOSE: compute the weight vector for the following G-algebra:
48@*       for r itself, if it is of the type ring,
49@*       or for a G-algebra, defined by the square polynomial matrix r
50THEORY:   @code{Gweights} returns a vector, which must be used to redefine the G-algebra. If the input is a matrix and the output is the zero vector then there is not a G-algebra structure associated to these relations with respect to the given variables. Another possibility is to use @code{weightedRing} to obtain directly the G-algebra with the new weighted ordering.
51EXAMPLE: example Gweights; shows examples
52SEE ALSO: weightedRing
53"{
54  matrix tails;
55  int novalid=0;
56  if (typeof(r)=="ring") //a ring is admissible as input
57  {
58    setring r;
59    def l = ncRelations(r);
60    tails = l[2]; // l=C,D we need D, the tails of the relations
61  }
62  else
63  {
64    if ( (typeof(r)=="matrix") || (typeof(r)=="intmat") )
65    {
66      if ( nrows(r)==ncols(r) ) //the input is a square matrix
67      {
68        tails = matrix(r);
69      }
70      else
71      {
72        novalid = 1;
73      }
74    }
75    else
76    {
77      novalid=1;
78    }
79  }
80  if (novalid==0)
81  {
82    intmat IM = SimplMat(tails);
83    if ( size(IM)>1 )
84    {
85      int n  = ncols(tails);
86      int m  = nrows(IM)-1;
87      int m1 = 0;
88      int m2 = m;
89      int m3 = 0;
90      ring simplexring=(real,10),(x),lp;// The simplex procedure requires a basering of this type
91      matrix M = IM;
92      list sol = simplex (M,m,n,m1,m2,m3);
93      return(weightvector(sol));
94    }
95    else
96    {
97      "Invalid input"; //usually because the input is a one variable ring
98      return();
99    }
100  }
101  else
102  {
103    "The input must be a ring or a square matrix";
104    return();
105  }
106}
107example
108{
109  "EXAMPLE:";echo=2;
110  ring r = (0,q),(a,b,c,d),lp;
111  matrix C[4][4];
112  C[1,2]=q; C[1,3]=q; C[1,4]=1; C[2,3]=1; C[2,4]=q; C[3,4]=q;
113  matrix D[4][4];
114  D[1,4]=(q-1/q)*b*c;
115  ncalgebra(C,D);
116  r;
117  Gweights(r);
118  Gweights(D);
119}
120
121///////////////////////////////////////////////////////////////////////////////
122
123// This procedure take a ring r, call to Gweights(r) and use the output
124// of Gweights(r) to make a change of order in r
125// The output is a new ring, equal to r but the order
126// r must be a G-algebra
127
128proc weightedRing(def r)
129"USAGE:   weightedRing(r); r a ring
130RETURN:  ring
131PURPOSE:  equip the variables of a ring with such weights,that the relations of new ring (with weighted variables) satisfies the ordering condition for G-algebras
132NOTE:    activate this ring with the \"setring\" command
133EXAMPLE: example weightedRing; shows examples
134SEE ALSO: Gweights
135"{
136  def wv=Gweights(r);
137  if (typeof(wv)=="intvec")
138  {
139    setring r;
140    int n=nvars(r);
141    // Generating an nxn-intmat order
142    intmat m[n][n];
143    m[1,1]=wv[1];
144    int i;
145    for (i=2; i<=n; i++)
146    {
147      m[1,i]=wv[i];
148      m[i,n+2-i]=1;
149    }
150    // End of generation.
151    def lr=ncRelations(r);
152    string newringstring="ring newring=("+charstr(r)+"),("+varstr(r)+"),M("+string(m)+")";
153    execute (newringstring);
154    def lnewring=imap(r,lr);
155    ncalgebra(lnewring[1],lnewring[2]);
156    return(newring);
157  }
158  else
159  {
160    "Invalid input.";//usually because the input is a one variable ring
161    return();
162  }
163}
164example
165{
166  "EXAMPLE:";echo=2;
167  ring r = (0,q),(a,b,c,d),lp;
168  matrix C[4][4];
169  C[1,2]=q; C[1,3]=q; C[1,4]=1; C[2,3]=1; C[2,4]=q; C[3,4]=q;
170  matrix D[4][4];
171  D[1,4]=(q-1/q)*b*c;
172  ncalgebra(C,D);
173  r;
174  def t=weightedRing(r);
175  setring t; t;
176}
177
178///////////////////////////////////////////////////////////////////////////////
179
180// This procedure computes ei+ej-f with f running in Newton(pij) and deletes the zero rows
181
182static proc Cij(intmat M, int i,j)
183{
184  M=(-1)*M;
185  int nc=ncols(M);
186  intvec N;
187  int k;
188  for (k=1; k<=nrows(M); k++)
189  {
190    M[k,i]=M[k,i]+1;
191    M[k,j]=M[k,j]+1;
192    if (intvec(M[k,1..nc])!=0)
193    {
194      N=N,intvec(M[k,1..nc]);
195    } // we only want non-zero rows
196  }
197  if (size(N)>1)
198  {
199    N=N[2..size(N)]; // Deleting the zero added in the definition of N
200    M=intmat(N,size(N)/nc,nc); // Conversion from vector to matrix
201  }
202  else
203  {
204    intmat M[1][1]=0;
205  }
206  return (M);
207}
208
209///////////////////////////////////////////////////////////////////////////////
210
211// This procedure run over the matrix of pij calculating Cij
212
213static proc Ct(matrix P)
214{
215  int    k = ncols(P);
216  intvec T = 0;
217  int    i,j;
218//  int notails=1;
219  def S;
220  for (j=2; j<=k; j++)
221  {
222    for (i=1; i<j; i++)
223    {
224      if ( P[i,j] != 0 )
225      {
226//        notails=0;
227        S = newtonDiag(P[i,j]);
228        S = Cij(S,i,j);
229        if ( size(S)>1 )
230        {
231          T = T,S;
232        }
233      }
234    }
235  }
236  if ( size(T)==1 )
237  {
238    intmat C[1][1] = 0;
239  }
240  else
241  {
242    T=T[2..size(T)]; // Deleting the zero added in the definition of T
243    intmat C = intmat(T,size(T)/k,k); // Conversion from vector to matrix
244  }
245  return (C);
246}
247
248///////////////////////////////////////////////////////////////////////////////
249
250// The purpose of this procedure is to produce the input matrix required by simplex procedure
251
252static proc SimplMat(matrix P)
253{
254  intmat C=Ct(P);
255  if (size(C)>1)
256  {
257    int r = nrows(C);
258    int n = ncols(C);
259    int f = 1+n+r;
260    intmat M[f][n+1]=0;
261    int i;
262    for (i=2; i<=(n+1); i++)
263    {
264      M[1,i]=-1; // (0,-1,-1,-1,...) objective function in the first row
265    }
266    for (i=2; i<=f; i++) {M[i,1]=1;} // All the independent terms are 1
267    for (i=2; i<=(n+1); i++) {M[i,i]=-1;} // wi>=1 is an identity matrix
268    M[(n+2)..f,2..(n+1)]=(-1)*intvec(C); // <wi,a> >= 1, a in C ...
269  }
270  else
271  {
272    int n = ncols(P);
273    int f = 1+n;
274    intmat M[f][n+1]=0;
275    int i;
276    for (i=2; i<=(n+1); i++) {M[1,i]=-1;} // (0,-1,-1,-1,...) objective function in the first row
277    for (i=2; i<=f; i++) {M[i,1]=1;} // All the independent terms are 1
278    for (i=2; i<=(n+1); i++) {M[i,i]=-1;} // wi>=1 is an identity matrix
279  }
280  return (M);
281}
282
283///////////////////////////////////////////////////////////////////////////////
284
285// This procedure generates a nice output of the simplex method consisting of a vector
286// with the solutions. The vector is ordered.
287
288static proc weightvector(list l)
289"ASSUME:  l is the output of simplex.
290RETURN: if there is a solution, an intvec with it will be returned"
291{
292  matrix m=l[1];
293  intvec nv=l[3];
294  int sol=l[2];
295  int rows=nrows(m);
296  int N=l[6];
297  intmat wv[1][N]=0;
298  int i;
299  if (sol)
300  {
301    "no solution satisfies the given constraints";
302  }
303  else
304  {
305    for ( i = 2; i <= rows; i++ )
306    {
307      if ( nv[i-1] <= N )
308      {
309        wv[1,nv[i-1]]=int(m[i,1]);
310      }
311    }
312  }
313  return (intvec(wv));
314}
315
316
317
318///////////////////////////////////////////////////////////////////////////////
319
320// This procedure recover the non-conmutative relations (matrices C and D)
321
322proc ncRelations(def r)
323"USAGE:   ncRelations(r); r a ring
324RETURN:  list L with two elements, both elements are of type matrix:
325@*         L[1] = matrix of coefficients C,
326@*         L[2] = matrix of polynomials D
327PURPOSE: recover the noncommutative relations via matrices C and D from
328a noncommutative ring
329SEE ALSO: ringlist, G-algebras
330EXAMPLE: example ncRelations; shows examples
331"{
332  list l;
333  if (typeof(r)=="ring")
334  {
335    int n=nvars(r);
336    matrix C[n][n]=0;
337    matrix D[n][n]=0;
338    poly f; poly g;
339    if (n>1)
340    {
341      int i,j;
342      for (i=2; i<=n; i++)
343      {
344        for (j=1; j<i; j++)
345        {
346          f=var(i)*var(j); // yx=c*xy+...
347          g=var(j)*var(i); // xy
348          while (C[j,i]==0)
349          {
350            if (leadmonom(f)==leadmonom(g))
351            {
352              C[j,i]=leadcoef(f);
353              D[j,i]=D[j,i]+f-lead(f);
354            }
355            else
356            {
357              D[j,i]=D[j,i]+lead(f);
358              f=f-lead(f);
359            }
360          }
361        }
362      }
363      l=C,D;
364    }
365    else { "The ring must have two or more variables"; }
366  }
367  else { "The input must be of a type ring";}
368  return (l);
369}
370example
371{
372  "EXAMPLE:";echo=2;
373  ring r = 0,(x,y,z),dp;
374  matrix C[3][3]=0,1,2,0,0,-1,0,0,0;
375  print(C);
376  matrix D[3][3]=0,1,2y,0,0,-2x+y+1;
377  print(D);
378  ncalgebra(C,D);
379  r;
380  def l=ncRelations(r);
381  print (l[1]);
382  print (l[2]);
383}
384
385///////////////////////////////////////////////////////////////////////////////
386
387proc findimAlgebra(matrix M, list #)
388"USAGE:   findimAlgebra(M,[r]); M a matrix, r an optional ring
389RETURN:  nothing
390PURPOSE: define a finite dimensional algebra structure on a ring
391NOTE:  the matrix M is used to define the relations x(j)*x(i) = M[i,j] in the
392basering (by default) or in the optional ring r.
393@* The procedure equips the ring with the noncommutative structure.
394@* The procedure exports the ideal (not a two-sided Groebner basis!), called @code{fdQuot}, for further qring definition.
395THEORY: finite dimensional algebra can be represented as a factor algebra
396of a G-algebra modulo certain two-sided ideal. The relations of a f.d. algebra are thus naturally divided into two groups: firstly, the relations
397on the variables of the ring, making it into G-algebra and the rest of them, which constitute the ideal which will be factored out.
398EXAMPLE: example findimAlgebra; shows examples
399"
400{
401  if (size(#) >0)
402  {
403    if ( typeof(#[1])!="ring" ) { return();}
404    else
405    {
406      def @R1 = #[1];
407      setring @R1;
408    }
409  }
410  int i,j;
411  int n=nvars(basering);
412  poly p;
413  ideal I;
414  number c;
415  matrix C[n][n];
416  matrix D[n][n];
417  for (i=1; i<=n; i++)
418  {
419    for (j=i; j<=n; j++)
420    {
421      p=var(i)*var(j)-M[i,j];
422      if ( (size(I)==1) && (I[1]==0) )   { I=p; }
423      else { I=I,p; }
424      if (j>i)
425      {
426        if ((M[i,j]!=0) && (M[j,i]!=0))
427        {
428          c = leadcoef(M[j,i])/leadcoef(M[i,j]);
429        }
430        else
431        {
432          c = 1;
433        }
434        C[i,j]=c;
435        D[i,j]= - M[j,i] +c*M[i,j];
436      }
437    }
438  }
439  ncalgebra(C,D);
440  ideal fdQuot = I;
441  export fdQuot;
442}
443example
444{
445  "EXAMPLE:";echo=2;
446  ring r=(0,a,b),(x(1..3)),dp;
447  matrix S[3][3];
448  S[2,3]=a*x(1); S[3,2]=-b*x(1);
449  findimAlgebra(S);
450  fdQuot = twostd(fdQuot);
451  qring Qr = fdQuot;
452  Qr;
453}
454
455///////////////////////////////////////////////////////////////////////////////
456
457proc isCentral(poly p, list #)
458"USAGE:   isCentral(p); p poly
459RETURN:  int, 1 if p commutes with all variables and 0 otherwise
460PURPOSE: check whether p is central in a basering (that is, commutes with every generator of a ring)
461NOTE: if @code{printlevel} > 0, the procedure displays intermediate information (by default, @code{printlevel}=0 )
462EXAMPLE: example isCentral; shows examples
463"{
464  //v an integer (with v!=0, procedure will be verbose)
465  int N = nvars(basering);
466  int in;
467  int flag = 1;
468  poly   q = 0;
469  for (in=1; in<=N; in++)
470  {
471    q = p*var(in)-var(in)*p;
472    if (q!=0)
473    {
474      if ( (size(#) >0 ) || (printlevel>0) )
475      {
476        "Noncentral at:", var(in);
477      }
478      flag = 0;
479    }
480  }
481  return(flag);
482}
483example
484{
485  "EXAMPLE:";echo=2;
486  ring r=0,(x,y,z),dp;
487  matrix D[3][3]=0;
488  D[1,2]=-z;
489  D[1,3]=2*x;
490  D[2,3]=-2*y;
491  ncalgebra(1,D); // this is U(sl_2)
492  poly c = 4*x*y+z^2-2*z;
493  printlevel = 0;
494  isCentral(c);
495  poly h = x*c;
496  printlevel = 1;
497  isCentral(h);
498}
499
500///////////////////////////////////////////////////////////////////////////////
501
502proc UpOneMatrix(int N)
503"USAGE:   UpOneMatrix(n); n an integer
504RETURN:  intmat
505PURPOSE: compute an  n x n matrix with 1's in the whole upper triangle
506NOTE: helpful for setting noncommutative algebras with complicated
507coefficient matrices
508EXAMPLE: example UpOneMatrix; shows examples
509"{
510  int ii,jj;
511  intmat U[N][N]=0;
512  for (ii=1;ii<N;ii++)
513  {
514    for (jj=ii+1;jj<=N;jj++)
515    {
516      U[ii,jj]=1;
517    }
518  }
519  return(U);
520}
521example
522{
523  "EXAMPLE:";echo=2;
524  ring   r = (0,q),(x,y,z),dp;
525  matrix C = UpOneMatrix(3);
526  C[1,3]   = q;
527  print(C);
528  ncalgebra(C,0);
529  r;
530}
531
532///////////////////////////////////////////////////////////////////////////////
533proc ndcond(list #)
534"USAGE:   ndcond();
535RETURN:  ideal
536PURPOSE: compute the non-degeneracy conditions of the basering
537NOTE: if @code{printlevel} > 0, the procedure displays intermediate information (by default, @code{printlevel}=0 )
538EXAMPLE: example ndcond; shows examples
539"
540{
541  // internal documentation, for tests etc
542  // 1st arg: v an optional integer (if v!=0, will be verbose)
543  // if the second argument is given, produces ndc wrt powers x^N
544  int N = 1;
545  int Verbose = 0;
546  if ( size(#)>=1 ) { Verbose = int(#[1]); }
547  if ( size(#)>=2 ) { N = int(#[2]); }
548  Verbose = ((Verbose) || (printlevel>0));
549  int cnt = 1;
550  int numvars = nvars(basering);
551  int a,b,c;
552  poly p = 1;
553  ideal res = 0;
554  for (cnt=1; cnt<=N; cnt++)
555  {
556    if (Verbose) { "Processing degree :",cnt;}
557    for (a=1; a<=numvars-2; a++)
558    {
559      for (b=a+1; b<=numvars-1; b++)
560      {
561        for(c=b+1; c<=numvars; c++)
562        {
563          p = (var(c)^cnt)*(var(b)^cnt);
564          p = p*(var(a)^cnt);
565          p = p-(var(c)^cnt)*((var(b)^cnt)*(var(a)^cnt));
566          if (Verbose) {a,".",b,".",c,".";}
567          if (p!=0)
568          {
569            if ( res==0 )
570            {
571              res[1] = p;
572            }
573            else
574            {
575              res = res,p;
576            }
577            if (Verbose) { "failed:",p; }
578          }
579        }
580      }
581    }
582    if (Verbose) { "done"; }
583  }
584  return(res);
585}
586example
587{
588  "EXAMPLE:";echo=2;
589  ring r = (0,q1,q2),(x,y,z),dp;
590  matrix C[3][3];
591  C[1,2]=q2; C[1,3]=q1; C[2,3]=1;
592  matrix D[3][3];
593  D[1,2]=x; D[1,3]=z;
594  ncalgebra(C,D);
595  r;
596  ideal j=ndcond(); // the silent version
597  j;
598  printlevel=1;
599  ideal i=ndcond(); // the verbose version
600  i;
601}
602
603
604///////////////////////////////////////////////////////////////////////////////
605proc Weyl(list #)
606"USAGE:   Weyl([p]); p an optional integer
607RETURN:  nothing
608PURPOSE: create a Weyl algebra structure on a basering
609NOTE: suppose the number of variables of a basering is 2k.
610(if this number is odd, an error message will be returned)
611@*    by default, the procedure treats first k variables as coordinates x_i and the last k as differentials d_i
612@*    if nonzero p is given, the procedure treats 2k variables of a basering as k pairs (x_i,d_i), i.e. variables with odd numbers are treated as coordinates and with even numbers as differentials
613SEE ALSO: makeWeyl
614EXAMPLE: example Weyl; shows examples
615"
616{
617  //there are two possibilities for choosing the PBW basis.
618  //The variables have names x(i) for coordinates and d(i) for partial
619  // differentiations. By default, the procedure
620  //creates a ring, where the variables are ordered as x(1..n),d(1..n).  the
621  // tensor product-like realization x(1),d(1),x(2),d(2),... is used.
622  string rname=nameof(basering);
623  if ( rname == "basering") // i.e. no ring has been set yet
624  {
625    "You have to call the procedure from the ring";
626    return();
627  }
628  int @chr = 0;
629  if ( size(#) > 0 )
630  {
631    if ( typeof( #[1] ) == "int" )
632    {
633      @chr = #[1];
634    }
635  }
636  int nv = nvars(basering);
637  int N = nv div 2;
638  if ((nv % 2) != 0)
639  {
640    "Cannot create Weyl structure for an odd number of generators";
641    return();
642  }
643  matrix @D[nv][nv];
644  int i;
645  for ( i=1; i<=N; i++ )
646  {
647    if ( @chr==0 ) // default
648    {
649      @D[i,N+i]=1;
650    }
651    else
652    {
653      @D[2*i-1,2*i]=1;
654    }
655  }
656  ncalgebra(1,@D);
657  return();
658}
659example
660{
661  "EXAMPLE:";echo=2;
662  ring A1=0,(x(1..2),d(1..2)),dp;
663  Weyl();
664  A1;
665  kill A1;
666  ring B1=0,(x1,d1,x2,d2),dp;
667  Weyl(1);
668  B1;
669}
670
671///////////////////////////////////////////////////////////////////////////////
672proc makeHeisenberg(int N, list #)
673"USAGE:  makeHeisenberg(n, [p,d]); int n (setting 2n+1 variables), optional int p (field characteristic), optional int d (power of h in the commutator)
674RETURN: nothing
675PURPOSE: create an n-th Heisenberg algebra in the variables x(1),y(1),...,x(n),y(n),h
676SEE ALSO: makeWeyl
677NOTE: activate this ring with the \"setring\" command
678EXAMPLE: example makeHeisenberg; shows examples
679"
680{
681  int @chr = 0;
682  int @deg = 1;
683  if ( size(#) > 0 )
684  {
685    if ( typeof( #[1] ) == "int" )
686    {
687      @chr = #[1];
688    }
689  }
690  if ( size(#) > 1 )
691  {
692    if ( typeof( #[2] ) == "int" )
693    {
694      @deg = #[2];
695      if (@deg <1) { @deg = 1; }
696    }
697  }
698  ring @@r=@chr,(x(1..N),y(1..N),h),lp;
699  matrix D[2*N+1][2*N+1];
700  int i;
701  for (i=1;i<=N;i++)
702  {
703    D[i,N+i]=h^@deg;
704  }
705  ncalgebra(1,D);
706  return(@@r);
707}
708example
709{
710  "EXAMPLE:";echo=2;
711  def a = makeHeisenberg(2);
712  setring a;   a;
713  def H3 = makeHeisenberg(3, 7, 2);
714  setring H3;  H3;
715}
716
717///////////////////////////////////////////////////////////////////////////////
718proc SuperCommutative(list #)
719"USAGE:   SuperCommutative([b,[e, [Q]]]);
720RETURN:  qring
721PURPOSE:  create the super-commutative algebra over a basering,
722NOTE:  activate this qring with the \"setring\" command
723THEORY: given a basering, this procedure introduces the anticommutative relations x(j)x(i)=-x(i)x(j) for all e>=j>i>=b,
724@* moreover, creates a factor algebra modulo the two-sided ideal, generated by x(b)^2, ..., x(e)^2[ + Q]
725EXAMPLE: example SuperCommutative; shows examples
726"
727{
728  string rname=nameof(basering);
729  if ( rname == "basering") // i.e. no ring has been set yet
730  {
731    ERROR("You have to call the procedure from the ring");
732    return();
733  }
734  int N = nvars(basering);
735
736  int b = 1;
737  int e = N;
738
739        def saveRing = basering;
740  ideal Q = 0;
741
742  if(size(#)>0)
743  {
744    if(typeof(#[1]) != "int")
745    {
746      ERROR("First argument 'b' must be an integer!");
747      return();
748    }
749    b = #[1];
750  }
751
752        if(size(#)>1)
753        {
754          if(typeof(#[2]) != "int")
755          {
756            ERROR("Last argument 'e' must be an integer!");
757            return();
758          }
759          e = #[2];
760        }
761
762        if(size(#)>2)
763        {
764          if(typeof(#[3]) != "ideal")
765          {
766            ERROR("Last argument 'Q' must be an ideal!");
767            return();
768          }
769          Q = #[3];
770        }
771       
772  list CurrRing = ringlist(basering);
773  def @R = ring(CurrRing);
774  setring @R; // @R;
775
776  matrix @E = UpOneMatrix(N);
777
778  int i, j;
779
780  for ( i = b; i < e; i++ )
781  {
782    for ( j = i+1; j <= e; j++ )
783    {
784      @E[i, j] = -1;
785    }
786  }
787
788  ncalgebra(@E, 0);
789
790        ideal Q = fetch(saveRing, Q);
791        j = ncols(Q) + 1;
792
793  for ( i=e; i>=b; i--, j++ )
794  {
795    Q[j] = var(i)^2;
796  }
797  Q = twostd(Q);
798  qring @EA = Q;
799
800//   "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "].";
801  return(@EA);
802}
803example
804{
805  "EXAMPLE:";echo=2;
806  ring R = 0,(x(1..4)),dp; // global!
807  def ER = SuperCommutative(); // the same as Exterior (b = 1, e = N)
808  setring ER; ER;
809  "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "].";
810  kill R; kill ER;
811  ring R = 0,(x(1..4)),(lp(1), dp(3)); // global!
812  def ER = SuperCommutative(2); // b = 2, e = N
813  setring ER; ER;
814  "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "].";
815  kill R; kill ER;
816  ring R = 0,(x(1..6)),(ls(2), dp(2), lp(2)); // local!
817  def ER = SuperCommutative(3,4); // b = 3, e = 4
818  setring ER; ER;
819  "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "].";
820  kill R; kill ER;
821}
822
823
824static proc ParseSCA()
825"
826RETURN: list {AltVarStart, AltVarEnd} is currRing is SCA, returns undef otherwise.
827"
828{
829  def saveRing = basering;
830  list L = ringlist(saveRing);
831
832  if( size(L)!=6 )
833  {
834    return("The current ring is commutative!");
835  }
836
837  module D = simplify(L[6], 2 + 4);
838
839  if( size(D)>0 )
840  {
841    return("The current ring is not SCA! (D!=0)");
842  }
843
844  int i, j;
845  int N = nvars(saveRing);
846
847  int b = N+1;
848  int e =  -1;
849
850  matrix C = L[5];
851  poly c;
852
853  for( i = 1; i < N; i++ )
854  {
855    for( j = i+1; j <= N; j++ )
856    {
857      c = C[i, j];
858
859      if( c == -1 )
860      {
861        if(i < b)
862        {
863                b = i;         
864        }
865       
866        if(j > e)
867        {
868                e = j;         
869        }
870      } else
871      { // should commute
872        if( c!=1 )
873        {
874          return("The current ring is not SCA! (C["+ string(i)+"," + string(j)+"]!=1)");
875        }
876      }
877    }
878  }
879
880  if( (b > N) || (e < 1))
881  {
882    return("The current ring is commutative!");
883  }
884
885  for( i = 1; i < N; i++ )
886  {
887    for( j = i+1; j <= N; j++ )
888    {
889      c = C[i, j];
890
891      if( (b <= i) && (j <= e) ) // S <= i < j <= E
892      { // anticommutative part
893        if( c!= -1 )
894        {
895          return("The current ring is not SCA! (C["+ string(i)+"," + string(j)+"]!=-1)");
896        }
897      } else
898      { // should commute
899        if( c!=1 )
900        {
901          return("The current ring is not SCA! (C["+ string(i)+"," + string(j)+"]!=1)");
902        }
903      }
904    }
905  }
906
907  list LL = list(L[1], L[2], L[3], ideal(0), L[5], L[6]);
908  ideal Q = L[4];
909//  "Q = ", string(Q);
910
911  def  E = ring(LL);
912  setring E; // not a qring!
913//  E;
914
915        ideal Q = fetch(saveRing, Q); // should belong to E!
916        Q = twostd(Q);
917
918//  "Q = ", string(Q);
919
920  for( i = b; i <= e; i++ )
921  {
922    if( NF(var(i)^2, Q) != 0 )
923    {
924        setring saveRing;
925      return("The current ring is not SCA! (Wrong quotient ideal)");
926    }
927  }
928
929        ////////////////////////////////////////////////////////////////////////
930  // ok. it is a SCA!!!
931
932  ideal QQ;
933
934  for( i = e; i >= b; i-- )
935  {
936    QQ[i - b + 1] = var(i)^2;
937  }
938
939  QQ = twostd(QQ);
940  Q = simplify(NF(Q, QQ),  1 + 2 + 4);
941
942  setring saveRing;
943
944  ideal QQ = fetch(E, Q);
945
946  return(list(b, e, QQ));
947}
948
949
950
951
952///////////////////////////////////////////////////////////////////////////////
953proc AltVarStart()
954"USAGE:   AltVarStart();
955RETURN:  int
956PURPOSE:  returns the number of the first alternating variable of basering
957NOTE:  basering should be a super-commutative algebra!
958EXAMPLE: example AltVarStart; shows examples
959"
960{
961  def l = ParseSCA();
962
963  if( typeof(l) != "string" )
964  {
965    return(l[1]);
966  }
967
968  ERROR(l);
969  return();
970}
971example
972{
973  "EXAMPLE:";echo=2;
974  ring R = 0,(x(1..4)),dp; // global!
975  def ER = SuperCommutative(2); // (b = 2, e = N)
976  setring ER; ER;
977  "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "].";
978}
979
980///////////////////////////////////////////////////////////////////////////////
981proc AltVarEnd()
982"USAGE:   AltVarStart();
983RETURN:  int
984PURPOSE:  returns the number of the last alternating variable of basering
985NOTE:  basering should be a super-commutative algebra!
986EXAMPLE: example AltVarEnd; shows examples
987"
988{
989  def l = ParseSCA();
990
991  if( typeof(l) != "string" )
992  {
993    return(l[2]);
994  }
995
996  ERROR(l);
997  return();
998}
999example
1000{
1001  "EXAMPLE:";echo=2;
1002  ring R = 0,(x(1..4)),dp; // global!
1003  def ER = SuperCommutative(2); // (b = 2, e = N)
1004  setring ER; ER;
1005  "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "].";
1006}
1007
1008///////////////////////////////////////////////////////////////////////////////
1009proc IsSCA()
1010"USAGE:   IsSCA();
1011RETURN:  int
1012PURPOSE:  returns 1 if basering is a supercommutative algebra and 0 otherwise.
1013NOTE:     no error message!
1014EXAMPLE: example IsSCA; shows examples
1015"
1016{
1017  def l = ParseSCA();
1018
1019  if( typeof(l) != "string" )
1020  {
1021    return(1);
1022  }
1023
1024  return(0);
1025}
1026example
1027{
1028  "EXAMPLE:";echo=2;
1029/////////////////////////////////////////////////////////////////////
1030  ring R = 0,(x(1..4)),dp; // commutative
1031  if(IsSCA())
1032    { "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "]."; }
1033  else
1034    { "Not a supercommutative algebra!!!"; }
1035  kill R;
1036/////////////////////////////////////////////////////////////////////
1037  ring R = 0,(x(1..4)),dp;
1038  ncalgebra(1, 0); // still commutative!
1039  if(IsSCA())
1040    { "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "]."; }
1041  else
1042    { "Not a supercommutative algebra!!!"; }
1043  kill R;
1044/////////////////////////////////////////////////////////////////////
1045  ring R = 0,(x(1..4)),dp;
1046  list CurrRing = ringlist(R);
1047  def ER = ring(CurrRing);
1048  setring ER; // R;
1049
1050  matrix E = UpOneMatrix(nvars(R));
1051
1052  int i, j; int b = 2; int e = 3;
1053
1054  for ( i = b; i < e; i++ )
1055  {
1056    for ( j = i+1; j <= e; j++ )
1057    {
1058      E[i, j] = -1;
1059    }
1060  }
1061
1062  ncalgebra(E,0);
1063  if(IsSCA())
1064    { "Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "]."; }
1065  else
1066    { "Not a supercommutative algebra!!!"; }
1067  kill R;
1068  kill ER;
1069/////////////////////////////////////////////////////////////////////
1070  ring R = 0,(x(1..4)),dp;
1071  def ER = SuperCommutative(2); // (b = 2, e = N)
1072  setring ER; ER;
1073  if(IsSCA())
1074    { "This is a SCA! Alternating variables: [", AltVarStart(), ",", AltVarEnd(), "]."; }
1075  else
1076    { "Not a supercommutative algebra!!!"; }
1077  kill R;
1078  kill ER;
1079
1080}
1081
1082
1083
1084///////////////////////////////////////////////////////////////////////////////
1085proc Exterior(list #)
1086"USAGE:   Exterior();
1087RETURN:  qring
1088PURPOSE:  create the exterior algebra of a basering
1089NOTE:  activate this qring with the \"setring\" command
1090THEORY: given a basering, this procedure introduces the anticommutative relations x(j)x(i)=-x(i)x(j) for all j>i,
1091@* moreover, creates a factor algebra modulo the two-sided ideal, generated by x(i)^2 for all i
1092EXAMPLE: example Exterior; shows examples
1093"
1094{
1095  string rname=nameof(basering);
1096  if ( rname == "basering") // i.e. no ring has been set yet
1097  {
1098    "You have to call the procedure from the ring";
1099    return();
1100  }
1101  int N = nvars(basering);
1102  string NewRing = "ring @R=("+charstr(basering)+"),("+varstr(basering)+"),("+ordstr(basering)+");";
1103  execute(NewRing);
1104  matrix @E = UpOneMatrix(N);
1105  @E = -1*(@E);
1106  ncalgebra(@E,0);
1107  int i;
1108  ideal Q;
1109  for ( i=1; i<=N; i++ )
1110  {
1111    Q[i] = var(i)^2;
1112  }
1113  Q = twostd(Q);
1114  qring @EA = Q;
1115  return(@EA);
1116}
1117example
1118{
1119  "EXAMPLE:";echo=2;
1120  ring R = 0,(x(1..3)),dp;
1121  def ER = Exterior();
1122  setring ER;
1123  ER;
1124}
1125
1126///////////////////////////////////////////////////////////////////////////////
1127proc makeWeyl(int n, list #)
1128"USAGE:  makeWeyl(n,[p]); n an integer, n>0; p an optional integer (field characteristic)
1129RETURN:  ring
1130PURPOSE: create an n-th Weyl algebra
1131NOTE:    activate this ring with the \"setring\" command.
1132@*       The presentation of an n-th Weyl algebra is classical: D(i)x(i)=x(i)D(i)+1,
1133@*       where x(i) correspond to coordinates and D(i) to partial differentiations, i=1,...,n.
1134SEE ALSO: Weyl
1135EXAMPLE: example makeWeyl; shows examples
1136"{
1137  if (n<1)
1138  {
1139    print("Incorrect input");
1140    return();
1141  }
1142  int @p = 0;
1143  if ( size(#) > 0 )
1144  {
1145    if ( typeof( #[1] ) == "int" )
1146    {
1147      @p = #[1];
1148    }
1149  }
1150  if (n ==1)
1151  {
1152    ring @rr = @p,(x,D),dp;
1153  }
1154  else
1155  {
1156    ring @rr = @p,(x(1..n),D(1..n)),dp;
1157  }
1158  setring @rr;
1159  Weyl();
1160  return(@rr);
1161}
1162example
1163{ "EXAMPLE:"; echo = 2;
1164   def a = makeWeyl(3);
1165   setring a;
1166   a;
1167}
1168
1169//////////////////////////////////////////////////////////////////////
1170proc isNC()
1171"USAGE:   isNC();
1172PURPOSE: check whether a basering is commutative or not
1173RETURN:   int, 1 if basering is noncommutative and 0 otherwise
1174EXAMPLE: example isNC; shows examples
1175"{
1176  string rname=nameof(basering);
1177  if ( rname == "basering") // i.e. no ring has been set yet
1178  {
1179    "You have to call the procedure from the ring";
1180    return();
1181  }
1182  int n = nvars(basering);
1183  int i,j;
1184  poly p;
1185  for (i=1; i<n; i++)
1186  {
1187    for (j=i+1; j<=n; j++)
1188    {
1189      p = var(j)*var(i) - var(i)*var(j);
1190      if (p!=0) { return(1);}
1191    }
1192  }
1193  return(0);
1194}
1195example
1196{ "EXAMPLE:"; echo = 2;
1197   def a = makeWeyl(2);
1198   setring a;
1199   isNC();
1200   kill a;
1201   ring r = 17,(x(1..7)),dp;
1202   isNC();
1203   kill r;
1204}
1205
1206
1207proc rightStd(def I)
1208"USAGE:  rightStd(I); I an ideal/ module
1209PURPOSE: compute a right Groebner basis of I
1210RETURN:  the same type as input
1211EXAMPLE: example rightStd; shows examples
1212"
1213{
1214  def A = basering;
1215  def Aopp = opposite(A);
1216  setring Aopp;
1217  def Iopp = oppose(A,I);
1218  def Jopp = groebner(Iopp);
1219  setring A;
1220  def J = oppose(Aopp,Jopp);
1221  return(J);
1222}
1223example
1224{ "EXAMPLE:"; echo = 2;
1225  LIB "ncalg.lib";
1226  def A = makeUsl(2);
1227  setring A;
1228  ideal I = e2,f;
1229  option(redSB);
1230  option(redTail);
1231  ideal LI = std(I);
1232  LI;
1233  ideal RI = rightStd(I);
1234  RI;
1235}
1236
1237
1238proc rightSyz(def I)
1239"USAGE:  rightSyz(I); I an ideal/ module
1240PURPOSE: compute a right syzygy module of I
1241RETURN:  the same type as input
1242EXAMPLE: example rightSyz; shows examples
1243"
1244{
1245  def A = basering;
1246  def Aopp = opposite(A);
1247  setring Aopp;
1248  def Iopp = oppose(A,I);
1249  def Jopp = syz(Iopp);
1250  setring A;
1251  def J = oppose(Aopp,Jopp);
1252  return(J);
1253}
1254example
1255{ "EXAMPLE:"; echo = 2;
1256  ring r = 0,(x,d),dp;
1257  ncalgebra(1,1); // the first Weyl algebra
1258  ideal I = x,d;
1259  module LS = syz(I);
1260  print(LS);
1261  module RS = rightSyz(I);
1262  print(RS);
1263}
1264
1265
1266proc rightNF(def v, def M)
1267"USAGE:  rightNF(I); v a poly/vector, M an ideal/module
1268PURPOSE: compute a right normal form of v w.r.t. M
1269RETURN:  poly/vector (as of the 1st argument)
1270EXAMPLE: example rightNF; shows examples
1271"
1272{
1273  def A = basering;
1274  def Aopp = opposite(A);
1275  setring Aopp;
1276  def vopp = oppose(A,v);
1277  def Mopp = oppose(A,M);
1278  Mopp = std(Mopp);
1279  def wopp = NF(vopp,Mopp);
1280  setring A;
1281  def w    = oppose(Aopp,wopp);
1282  w = simplify(w,2); // skip zeros in ideal/module
1283  return(w);
1284}
1285example
1286{ "EXAMPLE:"; echo = 2;
1287  LIB "ncalg.lib";
1288  ring r = 0,(x,d),dp;
1289  ncalgebra(1,1); // Weyl algebra
1290  ideal I = x; I = std(I);
1291  poly  p = x*d+1;
1292  NF(p,I); // left normal form
1293  rightNF(p,I); // right normal form
1294}
1295
1296// **********************************
1297// * NF: Example for vector/module: *
1298// **********************************
1299// module M = [x,0],[0,d]; M = std(M);
1300// vector v = (x*d+1)*[1,1];
1301// print(NF(v,M));
1302// print(rightNF(v,M));
1303
1304proc rightModulo(def M, def N)
1305"USAGE:  rightModulo(M,N); M,N are ideals/modules
1306PURPOSE: compute a right representation of the module (M+N)/N
1307RETURN:  module
1308ASSUME:  M,N are presentation matrices for right modules
1309EXAMPLE: example rightModulo; shows examples
1310"
1311{
1312  def A = basering;
1313  def Aopp = opposite(A);
1314  setring Aopp;
1315  def Mopp = oppose(A,M);
1316  def Nopp = oppose(A,N);
1317  def Kopp = modulo(Mopp,Nopp);
1318  setring A;
1319  def K = oppose(Aopp,Kopp);
1320  return(K);
1321}
1322example
1323{ "EXAMPLE:"; echo = 2;
1324  LIB "ncalg.lib";
1325  def A = makeUsl(2);
1326  setring A;
1327  option(redSB);
1328  option(redTail);
1329  ideal I = e2,f2,h2-1;
1330  I = twostd(I);
1331  print(matrix(I));
1332  ideal E  = std(e);
1333  ideal TL = e,h-1; // the result of left modulo
1334  TL;
1335  ideal T = rightModulo(E,I);
1336  T = rightStd(T+I);
1337  T = rightStd(rightNF(T,I)); // make the output canonic
1338  T;
1339}
1340
1341//////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.