Post Reply 
(35S ALG) Ruffini Polynomial Division
06-12-2014, 05:52 PM (This post was last modified: 06-15-2017 01:15 PM by Gene.)
Post: #1
(35S ALG) Ruffini Polynomial Division
Hi HPmuseum, I'm a new user and I'm going to share with you an HP 35s program that is able to calculate the coefficents of a polynomial divison using Ruffini Rule.
This program, developed in ALG mode, can divide a n-grade polynomial g(x) by hx-c.
It will ask you:
  • The grade of the polynomial to divide (G)
  • The coefficent h of the divisor (H)
  • The value of c (C)

Then, if one of these values is zero it will prompt an error and exit, else it will start a cycle on INPUT I where you have to put the coefficents the dividend polynomial in decrescent order(the current value of I will help you showing the grade of the coefficent you have to write). After each INPUT it will show you the coefficent of x^n-1 of the result polynomial(so if you have just entered the third grade coefficent it will show you the second grade coefficent of the result), then you have to press R/S to input a new coefficent. The last value shown is the rest of the division (R).
Here the code:

R001 LBL R
R002 CLVARS
R003 CLSTK
R004 SF 10
R005 DIVIDE BY Hx-C
R006 PSE
R007 CF 10
R008 0->D
R009 INPUT G
R010 x=0?
R011 GTO R036
R012 INPUT H
R013 x=0?
R014 GTO R036
R015 INPUT C
R016 x=0?
R017 GTO R036
R018 C/H->C
R019 G+2->G
R020 DSE G
R021 GTO R023
R022 RTN
R023 G-1->I
R024 INPUT I
R025 I/H+D->I
R026 I*C->D
R027 I*H->R
R028 G
R029 1
R030 x=y?
R031 GTO R034
R032 VIEW I
R033 GTO R020
R034 VIEW R
R035 RTN
R036 SF 10
R037 INVALID DATA
R038 PSE
R039 CF 10
R040 RTN


Let's do some example:
(2x^4 -5x^2 -2x -1) / (x-2)

so:
h=1 ; c=2

To solve this division you have to press:
XEQ R... ENTER (It will ask you the grade)
4 R/S (It will ask you h)
1 R/S (It will ask you c)
2 R/S (It will ask you the coefficent in decrescent order starting by 4)
2 R/S (The result coefficent of grade 3 is 2)
R/S 0 R/S (It will ask you the third grade coefficent and show you the second grade coefficent of the result: 4)
R/S -5 R/S (...first grade coefficent: 3)
R/S -2 R/S (...known term: 4)
R/S -1 R/S (rest: 7)

so our result is 2x^3+4x^2+3x+4 R=7

Any question will be answered...
Find all posts by this user
Quote this message in a reply
06-12-2014, 07:50 PM
Post: #2
RE: (35s ALG) Ruffini Polynomial Division
(06-12-2014 05:52 PM)d.nicotra Wrote:  Any question will be answered...

What's the meaning of life?
Big Grin

SCNR...

Welcome aboard!

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
06-12-2014, 08:03 PM
Post: #3
RE: (35s ALG) Ruffini Polynomial Division
I'm pleased to see another Italian...
about the meaning of life, well, I'll ask to my 35s!
Big Grin
Find all posts by this user
Quote this message in a reply
06-12-2014, 08:38 PM
Post: #4
RE: (35s ALG) Ruffini Polynomial Division
(06-12-2014 08:03 PM)d.nicotra Wrote:  I'm pleased to see another Italian...

There's a handful of us hereabout. ;)

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
06-12-2014, 08:40 PM
Post: #5
RE: (35s ALG) Ruffini Polynomial Division
Yeah I'm happy now Big Grin
I hope I can contribute to this community!
Have you tried this program?
Find all posts by this user
Quote this message in a reply
06-12-2014, 09:03 PM
Post: #6
RE: (35s ALG) Ruffini Polynomial Division
(06-12-2014 08:40 PM)d.nicotra Wrote:  I hope I can contribute to this community!
You already did!

(06-12-2014 08:40 PM)d.nicotra Wrote:  Have you tried this program?
No, sorry. The 35S is not among my favourites; I should dig it out, put some fresh batteries in and start hunting for keys on the keyboard... Wink

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
06-12-2014, 09:31 PM
Post: #7
RE: (35s ALG) Ruffini Polynomial Division
Should I spend time on making an RPN version of this program, in your opinion?
It seems to work pretty well in ALG mode; I don't think that it needs more speed.
Find all posts by this user
Quote this message in a reply
06-12-2014, 10:22 PM
Post: #8
RE: (35s ALG) Ruffini Polynomial Division
(06-12-2014 09:31 PM)d.nicotra Wrote:  Should I spend time on making an RPN version of this program, in your opinion?
It seems to work pretty well in ALG mode; I don't think that it needs more speed.

If you want to please us, calcaholics from another age, RPN is the way to go. Big Grin

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
06-13-2014, 12:28 PM
Post: #9
RE: (35s ALG) Ruffini Polynomial Division
(06-12-2014 10:22 PM)Massimo Gnerucci Wrote:  If you want to please us, calcaholics from another age, RPN is the way to go. Big Grin

OK I hope I can do it after my high school exams.
Find all posts by this user
Quote this message in a reply
06-13-2014, 02:44 PM
Post: #10
RE: (35s ALG) Ruffini Polynomial Division
(06-13-2014 12:28 PM)d.nicotra Wrote:  
(06-12-2014 10:22 PM)Massimo Gnerucci Wrote:  If you want to please us, calcaholics from another age, RPN is the way to go. Big Grin

