Post Reply 
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
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)
Find all posts by this user
Quote this message in a reply
03-28-2014, 03:18 AM
Post: #42
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. Smile

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.)
Find all posts by this user
Quote this message in a reply
03-28-2014, 08:28 AM
Post: #43
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.
Find all posts by this user
Quote this message in a reply
03-28-2014, 03:48 PM (This post was last modified: 03-28-2014 03:50 PM by Gerson W. Barbosa.)
Post: #44
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:

[Image: HP-55_Ex_zpsf98ffd20.png]

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.)

Please do!

Best regards,

Gerson.
Find all posts by this user
Quote this message in a reply
03-28-2014, 04:48 PM
Post: #45
RE: Programming Exercise (HP-15C, 15C LE - and others)
(03-28-2014 03:48 PM)Gerson W. Barbosa Wrote:  Please do!
1+
Find all posts by this user
Quote this message in a reply
03-28-2014, 07:17 PM
Post: #46
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)
Find all posts by this user
Quote this message in a reply
03-28-2014, 10:42 PM
Post: #47
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
Find all posts by this user
Quote this message in a reply
03-29-2014, 12:36 AM
Post: #48
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?
Find all posts by this user
Quote this message in a reply
03-29-2014, 02:21 AM (This post was last modified: 03-29-2014 02:46 AM by Gerson W. Barbosa.)
Post: #49
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.
Find all posts by this user
Quote this message in a reply
03-29-2014, 12:02 PM
Post: #50
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
What about:
Quote:(b) addition of terms from right to left
Compare the results and explain the difference.
Can you do even better?

Cheers
Thomas
Find all posts by this user
Quote this message in a reply
03-29-2014, 12:32 PM
Post: #51
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
What about:
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 Smile
Find all posts by this user
Quote this message in a reply
03-29-2014, 12:36 PM (This post was last modified: 03-29-2014 12:38 PM by Tugdual.)
Post: #52
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...
Find all posts by this user
Quote this message in a reply
03-29-2014, 01:29 PM
Post: #53
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
What about:
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.
Find all posts by this user
Quote this message in a reply
03-29-2014, 05:19 PM
Post: #54
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 Smile
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?
Find all posts by this user
Quote this message in a reply
03-29-2014, 05:41 PM
Post: #55
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 poweredSmile
Not bad for $20 machines.
Visit this user's website Find all posts by this user
Quote this message in a reply
03-29-2014, 05:59 PM
Post: #56
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?
Find all posts by this user
Quote this message in a reply
03-29-2014, 06:23 PM (This post was last modified: 03-29-2014 06:25 PM by Thomas Klemm.)
Post: #57
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
Sad

Quote:You sure you were on Home?
Pretty much. I didn't use CAS at all.
[Image: attachment.php?aid=422]


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
03-29-2014, 07:10 PM (This post was last modified: 03-29-2014 07:14 PM by Tugdual.)
Post: #58
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
Sad

Quote:You sure you were on Home?
Pretty much. I didn't use CAS at all.
[Image: attachment.php?aid=422]
Are you sure you use the latest version?
[Image: 10pujhc.png]

Oh and BTW the CAS version also fails in the emulator but with a different error message:
[Image: flyd5d.png]
Find all posts by this user
Quote this message in a reply
03-29-2014, 07:17 PM
Post: #59
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?
Find all posts by this user
Quote this message in a reply
03-29-2014, 08:07 PM
Post: #60
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 Smile
Find all posts by this user
Quote this message in a reply
Post Reply 




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