> Sometimes I call what I teach "Gnu Math", a pun on > "New Math" and an > accurate reflection of what we owe the GNU project, > in liberating us from > the high costs of intellectual property owners who > planned to squeeze it > out of us until the cows came home. Now we have > power tools galore, and > have started work on tractors: > > http://www.ted.com/talks/marcin_jakubowski.html > > Kirby
Here is a direct quote from something I'm writing back to a student, in this "correspondence school" I teach at (DETC is the certifying body, once the State license is obtained -- we're a startup and still navigating these waters).
I'm not revealing anything that will give an "artificial boost" to other students i.e. if they find this first regarding Python4, Project 1, so much the better.
I claim real insights into abstract algebra are possible in this project, a manifestation of my confidence about this "Gnu bridge" twixt STEM math and STEM engineering.
We're not just using graphing calculators anymore in Kansas, provided Dorothy is lucky enough to get "girl scout math" in her corner (I use "gsm" as an abbreviation for the kind of community service DIY based computational thinking the scouting community is more known for, what with geocaching and the like).
You have seen how basic calculator operations + * - / are mapped to special name methods __add__ __mul__ __sub__ __truediv__. The same is true for ** (powering): it maps to __pow__.
The first two tests, of reverser * reverser and squarer * squarer are easily modified to become tests of reverser ** 2 and squarer ** 2 respectively.
def test_inverse(self): reverser = Composable(reverse) nulltran = reverser ** 2 for s in "", "a", "0123456789", "abcdefghijklmnopqrstuvwxyz": self.assertEquals(nulltran(s), s)
def test_square(self): squarer = Composable(square) po4 = squarer ** 2 for v, r in ((1, 1), (2, 16), (3, 81)): self.assertEqual(po4(v), r)
As to the guts of your method, I am optimistic about it passing these tests. Some additional assertRaises might be nice. Note it's a ValueError, not a TypeError, that a negative integer exponent should raise (in the world of multiplication == composition, f**-1 is taken to be an "inverse function" but w're not trying to dive that deeply into abstract algebra here).