The Museum of HP Calculators

HP Articles Forum

[Return to the Index ]
[ Previous | Next ]

SOLVE and INTEG on HP's RPN-based models

Posted by Karl Schneider on 2 Oct 2005, 12:05 a.m.


This article summarizes the implementations of "SOLVE" and "INTEG" machine-coded functions on RPN-based Hewlett-Packard calculators. In addition, a procedure is presented for utilizing these functions on the HP-34C, HP-15C, and HP-41C/CV/CX with multiple-input, single-output (MISO) user-defined functions.



On many of its RPN-based scientific calculators, Hewlett-Packard offered sophisticated numerical rootfinding ("SOLVE") and numerical integration ("INTEG") of single variables within general user-defined functions. These are built-in or made available on the following models:

Original implementation

Later implementation

None of the following are addressed in this article, due to substantial differences in capabilities and protocol of usage:


The philosophy, methods, and effective utilization of 'SOLVE' and 'INTEG' were thoroughly described in the three user's manuals developed for the HP-34C and the HP-15C. These manuals are the only ones that provide exceptionally detailed insight into the 'SOLVE' and 'INTEG' functions. The two Journal articles were written for the HP-34C, but are also informative. Of course, the user should always refer to the pertinent Owner's Handbook for guidance in basic usage of 'SOLVE' and 'INTEG' on a particular model of calculator.

For each of these references, a scan of a printed copy (in Adobe Acrobat "PDF" format) is present on CD-ROM and DVD-ROM disks available from the MoHPC.


The SOLVE and INTEG functions were introduced on the HP-34C in 1979, and later directly ported to the HP-15C in 1982. For the HP-41C/CV/CX, the same functions were adapted with only slight modification in the Advantage Pac introduced in 1985. Consequently, the protocol for using SOLVE and INTEG on these models is almost identical.

The user's mathematical function to be solved or integrated must be programmed as an RPN routine. The routine must be designed to accept a value of the "floating" input variable to be solved or integrated from the stack x-register, and to return the calculated function to the x-register. SOLVE or INTEG will fill the stack with a current "updated" value of the floating variable to be utilized by the user's program, which will then be automatically executed. This process will continue as necessary -- by SOLVE until a root within the calculator's limit of accuracy is found (or determined to be unobtainable), or by INTEG until the integral is calculated to the estimated accuracy that is justifed by the user's specification.

Moreover, the program may include a SOLVE or INTEG instruction, thus allowing INTEG to be executed within SOLVE, or vice versa. This can be useful for solving a limit of integration, or a parameter of an integrand.

SOLVE and INTEG on the HP-34C, HP-15C, and HP-41C/CV/CX are ideally-suited for single input, single-output (SISO) user-defined functions. This is because these models provided only numbered and "indirect" storage registers, with no provision to assign alphabetical identifiers to variables.


The mathematical algorithms of SOLVE and INTEG remained virtually unchanged in the Pioneer-series HP-32S and HP-42S introduced in 1988 and the HP-32SII introduced in 1991. However, the protocol for utilizing and invoking these functions was adapted for the new features and capabilities of the Pioneer-series models.

One new feature was alphabetical identifiers for variables. Storage registers for variables on the Pioneer-series HP-32S and HP-32SII (as well as its derivative HP-33s and HP-35s), are designated by single letters. The Pioneer-series HP-42S allowed full alphanumeric identifiers for variables.

