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
 Gerson W. Barbosa Senior Member Posts: 1,199 Joined: Dec 2013
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.
06-04-2014, 05:32 AM
Post: #2
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
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
06-04-2014, 05:59 AM (This post was last modified: 06-04-2014 06:25 AM by Gerson W. Barbosa.)
Post: #3
 Gerson W. Barbosa Senior Member Posts: 1,199 Joined: Dec 2013
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.
06-04-2014, 07:11 AM (This post was last modified: 06-04-2014 07:12 AM by Thomas Klemm.)
Post: #4
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
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
06-04-2014, 07:33 AM
Post: #5
 Paul Dale Senior Member Posts: 1,491 Joined: Dec 2013
RE: Even faster quadratic formula for the HP-41C
The same program for a 34S is very very tiny

- Pauli
06-04-2014, 08:52 AM
Post: #6
 walter b On Vacation Posts: 1,957 Joined: Dec 2013
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

You can say that

d:-)
06-04-2014, 10:14 AM
Post: #7
 Ángel Martin Senior Member Posts: 1,033 Joined: Dec 2013
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

Not tinier than "QROOT" in the SandMath ;-)
06-04-2014, 10:22 AM
Post: #8
 Paul Dale Senior Member Posts: 1,491 Joined: Dec 2013
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

- Pauli
06-04-2014, 01:07 PM
Post: #9
 rprosperi Senior Member Posts: 3,576 Joined: Dec 2013
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
06-08-2014, 02:55 AM
Post: #10
 Gerson W. Barbosa Senior Member Posts: 1,199 Joined: Dec 2013
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

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.
06-08-2014, 03:00 AM
Post: #11
 Gerson W. Barbosa Senior Member Posts: 1,199 Joined: Dec 2013
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

You can say that

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.
06-08-2014, 03:41 AM (This post was last modified: 06-08-2014 03:41 AM by Gerson W. Barbosa.)
Post: #12
 Gerson W. Barbosa Senior Member Posts: 1,199 Joined: Dec 2013
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.
06-08-2014, 09:26 AM (This post was last modified: 06-08-2014 09:38 AM by Ángel Martin.)
Post: #13
 Ángel Martin Senior Member Posts: 1,033 Joined: Dec 2013
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 ;-)
06-08-2014, 06:25 PM
Post: #14
 Gerson W. Barbosa Senior Member Posts: 1,199 Joined: Dec 2013
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.
06-09-2014, 02:24 PM (This post was last modified: 06-09-2014 02:25 PM by Ángel Martin.)
Post: #15
 Ángel Martin Senior Member Posts: 1,033 Joined: Dec 2013
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!
 « Next Oldest | Next Newest »

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