ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 27 Feb 2018 13:47:02 -0600How to write the given program in sagehttp://ask.sagemath.org/question/41274/how-to-write-the-given-program-in-sage/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.
Mon, 26 Feb 2018 21:53:00 -0600http://ask.sagemath.org/question/41274/how-to-write-the-given-program-in-sage/Answer by j.c. for <p>I am new to sage. I have learned the basics of sage programming from various online notes.</p>
<p>I am interested to apply sage in linear algebra and graph theory.</p>
<p>My problem is I want to draw a graph as follows:</p>
<p>Vertices : Subspaces of a vector space of dimension $n$.</p>
<p>Edges: $V_1V_2\iff V_1 \subset V_2$ or $V_2\subset V_1$.</p>
<p>Please don't give me the solution.</p>
<p>Please help me how to write it step by step or give some resources from where I can find this.</p>
http://ask.sagemath.org/question/41274/how-to-write-the-given-program-in-sage/?answer=41290#post-id-41290[This stackoverflow answer](https://stackoverflow.com/a/12169578) 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](http://doc.sagemath.org/html/en/reference/modules/sage/modules/free_module.html).
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.Tue, 27 Feb 2018 13:37:02 -0600http://ask.sagemath.org/question/41274/how-to-write-the-given-program-in-sage/?answer=41290#post-id-41290Answer by tmonteil for <p>I am new to sage. I have learned the basics of sage programming from various online notes.</p>
<p>I am interested to apply sage in linear algebra and graph theory.</p>
<p>My problem is I want to draw a graph as follows:</p>
<p>Vertices : Subspaces of a vector space of dimension $n$.</p>
<p>Edges: $V_1V_2\iff V_1 \subset V_2$ or $V_2\subset V_1$.</p>
<p>Please don't give me the solution.</p>
<p>Please help me how to write it step by step or give some resources from where I can find this.</p>
http://ask.sagemath.org/question/41274/how-to-write-the-given-program-in-sage/?answer=41291#post-id-41291Note 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.
Tue, 27 Feb 2018 13:47:02 -0600http://ask.sagemath.org/question/41274/how-to-write-the-given-program-in-sage/?answer=41291#post-id-41291