[Python-Dev] calculator module

Raymond Hettinger raymond.hettinger at verizon.net
Wed Mar 10 02:26:18 EST 2004


I was thinking that if a student's calculator can do something, then
Python ought to handle most of the same tasks right out of the box.

For a while, we've held off on adding math functions because of several
principles:
* the math module is just a wrapper for libm, so nothing else belongs
there
* leaving high end stuff to comprehensive tools like NumPy or Numeric
* avoiding anything that cannot reliably (and provably) be implemented
to the precision expected of 
  numerical libraries

My thought is to create a pure python module with "pretty good"
implementations of things found on low to mid-range calculators like my
personal favorite, the hp32sII student scientific calculator.  It offers
a reasonably small but useful set of functions without any attempt to
comprehensively cover a given category.  For instance, there is a
single, simple solver -- and if it can't handle your function, then you
go to MatLab or somesuch.

Here are a few that may be worthy of a module:
* Combinations, permuations, and factorial (with a full gamma function)
* Two variable linear regression
* Hyperbolic trig
* % and %chg
* A simple integrator (adaptive trapezoidal method I think)
* A simple solver, given f(x)==c and hi/low bounds, solve for x if
possible.  (works like Goal Seek in Excel)
* Polar/Rectangular coordinate conversions
* A handfull of metric/English conversions (these could be skipped)
* Simple fraction implementation with a choice a maximum denominator or
some multiple of a fixed denominator.

Another variant of the calculator also offers:
* simple matrix functions up to 3x3 (addition, multiplication, inverse,
determinant)
* cross-product and dot product for 3 element vectors (x,y,z
coordinates).

To these, the HP12C financial calculator adds:
* solve for missing variable in (n i% pv pmt fv)
* internal rate of return and net present value for a stream of cash
flows

Though not present on the calculator, I could also see the inclusion of
probability distributions to capture what students normally have to look
up in tables and then can't find when they need it.  That is likely why
MS Excel includes these functions but excludes so many others.

By "pretty good" implementation, I mean that the implementations should
remain as straight-forward as possible and neither promise, nor get in a
snit about being accurate to the last place (i.e. a 9 place
approximation of gamma would be considered fine).



Raymond Hettinger





More information about the Python-Dev mailing list