source: git/Singular/LIB/nctools.lib @ 7d56875

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