making matrices

The simplest way to make a matrix is to give a doubly nested list of ring elements to the matrix command.

i1 : R = ZZ/101[x,y,z];
i2 : f = matrix {{x,0,y*z},{0,y^2,x^2}}

o2 = {0} | x 0  yz |
     {0} | 0 y2 x2 |

             2       3
o2 : Matrix R  <--- R

One way to construct a doubly nested list of ring elements is with the table command.

i3 : p = matrix table(3,3,(i,j) -> R_i^j)

o3 = {0} | 1 x x2 |
     {0} | 1 y y2 |
     {0} | 1 z z2 |

             3       3
o3 : Matrix R  <--- R
i4 : q = matrix table(3,3,(i,j) -> R_j^i)

o4 = {0} | 1  1  1  |
     {0} | x  y  z  |
     {0} | x2 y2 z2 |

             3       3
o4 : Matrix R  <--- R

The usual arithmetic operations among matrices are available, including direct sum (++) and tensor product (**). Scalars are converted to scalar matrices when necessary.

i5 : x*p

o5 = {0} | x x2 x3  |
     {0} | x xy xy2 |
     {0} | x xz xz2 |

             3       3
o5 : Matrix R  <--- R
i6 : 11-p

o6 = {0} | 10 -x    -x2    |
     {0} | -1 -y+11 -y2    |
     {0} | -1 -z    -z2+11 |

             3       3
o6 : Matrix R  <--- R
i7 : p*q

o7 = {0} | x4+x2+1   x2y2+xy+1 x2z2+xz+1 |
     {0} | x2y2+xy+1 y4+y2+1   y2z2+yz+1 |
     {0} | x2z2+xz+1 y2z2+yz+1 z4+z2+1   |

             3       3
o7 : Matrix R  <--- R
i8 : p++q

o8 = {0} | 1 x x2 0  0  0  |
     {0} | 1 y y2 0  0  0  |
     {0} | 1 z z2 0  0  0  |
     {0} | 0 0 0  1  1  1  |
     {0} | 0 0 0  x  y  z  |
     {0} | 0 0 0  x2 y2 z2 |

             6       6
o8 : Matrix R  <--- R
i9 : r = p++x

o9 = {0} | 1 x x2 0 |
     {0} | 1 y y2 0 |
     {0} | 1 z z2 0 |
     {0} | 0 0 0  x |

             4       4
o9 : Matrix R  <--- R
i10 : x ++ y ++ z ++ x*y*z

o10 = {0} | x 0 0 0   |
      {0} | 0 y 0 0   |
      {0} | 0 0 z 0   |
      {0} | 0 0 0 xyz |

              4       4
o10 : Matrix R  <--- R
i11 : p**p

o11 = {0} | 1 x x2 x x2 x3  x2 x3  x4   |
      {0} | 1 y y2 x xy xy2 x2 x2y x2y2 |
      {0} | 1 z z2 x xz xz2 x2 x2z x2z2 |
      {0} | 1 x x2 y xy x2y y2 xy2 x2y2 |
      {0} | 1 y y2 y y2 y3  y2 y3  y4   |
      {0} | 1 z z2 y yz yz2 y2 y2z y2z2 |
      {0} | 1 x x2 z xz x2z z2 xz2 x2z2 |
      {0} | 1 y y2 z yz y2z z2 yz2 y2z2 |
      {0} | 1 z z2 z z2 z3  z2 z3  z4   |

              9       9
o11 : Matrix R  <--- R

The components of a direct sum can be recovered later.

i12 : components r

o12 = {{0} | 1 x x2 |, {0} | x |}
       {0} | 1 y y2 |
       {0} | 1 z z2 |

o12 : List

There are commands for horizontal and vertical concatenation of matrices, and again, scalars are converted to scalar matrices when necessary.

i13 : p|q

o13 = {0} | 1 x x2 1  1  1  |
      {0} | 1 y y2 x  y  z  |
      {0} | 1 z z2 x2 y2 z2 |

              3       6
o13 : Matrix R  <--- R
i14 : p||q

