Programming Exercise (HP-15C, 15C LE - and others)
03-26-2014, 07:01 PM (This post was last modified: 03-26-2014 07:02 PM by Gerson W. Barbosa.)
Post: #41
 Gerson W. Barbosa Senior Member Posts: 1,452 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-26-2014 06:20 PM)churichuro Wrote:  version for HP PRIME:

Code:
 EXPORT TEST2() BEGIN   LOCAL suma,n;   suma:= 0;   FOR n FROM 10000 DOWNTO 1 DO     suma:= suma + (1/n)*(-1)^(n+1);   END;   MSGBOX("Suma="+suma); END;

result in about 1 sec !
Suma=.693097183059

Isn't "FOR n FROM 10000 DOWNTO 2 STEP -2 DO" a valid syntax in your UBASIC? If so, then the following would be worth trying. ¡Gracias!

Code:
 1 T=TIME @ S=0 @ FOR N=10000 TO 2 STEP -2 @ S=S+1/(N-1)-1/N @ NEXT N @ DISP S;TIME-T
.69309718306 247.27

4 minutes and 7 seconds! (HP-71B)
03-28-2014, 03:18 AM
Post: #42
 bkn42 Junior Member Posts: 19 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
I implemented the two term version of this on my "HP55".
Here is the code (sorry its not in location/keycode form but you get the idea):
Code:
   1 -   STO 0   0   STO 1 08:  X<>Y   ENTER   ENTER   *   +   1/x   STO + 1   2   STO - 0   RCL 0   0   X<=Y 0 8   RCL 1   GTO 0 0
R0 holds the current iteration and R1 is the series sum.

For N=100, it took about 82sec to finish. Based on this it would take about 2.25hours for N=10000.

Notice that I used double quotes around "HP55", that's because I don't own a real HP55 calculator (I only own a HP32SII, HP48SX, HP48GX, and HP50G). What to do if you don't own a classic HP? Use an emulator? -- Boring!! You build your own classic HP calculator, of course. For a learning experience (and for fun), I implemented a classic HP "core" in a Xilinx FPGA (designed in VHDL). I build this from scratch based on info I gleamed from the web (including the HP Museum). It can run ROMs for a HP35, HP45 and HP55.

My "HP55" runs at two speeds:
1. real mode -- matches the original HP55's 3500 instructions per second. The HP55 timer runs accurately in this mode.
2. turbo mode -- no throttling of instruction execution rate.

In turbo mode, with N=10000, my "HP55" completes this task in just under 5 seconds! I think, even if its not the fastest time posted, that's a record for classic HP hardware.

Brian

(If anyone wants more info on the FPGA Classic HP Core I designed, let me know and I'll try to write something up for a thread in the "Not quite HP Calculators - but related" forum.)
03-28-2014, 08:28 AM
Post: #43
 Didier Lachieze Senior Member Posts: 1,427 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-28-2014 03:18 AM)bkn42 Wrote:  (If anyone wants more info on the FPGA Classic HP Core I designed, let me know and I'll try to write something up for a thread in the "Not quite HP Calculators - but related" forum.)
Please do. I, for one, am very interested in this HW emulator.
03-28-2014, 03:48 PM (This post was last modified: 03-28-2014 03:50 PM by Gerson W. Barbosa.)
Post: #44
 Gerson W. Barbosa Senior Member Posts: 1,452 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-28-2014 03:18 AM)bkn42 Wrote:  For N=100, it took about 82sec to finish. Based on this it would take about 2.25hours for N=10000.

I would ask you about the result. Never mind, here it is:

Very accurate result in 2 h 16 m 53s. Not bad for a calculator in 1975!

I don't have an HP-55 either, but it should take exactly the same on a physical one. I've used Eric Smith's Nonpareil High-Fidellity Calculator Simulator (I don't have a working link right now, sorry!).

(03-28-2014 03:18 AM)bkn42 Wrote:  What to do if you don't own a classic HP? Use an emulator? -- Boring!! You build your own classic HP calculator, of course.

Quite impressive! Congratulations!

(03-28-2014 03:18 AM)bkn42 Wrote:  (If anyone wants more info on the FPGA Classic HP Core I designed, let me know and I'll try to write something up for a thread in the "Not quite HP Calculators - but related" forum.)

Best regards,

Gerson.
03-28-2014, 04:48 PM
Post: #45
 Thomas Klemm Senior Member Posts: 1,534 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-28-2014 03:48 PM)Gerson W. Barbosa Wrote:  Please do!
1+
03-28-2014, 07:17 PM
Post: #46
 Marcel Samek Member Posts: 53 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-28-2014 03:18 AM)bkn42 Wrote:  I implemented the two term version of this on my "HP55".
Here is the code (sorry its not in location/keycode form but you get the idea):

I used this code on the HP-67.

