simple symbolic math in Python
Delaney, Timothy
tdelaney at avaya.com
Sun Jan 7 22:50:32 EST 2001
This doesn't cover the general case ... only the specific case. Yes, sin may
now work - but cos won't, or atan, etc, unless you replace *everything* ...
Tim Delaney
Avaya Australia
+61 2 9352 9079
> -----Original Message-----
> From: Rainer Deyke [mailto:root at rainerdeyke.com]
> Sent: Monday, 8 January 2001 2:42 PM
> To: python-list at python.org
> Subject: Re: simple symbolic math in Python
>
>
> "Kragen Sitaker" <kragen at dnaco.net> wrote in message
> news:vE966.12210$K72.50241 at e420r-atl1.usenetserver.com...
> > I posted most of this to kragen-hacks
> > <kragen-hacks-subscribe at kragen.dnaco.net> late last millennium.
> >
> > I'm running into a problem: I can overload unary minus, but I can't
> > overload e.g. math.sin and math.cos, because they're not
> methods. It
> > would be really nice to have a way to do that. I can create objects
> > that act just like dictionaries or files, including working
> with almost
> > all of the built-in functions, but it doesn't look like I can create
> > objects that look just like numbers.
>
> import math
>
> class MyNumber:
> ...
>
> old_sin = math.sin
>
> def my_sin(n):
> if isinstance(n, MyNumber):
> ...
> else:
> return old_sin(n)
>
> math.sin = my_sin
>
>
> --
> Rainer Deyke (root at rainerdeyke.com)
> Shareware computer games - http://rainerdeyke.com
> "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
>
>
> --
> http://www.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list