pythonfinite-group-theory

Determine if (*,G) forms an associative group in group theory


Lets say I have a group G={a,b,e} where a,b are arbitrary elements and e denotes the neutral element. I came up with a certain Cayley table and want to verify that what I have done is right by checking the associativity.

That means I want to check for arbitrary x,y,z in G that x(yz)=(xy)z, because by hand I would have to check 3*3*3 = 27 cases, which is just nuts.

I didn't come far in my coding so far and I'd appreciate some hints or elegant ways how to approach this problem. I am a beginner at python but have a basic understanding of loops and functions.

My idea of the program:

I define a function lets say group which takes as an input a string. I add the string by the .extend(string) function to certain list which allows me to analyze the given input one by one.

Via an if statement lets say:

if checklist[0] == "a" and checklist[1] == "b":
    checklist.pop[0]
    checklist[0] = "e"

I could first drop the first entry of the list and then replace it by the desired new value. I did continue like that adding more and more if statements and at the end recursively called my function again and it would terminate if the length of my checklist is equal to 1.

However this is not a very elegant code which also runs into problems with special cases. Hence I believe my effort was in vain and I ought to believe that there is a much simpler and more elegant solution to this problem. I hope you can help me guide me in the right direction to find it.


Code example (not complete but conceptual):

checklist = []

def group(abc):
    if len(checklist) == 1:
        return checklist
    else:
        checklist.extend(abc)
        if (checklist[0] == "a" and checklist[1] == "a"):
            checklist.pop(0)
            checklist[0] = "b"
        if (checklist[0] == "a" and checklist[1] == "b"):
            checklist.pop(0)
            checklist[0] = "e"
        if (checklist[0] == "a" and checklist[1] == "e"):
            checklist.pop(0)
            checklist[0] = "a"
        if (checklist[0] == "b" and checklist[1] == "a"):
            checklist.pop(0)
            checklist[0] == "e"
        if (checklist[0] == "b" and checklist[1] == "b"):
            checklist.pop(0)
            checklist[0] = "a"
        if (checklist[0] == "b" and checklist[1] == "e"):
            checklist.pop(0)
            checklist[0] = "b"
        if (checklist[0] == "e" and checklist[1] == "a"):
            checklist.pop(0)
            checklist[0] = "a"
        if (checklist[0] == "e" and checklist[1] == "b"):
            checklist.pop(0)
            checklist[0] = "b"
        if (checklist[0] == "e" and checklist[1] == "e"):
            checklist.pop(0)
            checklist[0] = "e"
        group(checklist)
        return checklist

Solution

  • I would just use itertools.product to generate each triple of elements x, y, z of your group G and check that the triple is associative.

    You could define a function which checks to see whether your group operation on a particular triple is associative and then proceed to check each possible triple in the group in turn. If "associativity fails..." is printed, then G is not associative under your group operation.

    import itertools
    
    G = [0, 1, 2, 3, 4, 5] # or whatever your group might be
    
    def is_associative(x, y, z):
        if (x*y)*z == x*(y*z):
            return True
        return False
    
    xyz = itertools.product(G, repeat=3)
    
    for three in xyz:
        if not is_associative(*three):
             print("associativity fails for %s, %s, %s") % three
    

    Obviously, in the definition of is_associative, you'd want to replace * with whatever your group operation is.