source: git/Singular/LIB/matrix.lib @ e9fdf6

spielwiese
Last change on this file since e9fdf6 was bb7a4d, checked in by Motsak Oleksandr <motsak@…>, 16 years ago
*motsak: move the content of powers.lib into matrix.lib git-svn-id: file:///usr/local/Singular/svn/trunk@10813 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 38.6 KB
Line 
1///////////////////////////////////////////////////////////////////////////////
2version="$Id: matrix.lib,v 1.42 2008-06-27 18:08:53 motsak Exp $";
3category="Linear Algebra";
4info="
5LIBRARY:  matrix.lib    Elementary Matrix Operations
6
7PROCEDURES:
8 compress(A);           matrix, zero columns from A deleted
9 concat(A1,A2,..);      matrix, concatenation of matrices A1,A2,...
10 diag(p,n);             matrix, nxn diagonal matrix with entries poly p
11 dsum(A1,A2,..);        matrix, direct sum of matrices A1,A2,...
12 flatten(A);            ideal, generated by entries of matrix A
13 genericmat(n,m[,id]);  generic nxm matrix [entries from id]
14 is_complex(c);         1 if list c is a complex, 0 if not
15 outer(A,B);            matrix, outer product of matrices A and B
16 power(A,n);            matrix/intmat, n-th power of matrix/intmat A
17 skewmat(n[,id]);       generic skew-symmetric nxn matrix [entries from id]
18 submat(A,r,c);         submatrix of A with rows/cols specified by intvec r/c
19 symmat(n[,id]);        generic symmetric nxn matrix [entries from id]
20 tensor(A,B);           matrix, tensor product of matrices A nd B
21 unitmat(n);            unit square matrix of size n
22 gauss_col(A);          transform a matrix into col-reduced Gauss normal form
23 gauss_row(A);          transform a matrix into row-reduced Gauss normal form
24 addcol(A,c1,p,c2);     add p*(c1-th col) to c2-th column of matrix A, p poly
25 addrow(A,r1,p,r2);     add p*(r1-th row) to r2-th row of matrix A, p poly
26 multcol(A,c,p);        multiply c-th column of A with poly p
27 multrow(A,r,p);        multiply r-th row of A with poly p
28 permcol(A,i,j);        permute i-th and j-th columns
29 permrow(A,i,j);        permute i-th and j-th rows
30 rowred(A[,any]);       reduction of matrix A with elementary row-operations
31 colred(A[,any]);       reduction of matrix A with elementary col-operations
32 linear_relations(E);   find linear relations between homogeneous vectors
33 rm_unitrow(A);         remove unit rows and associated columns of A
34 rm_unitcol(A);         remove unit columns and associated rows of A
35 headStand(A);          A[n-i+1,m-j+1]:=A[i,j]
36 symmetricBasis(n,k);   ring, with a basis of a k-th symmetric power of an n-dim v.space
37 symmetricPower(A,k);   module, k-th symmetric power of a module/matrix A
38 exteriorBasis(n,k);    ring, with a basis of a k-th exterior power of an n-dim v.space
39 exteriorPower(A,k);    module, k-th exterior power of a module/matrix A
40          (parameters in square brackets [] are optional)
41";
42
43LIB "inout.lib";
44LIB "ring.lib";
45LIB "random.lib";
46LIB "general.lib"; // for sort
47LIB "nctools.lib"; // for SuperCommutative
48
49///////////////////////////////////////////////////////////////////////////////
50
51proc compress (A)
52"USAGE:   compress(A); A matrix/ideal/module/intmat/intvec
53RETURN:  same type, zero columns/generators from A deleted
54         (if A=intvec, zero elements are deleted)
55EXAMPLE: example compress; shows an example
56"
57{
58   if( typeof(A)=="matrix" ) { return(matrix(simplify(A,2))); }
59   if( typeof(A)=="intmat" or typeof(A)=="intvec" )
60   {
61      ring r=0,x,lp;
62      if( typeof(A)=="intvec" ) { intmat C=transpose(A); kill A; intmat A=C; }
63      module m = matrix(A);
64      if ( size(m) == 0)
65      { intmat B; }
66      else
67      { intmat B[nrows(A)][size(m)]; }
68      int i,j;
69      for( i=1; i<=ncols(A); i++ )
70      {
71         if( m[i]!=[0] )
72         {
73            j++;
74            B[1..nrows(A),j]=A[1..nrows(A),i];
75         }
76      }
77      if( defined(C) ) { return(intvec(B)); }
78      return(B);
79    }
80   return(simplify(A,2));
81}
82example
83{ "EXAMPLE:"; echo = 2;
84   ring r=0,(x,y,z),ds;
85   matrix A[3][4]=1,0,3,0,x,0,z,0,x2,0,z2,0;
86   print(A);
87   print(compress(A));
88   module m=module(A); show(m);
89   show(compress(m));
90   intmat B[3][4]=1,0,3,0,4,0,5,0,6,0,7,0;
91   compress(B);
92   intvec C=0,0,1,2,0,3;
93   compress(C);
94}
95///////////////////////////////////////////////////////////////////////////////
96proc concat (list #)
97"USAGE:   concat(A1,A2,..); A1,A2,... matrices
98RETURN:  matrix, concatenation of A1,A2,.... Number of rows of result matrix
99         is max(nrows(A1),nrows(A2),...)
100EXAMPLE: example concat; shows an example
101"
102{
103   int i;
104   for( i=size(#);i>0; i-- ) { #[i]=module(#[i]); }
105   module B=#[1..size(#)];
106   return(matrix(B));
107}
108example
109{ "EXAMPLE:"; echo = 2;
110   ring r=0,(x,y,z),ds;
111   matrix A[3][3]=1,2,3,x,y,z,x2,y2,z2;
112   matrix B[2][2]=1,0,2,0; matrix C[1][4]=4,5,x,y;
113   print(A);
114   print(B);
115   print(C);
116   print(concat(A,B,C));
117}
118///////////////////////////////////////////////////////////////////////////////
119
120proc diag (list #)
121"USAGE:   diag(p,n); p poly, n integer
122         diag(A);   A matrix
123RETURN:  diag(p,n): diagonal matrix, p times unit matrix of size n.
124@*       diag(A)  : n*m x n*m diagonal matrix with entries all the entries of
125                    the nxm matrix A, taken from the 1st row, 2nd row etc of A
126EXAMPLE: example diag; shows an example
127"
128{
129   if( size(#)==2 ) { return(matrix(#[1]*freemodule(#[2]))); }
130   if( size(#)==1 )
131   {
132      int i; ideal id=#[1];
133      int n=ncols(id); matrix A[n][n];
134      for( i=1; i<=n; i++ ) { A[i,i]=id[i]; }
135   }
136   return(A);
137}
138example
139{ "EXAMPLE:"; echo = 2;
140   ring r = 0,(x,y,z),ds;
141   print(diag(xy,4));
142   matrix A[3][2] = 1,2,3,4,5,6;
143   print(A);
144   print(diag(A));
145}
146///////////////////////////////////////////////////////////////////////////////
147
148proc dsum (list #)
149"USAGE:   dsum(A1,A2,..); A1,A2,... matrices
150RETURN:  matrix, direct sum of A1,A2,...
151EXAMPLE: example dsum; shows an example
152"
153{
154   int i,N,a;
155   list L;
156   for( i=1; i<=size(#); i++ ) { N=N+nrows(#[i]); }
157   for( i=1; i<=size(#); i++ )
158   {
159      matrix B[N][ncols(#[i])];
160      B[a+1..a+nrows(#[i]),1..ncols(#[i])]=#[i];
161      a=a+nrows(#[i]);
162      L[i]=B; kill B;
163   }
164   return(concat(L));
165}
166example
167{ "EXAMPLE:"; echo = 2;
168   ring r = 0,(x,y,z),ds;
169   matrix A[3][3] = 1,2,3,4,5,6,7,8,9;
170   matrix B[2][2] = 1,x,y,z;
171   print(A);
172   print(B);
173   print(dsum(A,B));
174}
175///////////////////////////////////////////////////////////////////////////////
176
177proc flatten (matrix A)
178"USAGE:   flatten(A); A matrix
179RETURN:  ideal, generated by all entries from A
180EXAMPLE: example flatten; shows an example
181"
182{
183   return(ideal(A));
184}
185example
186{ "EXAMPLE:"; echo = 2;
187   ring r = 0,(x,y,z),ds;
188   matrix A[2][3] = 1,2,x,y,z,7;
189   print(A);
190   flatten(A);
191}
192///////////////////////////////////////////////////////////////////////////////
193
194proc genericmat (int n,int m,list #)
195"USAGE:   genericmat(n,m[,id]);  n,m=integers, id=ideal
196RETURN:  nxm matrix, with entries from id.
197NOTE:    if id has less than nxm elements, the matrix is filled with 0's,
198         (default: id=maxideal(1)).
199         genericmat(n,m); creates the generic nxm matrix
200EXAMPLE: example genericmat; shows an example
201"
202{
203   if( size(#)==0 ) { ideal id=maxideal(1); }
204   if( size(#)==1 ) { ideal id=#[1]; }
205   if( size(#)>=2 ) { "// give 3 arguments, 3-rd argument must be an ideal"; }
206   matrix B[n][m]=id;
207   return(B);
208}
209example
210{ "EXAMPLE:"; echo = 2;
211   ring R = 0,x(1..16),lp;
212   print(genericmat(3,3));      // the generic 3x3 matrix
213   ring R1 = 0,(a,b,c,d),dp;
214   matrix A = genericmat(3,4,maxideal(1)^3);
215   print(A);
216   int n,m = 3,2;
217   ideal i = ideal(randommat(1,n*m,maxideal(1),9));
218   print(genericmat(n,m,i));    // matrix of generic linear forms
219}
220///////////////////////////////////////////////////////////////////////////////
221
222proc is_complex (list c)
223"USAGE:   is_complex(c); c = list of size-compatible modules or matrices
224RETURN:  1 if c[i]*c[i+1]=0 for all i, 0 if not, hence checking whether the
225         list of matrices forms a complex.
226NOTE:    Ideals are treated internally as 1-line matrices.
227         If printlevel > 0, the position where c is not a complex is shown.
228EXAMPLE: example is_complex; shows an example
229"
230{
231   int i;
232   module @test;
233   for( i=1; i<=size(c)-1; i++ )
234   {
235      c[i]=matrix(c[i]); c[i+1]=matrix(c[i+1]);
236      @test=c[i]*c[i+1];
237      if (size(@test)!=0)
238      {
239        dbprint(printlevel-voice+2,"// not a complex at position " +string(i));
240         return(0);
241      }
242   }
243   return(1);
244}
245example
246{ "EXAMPLE:";   echo = 2;
247   ring r  = 32003,(x,y,z),ds;
248   ideal i = x4+y5+z6,xyz,yx2+xz2+zy7;
249   list L  = nres(i,0);
250   is_complex(L);
251   L[4]    = matrix(i);
252   is_complex(L);
253}
254///////////////////////////////////////////////////////////////////////////////
255
256proc outer (matrix A, matrix B)
257"USAGE:   outer(A,B); A,B matrices
258RETURN:  matrix, outer (tensor) product of A and B
259EXAMPLE: example outer; shows an example
260"
261{
262   int i,j; list L;
263   int triv = nrows(B)*ncols(B);
264   if( triv==1 )
265   {
266     return(B[1,1]*A);
267   }
268   else
269   {
270     int N = nrows(A)*nrows(B);
271     matrix C[N][ncols(B)];
272     for( i=ncols(A);i>0; i-- )
273     {
274       for( j=1; j<=nrows(A); j++ )
275       {
276          C[(j-1)*nrows(B)+1..j*nrows(B),1..ncols(B)]=A[j,i]*B;
277       }
278       L[i]=C;
279     }
280     return(concat(L));
281   }
282}
283example
284{ "EXAMPLE:"; echo = 2;
285   ring r=32003,(x,y,z),ds;
286   matrix A[3][3]=1,2,3,4,5,6,7,8,9;
287   matrix B[2][2]=x,y,0,z;
288   print(A);
289   print(B);
290   print(outer(A,B));
291}
292///////////////////////////////////////////////////////////////////////////////
293
294proc power ( A, int n)
295"USAGE:   power(A,n);  A a square-matrix of type intmat or matrix, n=integer
296RETURN:  intmat resp. matrix, the n-th power of A
297NOTE:    for A=intmat and big n the result may be wrong because of int overflow
298EXAMPLE: example power; shows an example
299"
300{
301//---------------------------- type checking ----------------------------------
302   if( typeof(A)!="matrix" and typeof(A)!="intmat" )
303   {
304      "// no matrix or intmat!";
305      return (A);
306   }
307   if( ncols(A) != nrows(A) )
308   {
309      "// not a suare matrix!";
310      return();
311   }
312//---------------------------- trivial cases ----------------------------------
313   int ii;
314   if( n <= 0 )
315   {
316      if( typeof(A)=="matrix" )
317      {
318         return (unitmat(nrows(A)));
319      }
320      if( typeof(A)=="intmat" )
321      {
322         intmat B[nrows(A)][nrows(A)];
323         for( ii=1; ii<=nrows(A); ii++ )
324         {
325            B[ii,ii] = 1;
326         }
327         return (B);
328      }
329   }
330   if( n == 1 ) { return (A); }
331//---------------------------- sub procedure ----------------------------------
332   proc matpow (A, int n)
333   {
334      def B = A*A;
335      int ii= 2;
336      int jj= 4;
337      while( jj <= n )
338      {
339         B=B*B;
340         ii=jj;
341         jj=2*jj;
342      }
343      return(B,n-ii);
344   }
345//----------------------------- main program ----------------------------------
346   list L = matpow(A,n);
347   def B  = L[1];
348   ii     = L[2];
349   while( ii>=2 )
350   {
351      L = matpow(A,ii);
352      B = B*L[1];
353      ii= L[2];
354   }
355   if( ii == 0) { return(B); }
356   if( ii == 1) { return(A*B); }
357}
358example
359{ "EXAMPLE:"; echo = 2;
360   intmat A[3][3]=1,2,3,4,5,6,7,8,9;
361   print(power(A,3));"";
362   ring r=0,(x,y,z),dp;
363   matrix B[3][3]=0,x,y,z,0,0,y,z,0;
364   print(power(B,3));"";
365}
366///////////////////////////////////////////////////////////////////////////////
367
368proc skewmat (int n, list #)
369"USAGE:   skewmat(n[,id]);  n integer, id ideal
370RETURN:  skew-symmetric nxn matrix, with entries from id
371         (default: id=maxideal(1))
372         skewmat(n); creates the generic skew-symmetric matrix
373NOTE:    if id has less than n*(n-1)/2 elements, the matrix is
374         filled with 0's,
375EXAMPLE: example skewmat; shows an example
376"
377{
378   matrix B[n][n];
379   if( size(#)==0 ) { ideal id=maxideal(1); }
380   else { ideal id=#[1]; }
381   id = id,B[1..n,1..n];
382   int i,j;
383   for( i=0; i<=n-2; i++ )
384   {
385      B[i+1,i+2..n]=id[j+1..j+n-i-1];
386      j=j+n-i-1;
387   }
388   matrix A=transpose(B);
389   B=B-A;
390   return(B);
391}
392example
393{ "EXAMPLE:"; echo = 2;
394   ring R=0,x(1..5),lp;
395   print(skewmat(4));    // the generic skew-symmetric matrix
396   ring R1 = 0,(a,b,c),dp;
397   matrix A=skewmat(4,maxideal(1)^2);
398   print(A);
399   int n=3;
400   ideal i = ideal(randommat(1,n*(n-1) div 2,maxideal(1),9));
401   print(skewmat(n,i));  // skew matrix of generic linear forms
402   kill R1;
403}
404///////////////////////////////////////////////////////////////////////////////
405
406proc submat (matrix A, intvec r, intvec c)
407"USAGE:   submat(A,r,c);  A=matrix, r,c=intvec
408RETURN:  matrix, submatrix of A with rows specified by intvec r
409         and columns specified by intvec c.
410EXAMPLE: example submat; shows an example
411"
412{
413   matrix B[size(r)][size(c)]=A[r,c];
414   return(B);
415}
416example
417{ "EXAMPLE:"; echo = 2;
418   ring R=32003,(x,y,z),lp;
419   matrix A[4][4]=x,y,z,0,1,2,3,4,5,6,7,8,9,x2,y2,z2;
420   print(A);
421   intvec v=1,3,4;
422   matrix B=submat(A,v,1..3);
423   print(B);
424}
425///////////////////////////////////////////////////////////////////////////////
426
427proc symmat (int n, list #)
428"USAGE:   symmat(n[,id]);  n integer, id ideal
429RETURN:  symmetric nxn matrix, with entries from id (default: id=maxideal(1))
430NOTE:    if id has less than n*(n+1)/2 elements, the matrix is filled with 0's,
431         symmat(n); creates the generic symmetric matrix
432EXAMPLE: example symmat; shows an example
433"
434{
435   matrix B[n][n];
436   if( size(#)==0 ) { ideal id=maxideal(1); }
437   else { ideal id=#[1]; }
438   id = id,B[1..n,1..n];
439   int i,j;
440   for( i=0; i<=n-1; i++ )
441   {
442      B[i+1,i+1..n]=id[j+1..j+n-i];
443      j=j+n-i;
444   }
445   matrix A=transpose(B);
446   for( i=1; i<=n; i++ ) {  A[i,i]=0; }
447   B=A+B;
448   return(B);
449}
450example
451{ "EXAMPLE:"; echo = 2;
452   ring R=0,x(1..10),lp;
453   print(symmat(4));    // the generic symmetric matrix
454   ring R1 = 0,(a,b,c),dp;
455   matrix A=symmat(4,maxideal(1)^3);
456   print(A);
457   int n=3;
458   ideal i = ideal(randommat(1,n*(n+1) div 2,maxideal(1),9));
459   print(symmat(n,i));  // symmetric matrix of generic linear forms
460   kill R1;
461}
462///////////////////////////////////////////////////////////////////////////////
463
464proc tensor (matrix A, matrix B)
465"USAGE:   tensor(A,B); A,B matrices
466RETURN:  matrix, tensor product of A and B
467EXAMPLE: example tensor; shows an example
468"
469{
470   if (ncols(A)==0)
471   {
472     int q=nrows(A)*nrows(B);
473     matrix D[q][0];
474     return(D);
475   }
476
477   int i,j;
478   matrix C,D;
479   for( i=1; i<=nrows(A); i++ )
480   {
481     C = A[i,1]*B;
482     for( j=2; j<=ncols(A); j++ )
483     {
484       C = concat(C,A[i,j]*B);
485     }
486     D = concat(D,transpose(C));
487   }
488   D = transpose(D);
489   return(submat(D,2..nrows(D),1..ncols(D)));
490}
491example
492{ "EXAMPLE:"; echo = 2;
493   ring r=32003,(x,y,z),(c,ds);
494   matrix A[3][3]=1,2,3,4,5,6,7,8,9;
495   matrix B[2][2]=x,y,0,z;
496   print(A);
497   print(B);
498   print(tensor(A,B));
499}
500///////////////////////////////////////////////////////////////////////////////
501
502proc unitmat (int n)
503"USAGE:   unitmat(n);  n integer >= 0
504RETURN:  nxn unit matrix
505NOTE:    needs a basering, diagonal entries are numbers (=1) in the basering
506EXAMPLE: example unitmat; shows an example
507"
508{
509   return(matrix(freemodule(n)));
510}
511example
512{ "EXAMPLE:"; echo = 2;
513   ring r=32003,(x,y,z),lp;
514   print(xyz*unitmat(4));
515   print(unitmat(5));
516}
517///////////////////////////////////////////////////////////////////////////////
518
519proc gauss_col (matrix A, list #)
520"USAGE:   gauss_col(A[,e]); A a matrix, e any type
521RETURN:  - a matrix B, if called with one argument; B is the complete column-
522           reduced upper-triangular normal form of A if A is constant,
523           (resp. as far as this is possible if A is a polynomial matrix;
524           no division by polynomials).
525@*       - a list L of two matrices, if called with two arguments;
526           L satisfies L[1] = A * L[2] with L[1] the column-reduced form of A
527           and L[2] the transformation matrix.
528NOTE:    * The procedure just applies interred to A with ordering (C,dp).
529           The transformation matrix is obtained by applying 'lift'.
530           This should be faster than the procedure colred.
531@*       * It should only be used with exact coefficient field (there is no
532           pivoting and rounding error treatment).
533@*       * Parameters are allowed. Hence, if the entries of A are parameters,
534           B is the column-reduced form of A over the rational function field.
535SEE ALSO:  colred
536EXAMPLE: example gauss_col; shows an example
537"
538{
539   def R=basering; int u;
540   string mp = string(minpoly);
541   int n = nrows(A);
542   int m = ncols(A);
543   module M = A;
544   intvec v = option(get);
545//------------------------ change ordering if necessary ----------------------
546   if( ordstr(R) != ("C,dp("+string(nvars(R))+")") )
547   {
548     def @R=changeord("C,dp",R); setring @R; u=1;
549     execute("minpoly="+mp+";");
550     matrix A = imap(R,A);
551     module M = A;
552   }
553//------------------------------ start computation ---------------------------
554   option(redSB);
555   M = simplify(interred(M),1);
556   if(size(#) != 0)
557   {
558      module N = lift(A,M);
559   }
560//--------------- reset ring and options and return --------------------------
561   if ( u==1 )
562   {
563      setring R;
564      M=imap(@R,M);
565      if (size(#) != 0)
566      {
567         module N = imap(@R,N);
568      }
569      kill @R;
570   }
571   option(set,v);
572   // M = sort(M,size(M)..1)[1];
573   A = matrix(M,n,m);
574   if (size(#) != 0)
575   {
576     list L= A,matrix(N,m,m);
577     return(L);
578   }
579   return(matrix(M,n,m));
580}
581example
582{ "EXAMPLE:"; echo = 2;
583   ring r=(0,a,b),(A,B,C),dp;
584   matrix m[8][6]=
585   0,    2*C, 0,    0,  0,   0,
586   0,    -4*C,a*A,  0,  0,   0,
587   b*B,  -A,  0,    0,  0,   0,
588   -A,   B,   0,    0,  0,   0,
589   -4*C, 0,   B,    2,  0,   0,
590   2*A,  B,   0,    0,  0,   0,
591   0,    3*B, 0,    0,  2b,  0,
592   0,    AB,  0,    2*A,A,   2a;"";
593   list L=gauss_col(m,1);
594   print(L[1]);
595   print(L[2]);
596
597   ring S=0,x,(c,dp);
598   matrix A[5][4] =
599    3, 1, 1, 1,
600   13, 8, 6,-7,
601   14,10, 6,-7,
602    7, 4, 3,-3,
603    2, 1, 0, 3;
604   print(gauss_col(A));
605}
606///////////////////////////////////////////////////////////////////////////////
607
608proc gauss_row (matrix A, list #)
609"USAGE:  gauss_row(A [,e]); A matrix, e any type
610RETURN: - a matrix B, if called with one argument; B is the complete row-
611          reduced lower-triangular normal form of A if A is constant,
612          (resp. as far as this is possible if A is a polynomial matrix;
613          no division by polynomials).
614@*      - a list L of two matrices, if called with two arguments;
615          L satisfies transpose(L[2])*A=transpose(L[1])
616          with L[1] the row-reduced form of A
617          and L[2] the transformation matrix.
618NOTE:   * This procedure just applies gauss_col to the transposed matrix.
619          The transformation matrix is obtained by applying lift.
620          This should be faster than the procedure rowred.
621@*      * It should only be used with exact coefficient field (there is no
622          pivoting and rounding error treatment).
623@*      * Parameters are allowed. Hence, if the entries of A are parameters,
624          B is the row-reduced form of A over the rational function field.
625SEE ALSO: rowred
626EXAMPLE: example gauss_row; shows an example
627"
628{
629   if(size(#) > 0)
630   {
631     list L = gauss_col(transpose(A),1);
632     return(L);
633   }
634   A = gauss_col(transpose(A));
635   return(transpose(A));
636}
637example
638{ "EXAMPLE:"; echo = 2;
639   ring r=(0,a,b),(A,B,C),dp;
640   matrix m[6][8]=
641   0, 0,  b*B, -A,-4C,2A,0, 0,
642   2C,-4C,-A,B, 0,  B, 3B,AB,
643   0,a*A,  0, 0, B,  0, 0, 0,
644   0, 0,  0, 0, 2,  0, 0, 2A,
645   0, 0,  0, 0, 0,  0, 2b, A,
646   0, 0,  0, 0, 0,  0, 0, 2a;"";
647   print(gauss_row(m));"";
648   ring S=0,x,dp;
649   matrix A[4][5] =  3, 1,1,-1,2,
650                    13, 8,6,-7,1,
651                    14,10,6,-7,1,
652                     7, 4,3,-3,3;
653   list L=gauss_row(A,1);
654   print(L[1]);
655   print(L[2]);
656}
657///////////////////////////////////////////////////////////////////////////////
658
659proc addcol (matrix A, int c1, poly p, int c2)
660"USAGE:   addcol(A,c1,p,c2);  A matrix, p poly, c1, c2 positive integers
661RETURN:  matrix,  A being modified by adding p times column c1 to column c2
662EXAMPLE: example addcol; shows an example
663"
664{
665   int k=nrows(A);
666   A[1..k,c2]=A[1..k,c2]+p*A[1..k,c1];
667   return(A);
668}
669example
670{ "EXAMPLE:"; echo = 2;
671   ring r=32003,(x,y,z),lp;
672   matrix A[3][3]=1,2,3,4,5,6,7,8,9;
673   print(A);
674   print(addcol(A,1,xy,2));
675}
676///////////////////////////////////////////////////////////////////////////////
677
678proc addrow (matrix A, int r1, poly p, int r2)
679"USAGE:   addcol(A,r1,p,r2);  A matrix, p poly, r1, r2 positive integers
680RETURN:  matrix,  A being modified by adding p times row r1 to row r2
681EXAMPLE: example addrow; shows an example
682"
683{
684   int k=ncols(A);
685   A[r2,1..k]=A[r2,1..k]+p*A[r1,1..k];
686   return(A);
687}
688example
689{ "EXAMPLE:"; echo = 2;
690   ring r=32003,(x,y,z),lp;
691   matrix A[3][3]=1,2,3,4,5,6,7,8,9;
692   print(A);
693   print(addrow(A,1,xy,3));
694}
695///////////////////////////////////////////////////////////////////////////////
696
697proc multcol (matrix A, int c, poly p)
698"USAGE:   addcol(A,c,p);  A matrix, p poly, c positive integer
699RETURN:  matrix,  A being modified by multiplying column c by p
700EXAMPLE: example multcol; shows an example
701"
702{
703   int k=nrows(A);
704   A[1..k,c]=p*A[1..k,c];
705   return(A);
706}
707example
708{ "EXAMPLE:"; echo = 2;
709   ring r=32003,(x,y,z),lp;
710   matrix A[3][3]=1,2,3,4,5,6,7,8,9;
711   print(A);
712   print(multcol(A,2,xy));
713}
714///////////////////////////////////////////////////////////////////////////////
715
716proc multrow (matrix A, int r, poly p)
717"USAGE:   multrow(A,r,p);  A matrix, p poly, r positive integer
718RETURN:  matrix,  A being modified by multiplying row r by p
719EXAMPLE: example multrow; shows an example
720"
721{
722   int k=ncols(A);
723   A[r,1..k]=p*A[r,1..k];
724   return(A);
725}
726example
727{ "EXAMPLE:"; echo = 2;
728   ring r=32003,(x,y,z),lp;
729   matrix A[3][3]=1,2,3,4,5,6,7,8,9;
730   print(A);
731   print(multrow(A,2,xy));
732}
733///////////////////////////////////////////////////////////////////////////////
734
735proc permcol (matrix A, int c1, int c2)
736"USAGE:   permcol(A,c1,c2);  A matrix, c1,c2 positive integers
737RETURN:  matrix,  A being modified by permuting columns c1 and c2
738EXAMPLE: example permcol; shows an example
739"
740{
741   matrix B=A;
742   int k=nrows(B);
743   B[1..k,c1]=A[1..k,c2];
744   B[1..k,c2]=A[1..k,c1];
745   return(B);
746}
747example
748{ "EXAMPLE:"; echo = 2;
749   ring r=32003,(x,y,z),lp;
750   matrix A[3][3]=1,x,3,4,y,6,7,z,9;
751   print(A);
752   print(permcol(A,2,3));
753}
754///////////////////////////////////////////////////////////////////////////////
755
756proc permrow (matrix A, int r1, int r2)
757"USAGE:   permrow(A,r1,r2);  A matrix, r1,r2 positive integers
758RETURN:  matrix,  A being modified by permuting rows r1 and r2
759EXAMPLE: example permrow; shows an example
760"
761{
762   matrix B=A;
763   int k=ncols(B);
764   B[r1,1..k]=A[r2,1..k];
765   B[r2,1..k]=A[r1,1..k];
766   return(B);
767}
768example
769{ "EXAMPLE:"; echo = 2;
770   ring r=32003,(x,y,z),lp;
771   matrix A[3][3]=1,2,3,x,y,z,7,8,9;
772   print(A);
773   print(permrow(A,2,1));
774}
775///////////////////////////////////////////////////////////////////////////////
776
777proc rowred (matrix A,list #)
778"USAGE:   rowred(A[,e]);  A matrix, e any type
779RETURN:  - a matrix B, being the row reduced form of A, if rowred is called
780           with one argument.
781           (as far as this is possible over the polynomial ring; no division
782           by polynomials)
783@*       - a list L of two matrices, such that L[1] = L[2] * A with L[1]
784           the row-reduced form of A and L[2] the transformation matrix
785           (if rowred is called with two arguments).
786ASSUME:  The entries of A are in the base field. It is not verified whether
787         this assumption holds.
788NOTE:    * This procedure is designed for teaching purposes mainly.
789@*       * The straight forward Gaussian algorithm is implemented in the
790           library (no standard basis computation).
791           The transformation matrix is obtained by concatenating a unit
792           matrix to A. proc gauss_row should be faster.
793@*       * It should only be used with exact coefficient field (there is no
794           pivoting) over the polynomial ring (ordering lp or dp).
795@*       * Parameters are allowed. Hence, if the entries of A are parameters
796           the computation takes place over the field of rational functions.
797SEE ALSO:  gauss_row
798EXAMPLE: example rowred; shows an example
799"
800{
801   int m,n=nrows(A),ncols(A);
802   int i,j,k,l,rk;
803   poly p;
804   matrix d[m][n];
805   for (i=1;i<=m;i++)
806   {  for (j=1;j<=n;j++)
807      {  p = A[i,j];
808         if (ord(p)==0)
809         {  if (deg(p)==0) { d[i,j]=p; }
810         }
811      }
812   }
813   matrix b = A;
814   if (size(#) != 0) { b = concat(b,unitmat(m)); }
815      for (l=1;l<=n;l=l+1)
816   {  pmat(d);
817      k  = findfirst(ideal(d[l]),rk+1);
818      if (k)
819      {  rk = rk+1;
820         b  = permrow(b,rk,k);
821         p  = b[rk,l];         p = 1/p;
822         b  = multrow(b,rk,p);
823         for (i=1;i<=m;i++)
824         {
825            if (rk-i) { b = addrow(b,rk,-b[i,l],i);}
826         }
827         d = 0;
828         for (i=rk+1;i<=m;i++)
829         {  for (j=l+1;j<=n;j++)
830            {  p = b[i,j];
831               if (ord(p)==0)
832               {  if (deg(p)==0) { d[i,j]=p; }
833               }
834            }
835         }
836
837      }
838   }
839   d = submat(b,1..m,1..n);
840   if (size(#))
841   {
842      list L=d,submat(b,1..m,n+1..n+m);
843      return(L);
844   }
845   return(d);
846}
847example
848{ "EXAMPLE:"; echo = 2;
849   ring r=(0,a,b),(A,B,C),dp;
850   matrix m[6][8]=
851   0, 0,  b*B, -A,-4C,2A,0, 0,
852   2C,-4C,-A,B, 0,  B, 3B,AB,
853   0,a*A,  0, 0, B,  0, 0, 0,
854   0, 0,  0, 0, 2,  0, 0, 2A,
855   0, 0,  0, 0, 0,  0, 2b, A,
856   0, 0,  0, 0, 0,  0, 0, 2a;"";
857   print(rowred(m));"";
858   list L=rowred(m,1);
859   print(L[1]);
860   print(L[2]);
861}
862///////////////////////////////////////////////////////////////////////////////
863
864proc colred (matrix A,list #)
865"USAGE:   colred(A[,e]);  A matrix, e any type
866RETURN:  - a matrix B, being the column reduced form of A, if colred is
867           called with one argument.
868           (as far as this is possible over the polynomial ring;
869           no division by polynomials)
870@*       - a list L of two matrices, such that L[1] = A * L[2] with L[1]
871           the column-reduced form of A and L[2] the transformation matrix
872           (if colred is called with two arguments).
873ASSUME:  The entries of A are in the base field. It is not verified whether
874         this assumption holds.
875NOTE:    * This procedure is designed for teaching purposes mainly.
876@*       * It applies rowred to the transposed matrix.
877           proc gauss_col should be faster.
878@*       * It should only be used with exact coefficient field (there is no
879           pivoting) over the polynomial ring (ordering lp or dp).
880@*       * Parameters are allowed. Hence, if the entries of A are parameters
881           the computation takes place over the field of rational functions.
882SEE ALSO:  gauss_col
883EXAMPLE: example colred; shows an example
884"
885{
886   A = transpose(A);
887   if (size(#))
888   { list L = rowred(A,1); return(transpose(L[1]),transpose(L[2]));}
889   else
890   { return(transpose(rowred(A)));}
891}
892example
893{ "EXAMPLE:"; echo = 2;
894   ring r=(0,a,b),(A,B,C),dp;
895   matrix m[8][6]=
896   0,    2*C, 0,    0,  0,   0,
897   0,    -4*C,a*A,  0,  0,   0,
898   b*B,  -A,  0,    0,  0,   0,
899   -A,   B,   0,    0,  0,   0,
900   -4*C, 0,   B,    2,  0,   0,
901   2*A,  B,   0,    0,  0,   0,
902   0,    3*B, 0,    0,  2b,  0,
903   0,    AB,  0,    2*A,A,   2a;"";
904   print(colred(m));"";
905   list L=colred(m,1);
906   print(L[1]);
907   print(L[2]);
908}
909//////////////////////////////////////////////////////////////////////////////
910
911proc linear_relations(module M)
912"USAGE:   linear_relations(M);
913         M: a module
914ASSUME:  All non-zero entries of M are homogeneous polynomials of the same
915         positife degree. The base field must be an exact field (not real
916         or complex).
917         It is not checked whether these assumptions hold.
918RETURN:  a maximal module R such that M*R is formed by zero vectors.
919EXAMPLE: example linear_relations; shows an example.
920"
921{ int n = ncols(M);
922  def BaseR = basering;
923  def br = changeord("dp",basering);
924  setring br;
925  module M = imap(BaseR,M);
926  ideal vars = maxideal(1);
927  ring tmpR = 0, ('y(1..n)), dp;
928  def newR = br + tmpR;
929  setring newR;
930  module M = imap(br,M);
931  ideal vars = imap(br,vars);
932  attrib(vars,"isSB",1);
933  for (int i = 1; i<=n; i++) {
934    M[i] = M[i] + 'y(i)*gen(1);
935  }
936  M = interred(M);
937  module redM = NF(M,vars);
938  module REL;
939  int sizeREL;
940  int j;
941  for (i=1; i<=n; i++) {
942    if (M[i][1]==redM[i][1]) { //-- relation found!
943      sizeREL++;
944      REL[sizeREL]=0;
945      for (j=1; j<=n; j++) {
946        REL[sizeREL] = REL[sizeREL] + (M[i][1]/'y(j))*gen(j);
947      }
948    }
949  }
950  setring BaseR;
951  return(minbase(imap(newR,REL)));
952}
953example
954{ "EXAMPLE:"; echo = 2;
955  ring r = (3,w), (a,b,c,d),dp;
956  minpoly = w2-w-1;
957  module M = [a2,b2],[wab,w2c2+2b2],[(w-2)*a2+wab,wb2+w2c2];
958  module REL = linear_relations(M);
959  pmat(REL);
960  pmat(M*REL);
961
962
963//////////////////////////////////////////////////////////////////////////////
964
965static proc findfirst (ideal i,int t)
966{
967   int n,k;
968   for (n=t;n<=ncols(i);n=n+1)
969   {
970      if (i[n]!=0) { k=n;break;}
971   }
972   return(k);
973}
974//////////////////////////////////////////////////////////////////////////////
975
976proc rm_unitcol(matrix A)
977"USAGE:   rm_unitcol(A); A matrix (being row-reduced)
978RETURN:  matrix, obtained from A by deleting unit columns (having just one 1
979         and else 0 as entries) and associated rows
980EXAMPLE: example rm_unitcol; shows an example
981"
982{
983 int l,j;
984 intvec v;
985 for (j=1;j<=ncols(A);j++)
986 {
987    if (gen(l+1)==module(A)[j]) {l=l+1;}
988    else { v=v,j;}
989 }
990 if (size(v)>1)
991    {  v = v[2..size(v)];
992       return(submat(A,l+1..nrows(A),v));
993    }
994 else
995    { return(0);}
996}
997example
998{ "EXAMPLE:"; echo = 2;
999   ring r=0,(A,B,C),dp;
1000   matrix m[6][8]=
1001   0,  0,    A,   0, 1,0,  0,0,
1002   0,  0,  -C2,   0, 0,0,  1,0,
1003   0,  0,    0,1/2B, 0,0,  0,1,
1004   0,  0,    B,  -A, 0,2A, 0,0,
1005   2C,-4C,  -A,   B, 0,B,  0,0,
1006   0,  A,    0,   0, 0,0,  0,0;
1007   print(rm_unitcol(m));
1008}
1009//////////////////////////////////////////////////////////////////////////////
1010
1011proc rm_unitrow (matrix A)
1012"USAGE:   rm_unitrow(A); A matrix (being col-reduced)
1013RETURN:  matrix, obtained from A by deleting unit rows (having just one 1
1014         and else 0 as entries) and associated columns
1015EXAMPLE: example rm_unitrow; shows an example
1016"
1017{
1018 int l,j;
1019 intvec v;
1020 module M = transpose(A);
1021 for (j=1; j <= nrows(A); j++)
1022 {
1023    if (gen(l+1) == M[j]) { l=l+1; }
1024    else { v=v,j; }
1025 }
1026 if (size(v) > 1)
1027    {  v = v[2..size(v)];
1028       return(submat(A,v,l+1..ncols(A)));
1029    }
1030 else
1031    { return(0);}
1032}
1033example
1034{ "EXAMPLE:"; echo = 2;
1035   ring r=0,(A,B,C),dp;
1036   matrix m[8][6]=
1037   0,0,  0,   0, 2C, 0,
1038   0,0,  0,   0, -4C,A,
1039   A,-C2,0,   B, -A, 0,
1040   0,0,  1/2B,-A,B,  0,
1041   1,0,  0,   0, 0,  0,
1042   0,0,  0,   2A,B,  0,
1043   0,1,  0,   0, 0,  0,
1044   0,0,  1,   0, 0,  0;
1045   print(rm_unitrow(m));
1046}
1047//////////////////////////////////////////////////////////////////////////////
1048proc headStand(matrix M)
1049"USAGE:   headStand(M);  M matrix
1050RETURN:  matrix B such that B[i][j]=M[n-i+1,m-j+1], n=nrows(M), m=ncols(M)
1051EXAMPLE: example headStand; shows an example
1052"
1053{
1054  int i,j;
1055  int n=nrows(M);
1056  int m=ncols(M);
1057  matrix B[n][m];
1058  for(i=1;i<=n;i++)
1059  {
1060     for(j=1;j<=m;j++)
1061     {
1062        B[n-i+1,m-j+1]=M[i,j];
1063     }
1064  }
1065  return(B);
1066}
1067example
1068{ "EXAMPLE:"; echo = 2;
1069   ring r=0,(A,B,C),dp;
1070   matrix M[2][3]=
1071   0,A,  B,
1072   A2, B2, C;
1073   print(M);
1074   print(headStand(M));
1075}
1076//////////////////////////////////////////////////////////////////////////////
1077
1078// Symmetric/Exterior powers, thanks to Oleksandr Iena for his persistence ;-)
1079
1080proc symmetricBasis(int n, int k)
1081"USAGE:    symmetricBasis(n, k); n int, k int
1082RETURN:   ring: the basis of the k-th symmetric power of a n-dim vector space
1083NOTE:     The output consists of a polynomial ring in n variables, together with the ideal called I.
1084          The ideal I is the basis of the k-th symmetric power of a n-dim vector space (ordered lexicographically).
1085          The char. of the returned ring is the same as of current basis ring or zero.
1086SEE ALSO: exteriorBasis
1087KEYWORDS: symmetric basis
1088EXAMPLE:  example symmetricBasis; shows an example"
1089{
1090  int p = 0;
1091  if( nameof(basering) != "basering" )
1092  {
1093    p = char(basering);
1094  }
1095
1096  ring T = (p), (e(1..n)), dp;
1097  ideal I = simplify( NF(maxideal(k), std(0)), 1 + 2 + 8 );
1098  int N = ncols(I);
1099  I = sort(I)[1]; // lex
1100  I = I[N..1];
1101
1102  export I;
1103  return(T);
1104}
1105example
1106{ "EXAMPLE:"; echo = 2;
1107
1108def r = symmetricBasis(2, 3); setring r; r;
1109I; // basis of 3rd sym. power of a 2-dim v.s.
1110kill r;
1111
1112ring r = (0),(a, b, c, d), dp; r;
1113def g = symmetricBasis(3, 2); setring g; g; I;
1114
1115kill g, r;
1116
1117ring r = (32003),(a, b, c, d), dp; r;
1118def g = symmetricBasis(4, 2); setring g; g; I;
1119}
1120
1121//////////////////////////////////////////////////////////////////////////////
1122
1123proc exteriorBasis(int n, int k)
1124"USAGE:    exteriorBasis(n, k); n int, k int
1125RETURN:   ring: the basis of the k-th exterior power of a n-dim vector space
1126NOTE:     The output consists of a polynomial ring in n variables, together with the ideal called I.
1127          The ideal I is the basis of the k-th exterior power of a n-dim vector space (ordered lexicographically).
1128          The char. of the returned ring is the same as of current basis ring or zero.
1129
1130SEE ALSO: symmetricBasis
1131KEYWORDS: exterior basis
1132EXAMPLE:  example exteriorBasis; shows an example"
1133{
1134  int p = 0;
1135  if( nameof(basering) != "basering" )
1136  {
1137    p = char(basering);
1138  }
1139   
1140  ring S = (p), (e(1..n)), dp;
1141  def T = SuperCommutative(); setring T;
1142  ideal I = simplify( NF(maxideal(k), std(0)), 1 + 2 + 8 );
1143  int N = ncols(I);
1144  I = sort(I)[1];
1145  I = I[N..1 ];
1146
1147  export I;
1148  return(T);
1149}
1150example
1151{ "EXAMPLE:"; echo = 2;
1152
1153def r = exteriorBasis(2, 3); setring r; r;
1154"Basis: ", I; // basis of 3rd sym. power of a 2-dim v.s.
1155kill r;
1156
1157ring r = (0),(a, b, c, d), dp; r;
1158def g = exteriorBasis(3, 2); setring g; g; "Basis: ", I;
1159
1160kill g, r;
1161
1162ring r = (32003),(a, b, c, d), dp; r;
1163def g = exteriorBasis(4, 2); setring g; g; "Basis: ", I;
1164}
1165
1166//////////////////////////////////////////////////////////////////////////////
1167
1168proc symmetricPower(module A, int k)
1169"USAGE:    symmetricPower(A, k); A module, k int
1170RETURN:   module: the k-th symmetric power of A
1171NOTE:     the chosen bases (ordered lexicographically) and
1172          temporary data  may be shown if printlevel is big enough
1173SEE ALSO: exteriorPower
1174KEYWORDS: symmetric power
1175EXAMPLE:  example symmetricPower; shows an example"
1176{
1177  int p = printlevel - voice + 2;
1178  def save = basering;
1179
1180  int M = nrows(A);
1181  int N = ncols(A);
1182
1183  int i, j;
1184
1185  /////////////////////////////////////////////////////////////////
1186  def Tn = symmetricBasis(N, k); setring Tn;
1187  ideal Ink = I;
1188  dbprint(p-3, "Temporary Source Ring", basering);
1189  dbprint(p, "S^k(Source Basis)", Ink);
1190
1191  /////////////////////////////////////////////////////////////////
1192  def Tm = symmetricBasis(M, k); setring Tm;
1193  ideal Imk = I;
1194  dbprint(p-3, "Temporary Image Ring", basering);
1195  dbprint(p, "S^k(Image Basis)", Imk);
1196
1197  /////////////////////////////////////////////////////////////////
1198  def Rm = save + Tm;
1199  setring Rm;
1200  dbprint(p-2, "Temporary Working Ring", Rm);
1201
1202  module A = imap(save, A);
1203
1204  ideal B; poly t;
1205
1206  for( i = N; i > 0; i-- )
1207  {
1208    t = 0;
1209    for( j = M; j > 0; j-- )
1210    {
1211      t = t + A[i][j] * var( nvars(save) + j); // tensor product!!!
1212    }
1213
1214    B[i] = t;
1215  }
1216
1217  dbprint(p-1, "Matrix of simgle images", B);
1218
1219  map TMap = Tn, B; ideal C = TMap(Ink); // apply S^k A to Source basis vectors... (Ink)
1220  C = NF(C, std(0));
1221
1222  dbprint(p-1, "Image Matrix: ", C);
1223
1224  // and write it in Image basis (Imk)
1225
1226  ideal Imk = imap(Tm, Imk);
1227
1228  module D; poly lm; vector tt;
1229
1230  for( i = ncols(C); i > 0; i-- )
1231  {
1232    t = C[i];
1233    tt = 0;
1234
1235    while( t != 0 )
1236    {
1237      lm = leadmonom(t);
1238      //    lm;
1239      for( j = ncols(Imk); j > 0; j-- )
1240      {
1241        if( lm / Imk[j] != 0 )
1242        {
1243          tt = tt + (lead(t) / Imk[j]) * gen(j);
1244          break;
1245        }
1246      }
1247      t = t - lead(t);
1248    }
1249
1250    D[i] = tt;
1251//    tt;
1252  }
1253
1254  // D; print(D);
1255
1256
1257  setring save;
1258
1259  // basering;
1260
1261  module AA = imap(Rm, D);
1262
1263//  nrows(AA) = Nk; // ????
1264//  ncols(AA) = Mk;
1265
1266//  Nk, Mk;
1267
1268//  AA[Mk] = AA[Mk] * 1;
1269
1270  return(AA);
1271}
1272example
1273{ "EXAMPLE:"; echo = 2;
1274int save = printlevel; printlevel = 1;
1275
1276ring r = (0),(a, b, c, d), dp; r;
1277
1278module A = a*gen(1), b * gen(1), c*gen(1), d * gen(1);
1279
1280print(symmetricPower(A, 2));
1281print(symmetricPower(A, 3));
1282
1283module B = a*gen(1) + c* gen(2), b * gen(1) + d * gen(2);
1284
1285print(symmetricPower(B, 2));
1286print(symmetricPower(B, 3));
1287
1288kill r;
1289ring r = (0),(a, b, c, d), dp;def g = SuperCommutative();setring g;
1290
1291module A = a*gen(1), b * gen(1), c*gen(1), d * gen(1);
1292
1293print(symmetricPower(A, 2));
1294print(symmetricPower(A, 3));
1295
1296module B = a*gen(1) + c* gen(2), b * gen(1) + d * gen(2);
1297
1298print(symmetricPower(B, 2));
1299print(symmetricPower(B, 3));
1300
1301kill r;
1302
1303printlevel = save;
1304}
1305
1306//////////////////////////////////////////////////////////////////////////////
1307
1308proc exteriorPower(module A, int k)
1309"USAGE:    exteriorPower(A, k); A module, k int
1310RETURN:   module: the k-th exterior power of A
1311NOTE:     the chosen bases and temporary data
1312          may be shown if printlevel is big enough.
1313          Last rows may be invisible if zero.
1314SEE ALSO: symmetricPower
1315KEYWORDS: exterior power
1316EXAMPLE:  example exteriorPower; shows an example"
1317{
1318  int p = printlevel - voice + 2;
1319  def save = basering;
1320
1321  int M = nrows(A);
1322  int N = ncols(A);
1323
1324  int i, j;
1325
1326  /////////////////////////////////////////////////////////////////
1327  def Tn = exteriorBasis(N, k); setring Tn;
1328  ideal Ink = I;
1329  dbprint(p-3, "Temporary Source Ring", basering);
1330  dbprint(p, "E^k(Source Basis)", Ink);
1331
1332  /////////////////////////////////////////////////////////////////
1333  def Tm = exteriorBasis(M, k); setring Tm;
1334  ideal Imk = I;
1335  dbprint(p-3, "Temporary Image Ring", basering);
1336  dbprint(p, "E^k(Image Basis)", Imk);
1337
1338
1339  def Rm = save + Tm;
1340  setring Rm;
1341  dbprint(p-2, "Temporary Working Ring", Rm);
1342
1343  module A = imap(save, A);
1344
1345  ideal B; poly t;
1346
1347  for( i = N; i > 0; i-- )
1348  {
1349    t = 0;
1350    for( j = M; j > 0; j-- )
1351    {
1352      t = t + A[i][j] * var( nvars(save) + j); // tensor product!!!
1353    }
1354
1355    B[i] = t;
1356  }
1357
1358  dbprint(p-1, "Matrix of simgle images", B);
1359
1360  map TMap = Tn, B; ideal C = TMap(Ink); // apply S^k A to Source basis vectors... (Ink)
1361  C = NF(C, std(0));
1362
1363  dbprint(p-1, "Image Matrix: ", C);
1364
1365  // and write it in Image basis (Imk)
1366
1367  ideal Imk = imap(Tm, Imk);
1368
1369  module D; poly lm; vector tt;
1370
1371  for( i = ncols(C); i > 0; i-- )
1372  {
1373    t = C[i];
1374    tt = 0;
1375
1376    while( t != 0 )
1377    {
1378      lm = leadmonom(t);
1379      //    lm;
1380      for( j = ncols(Imk); j > 0; j-- )
1381      {
1382        if( lm / Imk[j] != 0 )
1383        {
1384          tt = tt + (lead(t) / Imk[j]) * gen(j);
1385          break;
1386        }
1387      }
1388      t = t - lead(t);
1389    }
1390
1391    D[i] = tt;
1392//    tt;
1393  }
1394
1395  // D; print(D);
1396
1397
1398  setring save;
1399
1400  // basering;
1401
1402  module AA = imap(Rm, D);
1403
1404//  nrows(AA) = Nk; // ????
1405//  ncols(AA) = Mk;
1406
1407//  Nk, Mk;
1408
1409//  AA[Mk] = AA[Mk] * 1;
1410
1411  return(AA);
1412}
1413example
1414{ "EXAMPLE:"; echo = 2;
1415  int save = printlevel; printlevel = 1;
1416
1417  ring r = (0),(a, b, c, d), dp; r;
1418
1419  module A = a*gen(1), b * gen(1), c*gen(1), d * gen(1);
1420
1421  print(exteriorPower(A, 2));
1422  print(exteriorPower(A, 3));
1423
1424  module B = a*gen(1) + c* gen(2), b * gen(1) + d * gen(2);
1425
1426  print(exteriorPower(B, 2));
1427  print(exteriorPower(B, 3));
1428
1429  kill r;
1430  ring r = (0),(a, b, c, d), dp;def g = SuperCommutative();setring g;
1431
1432  module A = a*gen(1), b * gen(1), c*gen(1), d * gen(1);
1433
1434  print(exteriorPower(A, 2));
1435  print(exteriorPower(A, 3));
1436
1437  module B = a*gen(1) + c* gen(2), b * gen(1) + d * gen(2);
1438
1439  print(exteriorPower(B, 2));
1440  print(exteriorPower(B, 3));
1441
1442  kill r;
1443
1444  printlevel = save;
1445}
1446
1447//////////////////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.