Hi, just wondering if anyone got a hp71b program to do prime factor of a number (and to calculate Euler's function)? appreciate if i can get it. thanks.
Hp 71 program to perform prime factor
|
|
« Next Oldest | Next Newest »
|
▼
12-20-2007, 12:27 AM
▼
12-20-2007, 09:47 AM
Here is a program for the Casio FX-850/880P that does prime factoring; with some modification it should run on the 71B as well. At least you can use it as a guideline... 5 ONERRORGOTO1000 10 MODE8:DIM:x=2:c$=CHR$(5) 20 CLS:PRINT"Prime factors (2óBase<10Çø)";:a$=" *" 40 LOCATE0,1:PRINTc$;"Base ?";:INPUT@11;x:LOCATE0,0 45 IFx<2 ORx>=1e10 ORFRACx<>0 THEN40 50 LOCATE0,1:PRINTc$;x;"= ....."; 60 u=0:v=0:n=1:t$="":a=x 70 GOTO130 100 u=2:GOSUB500 110 a=a/2 120 IFa-1=0 THEN240 130 IFFRAC(a/2)=0 THEN100 140 b=3 150 c=SQRa+1 160 IFb>=c THEN230 170 IFFRAC(a/b)=0 THEN190 180 b=b+2:GOTO160 190 IFa/b*b-a=0 THEN210 200 GOTO180 210 u=b:GOSUB500 220 a=a/b:GOTO150 230 u=a:GOSUB500 240 a$="":GOSUB530 250 PRINTc$;x;"=";t$;:z$=INPUT$(1,@):GOTO20 500 IFv=u THENn=n+1:GOTO550 520 IFv=0 THEN550 530 IFn>1 THENt$=t$+STR$(v)+"^"+MID$(STR$(n),2)+a$ELSEt$=t$+STR$(v)+a$ 540 n=1 550 v=u:RETURN 1000 IFERR=1 THENCLS:ONERRORGOTO0 1010 IFERL=40 THENRESUME40 1050 LOCATE0,1:PRINTc$;"not found";:z$=INPUT$(1,@):RESUME20
Edited: 20 Dec 2007, 10:16 a.m. ▼
12-20-2007, 07:29 PM
Appreciate everyone's help so far. Afraid I am still relatively new at this. Never really program in BASIC (or really much of any programming). Appreciate as much hand holding as anyone can give. I just got this recent urge to collect HP calcs. Got 8 of them (50g, 28s, 71b, 42s, 41cv, 41cx, 67, 35) in the last 2 months. This is in addition to 48sx and 32sii which i bought over 10 yrs ago. I got the prime factor program for hp 41/42s and hp 67. just want to test out how efficent and fast the hp 71 would be compared to others. I also got an hp 50g and hp 28s. Anyone know where i can get RPL prime factor programs? ;) Thank you. ▼
12-20-2007, 08:14 PM
Quote: The basic version I sent you is based upon this one: http://www.hpcalc.org/search.php?query=primefac Note: 1) There is at least one instance of NOT NOT in the RPL program. Of course they cancel each other and should be omitted; 2) K=IP(SQR(R)) in the BASIC program can be replaced with simply K=SQR(R). Regards,
Gerson . Edited: 20 Dec 2007, 8:16 p.m.
12-20-2007, 10:22 AM
Here is a very simple although inefficient method, in generalized BASIC:
Input A ▼
12-20-2007, 05:34 PM
I like that small, easy to understand program, Don. The only change I would suggest is the ending test. You should only have to check up to the square root of the number being factored. Then print the number tested. I would change it to: Loop While B*B<=A Print A I may have missed something, but this should make it much more efficient. ▼
12-20-2007, 06:53 PM
Hey Steve, I agree it would make it more efficient, but it won't work. I tried that when I first saw this particular algorithm. You are right, you normally only want to go up to the square root of the number, but doing so in this algorithm won't give you the final factor. For example, for input 45, it only gives you 3 and 3, and you don't get the 5. It may be an easy change to fix this (and only go to the square root), but I have not figured it out yet. Any takers?
12-20-2007, 07:32 PM
You can try the following, before you get something faster:
10 INPUT N Regards, Gerson.
▼
12-20-2007, 07:33 PM
Thanks will try this
12-20-2007, 08:05 PM
That does work but seem a little slow. The program on my hp42s gives the answer about 3 times as fast. Good starting point though i guess. ▼
12-20-2007, 08:31 PM
A port of the 42s program to the 71b would be fine, considering the 71b is about 2.5 times faster than the the 42s. Anyway, the BASIC program is based on an RPL program I wrote for the 28s, which in turn was based on the way I used to do that by hand... Regards, Gerson. ▼
12-21-2007, 07:29 AM
Bom dia, Gerson!
Glad to welcome you here after this three months absence. Cheers, Jean-Michel.
12-22-2007, 03:18 PM
Anyone else have any other idea to shorten the execution time? The above program is giving slower answer than would be expected for the hp 71. Thanks ▼
12-22-2007, 03:45 PM
wildpig says:
Quote:
Quote: There are faster machines and faster ways to do this. Knowing this and still wanting to be doing it on the 71B means you're doing it just for the fun of it. Why should anybody rob you of this fun??? Why should anybody do YOUR hobby for you???? ▼
12-22-2007, 03:59 PM
Just trying to see how fast these calculators can be. Which is one reasons why i collect hp calcs ▼
12-22-2007, 04:10 PM
Pig, I think Valentin and others have written that the 71B is NOT a fast machine, certainly by today's standards. But it is fun to see if they can do these tasks at all, especially given the limited resources on many vintage HP calcs. I recently implemented the HCC2007 programming contest problem on a HP-65, and it was a lot of fun to see if it could be done on a 33-year-old machine with 8 usable registers and 100 lines of code. And it works! So if speed is what you want, go modern! Otherwise enjoy doing things on old calcs for the fun of it! ▼
12-22-2007, 09:46 PM
Sorry for being so persistent. Hate to see the hp71 which is supposed to be faster than the 42s keeps losing... ;) ▼
12-24-2007, 11:33 AM
Quote:Where is this stated? The 71B and 42S both use a Saturn processor. The 71B is clocked at 640MHz [http://en.wikipedia.org/wiki/Saturn_(microprocessor)] and the 42S at 1MHz. The 42S also has a less complex programming and operating environment. I would be surprised if the 71B/BASIC bested the 42S/RPN. Input FACTORLX if you want to see 71B/Assembly in action. ▼
12-24-2007, 11:15 PM
Hmm, don't see it says what 42s clock speed is on there anywhere. According to HPmuseum, 71b is faster than 42s (http://www.hpmuseum.org/speed.htm) Same also at http://www.thimet.de/CalcCollection/CalcPerformance.html I have the optimized fibonacci program for both calcs and the 71b always beat the 42s by a good margin
12-24-2007, 11:17 PM
Is there a way to resume entering factorlx or do I have to type everything in all in one sitting. ? ;(
12-22-2007, 05:18 PM
Add the following line to the above program. The program will still be slow but at least this change will allow numbers like 111121121, for instance, to be processed under three minutes rather than hours :-) 12 IF MOD(N,2)=0 THEN 15 ELSE GOSUB 70 @ IF MOD(N,J)<>0 THEN PRINT N; @ END
And make this change to line 70: 70 R=N @ J=1 @ K=SQR(R) Regards, Gerson. ▼
12-22-2007, 09:42 PM
That additional line did speed up the evaluation of a prime number considerably ;). Evaluating a prime number was the cause of the slowdown on the 71. Although i think evaluation of non prime number and factors are still slightly faster on my 42s. I willl try to learn hp basic ;) anyone else help is also appreciated. Thanks G..
12-20-2007, 08:22 PM
Are you looking for speed or want to study the algorithm? For speed get FACTORLX and try:
10 INPUT "N: ";NE.g. >RUN ▼
12-20-2007, 11:08 PM
Where do i get FACTORLX? thanks ▼
12-21-2007, 01:59 AM
http://membres.lycos.fr/jeffcalc/lexfl1.zip Unzip, then mount lexfl1.lex under emu71 as :HDRIVE1 or 2. ▼
12-21-2007, 02:33 AM
Hmm, a 600k file. Guess this is only for the emu? can't load this into my hp 71b? ▼
12-21-2007, 09:23 AM
It's a LIF disk image. You have a few options: 1. With a DOS or Linux PC you can create a floppy (720K). Then you'll need a 9114 drive and HP-IL to get it on your 71B. 2. Use a PC with DOS/Linux and an HP-IL ISA adapter with the registered version of EMU71. Plus, HP-IL for 71B. Then, copy using HP-IL. 3. You can mount with EMU71, and use dumplex and makelex to hand type it in. I'll make it easy for you, I ran dumplex for you and posted the output here: http://sense.net/~egan/factorlx.txt You need to type in makelex, run it, and input all 1040 bytes of factorlx.txt. makelex:
10 SFLAG -1 @ ON ERROR GOTO 30 @ DESTROY ALL ▼
12-21-2007, 07:29 PM
No simple program that i can just type in eh? ;( The above program posted by Gerson does sorta work but is very slow since my 71 is getting the answer slower than the hp42s. I have the HPIL addon on the calc but not the cable. ;(
12-23-2007, 12:54 AM
Is there anyway to pause and turn off the calc while entering factorlx or will i have to start from scratch? ;( |