An Evolutionary RPN Calculator for Technical Professionals
Total Page:16
File Type:pdf, Size:1020Kb
An Evolutionary RPN Calculator for Technical Professionals Symbolic algebraic entry, an indefinite operation stack size, and a variety of data types are some of the advancements in HP's latest scientific calculator. by William C. Wickes THE HP-28C (Fig. 1} provides the most extensive • Symbolic algebra and calculus mathematical capabilities ever available in a hand An automated numerical root-finder (see article on page held calculator. Its built-in feature set exceeds even 30. the capabilities of the earlier HP-71B Handheld Computer1 • Vector and matrix math operations with its Math ROM.2 Furthermore, the HP-28C introduces Automatic plotting of functions and statistical data a new dimension in calculator math operations — symbolic Unit conversions among arbitrary combinations of 120 algebra and calculus. A user can perform many real and built-in units and user-defined units complex number calculations with purely symbolic quan • Integer base arithmetic, bit manipulations, and logic op tities, delaying numerical evaluation indefinitely. This al erations in either binary, octal, decimal, or hexadecimal lows a user to formulate a problem, work through to a notation solution, and study the mathematical properties of the so A keystroke-capture programming language enhanced lution entirely on the calculator. by high-level program control structures The HP-28C has the following features: An infrared printer interface for printing and graphics An RPN calculator interface allowing an indefinite output on the optional HP 82240A Infrared Printer. number of stack levels and a variety of data types The HP-28C's physical package differs from that of the A softkey menu system for key-per-function execution HP-18C Business Consultant (see page 4) in only two as of all built-in and user-defined procedures and data pects. The HP-28C uses different key nomenclature op • Extensive real and complex number functions timized for its math operations, and it contains an addi- Fig. 1 . The HP 28C Scientific Pro fessional Calculator features sym bolic entry of algebraic expres sions for an extensive range of functions capable of handling real and complex numbers, vectors and matrices, base 2, 8, 70, and 16 integers, lists, and built-in con version factors. The display can display up to four lines of the indef inite-depth stack or be used to plot functions with a resolution of 32 x 737 pixels. An integral in frared transmitter allows output of data and graphs to an optional printer. AUGUST 1987 HEWLETT-PACKARD JOURNAL 1 1 © Copr. 1949-1998 Hewlett-Packard Co. tional 64K bytes of ROM, for a total of 128K bytes. or hexadecimal bases. Lists are ordered collections of other The design philosophy for the HP-28C was to generalize objects. Data objects are characterized by the simple prop the ease of use, power, and flexibility of HP's RPN cal erty that the evaluation of the object just returns the same culator interface to a wider class of data types and applica object. tions while also eliminating some of the shortcomings of The generalized stack concept permits the introduction that interface. In the remainder of this article, we describe of object classes that have no counterpart in previous RPN some of the features of the HP-28C in the context of the implementations. A name object, for example, is a character evolution of the RPN interface. sequence that is used to identify other objects by name. In the HP-28C, the numbered storage registers on earlier cal Enhanced RPN culators are replaced by variables. A variable is a combina Reverse Polish notation (RPN), in which mathematical tion of a name object and any other object stored together expressions are written with functions following their argu in a linked list independent of the stack. Name objects have ments, is embodied in computers and calculators by means the property that evaluation of the name returns the object of a last-in-first-out (LIFO) data stack. Mathematical and stored with the named variable (and if the object is a pro logical functions take their arguments (inputs) from the top gram, executes the program). This means that a user variable of the stack, and return their results to the stack where behaves exactly like a built-in command. (In HP-28C ter they can be used as the arguments for subsequent opera minology, a command is a built-in, programmable operation.) tions. An RPN stack is the most efficient medium for chain A name for which no variable has yet been created fills ing and nesting calculations, and provides the greatest the role of a formal variable in mathematics, upon which keystroke efficiency in a calculator. operations can be performed, even before evaluation. Such The original HP RPN calculator user interface was first names just return themselves when evaluated. This prop used in the HP-35 Calculator3 in 1972. In that and sub erty is central to the implementation of symbolic mathema sequent HP calculators, the stack consisted of four fixed- tics on the HP-28C. length registers, each of which could contain one floating Evaluation by name and the linked list of variables are point number (the HP-41C Calculator4 also permits al modeled after a Forth dictionary. Built-in commands are phanumeric data in the form of a character string con compiled as their execution addresses, as in Forth. How strained to fit in a fixed-length number register). This sys ever, user-defined names are compiled unresolved. This tem was satisfactory for the numeric-only capability of the permits compilation of undefined (formal) variables, and early calculators, but with the advent of programmability also allows selective purging of variables from memory, and algorithms for more complicated data types, the restric neither of which is possible in Forth. There is a degradation tions of the fixed stack became more and more of a design of performance compared to Forth because of the necessity impediment. For example, in the HP-41C and HP-15C5 Cal for run-time resolution of user variables, but the overall culators, complex numbers are represented by two real throughput for user problem solving is usually better be floating-point numbers, one for the real part and one for cause of the ease of programming and flexibility of the the imaginary part. Two stack registers are needed for each HP-28C language. complex number, which means that a four-register stack The remaining new object class defined in the HP-28C can hold only two complex numbers, severely restricting is procedure objects. A procedure object contains an arbi the types of complex-number math operations that can be trary number of other objects that are executed automati performed on the stack. For example, the complex-number cally and sequentially when the procedure object itself is expression (A + B)(C + D) cannot be evaluated without stor evaluated. The procedure class includes programs, which ing an intermediate result away from the stack. are unrestricted sequences of data, commands, or variables, The HP-28C is the first HP calculator to modify the tra and algebraic objects, which represent mathematical ex ditional RPN interface. To begin with, the concept of a pressions and equations and therefore must satisfy certain stack register is generalized to a stack level that can hold syntax rules. Both procedure object types can be manipu an object of indeterminate size. An object can be one of lated on the stack, or named in a variable. In previous several types of data or procedures, each characterized by calculators, programs were created and edited only in a its internal structure and execution logic. Any object can special program mode. be manipulated on the stack as a single unit. For example, a complex number is represented by an ordered pair of Variable Stack Depth floating-point numbers that is entered and displayed in the In another major break with earlier calculator architec form (number, number). Since a complex-number object tures, the HP-28C stack grows dynamically as new objects now occupies a single stack level, it can be manipulated are entered onto the stack and shrinks as they are removed. with the same keystrokes used for a real-number object. The number of objects on the stack is limited only by avail For example, complex numbers in the first two stack levels able memory. There are two major benefits of this approach. can be added by pressing the + key, multiplied by pressing First, mathematical calculations of arbitrary complexity the x key, etc. can be carried out entirely on the stack. Second, it facilitates Besides real and complex numbers, HP-28C data objects structured programming — procedures can be defined exter include real and complex-valued arrays (matrices and vec nally in terms of the number and type of arguments they tors), alphanumeric strings, binary integers, and lists. Bi take from the stack and the number and type of result nary integers are binary coded integers of l-to-64-bit words objects they return. Subroutines can be nested to an arbi which can be entered or displayed in binary, octal, decimal, trary depth without concern for stack overflow. 12 HEWLETT-PACKARD JOURNAL AUGUST 1987 © Copr. 1949-1998 Hewlett-Packard Co. that are specified by name. Example Problem Different object types are identified within the command line by characteristic delimiter characters. For example, A farmer has 100 yards of fencing to enclose a rectangular strings are enclosed in double quotes, variable names and field, which is bounded on one side by a river. What length L algebraic expressions are surrounded by single quotes, and and width W of the field will enclose the maximum area? lists are enclosed in curly brackets.