# /home/jaubrey/webwork//pg_TRUNK/macros/MatrixUnits.pl

### From WeBWorK

# NAME

MatrixUnits.pl

# SYNOPSIS

Generates unimodular n x n (n=2,3,4) MathObject matrices with real entries.

# DESCRIPTION

This macro provides some routines for generating n x n (n=2,3,4)
MathObject matrices with real entries that have determinant in the
group of units of the integers Z (i.e., are Z-invertible). A matrix
`$M = GLnZ();`

(for det = +1 or -1) or <$M = SLnZ();> (for det = -1)
has all integer entries, is invertible, and its inverse has all integer entries.
The matrix entries are intentionally chosen to be integers close to zero
(so, if you want unimodular matrices with larger integer entries, you
may want to copy the source code and modify it to suit your needs).
The basic idea is to multiply several elementary matrices of
determinant +1 or -1 together to get a unimodular matrix (although the
code below accomplishes this by elementary row operations rather
than by multiplication of elementary matrices).

**To produce a determinant +1 or -1 MathObject matrix**`$A`

, use`$A = GL2Z();`

,`$A = GL3Z();`

,`$A = GL4Z();`

**To produce a determinant +1 MathObject matrix**`$A`

, use`$A = SL2Z();`

,`$A = SL3Z();`

,`$A = SL4Z();`

**For determinant +1 or -1 perl arrays, use**`@a = GL2Z_perl();`

,`@a = GL3Z_perl();`

,`@a = GL4Z_perl();`

**For determinant +1 perl arrays, use**`@a = SL2Z_perl();`

,`@a = SL3Z_perl();`

,`@a = SL4Z_perl();`

Note that the indexing on MathObject matrices starts at 1, while the indexing
on perl arrays starts at 0, so that `$A-<gt`

element(1,1);> corresponds to
`$a[0][0];`

. The perl arrays can be made into MathObject matrices by
`$A = Matrix(@a);`

, and this is, in fact, what the `GLnZ()`

and `SLnZ()`

subroutines do for you. The perl versions `@a = GLnZ_perl()`

and
`@a = SLnZ_perl()`

are useful if you want to have quick access to the matrix
values (as perl reals stored in `@a`

) without having to pull them out of a
MathObject matrix via `@b = $A-<gt`

value;> (in which case `@b`

is an
array of MathObject reals).

Note: There is overlap between MatrixUnits.pl (written after MathObject matrices were created) and MatrixUnimodular.pl (written before MathObject matrices were created). MatrixUnimodular.pl was left unchanged to provide legacy support for existing PG files.

# AUTHORS

Paul Pearson, Hope College, Department of Mathematics