First time here? Check out the FAQ!

Ask Your Question
0

apply Permutation cycles to a letters list second episode

asked 0 years ago

ortollj gravatar image

Hi

seeapply Permutation cycles to a letters list

I do not understand why there are errors when G.list() is used for tuples permutation cycles list:

import string
import sage.combinat.permutation as permutation

# apply each permutation cycle from tuples list to hL=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
def applyCyclesToLetters(tuplesL,hL) : 
    GL=[]
    firstL=[]
    for t in tuplesL :
        try :
            test=permutation.from_cycles(len(hL),t)
            GL.append([hL[test[i] - 1] for i in range(len(hL))])
            firstL.append(GL[-1][0]) # append only the first element of the permutation
        except Exception as e:
            print('error  ',t,e)
    return GL # ,firstL

hL=list(string.ascii_lowercase[0:8])
G = PermutationGroup([(1,2,3),(7,8)])

verticesL=[]
for el in G.list():
    verticesL.append(tuple(el))
verticesL
# verticesCopyL is copy paste of print (verticeL) , then it is ok for applyCyclesToLetters(verticesCopyL,hL)
verticesCopyL=[(), ((7,8),), ((1,3,2),), ((1,3,2), (7,8)), ((1,2,3),), ((1,2,3), (7,8))]

print('verticesL : ')
print(verticesL) 

print('verticesCopyL : ')
print(verticesCopyL)

print('applyCyclesToLetters(verticesCopyL)')
print(applyCyclesToLetters(verticesCopyL,hL))


print('applyCyclesToLetters(verticesL)')
print(applyCyclesToLetters(verticesL,hL))

print(type(verticesCopyL),[type(el) for el in verticesCopyL])
print(type(verticesL),[type(el) for el in verticesL])
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 0 years ago

Max Alekseyev gravatar image

updated 0 years ago

First off, on a minor note, in for el in G.list(): ... calling .list() is not needed and bears unnecessary overhead. You can simply state for el in G: ....

Now, about the errors you see. Inpermutation.from_cycles(len(hL),t), t is a tuple of PermutationGroupElement's, which confuses permutation.from_cycles() function. If you want to fix just this call, you can use permutation.from_cycles(len(hL),eval(str(t))) instead.

However, it's unclear why you convert elements of G into tuples at first place.

verticesL = G.list()

and then

test = permutation.from_cycles(len(hL), t.cycle_tuples())

or even simply

test = Permutation(t)

seems to be more natural here.

Preview: (hide)
link

Comments

Thank you @Max Alekseyev .

ortollj gravatar imageortollj ( 0 years ago )

.

import string
import sage.combinat.permutation as permutation

# apply each permutation cycle from tuples list to hL=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
def applyCyclesToLetters(tuplesL,hL) : 


    return GL 

hL=list(string.ascii_lowercase[0:8])
verticesCopyL=[(), ((7,8),), ((1,3,2),), ((1,3,2), (7,8)), ((1,2,3),), ((1,2,3), (7,8))]
G = PermutationGroup([(1,2,3),(7,8)])

verticesL=[]
for el in G:
    verticesL.append(tuple(el))
verticesL

Can someone help me write the body of the function that could handle both tuples from group G and tuples from verticesCopyL ? I'm sorry but I 'm not able to do it ;-(

ortollj gravatar imageortollj ( 0 years ago )

is python list of tuples not separated by comma a real Python object ?

ortollj gravatar imageortollj ( 0 years ago )
1

test = permutation.from_cycles(len(hL),eval(str(t))) should be most universal from this respect.

Max Alekseyev gravatar imageMax Alekseyev ( 0 years ago )

Yes it is working with that instruction, very sorry @Max Alekseyev, I did a mistake in my code when I first try it !.

code on sageCell

ortollj gravatar imageortollj ( 0 years ago )

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

Seen: 74 times

Last updated: Feb 19