Polynomial v2.1 by Steen S. Schmidt

August 5, 2001

 

Contents

Contents. 1

Disclaimer & Copyright 1

Credits. 2

Requirements & Installation. 2

Polynomial 2

A®P. 2

P®A.. 4

P2®A.. 4

P3®A.. 4

RAT?. 5

PDEG.. 5

PMONIC.. 6

PSIMP. 6

PADD.. 7

PSUB.. 7

PMUL. 7

PDIV.. 7

PPOW... 8

PDER.. 8

PINT. 8

PMATEVAL. 9

PSYSSOLVE. 9

LAGUERRE. 10

Vectors on the HP49G.. 10

Creating vectors. 10

Editing vectors. 11

Vector arithmetic. 12

Relationship w/ SymbToolz. 12

Revision History. 12

Disclaimer & Copyright

This program is freeware, but should be registered by sending me an email at SSchmidt@nospam.dk. This is merely so that I can track the use of my software – no licensing fee is necessary. You are free to distribute this program to anyone, as long as this document is included and they register by email as well.

I cannot take responsibility for any damage or data loss caused by this program – it is written in 100% SysRPL and there could be bugs in it. This also means that it will not run on the HP48 series.

If you have any suggestions, additions or find any bugs in the code, you’re welcome to contact me per the above-mentioned email. Please include details about ROM revision and flag settings if you’re reporting a bug.

Credits

The library is coded and compiled directly on the HP49G, which has proven to be a great tool for this too. A thanks goes to ACO for making it possible – including these programming tools on the calculator itself has made the job a lot easier.

Mr. Bernard Parisse (CAS author on the HP49G) has been a big help explaining his software to me. I have had especially great use of three pieces of software on the HP49G, which are Emacs, Keyman & Nosy.

Requirements & Installation

