[Edu-sig] Re: switching gears (and how)

Kirby Urner pdx4d@teleport.com
Wed, 07 Mar 2001 00:23:48 -0800


>The Pythagoreans were vegetarian, except that they did /not/ eat beans,
>being as how when you pop a bean open it resembles a foetus.

I'd never noticed.  Kidney beans aren't so interesting I don't 
think.

>To swing it back to Python, could dictionaries and tuples be used to
>represent groups?

Sure, why not? 

One common example of a group is a set of permutations, which 
are number or letter swappers.  This can be shown as a dictionary
e.g. {'A':'D','B':'E','C','F'...} -- each letter is being swapped
with another letter 3 letters further head in the alphabet, a 
so-called Julius Caeser cipher (hard to believe they'd have thought 
this secure -- I guess 'Z' wraps around somehow -- to 'C').  

You could show it like this:

Before:  ABCDEFGHIJKLMNOPQRSTUVWXYZ
After:   DEFGHIJKLMNOPQRSTUVWXYZABC
 
Such dictionaries may be re-expressed using what're called disjoint
subcycles:  (('A','D','G','J'...),('R','K','L')).  The way you
read this is to see each letter becoming the next one in the tuple,
e.g. 'A'->'D', with the last becoming the first e.g. 'L'->'R'.
The above tuples example isn't the same JC cipher exactly -- because
I wanted to have more than one subcycle.  But anyway it's a 
permutation.

So there you have it:  dictionaries and tuples of tuples, with 
optional Python code to convert back and forth between these 
two ways of giving the same info.

The group aspect comes in with this operation symbolized with *,
and which defines how two permutations related by this operator
result in.... you guessed it, another permutation (groups are 
'closed', meaning you always get a whatever-it-is when you 
operate on two whatevers-they-are).

Because group elements may include so many kinds of data (permutations
are just one kind go group element among any number), and because 
* means different things in different groups, it makes sense to 
use these data structures provided by Python AND the object-oriented 
syntax, since with OO we get the ability to override * by redefining 
__mul__ however we like.  

So whereas the _data_ of a group element might be stored in a tuple 
or dictionary, I like to think of these elements as _also_ containing 
knowledge of how to * (i.e. how to "multiply" -- whatever that means 
(depends on the group (there has to be something called an 
'identity element' though, such that A*e = e*A = A, and every group 
element has to have an 'inverse' such that A*A.inv()=e (* also has to 
be associative, i.e. A*B*C better not be ambiguous, in terms of its 
answer)))).

Mnemonic
========
CAIN:  Closure, Associative, Inverse, Neutral (identity)
Abel:  If * is also commutative (optional), it's an Abelian Group

Drawing from the book of Genesis.  Good place for a Py.. er snake.

Kirby