links from


Scientific Programmable Script
Webb - all rights reserved - ©2004
Author - Bryan Monosmith

Note: This script invented a simple macro capability, and was written before keystroke macro was built into RPN. It is therefore obsolete. I leave it here as an historical curiosity. The remaining useful elements, root extraction of polynomials, and numerical integration and summation, are included elsewhere on this site.


Basic scientific functions with,
- 71 step keystroke macro program capability.
- Fundamental physical constants in MKS units.
- Quadratic equation solver.
- Summation and Numerical Integration.
    (Credits to Jan Popelek , whose excellent implementation of the
factorial function I basically lifted for this script.)
! This script is almost 3k bytes in size. Users will need 'ClipHack' or
some other method of getting this into the clipboard

* Basic functions- These are mostly intuitive. The help mode will fill any
* "rec" (macro record)-  Brings up 4 options, Begin, End, Load and
Dump.  Begin starts the keystroke recorder. Every key touched is recorded,
except for "EEX", ".", and the script menu key. End terminates  keystroke
recording.  Dump will place the current macro onto the stack as a meta
object, where  the number at tos contains the count for how many additional
stack elements are contained in the macro dump. Load works in reverse.
These functions allow for the creation, saving, and loading of macros.
         NOTE: Numeric entry in macro mode is limited to single digits. In
order to use multi digit numbers in a macro, I have created 10 new storage
registers that can be preloaded with float values in run mode, then
accessed in macro mode. This is somewhat of a kludge and is either an
inability on my part to understand how to process full numeric input, or a
limitation of RPN functionality in this area. If the latter, I don't think
Russ ever anticipated that anyone would write a script to do what I have
* "play" - Execution of this function simply plays the recorded macro.
* "rcl" -  Execution with a tos value of 0-9, recalls the number stored in
the macro register. "inv", "rcl" stores the number at the second stack
position into the register number at tos.
* "stk"- Provides a menu of simple stack operations, primarily for use in
* "f" - Tapping "f" presents 4 options. Upper and lower limits, previously
put onto the stack, are entered by tapping the appropriate "upper" or
"lower" assignment functions. Summation and Integration functions will use
the assigned limits, and accomplish the desired computation using the
function recorded in macro memory. The macro function should be written to
assume, on entry, that the value of 'x' is at tos.
    Numerical integration uses the Romberg algorithm and returns the answer
in tos. Also on the stack is the 'estimated' error and the number of
iterations performed. This is a very small routine! It is optimized for
speed and does not contain the code necessary to watch for pathological or
ill behaved functions which may return erroneous values or cause the
algorithm to thrash. Lacking convergence, the routine will time-out after 9
iterations, which corresponds to a time on the order of a minute or so,
depending on the size of the macro function and the speed of the machine.
The error term is extremely crude and can normally be off by 2 orders of
magnitude and can be off by 4 orders of magnitude for ill behaved
functions. Despite these limitations, the error term is better than no
information at all.
    Summation will return the sum of the macro function, evaluated from the
lower limit to the upper limit, in tos. The value of the next term in the
series is returned in the next stack position and provides an indication of
the rate of convergence.

Example (1)   
Automate the evaluation of the polynomial:
x^3 + 5.127*x^2 - 2*x - 7 , for different values of x.
Put "5.127" on the stack. Now tap "0", "inv", "rcl". This stores 5.127 into
the macro register 0. Tap "rec", then "Begin". Notice the script put a
dummy number on the stack if you hadn't already placed one there. Enter the
function: tap "ENTER", "3", "y^x", "stk", "over", "x^2", "0", "rcl", "*",
"+", "stk", "swap", "2", "*", "-", "7", "-". Tap "rec", then "End". Now
find the value of the function at 4.2 by putting 4.2 on the stack and
tapping "play". The result should be 149.1282.

Example (2)   
Approximate the integral from 0 to infinity of the function
Tap "rec", then "Begin". Enter the function: "ENTER", "+/-", "exp", "*".
Now tap "rec", followed by "End". Put the numbers 0 and 20 (close enough to
infinity) on the stack, tap "f", followed by "upper", "lower", then
"Integ.". In less than a minute the answer appears as ~1, with ~6E-11 and 8
on the stack to indicate a crude estimate of the error and the number of
iterations required in the Romberg algorithm.


[e]     #'2.71828182845904524';
[p]     #'3.14159265358979324';
[P]     V1       #'0.577191652'v*-       #'0.988205891'v2P*+
                 #'0.897056937'v3P*-     #'0.918206857'v4P*+
                 #'0.756704078'v5P*-     #'0.482199394'v6P*+
                 #'0.193527818'v7P*-     #'0.035868343'v8P*+ ;
[!]     Vvvb<(  vCbn<(v; :vnV 1{_vvn*}vn* vnCPk2/)
         :       vCb >(  v2*Cp*s vCe/vP*
                         1 vm12t+ #'288'v2P*t+ #'139'#'51840'v3P*/+ *
                 :     1v{_v*v}CP*
         )       );
[g]D'light,Planck,e mass,charge\p
[s]D'|swap|over|rot|pick|\ESC|' xx(g1c(#'19':#'13':#'14':#'15':7)xyr2XyCTXy)Cj;
[d]D'\Set limits      Run
[N]D'   Keystroke
"inv:\\bm v3b"xw(C*:C^)CA;
"exp:\ln (shift)"CE;
"log:\10^x (shift)"CF;
"mod:\|x| (shift)"CG;
" r>p: x,y to r,theta coords.\r,theta to  x,y coords.(shift)"CH;
"!: factorial x\  gamma x (shift)"CI;
"fp: fractional part\    integer part (shift)"CJ;
"c: constants"CoCg;
"QE: quadratic solver\in: a,b,c\out: Im,Re,Im,Re"CoCK;
"f:Sum-x: summation value\Integrate-x: integral value\y: est. error    z: #
"rec:Keystroke macro recorder.\71 step memory."CoCN;
"rcl: 0-9 Rcl\    0-9 Sto (shift)"g10|!(CO:C*);

0.0009 secs

top of page

Webb - all rights reserved - ©2004
powered by Spinneret 0.10