o14 = {0} | 1  x  x2 |
      {0} | 1  y  y2 |
      {0} | 1  z  z2 |
      {0} | 1  1  1  |
      {0} | x  y  z  |
      {0} | x2 y2 z2 |

              6       3
o14 : Matrix R  <--- R
i15 : p|1

o15 = {0} | 1 x x2 1 0 0 |
      {0} | 1 y y2 0 1 0 |
      {0} | 1 z z2 0 0 1 |

              3       6
o15 : Matrix R  <--- R
i16 : x^3||p

o16 = {0} | x3 0  0  |
      {1} | 0  x3 0  |
      {2} | 0  0  x3 |
      {0} | 1  x  x2 |
      {0} | 1  y  y2 |
      {0} | 1  z  z2 |

              6       3
o16 : Matrix R  <--- R

The identity matrix can be obtained as the identity map on a free module.

i17 : id_(R^3)

o17 = {0} | 1 0 0 |
      {0} | 0 1 0 |
      {0} | 0 0 1 |

              3       3
o17 : Matrix R  <--- R

A matrix is regarded as a homomorphism between two free modules, its source and target.

i18 : M = target f

       2
o18 = R

o18 : R - module, free
i19 : N = source f

       3
o19 = R

o19 : R - module, free

Free modules are actually graded free modules, with the same sort of grading that the ring comes with. The degrees of the basis vectors of the target are always zero.

i20 : degree M_0

o20 = {0}

o20 : List
i21 : degree M_1

o21 = {0}

o21 : List

If possible, the degrees of the basis vectors of the source are set so that the map f turns out to a homogeneous map of degree zero. This opportunism isimportant because certain algorithms will run faster on homogeneous maps.

i22 : degree N_0

o22 = {1}

o22 : List
i23 : degree N_1

o23 = {2}

o23 : List
i24 : degree N_2

o24 = {2}

o24 : List
i25 : isHomogeneous f

o25 = true

A list of the degrees of all the basis vectors can be obtained with degrees.

i26 : degrees N

o26 = {{1}, {2}, {2}}

o26 : List

It may happen that the matrix can not be made homogeneous. In that case, the degree of a basis vector is currently set to the degree of the largest monomial occurring in the corresponding column of the matrix. In a future version of the program it might be more sensible to set the degrees of the basis vectors all to zero.

i27 : g = matrix {{x,0,y*z},{y^2,x^2,0}}

o27 = {0} | x  0  yz |
      {0} | y2 x2 0  |

              2       3
o27 : Matrix R  <--- R
i28 : isHomogeneous g

o28 = false
i29 : degrees source g

o29 = {{2}, {2}, {2}}

o29 : List

Suppose we multiply a homogeneous polynomial by a homogeneous matrix. The result ought to be homogeneous, but how can we arrange that? Scalar multiplication should not change the source or target of a map! Instead, we introduce one final complication: each matrix records a degree of its own, which is normally zero, and is used when deciding whether the matrix is homogeneous.

i30 : degree matrix {{x^10}}

o30 = {0}

o30 : List
i31 : degree f

o31 = {0}

o31 : List

Multiplying a matrix by a homogeneous polynomial adds the degree of the polynomial to the degree of the map.

i32 : h = x^10 * f

o32 = {0} | x11 0     x10yz |
      {0} | 0   x10y2 x12   |

              2       3
o32 : Matrix R  <--- R
i33 : degree h

o33 = {10}

o33 : List
i34 : degrees source h

o34 = {{1}, {2}, {2}}

o34 : List
i35 : isHomogeneous h

o35 = true

If you don't like this, you have an alternative. The degree of a tensor product of two matrices is the sum of the degrees, and its source module is the tensor product of the source modules.

i36 : h = x^10 ** f

o36 = {0} | x11 0     x10yz |
      {0} | 0   x10y2 x12   |

              2       3
o36 : Matrix R  <--- R
i37 : degree h

o37 = {0}

o37 : List
i38 : degrees source h

o38 = {{11}, {12}, {12}}

o38 : List
i39 : isHomogeneous h

o39 = true


topindexpreviousupnext