Post Reply 
Programming with HP50g
08-29-2015, 09:33 AM
Post: #21
RE: Programming with HP50g
I would like programm different loops (while, if, case, for,...). For these loops I would like to have different little examples/programs. In some cases you can replace one loop ( e.g. while) by (e.g. if) others or vise versa.

Could I find some examples for loop in
http://www.hpcalc.org/details.php?id=1771
where on this page and how?

If there problems in understanding my request let me know please. I do not know how to explain my problem in a better way.
Find all posts by this user
Quote this message in a reply
08-29-2015, 03:56 PM
Post: #22
RE: Programming with HP50g
(08-29-2015 09:33 AM)tigger Wrote:  I would like programm different loops (while, if, case, for,...). For these loops I would like to have different little examples/programs. In some cases you can replace one loop ( e.g. while) by (e.g. if) others or vise versa.

Could I find some examples for loop in
http://www.hpcalc.org/details.php?id=1771
where on this page and how?

If there problems in understanding my request let me know please. I do not know how to explain my problem in a better way.

Section 5, starting on page 18 with examples and exercises.


Visit this user's website Find all posts by this user
Quote this message in a reply
08-29-2015, 05:31 PM
Post: #23
RE: Programming with HP50g
(08-10-2015 07:23 AM)Tugdual Wrote:  It's working now.
For many days I see the web being quite chaotic.
Vacation and low maintenance? Heat wave? Storms?
Quoting myself... It is no longer working.
Forbidden again.
Find all posts by this user
Quote this message in a reply
08-29-2015, 08:11 PM (This post was last modified: 08-29-2015 08:49 PM by Allen.)
Post: #24
RE: Programming with HP50g
(08-07-2015 03:19 PM)rprosperi Wrote:  
(08-07-2015 10:05 AM)Gerald H Wrote:  Try this:

http://www.hpcalc.org/hp48/docs/programm...inmarv.zip

Excellent recommendation Gerald, you beat me to it!

There is no better single source of small programs, tips and techniques to learn (and quickly become impressed with the power of) RPL.

EVERY RPL user should review these great "marvels" from time to time.

I love this document! Thank you to the authors: Joe, Richard and Wlodek!!

The bottom of the last page challenges the users to submit a program to calculate \(A^3B-AB^3 \) in 27.5 bytes (7 steps). There are provided three checksums to indicate three possible 27.5 byte approaches.

For the interested reader, #D45Bh and #7FE7h (both on 48g) are checksums for two similar 25 byte solutions with only 6 steps each. (not sure if it's faster than the 27.5 byte solutions, but will at least tie one of them, I think).

A more complex approach (still 25 bytes and 6 steps) #13CAh based on:

\begin{equation} \operatorname{Im} \left( \frac{(A+iB)^4}{4}\right) =A^3B-AB^3 \end{equation}

(colorful proof)

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
08-30-2015, 05:10 AM
Post: #25
RE: Programming with HP50g
Well done, Allen, that's the neatest solution I've seen.
Find all posts by this user
Quote this message in a reply
08-30-2015, 07:24 AM
Post: #26
RE: Programming with HP50g
(08-29-2015 08:11 PM)Allen Wrote:  For the interested reader, #D45Bh and #7FE7h (both on 48g) are checksums for two similar 25 byte solutions with only 6 steps each. (not sure if it's faster than the 27.5 byte solutions, but will at least tie one of them, I think).

A more complex approach (still 25 bytes and 6 steps) #13CAh based on:

\begin{equation} \operatorname{Im} \left( \frac{(A+iB)^4}{4}\right) =A^3B-AB^3 \end{equation}

(colorful proof)

These make for nice HP-42S solutions:

Code:

00 { 11-Byte Prgm }
01 LBL A
02 COMPLEX
03 X^2
04 COMPLEX
05 *
06 2
07 /
08 END

Code:

00 { 12-Byte Prgm }
01 LBL B
02 COMPLEX
03 4
04 Y^X
05 RCL/ ST L
06 COMPLEX
07 END
Find all posts by this user
Quote this message in a reply
08-30-2015, 02:02 PM (This post was last modified: 08-30-2015 02:04 PM by Allen.)
Post: #27
RE: Programming with HP50g
(08-30-2015 07:24 AM)Gerson W. Barbosa Wrote:  These make for nice HP-42S solutions:
Program LBL A
Program LBL B

Gerson, yes, nicely written! Your program LBL A is exactly the approach used by the "less complex" approach on the 48g. I was looking for a way to calculate \(A^3B-AB^3 = AB(A^2-B^2) \) and thought.. wouldn't it be nice if we could make \(B\) imaginary before squaring to save a subtraction. Happily, both \(A^2-B^2 \) and \(AB\) appear in the real and imaginary part of \( z^2=(A+iB)^2 = A^2-B^2 +i2AB \), however it is necessary to halve the product just as you did in Program LBL A:
\begin{equation} \frac{\operatorname{Im}(z^2) \operatorname{Re}(z^2)}{2} =A^3B-AB^3 \end{equation}
I had explored a way to use the matrix determinant to calculate
\begin{equation} \operatorname{det} \begin{bmatrix}
A^2 & B^2 \\
AB & AB
\end{bmatrix} = A^3B-AB^3
\end{equation}

But, alas, the "stack stuff" needed to get A^2, B^2 and AB onto the stack was going to exceed 1 command.

Code:

<<"stack stuff"  DUP 2 IDN SIZE ->ARR DET>>

I also found if one expands \(z^n\) in the manner of this solution, it creates a multi-dimensional, multi-variate complex pascal's triangle. The solutions here only deal with a few elements:

[Image: pascalstriangle.jpg]

