[Edu-sig] LinuxFest and IPython

Kirby Urner urnerk at qwest.net
Tue Apr 20 18:30:33 EDT 2004


On Tuesday 20 April 2004 08:41 pm, David Handy wrote:

> > This is a way to get around a standard text book problem of elaborating
> > code.  Do you repeat the whole code swatch, making it longer each time?
> > With inheritance, you don't repeat, just inherit.  But of course one
> > wouldn't necessarily want to code this way for real -- it's more just a
> > way to demonstrate the concepts.
>
> Interesting approach. What concept were you demonstrating?

Well, in this case I just meant the concept of inheritance.  I'm showing how 
inheritance allows me to "continue" an evolving class definition across 
several versions.

But more specifically, I was going through slides of two "math objects" I'd 
consider good for introducing OO and, at the same time, reviewing enhancing 
basic mathematics understanding.  These two:  Q (rational number) and P 
(permutation).

Rational numbers are an obvious candidate because they store rather minimal 
data:  a numerator and a denominator (both integers), and then methods mess 
with these data in various ways, sometimes to return new Qs as a result (and 
there's a design pattern you need when returning Qs from multiple versions, 
as generally you don't want to return a previous generation of Q -- a parent 
-- when starting with a more advanced Q as an argument).

Permutations are just as simple, but unfortunately get hidden on the other 
side of Calculus Mountain, i.e. high school students don't get access to 
these creatures because they're considered a part of group theory or abstract 
algebra or what not.  I look at pre-college computer science as a way to 
disrupt these silly sequencing ideas, in search of programming challenges 
with lessons to teach on several levels.

So with a permutation, you basically switch elements around, and when you 
"multiply" two permutations, it's basically composition, i.e. you do the 
first switch, then apply the second to the first, getting back a third switch 
(i.e. shuffle, i.e. rearrangement, i.e. permutation) that's the composition 
of these two.  So of course we want to overload the __mul__ method for this.

The analogy with Q objects (rational numbers) is made clear in the code:  both 
Qs and Ps have a way to get a multiplicative inverse, such that q * ~q or p * 
~p nets you an "identity element" (in the case of permutations, that's a 
"switch" that takes every element to itself).

By the way, as my new Pyblosxom blog makes clear, I'm feeling exultant these 
days because I'm finally able to sit in cafes with a Linux laptop (recompiled 
the kernel myself to get power-management (preen, puff, strut)), write stuff, 
and commit it to the internet.  

That's what I'm doing right now, at the Powell's on Hawthorne.  As an 
exercise, I'm going to upload the LinuxFest ppt presentation (done in 
OpenOffice -- haven't tested in Windows Office yet) and post the URL in a 
next email to edu-sig.  

The link to my blog is here:
http://www.4dsolutions.net/cgi-bin/blog   There's hardly anything there yet 
(just started it last night).  But the relevance to edu-sig is this is rather 
minimal blog infrastructure written in Python (adapted from the Perl 
original).  Along with MoinMoin (and of course Zope and Plone), it shows off 
what Python can do in the realm of internet applications.  Plus I'm using aap 
to update this blog -- another Python tool.

Kirby




More information about the Edu-sig mailing list