generation of certain matrices

I'd like to create a list of roughly 100-1000 $2 \times 2$ matrices $[A_1,A_2,...,A_N]$ that have the following properties:

1. $\det A_j = 1$

2. The entries of each $A_j$ are in an imaginary quadratic integer ring, such as $\mathbb{Z}[i]$, or $\mathbb{Z}[\sqrt{-2}]$

For example, the matrix $$\begin{bmatrix} 1&2i \\ 0&1 \end{bmatrix}$$ fits the above specifications when the ring is $\mathbb{Z}[i]$.

I know that I probably want to run some kind of loop over the entries of the matrix, but I'm not sure how to do this. Perhaps I want to initially treat the matrices as lists of length 4, and then run an iterative loop over the lists. Then, when the above specifications are met, that list is stored somewhere else. I think I'd also like to put a bound on the "size" of the matrix entries, but that should be easy to do afterwards.

Thanks!

edit retag close merge delete

Hmm, there is a random_matrix command which might be helpful here.

Sort by » oldest newest most voted

Or you could use the algorithm='unimodular' option to random_matrix.

sage: random_matrix(GaussianIntegers(),2,algorithm='unimodular')

[-429*I + 54     -I - 10]
[   43*I - 1           1]
sage: random_matrix(GaussianIntegers(),2,algorithm='unimodular')

[  6*I - 7 -7*I - 12]
[    I - 1    -I - 2]
sage: random_matrix(GaussianIntegers(),2,algorithm='unimodular')

[   -6*I + 29 -221*I - 103]
[       I + 9    -74*I - 9]

You'd need to define your other rings and plop them in the right spot, of course. Edit: such as follows, though there are probably better ways to get this ring. In particular, be careful since the integral closure of $\mathbb{Z}[\sqrt{n}]$ isn't always equal to it, but depends on the residue class of n (mod 4), if I recall correctly.

K = NumberField(x^2 + 2, 's')
OK = K.ring_of_integers()
for n in range(3):
show(random_matrix(OK,2,algorithm='unimodular'))
more

This works well. It is a little bit annoying using the symbol 's' instead of the complex number sqrt(-2). Sage does seem to be able to work with it a little bit. For instance, M; M[1,0]; M[1,0]; M[1,0]; returns

[ s - 1 4*s + 19]

[ -s - 1 11*s - 12]

-s - 1

-1

-1

1

There are no problems for me... For instance:

sage: K.<s> = QuadraticField( -2 )
sage: OK    = K.ring_of_integers()
sage: M = random_matrix( OK, 2, algorithm = 'unimodular' )
sage: M
[  -s + 9 3*s + 10]
[      -s   -s + 1]
sage: M[0,0]
-s + 9
sage: M[0,1]
3*s + 10
sage: M[1,0]
-s
sage: M[1,1]
-s + 1
sage: a = M[0,0]
sage: a.list()
[9, -1]
sage: a
9
sage: a
-1

It seems that the entry $M_{00}=9-s = 9s^0+ (-1)s^1$ is stored as a list / as a vector, and asking for its components, a and a, implicitly forces the conversion to a list.

I'm sure there is a way to get the symbol to "look better" but I don't know how to do this as I typically only use the Gaussian integers, for which there is already the built-in symbol I.