Image from: "Pascal's triangle 5" by User:Conrad.Irwin originally User:Drini - Extracted from Image:PascalSimetria.svg with minor alterations. Licensed under CC BY-SA 3.0 via Commons - https://commons.wikimedia.org/wiki/File:...ngle_5.svg

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
08-30-2015, 03:43 PM (This post was last modified: 08-30-2015 06:27 PM by Gerson W. Barbosa.)
Post: #28
RE: Programming with HP50g
(08-30-2015 02:02 PM)Allen Wrote:  
(08-30-2015 07:24 AM)Gerson W. Barbosa Wrote:  These make for nice HP-42S solutions:
Program LBL A
Program LBL B

Gerson, yes, nicely written! Your program LBL A is exactly the approach used by the "less complex" approach on the 48g.

To Allen what belongs to Allen! The credits are all yours. After posting I realized I had done a small linguistic error. I should have written "Those make for nice HP-42S solutions" as I meant to refer to your original HP-48G solutions, mine being mere ports to the HP-42S.
When you presented the more complex solution, I tried to figure out what your less complex one might be. Then the one I found on the HP 50g was 25-byte long but the check-sum was # BEA0h, so I reached for my HP-48GX and verified the checksum was indeed #D45Bh on it. Multiplying by .5 instead of dividing by 2 gave a different checksum than #7FE7h, which means I've found only one of your other solutions. I'd like to know what are the other 7-command 27.5-byte solutions. The pdf gives the initials of the authors and timings only.

Regards,

Gerson.

P.S.: Here's an 11-byte 5-step HP-42S solution:

Code:

00 { 11-Byte Prgm }
01>LBL C
02 CLΣ
03 Σ+
04 RCL 14
05 RCL- 12
06 RCL× 15
07 .END.
Find all posts by this user
Quote this message in a reply
08-31-2015, 12:57 AM (This post was last modified: 08-31-2015 01:14 AM by Allen.)
Post: #29
RE: Programming with HP50g
(08-30-2015 03:43 PM)Gerson W. Barbosa Wrote:  P.S.: Here's an 11-byte 5-step HP-42S solution:

Code:

00 { 11-Byte Prgm }
01>LBL C
02 CLΣ
03 Σ+
04 RCL 14
05 RCL- 12
06 RCL× 15
07 .END.

This is a beautiful HP42S implementation,Thank you! I enjoy when a unique perspective and serendipity provide a way to program things smaller because of math tricks- I do not need special credit for that.

You asked about checksums? There are several variations on the programs checksums possible based on how the stack is collapsed at the end with the IM, 4 / or 2 / steps ( or multiply by 0.5):

\begin{equation} \frac{\operatorname{Im}(z^2) \operatorname{Re}(z^2)}{2} = \operatorname{Im}(z^2) \frac{\operatorname{Re}(z^2)}{2}= \frac{\operatorname{Im}(z^4)}{4} = \operatorname{Im}\left(\frac{z^4}{4}\right) = A^3B-AB^3 \end{equation}

I know how the authors arrived at some of the 7-step solutions- mostly through the use of LASTARG and a different factorization of the original polynomial:
hints:
#79C6h- "asp" (from rjn)
#72B5h- "psa" (from jkh)
#E090h- "pas"
#E8BAh- "sap"

17bii | 32s | 32sii | 41c | 41cv | 41cx | 42s | 48g | 48g+ | 48gx | 50g | 30b

Find all posts by this user
Quote this message in a reply
08-31-2015, 01:13 AM
Post: #30
RE: Programming with HP50g
(08-29-2015 08:11 PM)Allen Wrote:  For the interested reader, #D45Bh and #7FE7h (both on 48g) are checksums for two similar 25 byte solutions with only 6 steps each. (not sure if it's faster than the 27.5 byte solutions, but will at least tie one of them, I think).

Apparently the original timings were obtained on an HP 49G in exact mode. If such is the case then your first "less complex" solution is faster than all other four.

Original unoptimized program:

<< DUP 3 ^ ROT DUP 3 ^ ROT ROT * ROT ROT * SWAP - >>
122 ms

Your solution:

<< R->C SQ C->R * 2 / >>
90.8 ms

Another 7-command 27.5 byte solution:

<< DUP2 + LASTARG - * * * >
49.7 ms

Significantly faster, but longer. Also, it requires LASTARG (flag -55) to be enabled, which might be a great disadvantage.

Gerson.
Find all posts by this user
Quote this message in a reply
08-31-2015, 01:42 AM (This post was last modified: 08-31-2015 01:45 AM by Gerson W. Barbosa.)
Post: #31
RE: Programming with HP50g
(08-31-2015 12:57 AM)Allen Wrote:  I know how the authors arrived at some of the 7-step solutions- mostly through the use of LASTARG and a different factorization of the original polynomial:
hints:
#79C6h- "asp" (from rjn)
#72B5h- "psa" (from jkh)
#E090h- "pas"
#E8BAh- "sap"

Aha! #E090h- "pas" ( #C173h on the HP 49G) matches my previous version using LASTARG:

<< * LASTARG + LASTARG - * * >>
50.7 ms

One problem with LASTARG is that the Last Stack might be disabled sometimes, either intentionally or not. Disabling the Last Stack made sense on the HP-28C, which had only 2 KB RAM, but not on the latest RPL calculators, I think.

Gerson.
Find all posts by this user
Quote this message in a reply
08-31-2015, 09:26 AM
Post: #32
RE: Programming with HP50g
For opening this the Computer expects a keyword of the Administrator.


good program for developing User RPL programs on a PC:
http://www.hpcalc.org/details.php?id=6600

Best regards
[/quote]
Find all posts by this user
Quote this message in a reply
Post Reply 




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