Sei sulla pagina 1di 8

The Algebra Library for the HP-48

by Junichi Steven Sato


-IntroductionIt 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 DescriptionsPlease 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:
Function:
Author:
Comments:

SFACT
Factors polynomials
J. S. Sato
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

x^2-3*x+2
x^2-4
3*x^3-10*x^2+8*x

{ 1 -3 2 }
{ 1 0 -4 }
{ 3 -10 8
0 }
-2*x^2-9*x-7
{ -2 -9 -7
}
x^2+5*x-3
{ 1 5 -3 }
3*x^3-6*x+9
{ 3 0 -6 9
}
x^4-3*x^3+2*x-6
{ 1 -3 0 2
-6 }
27*x+72
{ 27 72 }
315*x^2+1711*x{ 315 1711
1376
-1376 }
18*x^9-129*x^8+
{ 18 -129
206*x^7+404*x^6206 404
1193*x^5+200*x^
-1193 200
4+448*x^3+1232*
448 1232
x^2-496*x-960
-496 -960
}
-6*x^10+44*x^9{ -6 44
102*x^8-12*x^7+
-102 -12
454*x^6-780*x^
454 -780
5+366*x^4+412*
366 412
x^3-648*x^2+336*
-648 336
x-64
-64 }

Result

Program:
Function:
Author:
Comments:

Approx. running time


5.2
5.2-ML

'(-1+X)*(-2+X)'
'(2+X)*(-2+X)'
'(-4+3*X)*(-2+X)*
X'
'-((7+2*X)*(1+X))
'
'-3+X^2+5*X'
'3*(3+X^3-2*X)'

7 sec.
8 "
15 "

5 sec.
6 "
9 "

11 "

7 "

9 "
12 "

6 "
9 "

'(2+X^3)*(-3+X)'

14 "

9 "

'9*(8+3*X)'
9 "
'(-32+45*X)*(43+ 184 "
7*X)'
'(1+X^2+X)*(2+3* 164 "
X)*(-4+3*X)*(-5+
2*X)*(2+X)*(-2+
X)^2*(-3+X)'

5 "
99 "

'-(2*(-4+3*X)*(1+
X)*(-1+X)^5*(2+
X)*(-2+X)^2)'

33 "

51 "

97 "

FACTS
Finds factors of a number
Anonymous; J. S. Sato, ed.
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
56
128
263

Result
{ 1 2 4 7 8 14 28 56 }
{ 1 2 4 8 16 32 64 128 }
{ 1 263 }

Program:
Function:
Author:

PRIM
Finds prime factors of a number
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
360
3844037
373
5.132E13

Result
{
{
{
{

2 2 2 3 3 5 }
29 41 53 61 }
373 }
2 2 2 2 2 2 2 2 2 2 2 2 5 5 5 5 5 5 5 5 5 5 1283 }

Program:
Function:
Author:

SQRT
Finds the square root of a number
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
-163296
576
269

'2*\v/5'
'108*\v/14*i'
24
'\v/269'

Program:
Function:
Author:
Comments:

D\->F
Converts a decimal to a fraction
Akira Ijuin
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
4.89897948557
1.29099444874
.714285714286
.267261241912

'5/2*\v/(1/6)'
'2*\v/6'
'\v/(5/3)'
'5/7'
'\v/(1/14)'

Program:
Function:
Author:
Comments:

D\->RT
Converts a decimal to a root
Anonymous
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
7.6095202129
-1.11

'3+\v/2'
'-5+\v/159'
'-13.6+\v/156'

Program:
Function:
Author:
Comments:

GCF
Finds the greatest common factor of two numbers
Anonymous
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


258 and -461
-16.8 and 22.4
-.089 and -.2136

75
-1
-5.6
-.0178

Program:
Function:
Author:
Comments:

LCM
Finds the least common multiple of two numbers
Anonymous
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
56 and -45
-240 and 16
-2.35621 and -45.1523

60
-2520
-240
-10638830.0783

Program:
Function:
Author:
Comments:

PCOEF
Extracts coefficients into a list
William Wickes
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

'(X+1)*(X^2-4)'
'Y^2-3*Y+2'
'4*S^2-N'
'J^3-3*J+6'

'X'
'Y'
'S'
'J'

3
4
2
1.5

Program:
Function:
Author:
Comments:

Result
{
{
{
{

1
0
4
0

1 -4 -4 }
0 1 -3 2 }
0 '-N' }
-3 6 }

ALGVERSION
Displays the Algebra Library logo and version number
Akira Ijuin; J. S. Sato, ed.
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 UninstallingTo 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 InformationTitle:
Algebra Library
Version:
3.5
Release date: August, 1992
Checksum:
# 209Ah or # 8346d
Bytes:
3461
Individual program information:
Program

Version

Release Date

SFACT
SFACT
SFCT2
SFCTJ
SFACT
SFCT2
SFCTJ
SFACT
SFACT
SFACT

1.0
2.0
1.0
1.0
2.2
1.1
1.1
4.0
4.2
5.0

November, 1990
December 13, 1990
December 13, 1990
December 13, 1990
December 17, 1990
December 17, 1990
December 17, 1990
February, 1991
February, 1991
April, 1991

SFACT
SFACT
SFACT
FACTS
FACTS
FACTS
FACTS
PRIM
PRIM
SQRT
SQRT
SQRT
SQRT
D\->F
D\->RT
D\->RT
GCF
GCF
GCF
LCM
LCM
PCOEF
ALGVERSION
ALGVERSION
ALGVERSION
RS (Subprogram)
RS (Subprogram)
Algebra Library
Algebra Library
Algebra Library
Algebra Library
Algebra Library

5.1
5.2
5.2-ML
?
Sato 1.1
Sato 2.0
Sato 2.1
?
Sato 1.1
1.0
1.1
2.0
3.0
?
?
Sato 1.1
?
Sato 1.1
Sato 1.2
?
Sato 1.1
?
1.0
Sato 2.0
Sato 2.1
1.0
Ijuin 2.0
1.0
2.0
2.1
Sato 3.0
Sato 3.5

June, 1991
June, 1992
June 21, 1992
October, 1990?
March, 1991
June, 1992
August, 1992
October, 1990?
March, 1991
October, 1990
December 13, 1990
June, 1992
August, 1992
June, 1992
?
March, 1991
March, 1991?
April, 1991
August, 1992
June, 1992?
August, 1992
May, 1990
May, 1992
June, 1992
August, 1992
(Not released)
May, 1992
(Not released)
May, 1992
May, 1992
June, 1992
August, 1992

-NoticeThe 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 AnswersQ: 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^9102*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".
-CorrespondenceSuggestions, 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.

Potrebbero piacerti anche