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

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