[Tutor] A little math and Python: Horner's rule

Scot W. Stevenson scot@possum.in-berlin.de
Tue, 20 Aug 2002 17:50:24 +0200


Hello Danny, 

> For example, let's say we'd like to
> calculate some 5th degree polynomial along several points.  

Just when I thought I had strange hobbies =8)...

> ...     return((((-27 * x - 7) * x - 39) * x - 40) * x - 12) * x - 35

At the risk of asking an amazingly stupid question, this looks like some of 
the constructs that I used to create in high school to feed my HP 15C 
calculator that uses an entry format called "reverse Polish notation" 
(RPN) which you are probably familiar with: You don't type "2 + 3 =" but 
rather "2 ENTER 4 +" - sounds strange, but after you get used to it, it is 
faster than anything else. Is this Horner's rule somehow related to RPN, 
or does it just look that way?

I seem to remember a factoid that Forth worked with RPN; is there any 
Python support? And, to stay on topic, just how hard would it be to change 
the current algebraic entry system in Python to RPN? You'd need to 
implement a stack somehow for every operation...maybe as a module that 
implements the stack as global variables, overrides the mathematical 
operations, and defines 'enter' and 'last x' commands?

[Nostalgic rant: A brief visit to the HP website shows me even their 
scientific calculators don't have RPN anymore (except in the HP 48 class), 
which is a damn shame. Fortunately, the old HP made fantastically robust 
products, so my HP 15C is still going strong even after being dropped, 
stepped on, and generally abused physically for almost 20 years now. The 
new stuff just looks flimsy - more like Texas Instruments clones than real 
HP calculators...ah, the days before shareholder value mania...]

Y, Scot

-- 
  Scot W. Stevenson wrote me on Tuesday, 20. Aug 2002 in Zepernick, Germany   
       on his happy little Linux system that has been up for 1526 hours       
        and has a CPU that is falling asleep at a system load of 0.00.