[Tutor] checking within a table for identity
Julieta Rangel
julieta_rangel@hotmail.com
Mon, 07 May 2001 02:21:01 -0500
As some of you might remember, I was trying to figure out how to check for
associativity within a set. By taking bits and pieces from you all's
advice, I put together the following:
import string
def getCayleyTable(op,set):
product = {}
for x in set:
for y in set:
prompt = "%s %s %s = ? "%(x,op,y)
print " "
z = raw_input(prompt)
product [x,y] = z
if z not in set:
print " "
print "No need to go any further: your set is not a group"
return product
print " "
items = product.items()
items.sort()
return product
print " "
def cross(set1,set2):
resulting_set = []
for s1 in set1:
for s2 in set2:
resulting_set.append( (s1, s2) )
return resulting_set
set = raw_input("Enter the elements of the set separated by a comma,ie,
a,b,c: ")
set = string.split(set, ",")
print " "
op = raw_input("Enter the binary operator sign, ie, * : ")
d = getCayleyTable( op,set )
print " "
m=cross(set,set)
v=[]
for x in m:
v.append(d[x])
print v
for x in set:
c= cross(set,v)
e= cross(v,set)
l=[]
for x in c:
l.append(d[x])
k=[]
for x in e:
k.append(d[x])
if l!=k: print "your set is not a group"
As you can see, I don't have experience in programming, but considering I
started learning about a month ago, my program is not that awful. Now I
want to figure out how to check for identity on a set. By identity I mean,
given a set, there is an element in the set(let's call it e) such that for
all elements x, x*e= e*x =x. For example, let's say I have the set
{e,a,b,ab}, which is accompanied by the following table:
>e*e=e a*e=a b*e=b ab*e=ab
>e*a=a a*a=e b*a=ab ab*a=b
>e*b=b a*b=ab b*b=e ab*b=a
>e*ab=ab a*ab=b b*ab=a ab*ab=e
As you might see, the set {e,a,b,ab} has an identity element, which is e. If
you check, e*a=a and a*e=a, so e is the identity element of the set. As you
can see, you have to do this for every element within the set. What I need
to do is to "check whether there is an item in the set, where (item,
whatever)== whatever, for each whatever in the set, and also check whether
(whatever, item) == whatever." (I'm quoting from one of you guys, I believe
it is from Ms. King). Does anyone have any suggestions?
Julieta
>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com