100: 47.4 seconds (.688172179)
10000: 1 hour 19 minutes 21.9 seconds (.693097183)
03-28-2014, 10:42 PM
Post: #47
 bkn42 Junior Member Posts: 19 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
Sorry, I forgot to mention the result from the turbo mode of my FPGA based HP55. The result was: 0.693097183

It seems people are interested in my FPGA design. So, I'll start a thread in the other forum describing its details. It might be a few days before I get something written.

Brian
03-29-2014, 12:36 AM
Post: #48
 Tugdual Senior Member Posts: 756 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
Nobody mentioned that entering $$\sum _{ K=1 }^{ 10000 }{ \frac { { (-1 })^{ K+1 } }{ K } }$$ on the Prime with no need for any sort of coding would instantly return 0.693097183025
Is that off scope consideration for this thread?
I know that the prime is blazing fast but the speed is so impressive that I wonder if the calculator is actually performing a loop?
03-29-2014, 02:21 AM (This post was last modified: 03-29-2014 02:46 AM by Gerson W. Barbosa.)
Post: #49
 Gerson W. Barbosa Senior Member Posts: 1,452 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 12:36 AM)Tugdual Wrote:  Nobody mentioned that entering $$\sum _{ K=1 }^{ 10000 }{ \frac { { (-1 })^{ K+1 } }{ K } }$$ on the Prime with no need for any sort of coding would instantly return 0.693097183025
Is that off scope consideration for this thread?
I know that the prime is blazing fast but the speed is so impressive that I wonder if the calculator is actually performing a loop?

It does do the summation, term by term (unless acceleration techniques I am not aware of are being used - anyway 10000 terms are too few, given the Prime clock speed) . Too bad the last two digits are wrong, though. This is the CAS, I presume, but the Prime has a more exact mode, I think.

This approximation is exact to 20 digits. The HP-71B evaluates it in 0.17 seconds:

Code:
 1 T=TIME @ N=10000 @ K=2*N+1 @ S=LOG(2)-1/(K+1/K) @ DISP S;TIME-T

.69309718306 .17

For the HP-71B, that's instantly :-)

Gerson.
03-29-2014, 12:02 PM
Post: #50
 Thomas Klemm Senior Member Posts: 1,534 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 12:36 AM)Tugdual Wrote:  Nobody mentioned that entering $$\sum _{ K=1 }^{ 10000 }{ \frac { { (-1 })^{ K+1 } }{ K } }$$ on the Prime with no need for any sort of coding would instantly return 0.693097183025
Is that off scope consideration for this thread?
I know that the prime is blazing fast but the speed is so impressive that I wonder if the calculator is actually performing a loop?
That's the solution to:
Quote:(a) addition of terms from left to right
Quote:(b) addition of terms from right to left
Compare the results and explain the difference.
Can you do even better?

Cheers
Thomas
03-29-2014, 12:32 PM
Post: #51
 Tugdual Senior Member Posts: 756 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 12:02 PM)Thomas Klemm Wrote:
(03-29-2014 12:36 AM)Tugdual Wrote:  Nobody mentioned that entering $$\sum _{ K=1 }^{ 10000 }{ \frac { { (-1 })^{ K+1 } }{ K } }$$ on the Prime with no need for any sort of coding would instantly return 0.693097183025
Is that off scope consideration for this thread?
I know that the prime is blazing fast but the speed is so impressive that I wonder if the calculator is actually performing a loop?
That's the solution to:
Quote:(a) addition of terms from left to right
Quote:(b) addition of terms from right to left
Compare the results and explain the difference.
Can you do even better?

Cheers
Thomas
For (b) I did:
$$\sum _{ K=10000 }^{ 1 }{ \frac { { (-1 })^{ K+1 } }{ K } }$$

I can't explain the difference because the result is the same
03-29-2014, 12:36 PM (This post was last modified: 03-29-2014 12:38 PM by Tugdual.)
Post: #52
 Tugdual Senior Member Posts: 756 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 02:21 AM)Gerson W. Barbosa Wrote:  It does do the summation, term by term (unless acceleration techniques I am not aware of are being used - anyway 10000 terms are too few, given the Prime clock speed) . Too bad the last two digits are wrong, though. This is the CAS, I presume, but the Prime has a more exact mode, I think.
This was in Home mode (the clue is the upper case variable name, Home accepts only upper case, CAS is on lower case).
BTW when I enter this (with lower case 'k') into CAS I get the message "Error: Invalid dimension". Oh well, that is just the Prime being prime-itive...
03-29-2014, 01:29 PM
Post: #53
 Gerson W. Barbosa Senior Member Posts: 1,452 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 12:02 PM)Thomas Klemm Wrote:
