[Edu-sig] Wrapping functions in a Function class
kirby.urner at gmail.com
Wed Dec 12 18:04:45 CET 2007
On Dec 12, 2007 8:35 AM, Andrew Harrington <aharrin at luc.edu> wrote:
> Nice wrapper class Kirby!
> One thought: multiplying functions is another operation. I would
> tend to reserve '*' for that, or you will be confusing of limited.
We say "another operation" but then we deliberately re-confuse them
(the two symbols) in abstract algebra by just using the same symbol,
suggesting it's all __mul__ under the hood, provided you've got closure,
an identity, an inverse or whatever. Then you need __add__ so you
can talk about rings and fields (two ops, connected by distributive
feature -- __div__ and __sub__ are derivative ops, provided we have
> Since the raised circle is not a python operator, it appears you need
> to use a different, nonstandard composition symbol. Perhaps '%' (it
> has a raise circle as part of it :-) ). Then have the Function class
> do the basic arithmetic operations *and* composition.
In my classroom, I'm doing the abstract algebra thing and showing
how __mul__ takes on a meaning depending on namespace. Over
here, it works with integers, over there, with functions, and over
there, with some other set of elements. Arithmetic takes a back
seat. This isn't Everyday Math or anything close (which isn't to
say these can't co-exist, as they already do).
More information about the Edu-sig