Post Reply 
(29C) Prime numbers up to 10'000
09-03-2018, 07:05 PM (This post was last modified: 09-03-2018 09:36 PM by Thomas Klemm.)
Post: #5
RE: (29C) Prime numbers up to 10'000
(09-03-2018 05:24 PM)Dieter Wrote:  Since I am not completely sure how the program works maybe Thomas can provide some more detailed hints for an HP67/97 version.

If we have only 26 registers we can only store these 23 primes:

[5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

But since register I occupies register 25 instead of 0 the whole list is shifted.
Thus the primes start with register 2 instead of 3 and so on.
We can't reuse some of the numbers anymore when initialising the registers but that shouldn't be a problem.
Code:
01:  2
02:  STO 0     ; ∆n = 2
03:  7
04:  STO 1     ; n = 7
05:  STO 3     ; π(3) = 7
06:  5
07:  STO 2     ; π(2) = 5
08:  4
09:  STO I     ; i = 4

You have to adjust the registers through out the whole program.
In the for i loop we have to initialise register I with 2 now.
And then we better switch this with calculating the next n:
Code:
36:  LBL 1     ; for n loop
37:  6         ; 6
38:  RCL 0     ; ∆n    6
39:  -         ; 6-∆n
40:  STO 0     ; ∆n' = 6-∆n
41:  STO+ 1    ; n' = n + ∆n
42:  2
43:  STO I     ; i = 2
44:  LBL 2     ; for i loop

We have to make sure that the index is smaller than 25.
Thus lines 32-33 have to be replaced by:
Code:
30:  ISZ       ; i = i+1
31:  RCL I     ; i
32:  2
33:  5         ; 25    i
34:  x>y       ; 25 > i ?
35:  GTO 0     ; next n

The line numbering will probably be off as well.

Since 97² = 9409 we can't go further than that. But the paper will run out anyway at about 9’300 so that's not a problem.

If you want to make really sure that register I isn't overwritten you can add the same check at the end of the program:
Code:
59:  ISZ       ; i = i+1
60:  GTO 2     ; next i

You may have noticed the Python programs in my last post. They might help understanding the algorithm.

HTH
Thomas

PS: When I contains 25 the command RCL (i) will return 25. Thus it will be checked if 25 is a divisor of n.
But we already checked if 5 is and that wasn't the case.
Furthermore the previous probe was 97 which is bigger and thus n > 25².
Thus we will happily increment I once more and get an error the next time we try to execute RCL (i).
At least that's what I assume would happen. I haven't tested it yet.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (29C) Prime numbers up to 10'000 - Thomas Klemm - 09-03-2018 07:05 PM



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