(03-29-2014 12:36 AM)Tugdual Wrote:  Nobody mentioned that entering $$\sum _{ K=1 }^{ 10000 }{ \frac { { (-1 })^{ K+1 } }{ K } }$$ on the Prime with no need for any sort of coding would instantly return 0.693097183025
Is that off scope consideration for this thread?
I know that the prime is blazing fast but the speed is so impressive that I wonder if the calculator is actually performing a loop?
That's the solution to:
Quote:(a) addition of terms from left to right
Quote:(b) addition of terms from right to left

You're right! I overlooked that when I suggested the Prime CAS was inexact for this one. It turns out I was inexact. Sorry!

The HP 50g gives the same result for item (a):

'∑(n=1,10000,(-1)^(n+1)/n)' EVAL --> 0.693097183025

For item (b), the Prime should give the same result we get on the HP 50g:

'∑(n=1,10000,(-1)^n/(10001-n))' EVAL --> 0.693097183059

However this takes too long on the HP 50g: 1 minute 50 seconds.

Cheers,

Gerson.
03-29-2014, 05:19 PM
Post: #54
 Thomas Klemm Senior Member Posts: 1,534 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 12:32 PM)Tugdual Wrote:  For (b) I did:
$$\sum _{ K=10000 }^{ 1 }{ \frac { { (-1 })^{ K+1 } }{ K } }$$

I can't explain the difference because the result is the same
That's interesting! Thus the order doesn't seem to be changed.
Could you try the following (similar to Gerson's 2nd example on the HP-50g):
$$\sum_{K=1}^{10000}{\frac{{(-1})^{K}}{10001-K}}$$

Thanks
Thomas

PS: When I tried this on the emulator I got:
Error: Invalid input
IIRC this was an issue with the original firmware which was fixed meanwhile.
I didn't bother to upgrade. Is a new version of the emulator available?
03-29-2014, 05:41 PM
Post: #55
 Steve Simpkin Senior Member Posts: 690 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 12:36 AM)Tugdual Wrote:  Nobody mentioned that entering $$\sum _{ K=1 }^{ 10000 }{ \frac { { (-1 })^{ K+1 } }{ K } }$$ on the Prime with no need for any sort of coding would instantly return 0.693097183025
Is that off scope consideration for this thread?
I know that the prime is blazing fast but the speed is so impressive that I wonder if the calculator is actually performing a loop?

For reference:
The TI-36X Pro arrived at the answer of 0.693097183 in 5:45 minutes.
The Casio fx-115ES Plus took just over 11 minutes to arrived at the answer of 0.6930971831.
It's a good thing these models are solar powered
03-29-2014, 05:59 PM
Post: #56
 Tugdual Senior Member Posts: 756 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 05:19 PM)Thomas Klemm Wrote:  That's interesting! Thus the order doesn't seem to be changed.
Could you try the following (similar to Gerson's 2nd example on the HP-50g):
$$\sum_{K=1}^{10000}{\frac{{(-1})^{K}}{10001-K}}$$
Now I do get a different result: 0.693097183059
So looks like the Prime is always reordering

(03-29-2014 05:19 PM)Thomas Klemm Wrote:  PS: When I tried this on the emulator I got:
Error: Invalid input
IIRC this was an issue with the original firmware which was fixed meanwhile.
I didn't bother to upgrade. Is a new version of the emulator available?
I do also get an error when using CAS. You sure you were on Home?
03-29-2014, 06:23 PM (This post was last modified: 03-29-2014 06:25 PM by Thomas Klemm.)
Post: #57
 Thomas Klemm Senior Member Posts: 1,534 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 05:59 PM)Tugdual Wrote:  So looks like the Prime is always reordering

Quote:You sure you were on Home?
Pretty much. I didn't use CAS at all.

Attached File(s) Thumbnail(s)

03-29-2014, 07:10 PM (This post was last modified: 03-29-2014 07:14 PM by Tugdual.)
Post: #58
 Tugdual Senior Member Posts: 756 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 06:23 PM)Thomas Klemm Wrote:
(03-29-2014 05:59 PM)Tugdual Wrote:  So looks like the Prime is always reordering

Quote:You sure you were on Home?
Pretty much. I didn't use CAS at all.

Oh and BTW the CAS version also fails in the emulator but with a different error message:
03-29-2014, 07:17 PM
Post: #59
 Thomas Klemm Senior Member Posts: 1,534 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 07:10 PM)Tugdual Wrote:  Are you sure you use the latest version?
(03-29-2014 05:19 PM)Thomas Klemm Wrote:  I didn't bother to upgrade. Is a new version of the emulator available?
03-29-2014, 08:07 PM
Post: #60
 Tugdual Senior Member Posts: 756 Joined: Dec 2013
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-29-2014 07:17 PM)Thomas Klemm Wrote:
(03-29-2014 07:10 PM)Tugdual Wrote:  Are you sure you use the latest version?
(03-29-2014 05:19 PM)Thomas Klemm Wrote:  I didn't bother to upgrade. Is a new version of the emulator available?
Hmmm kinda depend on the version you have now
 « Next Oldest | Next Newest »

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