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

How to draw the following graph

asked 5 years ago

Captcha gravatar image

updated 5 years ago

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

Suppose we consider the group Zn.

We consider an element aZn and form the subgroup generated by a i.e. a=a,2a,3a,0.

We form a graph G whose vertices are a and a and b are adjacent if either ab or ba .

How to plot the graph G is Sagemath?

I am giving an example to clear the question:

Consider Z4 then consider 0, 1 , 2, 3

Clearly 0=0, 1=1,2,3,0 , 2=2,0, 3=0,1,2,3.

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

1 is adjacent to 2 , 0,

2 is adjacent to 1 , 0, 3

and 3 is adjacent to 0, 2

Thus G becomes

https://imgur.com/Ef9P4uz

Preview: (hide)

Comments

1

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

rburing gravatar imagerburing ( 5 years ago )

Regarding the picture, i would say that @Captcha means that the vertices are elements of Zn, not its subgroups

tmonteil gravatar imagetmonteil ( 5 years ago )

2 Answers

Sort by » oldest newest most voted
1

answered 5 years ago

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:

ij in Zn 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:
                G.add_edge(i,j)
    return G

Then, you can do:

gr(4).plot()
Preview: (hide)
link

Comments

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 ( 5 years ago )
1

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 : https://doc.sagemath.org/html/en/them...

tmonteil gravatar imagetmonteil ( 5 years ago )
1

answered 5 years ago

rburing gravatar image

Here's a way:

n = 12
G = AdditiveAbelianGroup([n])
from collections import defaultdict
subgroup_gens = defaultdict(list)
for g in G:
    subgroup_gens[G.submodule([g])].append(ZZ(g[0]))
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

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

Seen: 452 times

Last updated: Aug 26 '19