Friday, January 11, 2008

Pythonic Algebra

The above screen snippet shows two algebraic functions, everyday inhabitants of classroom textbooks, getting wrapped by some Pythonic OO thing such that we're subsequently able to compose these functions using the multiplication operator, at no extra cost to administrators (Python is free).

That's how group theorists want us to think of functions, or permutations, as elements you might chain together by means of a binary operation variously called composition or multiplication.

f(g(x)) and g(f(x)) are respective synonyms for (f*g)(x) and (g*f)(x).

Does commutativity pertain? That depends on the group, if it is a group. Maybe it's a ring too.

Welcome to high school algebra.

The wrapping Function class, shown below, overloads both __mul__ and __call__. We don't just want to compose them, we want to pass them arguments (food) and have them do work (expend energy).

click for larger view

Related thread on math-thinking-l.