Post Reply 
Even faster quadratic formula for the HP-41C
06-04-2014, 04:25 AM (This post was last modified: 06-04-2014 04:52 AM by Gerson W. Barbosa.)
Post: #1
Even faster quadratic formula for the HP-41C
This is yet another attempt at finding a shorter (but not necessary faster) quadratic formula program for the HP-41C, while preserving the stack register T (Thanks to Jeff Kearns - if it were not because of his interest, I wouldn't have taken a second look at this old thread)

Code:
01 LBL 'Q
02 X<> Z 
03 CHS
04 ST/ Z
05 ST+ X
06 /
07 STO Z
08 X^2
09 +
10 SQRT
11 RCL Y
12 ST+ Z
13 +
14 ST- Y
15 END

x₂ is computed using this well-known property:

\[x_{1}+x_{2}=-\frac{b}{a}\]

Real roots only, but since the stack register T is preserved it will solve the first example for the HP-42S program here.

I'd rather present it here first, before submitting it to the HP-41C Software Library, as any issue I might have overlooked would surely be pointed out soon. Thanks!

Gerson.

PS.: The title should read ...faster quadratic formula program... - as the formula is essentially the same, but I cannot edit it.
Find all posts by this user
Quote this message in a reply
06-04-2014, 05:32 AM
Post: #2
RE: Even faster quadratic formula program for the HP-41C
Code:
00 { 22 Byte-Prgm }
01 LBL "Q"
02 X<> ST Z 
03 STO/ ST Z
04 STO+ ST X
05 /
06 ENTER
07 X^2
08 RCL- ST Z
09 SQRT
10 -
11 +/-
12 STO/ ST Y
13 END

x₂ is computed using this well-known property:

\[x_{1}\cdot x_{2}=\frac{c}{a}\]

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
06-04-2014, 05:59 AM (This post was last modified: 06-04-2014 06:25 AM by Gerson W. Barbosa.)
Post: #3
RE: Even faster quadratic formula for the HP-41C
(06-04-2014 05:32 AM)Thomas Klemm Wrote:  
Code:
00 { 22 Byte-Prgm }
01 LBL "Q"
02 X<> ST Z 
03 STO/ ST Z
04 STO+ ST X
05 /
06 ENTER
07 X^2
08 RCL- ST Z
09 SQRT
10 -
11 +/-
12 STO/ ST Y
13 END

x₂ is computed using this well-known property:

\[x_{1}\cdot x_{2}=\frac{c}{a}\]

Cheers
Thomas

Thomas,

I fear there might be trouble when c = 0. Also, the HP-41 lacks recall arithmetic.
Anyway, records exist to be broken. I won't be surprised if you or someone else comes up with a shorter (or a lower byte-count) HP-41 or 42S program.

Cheers,

Gerson.

P.S.: On the HP-42S, replace line 10 with

10 +

P.P.S.: This won't solve the case when both b and c are zero, however.
Find all posts by this user
Quote this message in a reply
06-04-2014, 07:11 AM (This post was last modified: 06-04-2014 07:12 AM by Thomas Klemm.)
Post: #4
RE: Even faster quadratic formula program for the HP-41C
(06-04-2014 05:59 AM)Gerson W. Barbosa Wrote:  I fear there might be trouble with c = 0.
I know. But then who is going to use this program to solve \(ax^2+bx=0\)?

Quote:Also, the HP-41 lacks recall arithmetic.
I tend to forget this.

Quote:P.S.: On the HP-42S, replace line 10 with
10 +
This won't solve the case when both b and c are zero, however.
Should this solve the problem with the division by zero?
In case of \(c=0\) this depends on the sign of \(b\).
So it doesn't really matter whether we use + or -.
I prefer to have \(x_1\) in register X.

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
06-04-2014, 07:33 AM
Post: #5
RE: Even faster quadratic formula for the HP-41C
The same program for a 34S is very very tiny Smile

- Pauli
Find all posts by this user
Quote this message in a reply
06-04-2014, 08:52 AM
Post: #6
RE: Even faster quadratic formula for the HP-41C
(06-04-2014 07:33 AM)Paul Dale Wrote:  The same program for a 34S is very very tiny Smile

You can say that Smile

d:-)
Find all posts by this user
Quote this message in a reply
06-04-2014, 10:14 AM
Post: #7
RE: Even faster quadratic formula for the HP-41C
(06-04-2014 07:33 AM)Paul Dale Wrote:  The same program for a 34S is very very tiny Smile

