source: git/Singular/LIB/nctools.lib @ 2a5ce36

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