OK I hope I can do it after my high school exams.

Take your time.
It's good to find (much!) younger adepts to the cult. Big Grin

My best wishes for the upcoming exams.

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
06-13-2014, 09:08 PM
Post: #11
RE: (35s ALG) Ruffini Polynomial Division
Thank you very much,
I really like HP Graphing calculators and I hope to buy one as soon I can. I've seen the Prime, do you think it worths the price? I'm fascinated by the 50g too so I can't make a choice. Should I make a separated topic on it or can you give me some advice?
Thanks
Find all posts by this user
Quote this message in a reply
06-13-2014, 09:39 PM
Post: #12
RE: (35s ALG) Ruffini Polynomial Division
(06-13-2014 09:08 PM)d.nicotra Wrote:  Thank you very much,
I really like HP Graphing calculators and I hope to buy one as soon I can. I've seen the Prime, do you think it worths the price? I'm fascinated by the 50g too so I can't make a choice. Should I make a separated topic on it or can you give me some advice?
Thanks

I am a fan of an older school.
The Prime didn't catch my attention (and I bless that now has its own subforum) but I think I will buy one once it matures. It will be placed alongside all its forefathers in my collection.
The 50g is a really nice machine, well worth its price (well, maybe not here in Italy...).
You will find both ALG and RPL on it, Prime is a different beast with its own, new, programming language HPPPL.

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
06-14-2014, 07:54 AM
Post: #13
RE: (35s ALG) Ruffini Polynomial Division
Sic stantibus rebus, I think I'll wait for the Prime to mature. I would like to see how far it can go with its new hardware(performance, touch, connectivity) and software(programming language, system, application management). In the meantime I'll try to get a 50g for a special deal. My personal idea is that an HP Prime in 2013 could be muuuuuch more than just a competitor of ti nspire cas, especially seeing what Wolfram has done with its Alpha Project. We have, today, raw materials to make the Final Math Device that can only become better in performace of algorithm.
Find all posts by this user
Quote this message in a reply
06-14-2014, 09:23 AM
Post: #14
RE: (35s ALG) Ruffini Polynomial Division
(06-14-2014 07:54 AM)d.nicotra Wrote:  Sic stantibus rebus, I think I'll wait for the Prime to mature. I would like to see how far it can go with its new hardware(performance, touch, connectivity) and software(programming language, system, application management). In the meantime I'll try to get a 50g for a special deal. My personal idea is that an HP Prime in 2013 could be muuuuuch more than just a competitor of ti nspire cas, especially seeing what Wolfram has done with its Alpha Project. We have, today, raw materials to make the Final Math Device that can only become better in performace of algorithm.

Good, but that's just my own point of view; ask somebody else and you'll have different answers. There's a lot of Prime aficionados... just a section away. ;)

I concur that it's an interesting machine and, probably, its main sins of youth were already solved.

Greetings,
    Massimo

-+×÷ ↔ left is right and right is wrong
Visit this user's website Find all posts by this user
Quote this message in a reply
06-14-2014, 10:05 AM
Post: #15
RE: (35s ALG) Ruffini Polynomial Division
Thank you!
Have a nice posting!
Find all posts by this user
Quote this message in a reply
06-12-2022, 08:31 PM
Post: #16
RE: (35S ALG) Ruffini Polynomial Division
We can use the following RPN program, here for the HP-42S but similar in case of other models:
Code:
00 { 4-Byte Prgm }
01 X<>Y
02 R↑
03 ×
04 +
05 END

Example

\(
(2x^4 -5x^2 -2x -1) \div (x-2)
\)

First fill the stack with \(c = 2\):

2
ENTER
ENTER

Initialize the coefficient of the resulting polynomial with \(0\):

0
ENTER

Then enter the coefficients of the polynomial to divide one by one:

2 R/S
2

0 R/S
4

-5 R/S
3

-2 R/S
4

-1 R/S
7

Thus we get \(2x^3+4x^2+3x+4\) and the remainder \(R=7\).



This works only in the case \(h = 1\).
But this is not really a problem since both polynomials can be reduced by \(h\) otherwise.
Find all posts by this user
Quote this message in a reply
06-13-2022, 01:05 PM (This post was last modified: 06-13-2022 03:09 PM by Albert Chan.)
Post: #17
RE: (35S ALG) Ruffini Polynomial Division
(06-12-2022 08:31 PM)Thomas Klemm Wrote:  \(
(2x^4 -5x^2 -2x -1) \div (x-2)
\)
...
Thus we get \(2x^3+4x^2+3x+4\) and the remainder \(R=7\).

We can use multiply key, instead of a program.
Horner's rule to get f(x=2), intermediates are quotient coefs.

Code:
2 [Enter] [Enter] [Enter] 
2            // 2 
[×] 0 [+]    // 4
[×] 5 [-]    // 3
[×] 2 [-]    // 4
[×] 1 [-]    // 7 = f(2)

Comment: if we don't expect coefs to be huge, we can use other base, instead of x:
Example, let base x = 1000

lua> (2e12 - 5002001) / (1000-2)
2004003004.007014

Remainder = .007014 * (1000-2) = 7 (round to integer)
Quotient = 2*x^3 + 4*x^2 + 3*x + 4
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)