Ask Your Question
2

How to construct matrix space over the set {+1, -1, 0} ?

asked 2022-08-21 12:15:41 +0100

the1diot gravatar image

I want to construct a set of matrices with entry either +1, -1 or 0. How to do this either matrix way or using digraph way, that is, if I consider set of digraphs over n vertices, then how do I make the edges have weights either +1, -1 or 0?

edit retag flag offensive close merge delete

Comments

I do not understand the question. Matrix entries and edge labels can be assigned to any numbers including -1, 0, +1.

Max Alekseyev gravatar imageMax Alekseyev ( 2022-08-21 16:04:46 +0100 )edit

Actually, what I want to do is construct the set of all matrices of given order n whose entries are either +1, -1 or 0. I know that the following: MS = MatrixSpace(GF(2),n,n) given me a space of all matrices with entries 1 or 0, but here 1+1=0, whereas I want the addition to be done over the integer field. In terms of digraphs, is there a way to restrict the weights to only +1, -1 or 0?

the1diot gravatar imagethe1diot ( 2022-08-21 18:25:10 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-08-21 20:53:09 +0100

updated 2022-08-21 20:57:10 +0100

There is no built-in way to construct such a set of matrices, but you can construct the set of integer lists of length n^2 with entries 0, 1, 2. Then you can subtract 1 from each entry to get entries -1, 0, 1, and then you can form a matrix from them:

sage: n = 3
sage: L = IntegerListsLex(length=n**2, max_part=2)
sage: len(L)
19683
sage: L[:6]
[[2, 2, 2, 2, 2, 2, 2, 2, 2],
 [2, 2, 2, 2, 2, 2, 2, 2, 1],
 [2, 2, 2, 2, 2, 2, 2, 2, 0],
 [2, 2, 2, 2, 2, 2, 2, 1, 2],
 [2, 2, 2, 2, 2, 2, 2, 1, 1],
 [2, 2, 2, 2, 2, 2, 2, 1, 0]]
sage: [matrix(n, n, [b-1 for b in a]) for a in L[:6]]
[
[1 1 1]  [1 1 1]  [ 1  1  1]  [1 1 1]  [1 1 1]  [ 1  1  1]
[1 1 1]  [1 1 1]  [ 1  1  1]  [1 1 1]  [1 1 1]  [ 1  1  1]
[1 1 1], [1 1 0], [ 1  1 -1], [1 0 1], [1 0 0], [ 1  0 -1]
]

sage: M = [matrix(3, 3, [b-1 for b in a]) for a in L]
sage: len(M)
19683

Using M = (matrix(...)) with parentheses instead of square brackets is faster and more memory efficient, because it doesn't create the whole list at once. In particular, if you want to loop over the set, don't construct the whole list, but do something like this:

sage: for a in L:
....:    mat = matrix(3, 3, [b-1 for b in a])
....:    ... do stuff with mat ...
edit flag offensive delete link more
1

answered 2022-08-21 21:30:52 +0100

Max Alekseyev gravatar image

updated 2022-08-21 21:32:15 +0100

To get all matrices over $\{ -1, 0, +1\}$ one can construct matrix space over GF(3) and then change ring of each matrix to ZZ and subtract 1 from each element:

for T in MatrixSpace(GF(3),2,2):
    M = T.change_ring(ZZ).apply_map(lambda x: x-1)
    print(M,'\n')
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-08-21 12:15:41 +0100

Seen: 336 times

Last updated: Aug 21 '22