Ask Your Question
0

How to draw a graph whose vertices are elements of permutation group

asked 2019-08-05 15:51:11 +0200

Captcha gravatar image

updated 2019-08-26 21:14:07 +0200

FrédéricC gravatar image

How to write the following program in SageMath:

Consider the Permutation Group $S_3$.

The elements of $S_3$ are $e,(12),(13),(23),(123),(132)$.

I want to draw a graph $G$ whose members are the elements of $S_3$ and two vertices $x,y$ are adjacent if and only if $xy\neq yx$.

I am stuck in doing the following things:

  1. How to call the elements of $S_3$ through a loop?
  2. How to draw the graph $G$ ?

I can check whether they commute or not but I am stuck in the two things. Is there any way to write the code in SageMath?

As an example if I input $S_3$ I want to get the following graph

$G=Graph({1:[2,3,4,5],2:[1,3,4,5],3:[1,2,4,5],4:[1,2,3],5:[1,2,3]})$

Any help will be highly appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-08-05 18:52:47 +0200

For #1:

sage: G = groups.permutation.Symmetric(3)
sage: for x in G:
....:       (do stuff with x)

For example:

sage: G = groups.permutation.Symmetric(3)
sage: d = {}
sage: for x in G:
....:     for y in G:
....:         if x*y != y*x:
....:             if x in d:
....:                 d[x].append(y)
....:             else:
....:                 d[x] = [y]
....:

At this point, d is a dictionary. The keys are the non-identity elements of G, and the value corresponding to x is the list of elements y that do not commute with x. So for #2:

sage: gr = Graph(d)
sage: view(gr)

image description

edit flag offensive delete link more

Comments

I am extremely thankful for the answer sir. Can you kindly explain the logic behind "if x in d: d[x].append(y) else d[x]=[y]" If you could explain why is it written this way I will be grateful

Captcha gravatar imageCaptcha ( 2019-08-06 03:59:06 +0200 )edit

d[x] is supposed to be a list consisting of the elements y which do not commute with x. If that list hasn't been created yet (because no such elements y have been found), then if x in d will return False, so you set d[x] to be the list containing y. Otherwise d[x] exists, so append y to the end of the list.

John Palmieri gravatar imageJohn Palmieri ( 2019-08-06 05:25:22 +0200 )edit

Note that using a defaultdict(list) (imported from collections) instead of a dict, you could replace those 4 lines with d[x].append(y)

tmonteil gravatar imagetmonteil ( 2019-08-26 22:51:05 +0200 )edit

Thank you for your answer

Captcha gravatar imageCaptcha ( 2019-08-27 10:35:53 +0200 )edit

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: 2019-08-05 15:51:11 +0200

Seen: 226 times

Last updated: Aug 26 '19