Ask Your Question
0

How to write the given program in sage

asked 2018-02-26 21:53:00 -0500

Captcha gravatar image

I am new to sage. I have learned the basics of sage programming from various online notes.

I am interested to apply sage in linear algebra and graph theory.

My problem is I want to draw a graph as follows:

Vertices : Subspaces of a vector space of dimension $n$.

Edges: $V_1V_2\iff V_1 \subset V_2$ or $V_2\subset V_1$.

Please don't give me the solution.

Please help me how to write it step by step or give some resources from where I can find this.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-02-27 13:37:02 -0500

j.c. gravatar image

updated 2018-02-27 13:50:03 -0500

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 != y and (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.

edit flag offensive delete link more
0

answered 2018-02-27 13:47:02 -0500

tmonteil gravatar image

Note that if you work on the reals, your graph will have uncountably many vertices, and Sage is not able to handle that. So, the first thing could be to precise on which field are your vector spaces defined.

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: 2018-02-26 21:53:00 -0500

Seen: 38 times

Last updated: Feb 27