The Algebra Library for the HP-48 by Junichi Steven Sato -Introduction- It all began on a November day in 1990. The first version of SupraFactor, originally known as SuperFactor, was completed. SuperFactor used 30 subprograms, 121 variables, and all the time in the world. The amount of memory space it took was about 40 kilobytes. Three months later in February 1991, version 4.2 was completed. Although it only factored up to eighth order polynomials (SuperFactor factored up to twelfth order polynomials), it was the first bug-free SupraFactor program. SupraFactor 4.2 used only one subprogram and four independent programs, causing it to run much faster than any of its previous versions. A special feature was also added, called the "root found" beep. Setting a particular flag made the program beep every time a root was found. SupraFactor 5.0 further expanded the capabilities of version 4.2. Not only were subprograms eliminated, but the program itself as a whole had been completely altered resulting in a more compact program (some 4313 bytes less than SupraFactor 4.2) and no limitations on the size of polynomials (with memory and time limitations, of course). Small improvements were made in versions 5.1 and 5.2, each version being smaller and faster than the one before. But none other is more compact or faster than version 5.2-ML. Version 5.2-ML is exactly the same as version 5.2 but written in machine language (system RPL, to be exact) and thus, the name. One of the many special thanks goes to Mr. Joe Horn, whose Goodies Disks have helped me better understand and gain access to the internals of the HP-48. I would also like to thank Mr. Rick Grevelle for his Hackit library, which I used to create most of the programs, Dr. William Wickes for his PCOEF program which I included in the library, and Mr. Akira Ijuin for his support, suggestions, criticisms, etc., during the process of creating this library. Finally, I would like to thank a few others whose programs were included in the library, but unfortunately, whose names I do not know. If you have any idea as to who these people are, please let me know. Junichi Steven Sato August 8, 1992 -Program Descriptions- Please note that all of the programs included in this library were originally written in user RPL. All of the programs have been converted to system RPL by Junichi Sato. Program: SFACT Function: Factors polynomials Author: J. S. Sato Comments: Displays two numbers while operating: the number at the top is the guess being used to find a rational root and the number at the bottom is the number of rational roots found. Results may be affected by flag -3. SFACT does not work if the last stack option is disabled. Results are given in algebraic form. SFACT factors polynomials of first order or higher as long as if there is enough memory available. It requires in level 1 of the stack a list containing coefficients of a polynomial in decreasing order of power. The list, however, may not begin with a 0. Examples: Polynomial List Result Approx. running time 5.2 5.2-ML x^2-3*x+2 { 1 -3 2 } '(-1+X)*(-2+X)' 7 sec. 5 sec. x^2-4 { 1 0 -4 } '(2+X)*(-2+X)' 8 " 6 " 3*x^3-10*x^2+8*x { 3 -10 8 '(-4+3*X)*(-2+X)* 15 " 9 " 0 } X' -2*x^2-9*x-7 { -2 -9 -7 '-((7+2*X)*(1+X)) 11 " 7 " } ' x^2+5*x-3 { 1 5 -3 } '-3+X^2+5*X' 9 " 6 " 3*x^3-6*x+9 { 3 0 -6 9 '3*(3+X^3-2*X)' 12 " 9 " } x^4-3*x^3+2*x-6 { 1 -3 0 2 '(2+X^3)*(-3+X)' 14 " 9 " -6 } 27*x+72 { 27 72 } '9*(8+3*X)' 9 " 5 " 315*x^2+1711*x- { 315 1711 '(-32+45*X)*(43+ 184 " 99 " 1376 -1376 } 7*X)' 18*x^9-129*x^8+ { 18 -129 '(1+X^2+X)*(2+3* 164 " 97 " 206*x^7+404*x^6- 206 404 X)*(-4+3*X)*(-5+ 1193*x^5+200*x^ -1193 200 2*X)*(2+X)*(-2+ 4+448*x^3+1232* 448 1232 X)^2*(-3+X)' x^2-496*x-960 -496 -960 } -6*x^10+44*x^9- { -6 44 '-(2*(-4+3*X)*(1+ 51 " 33 " 102*x^8-12*x^7+ -102 -12 X)*(-1+X)^5*(2+ 454*x^6-780*x^ 454 -780 X)*(-2+X)^2)' 5+366*x^4+412* 366 412 x^3-648*x^2+336* -648 336 x-64 -64 } Program: FACTS Function: Finds factors of a number Author: Anonymous; J. S. Sato, ed. Comments: The larger the number, the longer it takes for FACTS to return a result. The ATTN key interrupts the program and returns two lists in levels 1 and 2 and the original number in level 3. FACTS factors a non-negative integer given in level 1 of the stack. It leaves other real numbers alone. Factors are returned in a list. Examples: Number Result 56 { 1 2 4 7 8 14 28 56 } 128 { 1 2 4 8 16 32 64 128 } 263 { 1 263 } Program: PRIM Function: Finds prime factors of a number Author: Anonymous PRIM finds prime factors of a positive real number and returns the results in a list. PRIM returns an empty list for the number 1 and leaves non-positive numbers alone. Examples: Number Result 360 { 2 2 2 3 3 5 } 3844037 { 29 41 53 61 } 373 { 373 } 5.132E13 { 2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 5 5 5 5 5 1283 } Program: SQRT Function: Finds the square root of a number Author: J. S. Sato SQRT requires a real number from the stack and it returns the square root of the number in the simplest radical form. The solution will contain the variable 'i' if the number is negative. Examples: Number Result 20 '2*\v/5' -163296 '108*\v/14*i' 576 24 269 '\v/269' Program: D\->F Function: Converts a decimal to a fraction Author: Akira Ijuin Comments: Results may be affected by flag -3. D\->F converts a decimal number (any real number) to a fraction in the form 'a/b*\v/(c/d)'. Integers, however, are returned as integers. If '\v/(c/d)' is equal to 1, only 'a/b' is returned. If 'a/b' is equal to 1, only '\v/(c/d)' is returned. Examples: Number Result 1.02062072616 '5/2*\v/(1/6)' 4.89897948557 '2*\v/6' 1.29099444874 '\v/(5/3)' .714285714286 '5/7' .267261241912 '\v/(1/14)' Program: D\->RT Function: Converts a decimal to a root Author: Anonymous Comments: Decimal numbers must be accurate to at least five decimal places. ATTN interrupts the program, leaving the original decimal in level 2 and the current guess in level 1. D\->RT converts a real number to a root in the form 'a+\v/b', where 'a' is either a whole number or a number with one decimal place and 'b' is a positive whole number. Integers and numbers with only one decimal place are ignored. The program may run infinitely if random numbers are used. The program searches for 'b' in the above equation by starting with 1. It then increments the counter by 1 until 'b' is found. Therefore, the decimal 8.0891438104 ('-20+\v/789') would take much longer than the decimal 12.2360679775 ('10+\v/5'). Examples: Number Result 4.4142136 '3+\v/2' 7.6095202129 '-5+\v/159' -1.11 '-13.6+\v/156' Program: GCF Function: Finds the greatest common factor of two numbers Author: Anonymous Comments: To find the greatest common factor of three or more numbers, put the numbers on the stack and execute GCF once less than the total number of numbers. For example, for four numbers, execute GCF three times, for ten numbers, execute GCF nine times, etc. GCF returns a negative number if one of the numbers is negative. GCF finds the greatest common factor of two real numbers. Examples: Numbers Result 300 and 1275 75 258 and -461 -1 -16.8 and 22.4 -5.6 -.089 and -.2136 -.0178 Program: LCM Function: Finds the least common multiple of two numbers Author: Anonymous Comments: Follow the guideline given in GCF to find the least common multiple of three or more numbers. LCM returns a negative number if one of the numbers is negative. LCM finds the least common multiple of two real numbers. Examples: Numbers Result 5 and 12 60 56 and -45 -2520 -240 and 16 -240 -2.35621 and -45.1523 -10638830.0783 Program: PCOEF Function: Extracts coefficients into a list Author: William Wickes Comments: Results may be affected by flag -3. PCOEF may be coordinated with SFACT. However, care must be taken when doing this (keep in mind that SFACT does not work when the list begins with a 0). PCOEF requires an algebraic expression in level 3, a variable name in level 2, and a number representing the order number of the polynomial in level 3 in level 1. It returns a list of coefficients in order of decreasing power. If the number in level 1 is a decimal, it is rounded to the nearest whole number. If it is non-positive, PCOEF returns only the coefficient of x^0. If the number is larger than the order number of the polynomial, the resulting list will contain leading 0's. This list cannot be used with SFACT. Examples: Polynomial Name Number Result '(X+1)*(X^2-4)' 'X' 3 { 1 1 -4 -4 } 'Y^2-3*Y+2' 'Y' 4 { 0 0 1 -3 2 } '4*S^2-N' 'S' 2 { 4 0 '-N' } 'J^3-3*J+6' 'J' 1.5 { 0 -3 6 } Program: ALGVERSION Function: Displays the Algebra Library logo and version number Author: Akira Ijuin; J. S. Sato, ed. Comments: ALGVERSION does not affect PICT or PPAR. ALGVERSION displays the Algebra Library logo and its version number along with the release date. Pressing any key will return you to the stack. Note: All of the results given in the examples above were obtained using default flags. -Installing and Uninstalling- To install the Algebra Library, download the ALGEBRA.LIB file to the calculator in binary form and store it in a variable. Recall the contents of the variable to the stack and execute DUP. Check to see if the library object is valid by executing BYTES. The library object should be 3461 bytes with a checksum of # 209Ah or # 8346d. Do not use the library if the figures do not match. Store the library object in a port by placing a port number on the stack and executing STO. Turn the calculator off and then on. The calculator will perform a system halt, and the library will automatically attach itself to the home directory. Purge the variable in which the library was stored. To remove the Algebra Library, place a tagged object on the stack in the form x: 1060 where 'x' is the port number in which the Algebra Library was stored. Execute DUP, then DETACH, then PURGE. -Miscellaneous Information- Title: Algebra Library Version: 3.5 Release date: August, 1992 Checksum: # 209Ah or # 8346d Bytes: 3461 Individual program information: Program Version Release Date SFACT 1.0 November, 1990 SFACT 2.0 December 13, 1990 SFCT2 1.0 December 13, 1990 SFCTJ 1.0 December 13, 1990 SFACT 2.2 December 17, 1990 SFCT2 1.1 December 17, 1990 SFCTJ 1.1 December 17, 1990 SFACT 4.0 February, 1991 SFACT 4.2 February, 1991 SFACT 5.0 April, 1991 SFACT 5.1 June, 1991 SFACT 5.2 June, 1992 SFACT 5.2-ML June 21, 1992 FACTS ? October, 1990? FACTS Sato 1.1 March, 1991 FACTS Sato 2.0 June, 1992 FACTS Sato 2.1 August, 1992 PRIM ? October, 1990? PRIM Sato 1.1 March, 1991 SQRT 1.0 October, 1990 SQRT 1.1 December 13, 1990 SQRT 2.0 June, 1992 SQRT 3.0 August, 1992 D\->F ? June, 1992 D\->RT ? ? D\->RT Sato 1.1 March, 1991 GCF ? March, 1991? GCF Sato 1.1 April, 1991 GCF Sato 1.2 August, 1992 LCM ? June, 1992? LCM Sato 1.1 August, 1992 PCOEF ? May, 1990 ALGVERSION 1.0 May, 1992 ALGVERSION Sato 2.0 June, 1992 ALGVERSION Sato 2.1 August, 1992 RS (Subprogram) 1.0 (Not released) RS (Subprogram) Ijuin 2.0 May, 1992 Algebra Library 1.0 (Not released) Algebra Library 2.0 May, 1992 Algebra Library 2.1 May, 1992 Algebra Library Sato 3.0 June, 1992 Algebra Library Sato 3.5 August, 1992 -Notice- The Algebra Library is freeware and is not to be bought or sold. The library and documentation may be copied freely and doing so is encouraged, provided that the materials are not altered in any way. Nobody but the user may be held responsible for any consequential damages resulting from the use and/or misuse of the library and/or the programs included in the library. The programs included in the library may be used by other programs as long as the creator gives proper credit in the new program's documentation and clearly specifies that this Algebra Library is required to run the program. -Questions and Answers- Q: What method does SupraFactor use? A: SupraFactor uses synthetic division. Q: Why does '315*x^2+1711*x-1376' take longer to factor than '-6*x^10+44*x^9- 102*x^8-12*x^7+454*x^6-780*x^5+366*x^4+412*x^3-648*x^2+336*x-64' even though the first is a 2nd order polynomial and the latter is a 10th order polynomial? A: Take a look at the coefficients of the highest degree and the coefficients of x^0. The larger the value of these coefficients, the longer SupraFactor takes. The order of the polynomial has very little to do with running time. Q: How can SupraFactor come up with so many lucky guesses? A: SupraFactor does not make random guesses. These guesses are actually calculated. Q: Why does it take long before SupraFactor begins searching for a root? A: The reason why SupraFactor takes this time is to create a list of possibilities or guesses to be used in the searching process. If the value of the coefficient of the highest degree and the value of the coefficient of x^0 is large, the program takes a long time before starting the search. Q: After a root is found, SupraFactor pauses for a while. Is that to show the user what the root is? A: It wasn't meant to be, but it seems like it. When the program "freezes" the display after a root is found, it is actually creating a new list of possibilities to be used in the searching process for the next root. Quite convenient, isn't it? Q: Why does it take long to return the solution after SupraFactor finds all the roots to a given polynomial? A: SupraFactor is creating an algebraic form of the factored polynomial. Q: Why does SupraFactor go through the trouble of creating an algebraic solution? Wouldn't it be faster without using this method? Wouldn't SupraFactor take up less memory if it only returned the roots? A: SupraFactor would indeed be faster and smaller if it only returned roots. But then the program would not be called "SupraFactor," it would be called something more silly, like "UltraRoots," or something to that effect. Of course, many users complained about previous versions that SupraFactor was too slow and took up too much of their RAM, but the main reason for having so many versions of SupraFactor was due to the effort of cutting down memory space and increasing speed. Many methods and techniques were used including Newton's method to improve the program as much as possible. However, it was found that only one technique was possible to maintain the general purpose of creating SupraFactor: not only to find the rational roots of a given polynomial, but also to factor. This one technique is known as synthetic division. Restricted to this one method, many attempts were made to quicken the program and to decrease its size. With the aid of several amazing programs like GCF, this was soon made possible. Version 5.2-ML by itself is already 250% faster and 1121% smaller than version 2.0. Q: The number .333333333333 does not work with the program D\->F. Is this a bug? A: Yes it is. Be patient, we're working on it. Q: Does the number 1060 (Algebra Library ROM ID) have any meaning? A: Yes it does. 1059 was the ROM ID for the Algebra Library, version 3.0, and since version 3.5 is the next version released, the number has been incremented to 1060. 1059 is the sum of the HP-48 character codes for each of the characters in the string "ALGEBRA LIBRARY". -Correspondence- Suggestions, comments, ideas, questions, etc. are all welcome. Please send them to the following address: Junichi Steven Sato c/o SupraFactor 5.2-ML 707 West Waveland Avenue, #311 Chicago, IL 60613-4112 (Address may change without notice) or E-Mail at jssato@aol.com Due to time limitations, not all questions will be answered, but please send them anyway.