MathTools v7.0 Mathematical Library for the HP48 S/Sx/G/Gx calculator written in 95% SysRPL, 5% ML (c) 1996 by Jack Levy 0.0 INDEX ========= 1.0 Introduction 2.0 Disclaimer 2.1 Email-ware 3.0 Installing the Library 3.1 Library Information 4.0 Overview of Programs 4.1 Program Information in Detail 5.0 Removing the Library 5.1 Credits 5.2 What's With the Names? 5.3 Version History 1.0 INTRODUCTION ================ When I bought a HP48GX I found that many of the new INFORM/CHOOSE menus were slow and cumbersome. I then attempted to use the old "SX" compatibility menus, but I found that while they were fast, they were very un-user-friendly. So I began developing my own small programs which perform specific functions quickly and easily. Because memory is a serious limit for all S/G users, I have tried to make the programs as small as possible. 2.0 DISCLAIMER ============== MathTools and its attached documentation are provided "as is", and are subject to change without prior notice. The author gives no warranty of any kind with regard to the software or documentation, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The author shall not be held liable for any damages, including any general, special, incidental, or consequential damages arising out of the use or inability to use any or all of the included programs. Use of any part of the MathTools library code is not allowed for any purpose, except, of course, when used directly from the MathTools library. You may not reproduce or modify any part of the MathTools library code without prior written permission from the author. Permission to copy the MathTools library as a whole, unmodified package is granted provided that the copies are not made or distributed for resale (excepting nominal copying fees). 2.1 EMAIL-WARE ============== The MathTools library is "Email-ware". What does this mean? If you like this program and use it regularly, you must send me an email message. (Not too steep, huh?) The idea is simple: If I know people are using this library, I will be more inclined to update it and write new programs. My internet address is jlevy@nyx.net. 3.0 INSTALLING THE LIBRARY ========================== To install MathTools in your HP48, follow these steps: 1. Transfer the library to your HP48 using Kermit/Xmodem/etc. 2. Press the soft-key associated with the library file (MT70.LIB). "Library 1155: MT..." should now be displayed on level1 of the stack. 3. Purge the MT10.LIB variable, leaving the library on the stack. 4. Enter the port number you want to store the library into. Note: For S/G users, this number must be 0. For SX/GX users, the library can safely be stored in any port. However, for GX users, it is recommended that you store it in either port 0 or 1, as execution from a covered port is slower. 5. Press STO. 6. Turn the calculator off and then on again. To access the library, press right-shift-library (2), and then NXT until you see "MT". Press the corresponding soft-key to access the MT menu. 3.1 LIBRARY INFORMATION ======================= Size : 7314.5 bytes Checksum : #E6D1h [#59089d] Version : 7.0 Library Number : 1091 You can check these numbers by putting the library on the stack and pressing LS-[VAR] [BYTES]. The above statistics correspond to the distributed version, and if they do not match your results, your copy of the library may have been modified. MathTools has been tested on a SX Revisions D/J, G Revision R, and GX Revisions P/R. However, as always, you should BACKUP YOUR MEMORY before running this application. 4.0 OVERVIEW OF THE PROGRAMS ============================ MathTools is built around a few general ideas. Here are some notes so that you can get a quick idea of how the programs will work. In general, pressing [ON] at a prompt will abort an entire process. Traps have been made for these circumstances, so there should be no problems. Throughout the MT library, you will be prompted for equations. Here is where a very useful feature comes in; All utilities in MT will recognize implied multiplication! For example, if you enter the equation 'Y=4X^2-8X+2 SIN(4)' exactly as shown (the space before SIN is automatically entered; it is actually optional), programs will convert it to 'Y=4*X^2-8*X+2*SIN(4)' and work properly. If there is an error in the equation you enter, these programs will beep and return the equation to you for re-editing at the location of the error. There are a few known limitations to the identification I have created. If you are multiplying a variable by something enclosed in ()'s, you must put the variable AFTER the ()'s and not before. For example, if you enter the equation 'Y=5+X(18+X)', it will not insert the proper multiplication. This is because the expression 'X(18+X)' is accepted internally as (18+X) being a function of X. In order to enter this equation, you would have to enter it as 'Y=5+(18+X)X' instead. The other limitation to this is that something such as 'XY' is recognized as ONE variable, not two multiplied together. If you are multiplying two variables, you must insert the '*' yourself. (For example, 5X*Y will work) Finally, remember that all the programs in this library are built around speed. They are all designed to either expand on the functionality of, or greatly speed up and ease, certain functions. For this reason, I will generally not use full screen graphical menus or choose boxes. 4.1 PROGRAM INFORMATION IN DETAIL ================================= Upon viewing the library menu, you will see a number of commands you can page through with the [NXT] key. What follows is a detailed description of how to use each. NOTE: In the following documentation, a '*' by a command denotes G/GX *only*! An error message will be returned if you attempt to use the function on a S/SX. MTOOLS This is a menuline interface to the programs in this library. The first ten keys run the math tools, and the last two provide access to the configuration and program information. I assign this program to the left-shift-PRG button. To do so, change to user mode if you aren't already in it (left-shift-alpha) and enter: { MTOOLS } HEAD 22.2 ASN This key is automatically assigned when MTCFG keys assignments are made. In the following command lists, the name in []'s is the label as it appears under MTOOLS. MPLOT [PLOT] MPLOT is replacement front-end for the built-in INFORM and menuline interfaces to the plotter. It will allow you to enter multiple equations easily, use implied multiplication, automate the configuration of PPAR/ZPAR/EQ/etc files, support stack graphs, and much more. Here is the order of execution when loading the plot module: - Change to HOME directory - Reconfigure settings to those set by the user, regardless of their state - Prompt for equations, parsing for implied multiplication - Perform operations set by the user (such as auto zoom) - If necessary, clean up "shrapnel" (such as auto zoom variables) - Display graph and allow interactive manipulation - Upon completion, return to the original directory. Therefore, you can see that MPLOT will automate the handling of all configuration files and settings. There is no more need to worry about multiple PAR files in different directories, as MPLOT will always use the ones in HOME. There is no more need for multiple EQ files, as MPLOT will always store information in the EQ variable in HOME. Finally, there is no need to worry about messing up parameters (such as changing tic mark intervals, etc) as MPLOT will create a new set on every execution. MPLOT has modes for function, polar, and conic graphing. Before graphing, you should select the mode you wish to use. To graph a function, select the rectangular coordinate system. To graph a polar EQ, select either the polar (cylindrical) or spherical coordinate system. Selection is done using the POLAR key on the calculator (right-shift-MTH). If the R> TEVAL >> in RAD/FUNCTION. Resolution of 0 pixels : 9.81 seconds Resolution of 1 pixels : 9.79 seconds Resolution of 2 pixels : 6.05 seconds - << 'r=' STEQ << ERASE DRAX DRAW >> TEVAL >> in RAD/POLAR. Resolution of 0 pixels : 18.98 seconds Resolution of 1 pixels : 8.17 seconds Resolution of 2 pixels : 5.29 seconds As you can see, a resolution of 2 for functions and 1 for polar graphs is probably the best combination of speed/detail. I keep this assigned to my left-shift-plot button for easy access. To do so, enter user mode if you aren't already in it (left-shift-alpha) and enter the following command: { MPLOT } HEAD 63.2 ASN This key is automatically assigned when MTCFG key assignments are made. ITABLE [TABL] ITable is a useful function I noticed is missing in HP calculators: A simple table of values. This list can enable you to quickly assess any pattern in the numeric values of a function. When the program is run, the first prompt is for the equation to examine in a 'Y=' form. You can either enter one (using the menu if you wish) or press [ENTER] which will tell the calculator to use the equation currently in your EQ variable. It will then prompt you for the initial value of X (default 0) and a rate of increment (default 1). The increment rate is the amount between each entry of X on the table. After answering these three prompts, a table is quickly generated. Any illegal values which cause an error in calculations are marked as "Undefined" (an example of this would be analyzing 'Y=1/X' from -2 with a step of 1). After calculations are complete, the table is displayed in ABUFF using fast ML display routines. The following menuline allows movement in the ITable viewing screen: [PAGv] Generate next six values using given increment rate. [PAG^] Generate previous six values using given increment rate. [ONEv] Generate next value using given increment rate. [ONE^] Generate previous value using given increment rate. [STEP] Prompts for a new increment rate (default 1). Redisplays table from top Xvalue with new increment. [GOTO] Jump to any X value (default 0). Redisplays table from defined Xvalue. Pressing [ENTER] or [ON] will exit the table. [NOTE: Internal calculations of the table are done to 12 digit precision, as are all working values stored. However, displayed values are rounded to four decimal places. This makes reading the table much easier, and keeps results like 7.6*10^-9 from causing misconceptions.] You can enter the equation in ITable as a function of any variable. ITable will automatically detect the independent variable and make the proper adjustments. However, if there is more than one variable used in the equation, ITable will exit with an error. (Example: 'G=14*U' will work correctly) In creating the table, the right side of an equation is used, and the left side is ignored. Therefore, 'X+3' would be treated as 'Y=0'because there is no right side; 18*Q+4W=4' is treated as 'Y=4'. If you opt to use the current equation and EQ contains a list, ITable will use the first equation. ITable supports "implied multiplication" identification. For example, entering 'Y=3SIN(2X)' will process properly. See the overview for more information on this. In addition, as in MPLOT, right-shift-NXT will recall the X's menu if you enter a different one. You can enter symbolic numbers or expressions as long as they are contained in the '' delimiters. Here is an easy example (in RAD mode): Equation: 'Y=SIN(X)' Initial Value: 0 Increment rate: 'ã/2' If you enter the above values (with proper delimiters), you should see a table with corresponding numeric values of [0, 0] [ã/2, 1] etc. I assign this program to the left-shift-STAT button. To do so, change to user mode if you aren't already in it (left-shift-alpha) and enter: { ITABLE } HEAD 73.2 ASN This key is automatically assigned when MTCFG key assignments are made. QSOLVE [QSLV] This is a quicker, cleaner equation solver. I use this for easy storage, viewing, and solving of equations. This way I can store each equation in a variable, press the key to view it, and if necessary, solve quickly. To use, simply put an algebraic equation (with '' delimiters) into level1 of the stack and run. QSOLVE will either automatically delete the variables created, or store them in the HIDDEN directory (see the section on HIDDEN for more information on this). This setting is determined by the option in MTCFG. Run QSOLVE with an algebraic or list of algebraics on level 1. After preparing the proper environment for the variables, the program then loads either SOLVR or MSOLVR, depending on what you put on the stack. If the data on level1 of the stack is an algebraic equation, it will load SOLVR. If the data is a list of EQNs in the { '' '' ... '' } form, it will load them into MSOLVR. IMPORTANT: To exit this program, you >must< press the [ON] key when you are done. The program makes a temporary key-trap for the [ON] key, and when pressed, it will automatically return you to your original directory or delete the temporary variables created. EQ is deleted if you are not in HOME; otherwise it is saved. This allows you to keep one master EQ variable. The following keys are valid in the QSOLVR/QMSOLVR environment: [SOFTKEY] Assign value in level1 to the corresponding variable [RT] [SOFTKEY] Recall contents of corresponding variable to stack [LFT] [SOFTKEY] Solve for corresponding variable using entered values [CST] Return to solver menu (if you change menus) [RT] [VIEW] Display contents of EQ and solver variables *[ON]* Exit QSOLVE and clean up variables. *IMPORTANT* The following keys are available only in the QMSOLVR environment: [ALL] Reset values of all variables [RT] [ALL] View variables you have solved for and values [LFT] [ALL] Solve for all unknowns remaining In the MSOLVR environment, all variables in all equations are assigned keys just as in SOLVR. You store and solve for a variable in the same way, but when you assign a variable a value, the key label becomes inverted on the screen. As well, when a variable is used in the previous solve, a small box is put on the key. The left-shift-ALL to attempt to solve for all unknowns obviously will not work if you have not assigned enough knowns. For more information on MSOLVR, read section 25-6 in the 48G/GX users manual. Here is a quick example of using the MSOLVR on Heron's Formula: { 's=(a+b+c)/2' 'k=û(s*(s-a)*(s-b)*(s-c))' } Entering this equation into QSOLVE will load MSOLVE, assigning the variables { K A B C S } to keys. Entering values for A, B, and C, and then pressing left-shift-ALL will first solve for S, and then K. If S is not important, pressing left-shift-K will automatically solve for S and then use it to find K. Press right-shift-ALL to view the answers. When you're done, press the [ON] key to cleanup and return you to where you started. [ NOTE: MSOLVR is not available on S/SX. ] I keep this assigned to my left-shift-solve button for easy access. To do so, change to user mode if you aren't already in it (left-shift-alpha) and enter: { QSOLVE } HEAD 62.2 ASN This key is automatically assigned when MTCFG key assignments are made. EWRIT [EQN] This is a replacement for the EquationWriter. It prompts you for an equation, and you can abort by pressing ENTER or [ON]. A menuline of X's and Y's is given (or R's and THETA's if you're in POLAR mode) and implied multiplication is supported! Press enter when done, and error checking will begin. If the equation is invalid, it will be returned with the cursor and the location of the error. If you enter another menu (such as MTH), you can recall the X/Y menu by pressing right-shift-NXT (menu). I keep this assigned to my left-shift-enter button for easy access. To do so, enter user mode if you aren't already in it (left-shift-alpha) and execute the following command: { EWRIT } HEAD 51.2 ASN This key is automatically assigned when MTCFG key assignments are made. * MWRIT [MTX] This is my replacement for the MatrixWriter. While the MatrixWriter is good for editing existing matrices, I find it very slow when you just want to create new ones. Entering matrices is very simple: Enter each row of the matrix, and then press [ENTER] on an empty [] to finish. If the dimensions of each row are not identical, MWRIT will end in an error. [I found that the size of the code to include error checking and modification for this was not worth it--just make sure you enter valid dimensions.] MWRIT can be toggled to create either numerical or symbolic matrices. The first softkey in the menuline will display the current mode (either NUM or SYM); to change modes, simply press this key. When in symbolic mode, the prompt is list brackets {}, and a menuline of A/B/C/X/Y is provided. To enter algebraics in this 'matrix', simply use tick marks in the item. Besides this, matrix creation is identical to that of numerical matrices. Note that the NUM/SYM option status is saved in the parameters file. It will always return to the same mode previously set. I keep this assigned to my right-shift-enter button for easy access. To do so, enter user mode if you aren't already in it (left-shift-alpha) and execute the following command: { MWRIT } HEAD 51.3 ASN This key is automatically assigned when MTCFG key assignments are made. FSIM [FSIM] This is a simple but useful program for simplifying equations. While similar to the EXCO program floating around, it is written in SysRPL. It first runs EXPAN on an algebraic equation in level 1 until it has no effect on the equation. It then runs COLCT until it has no effect. While this is running, FAST routines which disable the display are called to increase efficiency. [Execution time is decreased by approximately 11%] Example: 'X*(Y-Z)^2+2*(X-Z)^2' Returns: 'XY^2-2XYZ+XZ^2+2X^2-4XZ+2Z^2 According to TEVAL (from GxTools), simplification takes 11.49 seconds on my Revision R. I keep this assigned to my left-shift-symbolic button for easy access. To do so, enter user mode if you aren't already in it (left-shift-alpha) and execute the following command: { FSIM } HEAD 64.2 ASN This key is automatically assigned when MTCFG key assignments are made. * POLYN [POLY] This is a quicker polynomial solver. Yes, this feature is already built into the GX (right-shift solve, solve poly) however, I found it cumbersome to go through any inform menu. So this is a quick way to find the roots of any polynomial which requires many less key strokes; Run, enter the coefficients separated by a space (the [SPC] key), and press enter. SDIV [SDIV] This is a polynomial division program. This performs what is commonly known as synthetic division. For example, to divide the polynomial "X^4-3X^2+4X+2" by "2X-1", you simply enter the coefficients of the first equation when prompted and the X value to divide by afterwards. So you would enter [1 0 -3 4 2] for the coefficients, and '1/2' for the x value to divide by (solving for '2X-1=0'). What is returned is the list of coefficients of the new equation. If you want to use a matrix on level1 to divide into, press ENTER instead of entering coefficients. Note that the very last number is NOT a singular item--it is the remainder. Look at this example, and note the last number's equivalent: Dividing [1 0 -3 4 2] by '-3' gives this result: [1 -3 6 -14 44], which means 'X^3-3X^2+6X-14+44/(X+3)' Entering complex numbers works just the same; enter them as rectangular or polar coordinates in the (x,y) format. All resulting coefficients, real or complex, will be returned in this notation. LDIV [LDIV] Sometimes, rather than a decimal, a remainder is needed in division calculations. LDIV is just a simple program to do long division (51 bytes). Arguments required are a number on level2 and the number to divide it by on level1. When executed, it will return a string with "Quotient r Remainder" to level1. * MUC [MUC] MUC is a multi-unit converter which can ease certain conversions. Simply place any number attached to any valid unit and run MUC. After a slight pause (depending on how many units it must convert), a full screen choose list will appear with all "legal" conversions for the unit within its group. Scroll with arrow keys; cancel will leave the original number, [ENTER] or [OK] will swap it with the unit you selected. MUC will handle compound units. An example of this (taken from the Unit Converter documentation) is converting 1_m^2*kg/s^3. MUC will automatically recognize this and convert it to units in the Power group (W and HP). If an invalid unit, non-unit object, or combined unit with no direct conversions is given, MUC will return some kind of an error. If you wish to abort the process while MUC is working, simply press the [ON] key. I keep this assigned to my left-shift-units button for easy access. To do so, enter user mode if you aren't already in it (left-shift-alpha) and execute the following command: { MUC } HEAD 74.2 ASN This key is automatically assigned when MTCFG key assignments are made. FAST [FAST] Displaying the display consumes 11% of the CPU processing time. This routine, written by Detlef Muellor, turns off the display, executes the command or program on level 1 of the stack, and then restores the display. It can be used with any program that does not require a visual display. If a command interferes with the screen display, it may require you to blindly turn the calculator OFF and then ON again. If this still does not work, pressing ON-C will always restore it. This program is included because it is often very useful in conjunction with other math tools. It can be used with any mathematical tool that does not require user interaction, such as FSIM. (It is already incorporated) MTCFG [CFG] Two prompt configuration for options in limbo. "Use Clean Solver?" :: If you answer YES, QSOLVE will purge all variables created after a solve. If you answer NO, the variables will be stored in the hidden directory. "Assign User Keys?" :: Installs the 8 key definitions for MathTools [ MTOOLS, MPLOT, QSOLVE, FSIM, ITABLE, MUC, EWRIT, MWRIT ]. If you are using GxTools, MTCFG will automatically leave the GXTOOLS key assignment for the menuline. It will also change the calculator to user mode. ABOUTMT [INFO] Quick information screen with my name and internet email address. 5.0 REMOVING THE LIBRARY ======================== To remove the library from your HP48, do the following: 1. Enter the port ID in the form :PORT:1091 and press ENTER *TWICE*. Example: If MathTools is stored in port 0, enter :0:1091 DUP The port ID should now be on levels 1 and 2 of your stack. 2. Press the DETACH button (either by typing in by hand, or pressing left-shift-library, DETACH). 3. Press the PURGE key. MathTools should now be removed from your calculator. If you still get an "Object in use error", try turning off USER mode and switching to the HOME directory. Occasionally, if you have used MathTools extensively, you may have to do a warmboot (ON-C) before it will allow you to PURGE the library. 5.1 CREDITS =========== While all of the code was written by myself (except for FAST), there is much credit due to others. Thanks go out to: Lee Buck : Many SysRPL routines and questions answered Mika Heiskanen : Inverse label menubuilders, questions answered Detlef Mueller : FAST program routines Animesh Sabnis : Beta testing of pre-releases Richard Steventon : Beta testing of pre-releases Alfred Arduengo : Mathlib source, ITABLE ideas, evaluation If you use this program and have comments and/or suggestions, you can contact me at jlevy@nyx.net. I can also be found on IRC (#HP48) occasionally as "jacklevy". This library is actively supported and any reported bugs will be fixed immediately. Any suggestions will be considered! 5.2 WHAT'S WITH THE NAMES? ========================== I know a lot of people are confused as to what I've done with these libraries. Just to clear up what is being continued and what is abandoned, here is the complete story: The original library was QuickTools, and consisted of small, fast tools. As it got larger, I made some major modifications, and created a new library called GxTools. GxTools had a popular plotter in it (MPLOT), so by demand I released this individually, resulting in the MPLOT library. This was as of version 4.0--when version 5.0 hit, the library got so large that I saw it necessary to split it. From v5.0 on, the GxTools library will contain just that--utilities for your GX. All mathematical tools have been moved into the MathTools library, and the MPLOT library has been discontinued. All new versions of MPLOT will be updated in the MTools library from now on. 5.3 VERSION HISTORY =================== Changes and updates are now listed in the file MT70.NEW. mt70.lib [1091] code by jack levy [jlevy@nyx.net] dated 05/26/96, 7:44pm