On the HP-32S and HP-42S, the user's mathematical function to be solved or integrated must be programmed as an RPN routine. On the HP-32SII, HP-33s, and HP-35s, the user's function may be programmed as an RPN routine or entered as an algebraic expression. (Alternatively, on the HP-33s and HP-35s, the user's function may be programmed as an algebraic-entry routine.)

The protocol of SOLVE and INTEG on each of these models is well-suited for multiple-input, single-output (MISO) user-defined functions. This is because SOLVE and INTEG pass values of the "floating" input variable to the user's function by its storage register, not by the stack x-register.

The user must specify (by letter or name) the root variable to SOLVE or the dummy variable of integration to INTEG. Upon invokation, SOLVE or INTEG will prompt the user for the fixed values of all other variables appearing in the algebraic expression or entered via an INPUT instruction. Finally, the user's RPN routine or algebraic expression must recall any input variable from its storage register.

Neither the HP-32S, the HP-32SII, the HP-33s, nor the HP-35s provide the capability to execute INTEG within SOLVE, or vice versa. The HP-42S, however, retained that capability of the original implementation.

On the HP-33s and HP-35s, a direct-solution method for algebraic expressions (seemingly adapted from the algebraic solver on the HP-17/18/19/27 models) was incorporated into SOLVE. When the form of the user's equation is such that one root can be determined by algebraic manipulation, the HP-33s and HP-35s will always return that solution, no matter what the initial first guesses are.


'INTEG' uses a Romberg method for calculating the result of an integral. It takes samples that are not uniformly spaced, in order to suppress resonance or aliasing that can result from sampling periodic functions.

The developers of 'INTEG' recognized the impracticality of requiring the user to specify the number of evaluations of the integrand, as other implementations had done. Instead, 'INTEG' requires the user to specify an uncertainty or accuracy factor of the integrand. 'INTEG' will generally succeed at calculating the integral to an accuracy that is well within the estimate of maximum error derived from the given uncertainty and the range of integration.

On all of the RPN-based calculators, the calculated value of the integral is placed in the x-register; the estimated maximum error is placed in the y-register. This allows for easy summation of a subdivided integral and estimated error using the statistical Sigma+ function.

HP-34C, HP-15C, HP-41 Advantage Pac, HP-32S, HP-32SII:

On these calculators, the user specifies the uncertainty of the integrand by setting the display mode (i.e., FIX, SCI, ENG, or ALL). The premise is as follows: The uncertainty of the integrand is assumed to be half the resolution of the value displayed under the mode setting. In other words, the "true value" of the integrand is assumed to be anywhere within the range for which the displayed value is the correct rounded value.

FIX, SCI, and ENG are used with an argument up to 9 on the HP-34C, HP-15C, and HP-41; they are used with an argument up to 11 on all Saturn-processor models and their derivatives, including the HP-32S and HP-32SII.

The FIX display mode specifies an absolute uncertainty of 0.5 x 10-N, where N is the lesser of the number of displayed or displayable digits following the decimal point. (Thus, an integrand value of -3141592.654 on the HP-34C, HP-15C, or HP-41 would carry a "FIX 3" uncertainty, even if specified as "FIX 4".) If all decimal digits of the integrand are displayable in "FIX N" format over the lower and upper limits of integration "a" and "b", the estimate of maximum error is simply (b-a) * 0.5 x 10-N.

The SCI and ENG display modes specify a stepwise relative uncertainty of 0.5 x 10M-N, where N is the number of digits after the decimal point and M is the value of the base-10 exponent of the integrand, if displayed in the selected format. Thus, SCI and ENG give identical results for a given N. "ALL" -- on the HP-32S/SII models -- is equivalent to "SCI 11" or "ENG 11".

When M = 0 (integrand value between 1 and 10), SCI and ENG specify the same uncertainty as FIX for a given N. When M < 0 (integrand value between 0 and 1), SCI and ENG specify a smaller uncertainty than FIX for a given N. The calculator must determine the estimate of maximum error by integrating the uncertainty formula over the set of sample points.

While it may not be considered ideal to utilize a display-mode setting to specify the numerical uncertainty of a function output, this "original" method is clever. Because some display-mode setting is always in effect, the user cannot omit the uncertainty parameter, which is necessary for specifying the scope of the calculation but never appears in the actual problem. Moreover, the display-mode settings most favored by users (e.g, FIX 5, SCI 3, ENG 4) will usually provide accurate answers without excessive evaluation of the integrand function.


The HP-42S utilizes the approach introduced in the HP-71B Math ROM, in which the user must enter the uncertainty of the integrand as a relative per-unit "accuracy" parameter. This value, entered as the variable "ACC" in the HP-42S, is a multiplicative tolerance, whose operative value within 'INTEG' is restricted to positive real values up to and including unity (0 < "ACC" <= 1). The "true" value of the integrand is taken to lie within a band whose width is +/- "ACC" (as restricted) times the calculated value of the integrand.

Thus, the estimate of maximum error ("uncertainty of computation") of the calculated integral over the specified range will generally be within "ACC" times the integral of the absolute value of the integrand function over the same range.

This approach has definite advantages: The bandwidth of uncertainty is smooth -- directly proportional to the value of the integrand. Any value of "ACC" between zero and unity may be utilized, including those that correspond directly to the accuracy of an integrand that best fits measured data. This approach is practical on the HP-42S, because the required accuracy factor "ACC" is a named variable that need not be placed on the stack, and is difficult to overlook on the integration menu.

HP-33s and HP-35s:

The HP-33s and HP-35s also require the user to specify a proportional accuracy factor la "ACC" in the HP-42S, but that value is defined by use of the display-mode settings FIX, SCI, ENG, and ALL. For example, FIX 3 specifies an accuracy factor of 0.001. The approach used in the HP-33s and HP-35s is the same one used for the RPL-based HP-48 series. Because display-mode settings must be used, the only permitted values of accuracy factor are of the form 10-N, where N is the parameter provided to FIX, SCI, ENG, or ALL.

Thus, the estimated maximum error of integration is about 10-N times the integral of the absolute value of the integrand. (ALL corresponds to N = 11.) FIX, SCI, or ENG will yield identical results for a given value of N.


In order to conveniently employ SOLVE or INTEG on the HP-34C/15C/41C for multiple-input, single-output (MISO) user-defined functions, the user's program should emulate the way SOLVE and INTEG manage input variables on the three Pioneer-series models and the HP-33s.

Assume that a MISO function is to be programmed as an RPN routine on a HP-34C, HP-15C, or HP-41C/CV/CX. A user may wish to use SOLVE or INTEG successively for any selected "focus" variable with all others held constant, and without having to edit the RPN routine. Here is a simple procedure for this purpose:

  1. Choose a numbered storage register for each variable in the function.

  2. On the 41C/CV/CX, choose another numbered register as the indirect storage register. (Do not use a stack register, as it will be overwritten by SOLVE or INTEG.)

    In PROGRAM mode:

  3. Program the function as an RPN routine that not only meets the basic requirements, but also retrieves each variable from its chosen storage register when it is used. (On the 41C/CV/CX, the label beginning the routine must be an external label.)

  4. The second instruction of the routine (immediately after LBL) should store the stack x-register value to the indirectly-referenced register. This instruction is "STO (i)" on the HP-34C and HP-15C; it is "STO IND nn" on the HP-41C/CV/CX.

    In RUN mode:

  5. Store the desired constant values of the fixed-value variables to their storage registers.

  6. Store the register number containing the floating variable to the indirect storage register.

  7. Invoke SOLVE or INTEG in the usual manner.

This procedure utilizes indirect storage to make the RPN program more flexible. SOLVE and INTEG feed the each value of the floating variable as input to the user program, which immediately stores the value indirectly to its user-chosen register. Each variable in the function is then recalled for use in calculations, so the user program need not be structured to receive any particular variable from the stack.


f(x, y, z) = 2*x - ln y + 1/z

x in R1; y in R2; z in R3 indirect in R00 (HP-41 only)

HP-15C/HP-34C program: HP-41C/CV/CX program:

LBL A LBL "AA" STO (i) STO IND 00 RCL 1 RCL 01 2 2 * * RCL 2 RCL 02 LN LN - - RCL 3 RCL 03 1/x 1/x + + RTN RTN

In RUN mode, solve for x such that f(x, y=15.1, z=5.3) = 0

HP-15C/HP-34C: HP-41C/CV/CX:

15.1 15.1 STO 2 STO 02 5.3 5.3 STO 3 STO 03 1 1 STO I STO 00 0.5 0.5 ENTER ENTER 5 5 SOLVE A "AA" (enter AA in alpha mode) XEQ "SOLVE"

(Answer is 1.263007749)

Next, solve for y such that f(x=0.7, y, z=3.3) = 0

HP-15C/HP-34C: HP-41C/CV/CX:

0.7 0.7 STO 1 STO 01 3.3 3.3 STO 3 STO 03 2 2 STO I STO 00 0.5 0.5 ENTER ENTER 6 6 SOLVE A "AA" (enter AA in alpha mode) XEQ "SOLVE"

(Answer is 5.490560270)

Finally, integrate f(x=1.7, y=4.1, z) over z = 1.0 to 6.0. Specify 5 decimal-digit absolute function accuracy:

HP-15C/HP-34C: HP-41C/CV/CX:

FIX 5 FIX 5 1.7 1.7 STO 1 STO 01 4.1 4.1 STO 2 STO 02 3 3 STO I STO 00 1 1 ENTER ENTER 6 6 INTEG A "AA" (enter AA in alpha mode) XEQ "INTEG"

(answer is 11.73682)

Edited: 12 Dec 2010, 5:54 a.m.


[ Return to the Message Index ]

Go back to the main exhibit hall