[Edu-sig] computer algebra
kirby.urner at gmail.com
Sun Dec 14 18:03:08 CET 2008
On Wed, Dec 10, 2008 at 8:27 PM, Guido van Rossum <guido at python.org> wrote:
<< SNIP >>
> Fortunately Python supports a way of overloading binary operators
> where it is sufficient if *one* of the operands knows how to deal with
> the other. So Fraction(3, 4) * 2j happily returns 1.5j. You don't have
> to teach Fraction about Matrix if you can teach Matrix about Fraction.
This is one I keep coming back to.
At the other end of the spectrum is thinking of * almost like an
object and trying to write class methods using Mul as a platform. You
have to check: is this a matrix by a vector? a Fraction by a floating
point?... and so on through the myriad types allowed to multiply
together (quite a long list).
In contrast, with OO, numbers (those things which multiply) became
more intelligent and swallowed their own methods, show up already fit
to multiply, don't need "operators" floating out in space, match
makers on steroids. 1 contains __mul__ inside of it, meets up with a
complex, and... we get into left and right valency, i.e. operators
I think lots of experiments with this in the lab, and certainly fine
to do those somewhat demented things like make __mul__ mere
concatenation, otherwise oversimplify. This goes with my segment on
"biotum", a sort of "hello world" from the OO world, where we make a
Biotum class with primitive methods.
The advent of 'Spore' has helped a lot I'd say.
More information about the Edu-sig