You need to copy the library (library #1125) to the calculator (with HPComm for example) and store it in a port (any port should do).

To store it in port 2 for example, you will need to recall the library to the stack, type 2 and STO.

 

 

Hold down ON and press F3, release both keys and the calc should warm boot (warning: you’ll loose all stack contents, but calc memory will remain intact). When this is done, your port 2 should contain the entry for the library (press left shift APPS to enter the Filer):

 

  à 

 

Running BYTES on the library on the stack should yield #C37h and 3729 bytes.

 

  à 

 

This document is showing stack syntax for RPN mode, but algebraic mode works too.

Polynomial

This library is a small set of commands to handle polynomials as vectors of coefficients – in this document called vector polynomials, and denoted [ coefficients ]. On several occasions on comp.sys.hp48, there has been requested a way to extract the coefficients from a polynomial. This is now possible with this library, as it was on the HP48 with NeoPolys. I’m not trying to take any fame or glory away from NeoPolys, nor have a looked at the code therein – this is a totally independent development.

The commands in this library are listed below.

 

A®P

Algebraic to polynomial command:

The basic command used to convert an algebraic expression or equation into its two vector polynomials – the numerator and the denominator.


Level 2

Level 1

à

Level 2

Level 1

symbolic

global name

à

[ coefficientsNum ]

[ coefficientsDenom ]

numberx

global name

à

[ numberx ]

[1]

 

This command is indifferent to the algebraic form of the Level 2 argument, as different forms don’t affect performance much. The two conversions below are the same polynomial, the first written in a compact form, a form one would most likely see it in, the second is the expanded form, revealing that it is actually a 10th degree polynomial, divided by a 7th degree polynomial.

 

  à 

Or

 

The first conversion is calculated in 1.91 seconds, and the second one is calculated in 1.51 seconds (yielding the same result). This would make it seem obvious that it is best to expand expressions before using A®P, but the picture is different when considering that the HP49G will spend 2.89 seconds expanding the first form to the second one. In short, it doesn’t matter what form you feed into A®P.

 

If the denominator is [1] you can delete it, since the numerator then represents the complete polynomial.

 

  à 

 

Equations are also valid input.

 

  à 

 

You can combine al sorts of coefficients, reals, complex numbers, integers and symbolics.

 

  à 

 

Irrational input is handled in a special way. The goal of A®P is that P®A always shall return the original expression, even though the coefficient vector contains the variable itself (e.g. X). Generally, an irrational part will always end up being the constant part of the vector.

 

  à 

  à 

 

When the vector polynomial contains the polynomial variable, as in the above two examples, it will generally not be valid to use the commands in this library that are variable dependent, namely PDER and PINT.

 

P®A

Polynomial to algebraic command:

The basic command used to convert a vector polynomial into its algebraic representation.

 

Level 2

Level 1

à

Level 1

[ coefficients ]

global name

à

symbolicPolynomial

 

Basically, all it does is to set the global name to an iterating power, while multiplying it with the corresponding coefficient.

 

  à 

 

P2®A

Polynomial fraction to algebraic command:

Converts a vector polynomial numerator and denominator into its algebraic representation.

 

Level 3

Level 2

Level 1

à

Level 1

[ coefficientsNum ]

[ coefficientsDenom ]

global name

à

symbolicPolynomial

 

This is the reciprocal to A®P.

 

  à 

 

P3®A

Polynomial partial fraction to algebraic command:

Converts a vector polynomial and a vector polynomial numerator/denominator into its algebraic representation.

 

Level 3

Level 2

Level 1

Level 3

à

Level 1

[ coeff ]

[ coeffNum

[ coeffDenom ]

global name

à

symbolicPolynomial

 

This command can convert the output of PDIV into its algebraic representation.

 

  à 

 

RAT?

Rationality test command:

Tests whether an expression or equation is rational in a given variable. Possible outputs are true or false, denoted by 1. or 0. respectively.

 

Level 2

Level 1

à

Level 1

symbolic

global name

à

0. or 1.

number

global name

à

1.

 

Even though an expression is rational, doesn’t mean that it is a polynomial. It does mean however, that it is a polynomial fraction consisting of a numerator polynomial and a denominator polynomial in that variable. An expression can be rational in some variables and irrational in others.

 

  à 

  à 

 

PDEG

Polynomial degree command:

Returns the degree/order of a polynomial. It will accept an algebraic as well as a vector polynomial.

 

Level 2

Level 1

à

Level 2

Level 1

symbolic

global name

à

nDeg,Num

nDeg,Denom

 

[ coefficients ]

à

nDeg,Num

0

 

Since PDEG must return both the degree of the numerator as well as of the denominator, if it was given an algebraic, it also returns two values when given a vector polynomial. This is to make programmable use of it simple. If the input was a vector, then the Level 1 output is zero and can be discarded.

 

  à 

  à 

 

PMONIC

To monic polynomial command:

Converts a vector polynomial into its monic representation.

 


Level 1

à

Level 1

[ coefficients ]

à

[ coefficientsMonic ]

 

A monic polynomial is a polynomial whose leading coefficient is 1, so ultimately, this command simply divides all coefficients by the leading coefficient.

 

  à 

 

PSIMP

Simplify polynomial command:

Simplifies a vector polynomial. Basically, it will call EVAL on numeric coefficients (coefficients consisting of only reals, complex numbers or integers), and COLLECT on all other symbolic constructs. This is necessary because no commands in this library simplify their output. This means that vector polynomials can contain large constructs that can be simplified, as well as leading zeroes.

The reason that COLLECT is called instead of FACTOR, is that COLLECT only factors over the integers, which yields a “nicer” result:

 

  à    but    à 

  à    and    à 

 

The reason that COLLECT doesn’t get called upon numeric constructs is obvious:

 

  à    while     à 

 

Since COLLECT factors numeric constants in symbolic constructs, the result can get mangled. Notice the denominator of the second to last coefficient in the example below:

 

  à 

 

I considered calling SIMPLIFY before COLLECT to take care of transcendental functions, but I thought it a waste of time, since it’s rarely necessary.

 

PADD

Add polynomials command:

Adds two vector polynomials.

 

Level 2

Level 1

à

Level 1

[ coefficients ]

[ coefficients ]

à

[ coefficients ]

 

The vectors may differ in length.

 

  à 

 

PSUB

Subtract polynomials command:

Subtracts two vector polynomials.

 

Level 2

Level 1

à

Level 1

[ coefficients ]

[ coefficients ]

à

[ coefficients ]

 

The vectors may differ in length.

 

  à 

 

PMUL

Multiply polynomials command:

Multiplies two vector polynomials.

 

Level 2

Level 1

à

Level 1

[ coefficients ]

[ coefficients ]

à

[ coefficients ]

 

The vectors may differ in length.

 

  à 

 

PDIV

Polynomial division command:

Divides two vector polynomials by long division. This will produce a quotient (Level 2/Level 1), and a remainder.

 

Level 2

Level 1

à

Level 3

Level 2

Level 1

[ coeffNum ]

[ coeffDenom ]

à

[ coeffQuotient ]

[ coeffRem,Num ]

[ coeffRem,Denom ]

 

If one polynomial is divided by another polynomial of higher degree, then the quotient will be zero, and the remainder will be the original fraction. An example will illustrate how it works:

 

  à      º   

 

…and when Level 2 is [0], there is no remainder, and the two lower levels can be discarded:

 

  à      º   

 

PPOW

Polynomial to a power command:

Takes a vector polynomial to a given power.

 

Level 2

Level 1

à

Level 1

[ coefficients ]

nPower

à

[ coefficients ]

 

The execution time can be very long for high powers.  takes ~35 seconds to calculate (but the calc takes ~50 seconds to expand the same expression, so maybe it’s not that long anyway J).

 

  à 

 

PDER

Polynomial derivative command:

Takes the derivative of a vector polynomial.

 


Level 1

à

Level 1

[ coefficients ]

à

[ coefficients ]

 

Remember that the derivative is not valid if the polynomial variable is present in the vector.

 

  à 

 

PINT

Polynomial integration command:

Integrates a vector polynomial.



Level 1

à

Level 1

[ coefficients ]

à

ò[ coefficients ]

 

Remember that the integral is not valid if the polynomial variable is present in the vector. As in any integration, you can add an arbitrary constant while maintaining integrity.

 

  à 

 

PMATEVAL

Polynomial matrix evaluation command:

Evaluates a matrix in a polynomial.

 

Level 3

Level 2

Level 1

à

Level 1

symbolic

global name

[ matrix ]

à

[ matrix ]

 

To evaluate a matrix in a polynomial, is best illustrated with an example:

 

Consider the matrix , in the polynomial .

This means

 

  à 

 

PSYSSOLVE

Solve polynomial system command:

Solves a polynomial system, like the built-in LINSOLVE does.

 

Level 2

Level 1

à

Level 1

[ symbolicSystem ]

[ global nameVars ]

à

[ solutions ]

 

The example system here is still considered simple, even though PSYSSOLVE does well. A 10x10 system, for example, is considered complex, but far too big to use as example. Just take my word for it, that this command will solve such systems up to 10 times faster than the built-in functions.

 

      solved for ,  and .

 

SOLVE:   13.45 s.

LINSOLVE:   16.72 s.

PSYSSOLVE:   12.82 s.

 

  à 

 

LAGUERRE

N’th LaGuerre polynomial command:

Returns the n’th order LaGuerre polynomial, similar to the built-in commands TCHEBYCHEFF, HERMITE and LEGENDRE.

 


Level 1

à

Level 1

nOrder

à

[ coefficientsLaGuerre ]

 

Negative orders are not allowed. The 4th order LaGuerre polynomial :

 

  à 

Vectors on the HP49G

A vector on the HP49G can look like this; [1 3 –5 ‘X+2’ 9], can contain reals (e.g. 2.2514784455), complex numbers (e.g. (1.2,4.7)), integers (e.g. 5) and symbolics (e.g. ‘X’ or ‘(A-2)/7’), or a mix of them. There are different ways on the calc to create and edit these vectors.

 

Creating vectors

There are four (simple) ways to create a vector on the calc.

 

 

                Figure 1                                   Figure 2                                   Figure 3

                     

 

 

                Figure 4                                   Figure 5                                   Figure 6

                     

 

 

                Figure 7                                   Figure 8

                

 

When you’ve input all elements, press ENTER to have the vector put on the stack (see Figure 10 & 11).

 

Figure 9                                  Figure 10                                 Figure 11

           

 

Editing vectors

You can edit vectors in much the same way as creating them. You need to have the vector on stack Level 1 for all of these methods to work.

 

 

 

The disadvantage of the MTRW is that it can be difficult to make big changes in the vector. It is easier with the list method to add items in the middle of the vector, or to add elements to the beginning aso.

 

Vector arithmetic

When dealing with vectors there are many operations that are valid on them. I’ll concentrate here on the ones that have relation to polynomials.

Relationship w/ SymbToolz

The commands A®P, P®A and RAT? did reside in the SymbToolz library up until v1.1. From SymbToolz  v2.0 (not released yet) onwards, this library will be necessary for it to run. This library is the natural place for such commands, and therefore they have been removed from SymbToolz.

Revision History

v1.0:              Initial public release.

 

v2.0:              Added commands P2®A, P3®A, PMATEVAL and PSYSSOLVE.

 

v2.1:              Fixed a bug that affected some of the commands in this library – numeric vector (type 3) input could cause a TTRM.