[Tutor] determining whether a set is a group
Daniel Yoo
dyoo@hkn.eecs.berkeley.edu
Sun, 29 Apr 2001 00:05:50 -0700 (PDT)
On Sat, 28 Apr 2001, Sheila King wrote:
> The axioms (basic rules) for a group are:=20
> ( where the dot (=95) symbolizes some operation...)
>=20
> 1.CLOSURE: If a and b are in the group then a =95 b is also in the gro=
up.=20
> 2.ASSOCIATIVITY: If a, b and c are in the group then (a =95 b) =95 c =
=3D a =95 (b =95
> c).=20
> 3.IDENTITY: There is an element e of the group such that for any eleme=
nt a
> of the group
> a =95 e =3D e =95 a =3D a.=20
> 4.INVERSES: For any element a of the group there is an element a^(-1) =
such
> that=20
> a =95 a^(-1) =3D e=20
> and=20
> a^(-1) =95 a =3D e=20
Doing stuff with infinite sets looks messy, so let's try working with
finite groups for now. It appears that a group is a combination of:
1. a set of elements.
2. some operation that combines any two elements.
There's no built-in that perfectly represents a set in Python, but in a
pinch, the list structure works very well. Also, Python functions seem
like a great way to represent a group operator. For example, we can say
that:
###
def addModFour(x, y):
return (x + y) % 4
mygroup =3D ([0, 1, 2, 3], addModFour)
###
would be one way to represent a group in Python, as a 2-tuple. What's
nice is that this representation allows us to test for all four cases
fairly nicely. Here's a little snippet that hints at a possible way to
test for closure:
###
elements, operator =3D mygroup
if operator(elements[0], elements[1]) in elements:
print "Our group might not be closed,"
print "but at least %s dotted with %s is in our set" % (elements[0],
elements[1]")
else:
print "There's no way this is a group, because it's not closed!"
###
Once you get through the for-loops and lists chapter in Teach Yourself
Python, try writing the closure checking function; I think you'll be
pleasantly surprised.
Hope this helps!