Not tinier than "QROOT" in the SandMath ;-)

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
06-04-2014, 10:22 AM
Post: #8
RE: Even faster quadratic formula for the HP-41C
(06-04-2014 10:14 AM)Ángel Martin Wrote:  Not tinier than "QROOT" in the SandMath ;-)

Same number of steps Smile


- Pauli
Find all posts by this user
Quote this message in a reply
06-04-2014, 01:07 PM
Post: #9
RE: Even faster quadratic formula for the HP-41C
(06-04-2014 07:11 AM)Thomas Klemm Wrote:  
(06-04-2014 05:59 AM)Gerson W. Barbosa Wrote:  Also, the HP-41 lacks recall arithmetic.
I tend to forget this.

I re-learn this every time I come back to using my 41. Which I suppose means I never really learn it all...

Very nice Gerson. Short AND sweet.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
06-08-2014, 02:55 AM
Post: #10
RE: Even faster quadratic formula for the HP-41C
(06-04-2014 07:33 AM)Paul Dale Wrote:  The same program for a 34S is very very tiny Smile

It won't solve this one, however, unlike the HP-42S programs (mine and Thomas's). But what would CSLVQ (SSIZE8 mode only) be useful for anyway?

Gerson.
Find all posts by this user
Quote this message in a reply
06-08-2014, 03:00 AM
Post: #11
RE: Even faster quadratic formula for the HP-41C
(06-04-2014 08:52 AM)walter b Wrote:  
(06-04-2014 07:33 AM)Paul Dale Wrote:  The same program for a 34S is very very tiny Smile

You can say that Smile

d:-)

In another post, about two years ago, I said "nothing beats SLVQ on the WP 34S, however". Definite a killjoy, but very useful :-) (I remember having used SLVQ in a program once).

Gerson.
Find all posts by this user
Quote this message in a reply
06-08-2014, 03:41 AM (This post was last modified: 06-08-2014 03:41 AM by Gerson W. Barbosa.)
Post: #12
RE: Even faster quadratic formula for the HP-41C
(06-04-2014 01:07 PM)rprosperi Wrote:  Very nice Gerson. Short AND sweet.

Thanks, Bob!

For the sake of documentation I should have mentioned that I have used the quadratic formula in this form, valid when a = -1:

\[x_{1}= \frac{b}{2}+\sqrt{\left ( \frac{b}{2} \right )^{2}+c}\]

Please see Allen's post in this thread from 2007.

Regards,

Gerson.
Find all posts by this user
Quote this message in a reply
06-08-2014, 09:26 AM (This post was last modified: 06-08-2014 09:38 AM by Ángel Martin.)
Post: #13
RE: Even faster quadratic formula for the HP-41C
(06-08-2014 02:55 AM)Gerson W. Barbosa Wrote:  It won't solve this one, however, unlike the HP-42S programs (mine and Thomas's). But what would CSLVQ (SSIZE8 mode only) be useful for anyway?

ZQRT in the 41Z module does too ;-)

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
06-08-2014, 06:25 PM
Post: #14
RE: Even faster quadratic formula for the HP-41C
(06-08-2014 09:26 AM)Ángel Martin Wrote:  
(06-08-2014 02:55 AM)Gerson W. Barbosa Wrote:  It won't solve this one, however, unlike the HP-42S programs (mine and Thomas's). But what would CSLVQ (SSIZE8 mode only) be useful for anyway?

ZQRT in the 41Z module does too ;-)

...with no native complex number support, you might have said! Sorry for my ignorance!

Gerson.
Find all posts by this user
Quote this message in a reply
06-09-2014, 02:24 PM (This post was last modified: 06-09-2014 02:25 PM by Ángel Martin.)
Post: #15
RE: Even faster quadratic formula for the HP-41C
Yes, quadratic and cubic equations with complex coefficients and obviously results. Interestingly, I took the opportunity to review the code in the 41Z - finding a typo (a.k.a. bug) on the Spherical Hankel functions (not in the Bessel functions, those were ok). It appears that, like rust, bugs never sleep!

"To live or die by your own sword one must first learn to wield it aptly."
Find all posts by this user
Quote this message in a reply
Post Reply 




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