ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
Re: [Tutor] determining whether a set is a group
by Daniel Yoo other posts by this author
Apr 29 2001 1:05AM messages near this date
Re: [Tutor] determining whether a set is a group | Re: [Tutor] determining whether a set is a group
On Sat, 28 Apr 2001, Sheila King wrote:

>  The axioms (basic rules) for a group are: 

>  ( where the dot (•) symbolizes some operation...)

>  

>     1.CLOSURE: If a and b are in the group then a • b is also in the group. 

>     2.ASSOCIATIVITY: If a, b and c are in the group then (a • b) • c = a • (b •

>  c). 

>     3.IDENTITY: There is an element e of the group such that for any element a

>  of the group

>       a • e = e • a = a. 

>     4.INVERSES: For any element a of the group there is an element a^(-1) such

>  that 

>            a • a^(-1) = e 

>            and 

>            a^(-1) • a = e 


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 = ([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 = 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!


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Julieta
Sheila King
Daniel Yoo
Benoit Dupire
Benoit Dupire
Corran Webster
Sheila King
Sheila King
Deirdre Saoirse Moen
Daniel Yoo

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved