Ask Your Question

How to draw the following graph

asked 2019-08-26 16:02:04 +0200

Captcha gravatar image

updated 2019-08-26 16:03:07 +0200

I want to write the following code in sagemath but unable to write it:

Suppose we consider the group $\Bbb Z_n$.

We consider an element $a\in \Bbb Z_n$ and form the subgroup generated by $a$ i.e. $\langle a\rangle ={a,2a,3a,\ldots 0}.$

We form a graph $G$ whose vertices are $\langle a\rangle $ and $\langle a\rangle $ and $\langle b\rangle $ are adjacent if either $\langle a\rangle \subset \langle b\rangle $ or $\langle b\rangle \subset \langle a\rangle $ .

How to plot the graph $G$ is Sagemath?

I am giving an example to clear the question:

Consider $\Bbb Z_4$ then consider $\langle 0\rangle $, $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$

Clearly $\langle 0\rangle ={0}$, $ \langle 1\rangle={1,2,3,0}$ , $ \langle 2={2,0}\rangle$, $ \langle 3={0,1,2,3}\rangle$.

Thus the graph $G$ has vertices as $\langle 0\rangle $, $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$ and $\langle 0\rangle $ is adjacent to $ \langle 1\rangle$ , $ \langle 2\rangle$, $ \langle 3\rangle$,

$\langle 1\rangle $ is adjacent to $ \langle 2\rangle$ , $ \langle 0\rangle$,

$\langle 2\rangle $ is adjacent to $ \langle 1\rangle$ , $ \langle 0\rangle$, $ \langle 3\rangle$

and $\langle 3\rangle $ is adjacent to $ \langle 0\rangle$, $ \langle 2\rangle$

Thus $G$ becomes

edit retag flag offensive close merge delete



Why are $1$ and $3$ different vertices in your graph? They generate the same additive subgroup, i.e. $\langle 1\rangle = \langle 3 \rangle$.

rburing gravatar imagerburing ( 2019-08-26 16:56:57 +0200 )edit

Regarding the picture, i would say that @Captcha means that the vertices are elements of $\mathbb{Z}_n$, not its subgroups

tmonteil gravatar imagetmonteil ( 2019-08-26 17:52:49 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2019-08-26 17:49:11 +0200

tmonteil gravatar image

Unfortunately, if you start defining your groups the "normal" way with groups.misc.AdditiveCyclic, you will not find a way to construct subgroups (at least i did not find any subgroup method or similar). So, you will have to use permuation groups (they can compute subgroups) wich is already a workaround.

So, let me suggest to work directly with this basic property of cyclic groups:

$\langle i \rangle \subseteq \langle j \rangle$ in $\mathbb{Z}_n$ if, and only if, $gcd(j,n) | gcd(i,n)$ (where $|$ stands for "divides").

Hence, the following code should do the trick:

def gr(n):
    G = Graph(n)
    for i in range(n):
        for j in range(i+1,n):
            a,b = gcd(i,n), gcd(j,n)
            if (a.divides(b) or b.divides(a)) and a != b:
    return G

Then, you can do:

edit flag offensive delete link more


I am extremely thankful for the answer. Can you kindly say how to start learning coding in sagemath? How to know the way to write loops , how to draw a graph, add edges as you have etc.??

Captcha gravatar imageCaptcha ( 2019-08-27 10:33:41 +0200 )edit

I think you should first learn some python, for loops, functions, tests, etc. There are tons on nice tutorials on the web. Then, you will learn Sage specifics from the experience, you can have a look at the thematic tutorials at :

tmonteil gravatar imagetmonteil ( 2019-08-28 13:45:05 +0200 )edit

answered 2019-08-26 17:40:15 +0200

rburing gravatar image

Here's a way:

n = 12
G = AdditiveAbelianGroup([n])
from collections import defaultdict
subgroup_gens = defaultdict(list)
for g in G:
mylabel = lambda H: LatexExpr('$' + '='.join('\\langle ' + str(g) + ' \\rangle' for g in subgroup_gens[H]) + '$')
Graph([(mylabel(H),mylabel(K)) for H in subgroup_gens.keys() for K in subgroup_gens.keys() if H != K and H.is_submodule(K)]).plot(figsize=6)

additive subgroups of Z/12Z

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


Asked: 2019-08-26 16:02:04 +0200

Seen: 370 times

Last updated: Aug 26 '19