I did an emulation, some 15 or 20 years ago, in visual basic 5 -based on
an ancient but still working, HP11C which a predecessor of the 50g. It
definitely can be done in J (I had to set up my own complex number
subroutines). New values were added at the bottom of the stack as with
HP calculators
Might I suggest that there be a single *rollup * stack operation (of 1
step) and a single *rolldown* operation (1 step) for the stack
manipulation. these by them selves rotate the stack up or down by 1
position. . Essentially roll up becomes*x,stack* and the top element
of the stack (if you want to limit it to 4, 10 or whatever) is
dumped.Rolldown is a reverse rotation.
*Enter *involves a roll up and a replacement of the 0 or x element.
Note that the stack can be considered as a row rather than a column.This
may help.
Monadic operations only modify the first (0)element without a stack
shift operation.so sqrt =: %:0{stack
Dyadic operations work with only the first two elements- replacing the
"x" value with the result of f(x,y) and drop the rest of the stack
(x and y disappear as individual values so we get f(x,y), z, t,... (this
appears in line with your stack operations0
Swap involves only the 0, 1 ( x, y) terms and swapping these should be
fairly easy-amending the first two elements of the stack
The batteries in my ancient HP11C appear to be dying so I cannot emulate
this action at the moment- but the visual basic version still works.. It
has added some factors such as quadratic roots and low order
simultaneaous equations.
J can do this and more with primitive operations.
The question in my mind is:
If you have J , all you can do with an RPN calculator is model
it-preferably with a graphics interface.
Given a problem, it seems that J used directly does the job more
easlly-but- the exercise and the result of having an RPN caculator on
hand is worth it.
looking forward with interest
Don Kelly
.
On 12/09/2014 6:17 AM, Kip Murray wrote:
I'm proud of the Reverse Polish Notation calculator shown below (think HP
50g in rpn mode). My question is, can you devise an adverb monad so that
sqrt =: %: monad
produces the sqrt verb below?
Examples
clear'' NB. Initialize global vector STACK
5 2 enter''
5
2
1 dup''
5
2
2
times''
5
4
plus''
9
sqrt''
3
Verbs
clear =: 3 : ',.STACK =: '''''
NB. create and display empty STACK
enter =: 4 : ',.STACK =: STACK , x'
NB. x a list of numbers
dup =: 4 : ',.STACK =: STACK , (- x) {. STACK'
NB. x a non-negative integer
drop =: 4 : ',.STACK =: (- x) }. STACK'
NB. swap?
chs =: 3 : ',.STACK =: (_1 }. STACK), - _1 {. STACK'
sqrt =: 3 : ',.STACK =: (_1 }. STACK), %: _1 {. STACK'
plus =: 3 : ',.STACK =: ( _2 }. STACK), +/ _2 {. STACK'
minus =: 3 : ',.STACK =: ( _2 }. STACK), -/ _2 {. STACK'
times =: 3 : ',.STACK =: ( _2 }. STACK), */ _2 {. STACK'
divide =: 3 : ',.STACK =: ( _2 }. STACK), %/ _2 {. STACK'
--Kip Murray
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm