In his book, HP48 Insights Part 1: Principles and Programming, Bill Wickes
talks about the inability of the HP48 to deal with symbolic elements in
arrays and provides a collection of programs to deal with Symbolic Arrays
(section 11.7). He describes a Symbolic Array as a list of lists that
follow the convention: an n * m array is represented as a list containing
n m-element lists. For example, the list {{a b}{c d}{e f}} stands for the
matrix:
[[a b]
[c d]
[e f]]
A whole host of programs are provided to pack and unpack symbolic arrays,
convert them into a matrix and back again, apply a function to one or two
symbolic arrays, and transpose a symbolic matrix. You'll need to get hold
of the book if you want these.
The following set of programs extend the range of those presented in the
book and can be used in isolation to very good effect. I don't expect to
put Lotus or the other proper spreadsheet writers out of business, but
what do you want for nothing?
NEWSA creates a new symbolic array. The number of rows is given in level 2
of the stack, and the number of columns in level 1. The user is asked to
enter values for each cell in the array. Press the ENTER key after each
value (or program or algebraic).
CONSA is similar to the built in function CON. CONSA takes the number of
rows, the number of columns and a value and creates a symbolic array with
every cell set to the specified value.
EDITSA takes a symbolic array from the stack and lets you edit each value
in turn.
The SPRD program provides a simple spreadsheet style operation to take
a symbolic array of instructions and values, and turn them into a result
array. The examples show how the program can be used. Note that the
result matrix is called 'M' whilst the program is running and hence the
'instructions' in the symbolic array are all of the form 'M(row,column)'.
SPRD can use the advanced symbolic capabilities of the HP48. The example 'EQ'
only uses algebraic operations, but you can put programs into the symbolic
array and have them executed, so long as they get their input from the values
which exist already in the 'M(row,column)' matrix. The matrix elements are
evaluated starting with the top row, first column, second column, third
column, etc. A more complicated example is given in 2 below.
The COLOP program is provided to do simple operations on arrays (proper
ones, not symbolic arrays) in a more efficient way, but it lacks the
flexibility of SPRD.
CPM (no pun intended) copies small arrays into larger ones. The built in
function RDM (Redimension) provides similar capabilities. RDM treats the
values in the source array as a list and places them into an array of the
specified dimensions. CPM copies the elements in the source array into the
corresponding position in the target array. CPM works on real and complex
arrays, not on symbolic arrays.
I have provided checksums for the individual routines and for the directory
as a whole. Remember that if you are typing the programs direct into your
HP48, you don't need to include the comments. Also, you can omit COLOP and
CPM if you like as they are designed only to manipulate the resulting
matrix - something which is done reasonably well by the matrix editor which
HP built in.
The Programs
------------
-----cut here
%%HP: T(3)A(D)F(.);
DIR @ Checksum #E84Ah Size 1520.5 bytes
EQ @ Checksum #D7BAh Size 609.5 bytes
@ Example Spreadsheet: Two columns of sales figures need adding up to
@ provide a monthly figure and then the months comparing against each
@ other.
{{ 1 2 'M(1,1)+M(1,2)' 0 }
{ 3 4 'M(2,1)+M(2,2)' 'M(2,3)-M(1,3)' }
{ 5 6 'M(3,1)+M(3,2)' 'M(3,3)-M(2,3)' }
{ 7 8 'M(4,1)+M(4,2)' 'M(4,3)-M(3,3)' }
{ 9 10 'M(5,1)+M(5,2)' 'M(5,3)-M(4,3)' }
{ 11 12 'M(6,1)+M(6,2)' 'M(6,3)-M(5,3)' } }
NEWSA @ Checksum #7535h Size 42.5 bytes
@ Takes number of rows from level 2 of the stack, number of columns
@ from level 1, creates an empty symbolic array of that size and
@ allows you to put values into each cell.
\<< "" CONSA EDITSA
\>>
CONSA @ Checksum #213Fh Size 92 bytes
@ Like the inbuilt function CON. Takes: number of rows, number of columns
@ and value from the stack and creates a symbolic array of that size with
@ every cell containing the value specified.
\<< \-> n m v
\<< 1 n
FOR i 1 m
FOR j v
NEXT m \->LIST
NEXT n \->LIST
\>>
\>>
EDITSA @ Checksum #25Ch Size 169 bytes
@ Takes a symbolic array from the stack and lets you edit each cell in
@ turn. The result is left on the stack. Note that for simplicity the
@ stack is used throughout to hold the edited elements, so don't
@ disturb it when entering values.
\<< DUP DIM \-> a n m
\<< STD 1 n
FOR i 1 m
FOR j "Edit M(" i + "," + j + ")" +
a i GET j GET \->STR INPUT OBJ\->
NEXT m \->LIST
NEXT n \->LIST
\>>
\>>
SPRD @ Checksum #60CEh Size 181 bytes
@ The spreadsheet program. To use: put the symbolic array on the stack
@ and press SPRD. A matrix containing the results is left on the stack.
@ Press the down arrow key to enter the matrix editor and see the results.
\<< DUP DIM \-> a n m
\<< n m 2 \->LIST 0 CON 'M' STO 1 n
FOR i 1 m
FOR j a i GET j GET EVAL 'M(i,j)' STO
NEXT
NEXT M 'M' PURGE
\>>
\>>
DIM @ Checksum #2BA8h Size 32.5 bytes
@ returns the dimensions n (rows) and m (columns) of a symbolic array
@ from HP48 Insights Part 1: Principles and Programming by
@ William C. Wickes (p. 302).
\<< DUP SIZE SWAP 1 GET SIZE
\>>
COLOP @ Checksum #5CBh Size 213.5 bytes
@ Given a source matrix, two column numbers, an operation (in a list)
@ and a result column, works through every row performing the operation
@ on the columns specified and writes the result into the target column.
\<< \-> s c1 c2 op c3
\<< s SIZE OBJ\-> DROP \-> rows cols
\<< 1 rows
FOR r 's(r,c1)' 's(r,c2)' op EVAL EVAL 's(r,c3)' STO
NEXT
\>> s
\>>
\>>
CPM @ Checksum #652Eh Size 174 bytes
@ Copies the contents of a small matrix into a larger one leaving
@ the unused cells set to zero. Note: no error checking!
\<< \-> s t
\<< s SIZE OBJ\-> DROP \-> rows cols
\<< 1 cols
FOR c 1 rows
FOR r 's(r,c)' EVAL 't(r,c)' STO
NEXT
NEXT
\>> t
\>>
\>>
END
-----cut here
Examples
--------
1) Using SPRD:
a) Press EQ to put the spreadsheet instruction list onto the stack.
b) Press SPRD to perform the calculation. A normal matrix is left on the
stack.
c) Press the down arrow to see the result matrix in the matrix writer:
[[ 1 2 3 0 ]
[ 3 4 7 4 ]
[ 5 6 11 4 ]
[ 7 8 15 4 ]
[ 9 10 19 4 ]
[ 11 12 23 4 ]]
The first two columns contain the monthly sales figures for two shops.
The third column contains the totals for the two, and the final column
shows the difference between the monthly totals - you can tell, business
is a bit linear!
2) Create an 2 x 2 symbolic array containing various items:
a) 2 2 NEWSA
b) The program prompts for M(1,1)
c) Type 30 ENTER
d) Prompts for M(1,2), type 'SIN(M(1,1))' ENTER
e) Prompts for M(2,1), type << 'M(1,2)' EVAL 3 ^ >> ENTER
f) Prompts for M(2,2), type {TICKS B->R} ENTER
g) Leaves the following symbolic array on the stack:
{{30 'SIN(M(1,1))'}
{ << 'M(1,2)' EVAL 3 ^ >> {TICKS B->R}}}
h) Press SPRD to give:
[[ 30 .5]
[ .125 bignumber]]
3) Create a 2 x 3 symbolic array containing all zeroes:
2 3 0 CONSA ---> {{ 0 0 0 }
{ 0 0 0 }}
4) COLOP provides a quick way of doing the same operation on all rows in
a couple of columns in a matrix and leaving the result in another
(or the same) column e.g.
[[ 1 2 0] [[ 1 2 3]
[ 3 4 0] 1 2 << + >> 3 COLOP ---> [ 3 4 7]
[ 5 6 0]] [ 5 6 11]]
5) CPM copies a small matrix into a larger one e.g.
[[ 1 2 ] {4 4} 0 CON CPM ---> [[ 1 2 0 0]
[ 3 4 ]] [ 3 4 0 0]
[ 0 0 0 0]
[ 0 0 0 0]]
Progress
--------
It is a shame that you cannot put strings into cells in the matrix editor.
If you could, a good proportion of what a proper spreadsheet provides could
be yours on your HP48. Imagine all of the error checking which would be
needed in all of those functions which use matrices properly though.
One solution might be to put the results back into the original symbolic
array, leaving cells which contain strings, as they are. Then all you have
to do is write a symbolic matrix editor!
Fame and fortune could lure one to do this, but for the time being let's
keep it simple.
Finally thanks to Bill Wickes for the machine and the Insights. Without
him I'd still be trying to do this sort of stuff on an HP41 with an HP-IL
Video Adaptor.
That books sounds interesting, any more you can tell me (us) about it?
Is it specific towards the G/GX?
Also, anyone else reading this, I'd like to know what books you find
helpful in exploring your HP calculator. I've got the HP48G and the AUR
so far.
Thanks,
Esmail
--
-----
bo...@herky.cs.uiowa.edu
>That books sounds interesting, any more you can tell me (us) about it?
>Is it specific towards the G/GX?
>Also, anyone else reading this, I'd like to know what books you find
>helpful in exploring your HP calculator. I've got the HP48G and the AUR
>so far.
Dr. Bill Wickes was on the development team for the HP48 and is a long-time
user of HP calculators. (these are both understatements). He has written
three well-known books about the 48 (so far). The first was for people
converting from the HP41. I don't remember the title but it was something lke
41 to 48 Transitions. (someone correct me please.).
The next two were HP48 Insights parts I and II. Both of these were written
in the days of the HP48 S and SX (not the G series). They are both excellent
discussions of the calculator and it's applications. They were not
specifically aimed at the S series and are not made obsolete by the
introduction of the G. I think he should write a third book (Insights III,
48G extended applications, please Bill) on the extensions the G has added
to the system but the first two would still not be obsolete.
Richard Helps BYU, Provo Utah
In the USA the books are available from EduCalc and Bill Wickes himself. I
understand that some calculator shops and technical bookstores can also get
them.
There are currently three 'Insights' books:
HP48S/SX Insights Part I Principles and Programming
HP48S/SX Insights Part II Power Tools
HP48G/GX Insights Part I (updated from the S/SX version)
If sufficient G/GX owners lobby Bill, he would no doubt produce an updated
Insights II.
Another useful book which I have recently received is called HP48S/SX Machine
Language. It is translated from the French "Journey to the centre of the HP48"
(or something like that, only in French of course). This book contains:
basic HP48 use; system RPL; machine code, and a pile of programs to enable
you to type in machine code programs, disassemble them on the '48, etc. It
also has some useful maths programs, and a few games. Again, this was obtained
through the HPCC.