Loading [MathJax]/jax/output/HTML-CSS/jax.js
Ask Your Question
0

How to write the given program in sage

asked 7 years ago

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: V1V2V1V2 or V2V1.

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.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 7 years ago

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.

Preview: (hide)
link
0

answered 7 years ago

j.c. gravatar image

updated 7 years ago

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 Fn over F=GF(pk):

 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(32), 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.

Preview: (hide)
link

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: 7 years ago

Seen: 489 times

Last updated: Feb 27 '18