[Python-ideas] Including elementary mathematical functions in the python data model

Nick Coghlan ncoghlan at gmail.com
Tue Sep 21 23:53:09 CEST 2010

On Wed, Sep 22, 2010 at 4:44 AM, Michael Gilbert
<michael.s.gilbert at gmail.com> wrote:
> Hi,
> It would be really nice if elementary mathematical operations such as
> sin/cosine (via __sin__ and __cos__) were available as base parts of
> the python data model [0].  This would make it easier to write new math
> classes, and it would eliminate the ugliness of things like self.exp().
> This would also eliminate the need for separate math and cmath
> libraries since those could be built into the default float and complex
> types.  Of course if those libs were removed, that would be a potential
> backwards compatibility issue.
> It would also help new users who just want to do math and don't know
> that they need to import separate classes just for elementary math
> functionality.
> I think full coverage of the elementary function set would be the goal
> (i.e. exp, sqrt, ln, trig, and hyperbolic functions).  This would not
> include special functions since that would be overkill, and they are
> already handled well by scipy and numpy.

I think the basic problem here is that, by comparison to the basic
syntax-driven options, the additional functionality covered by the
math, cmath and decimal modules is much harder to implement both
correctly and efficiently. It's hard enough making good algorithms
that work on a single data type with a known representation, let alone
ones which work on arbitrary data types.

Also, needing exp, sqrt, ln, trig and hyperbolic functions is
*significantly* less common than the core mathematical options, so
telling people to do "from math import *" if they want to do a lot of
mathematical operations at the interactive prompt isn't much of a


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list