Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This stackoverflow answer by John Palmieri has some very relevant information. In particular, from the first code block in John Palmieri's answer we easily see (1) how to define in SageMath a vector space $\mathbf{F}^n$ over $\mathbf{F}=GF(p^k)$:

 p = 3
 k = 2
 K = GF(p^k, 'a')
 n = 3
 V = K^n

and (2) how to get lists of subspaces of various dimensions, e.g.:

 m = 1
 Vm = list(V.subspaces(m))

After running this code, V will be a SageMath object representing a vector space of dimension 3 over the finite field $GF(3^2)$, and Vm will be a list of the subspaces of V of dimension m=1 (with 91 elements).

For reference, please see this documentation page.

Now let us compute a list of all subspaces of V, as this will correspond to your set of vertices. You might do this by writing a list comprehension involving the dimension m in V.subspaces(m), e.g.

 subspacesbydimension = [list(V.subspaces(m) for m in range(n+1)]

You can check that this is a list of 4 lists where the lengths of each of the sublists are 1, 91, 91, and 1. To make a list of vertices, we flatten this list:

 vertices = flatten(subspacesbydimension)

You now want to generate a list of pairs of adjacent vertices. We can follow John Palmieri's second code block (except that we use the function .is_subspace() to check adjacency and we make a few changes so that it works):

 d = {}
 for x,X in enumerate(vertices):
     L = []
     for y,Y in enumerate(vertices):
     if X.is_subspace(Y) or Y.is_subspace(X):
          L.append(y)
     d[x] = L

Now generate the graph:

 G = Graph(d)

Hopefully that's more or less what you're after.

This stackoverflow answer by John Palmieri has some very relevant information. In particular, from the first code block in John Palmieri's answer we easily see (1) how to define in SageMath a vector space $\mathbf{F}^n$ over $\mathbf{F}=GF(p^k)$:

 p = 3
 k = 2
 K = GF(p^k, 'a')
 n = 3
 V = K^n

and (2) how to get lists of subspaces of various dimensions, e.g.:

 m = 1
 Vm = list(V.subspaces(m))

After running this code, V will be a SageMath object representing a vector space of dimension 3 over the finite field $GF(3^2)$, and Vm will be a list of the subspaces of V of dimension m=1 (with 91 elements).

For reference, please see this documentation page.

Now let us compute a list of all subspaces of V, as this will correspond to your set of vertices. You might do this by writing a list comprehension involving the dimension m in V.subspaces(m), e.g.

 subspacesbydimension = [list(V.subspaces(m) for m in range(n+1)]

You can check that this is a list of 4 lists where the lengths of each of the sublists are 1, 91, 91, and 1. To make a list of vertices, we flatten this list:

 vertices = flatten(subspacesbydimension)

You now want to generate a list of pairs of adjacent vertices. We can follow John Palmieri's second code block (except that we use the function .is_subspace() to check adjacency and we make a few changes so that it works):

 d = {}
 for x,X in enumerate(vertices):
     L = []
     for y,Y in enumerate(vertices):
     if X.is_subspace(Y) x != y and (X.is_subspace(Y) or Y.is_subspace(X):
Y.is_subspace(X)):
          L.append(y)
     d[x] = L

Now generate the graph:

 G = Graph(d)

Hopefully that's more or less what you're after.