(EL-5030) Prime Factors - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: Not HP Calculators (/forum-7.html) +--- Forum: Not remotely HP Calculators (/forum-9.html) +--- Thread: (EL-5030) Prime Factors (/thread-18286.html) |
(EL-5030) Prime Factors - Dave Britten - 04-21-2022 03:01 PM I got one of these odd little programmable Sharp calculators recently, and worked out how to do the typical mod-30 factor finder with its somewhat-limited "AER" (Algebraic Expression Reserve) programming language. Notable limitations of AER as seen on this model: - No arbitrary GOTO, only a looping structure resembling nested WHILE loops. - IF/THEN/ELSE structure, but no loops allowed inside the THEN/ELSE clauses. - Can do subroutines, but the subroutines can't contain any loops or conditionals. - Only comparison operators are >, >=, and <> (not equal). To do other comparisons, swap the order of the arguments, or swap your THEN/ELSE bodies. It does have arrays with indirect addressing, and that's enough to make this workable. To run this, use the TITLE key to call up the factor program, press COMP, input a number to factor, and press COMP. The program will stop and display the first factor; press COMP to continue finding additional factors. The last factor will be displayed as a negative number. Some translation notes, because AER uses a lot of symbols that aren't necessarily present in all fonts: #1 : Reverse-video numbers (subroutines, e.g. 2ndF+Alpha+1) => : STO \-> : Loop start (2ndF 0) <-\ : Loop end (2ndF .) <> : Not equal (2ndF 6) =Y=>[, =N=>[ : THEN and ELSE clauses (2ndF 1, 2ndF 2) / : Division Note that the last step should be negative X (unary minus, not subtraction). This page has a nice history of Sharp's AER programming system: http://www.arithmomuseum.com/szamologep.php?id=25&lang=en I couldn't find a manual for the EL-5030 anywhere, but the EL-9000 manual is sufficient. The EL-5030 is largely equivalent to the AER I mode of the EL-9000. Program code has been heavily broken up and indented for clarity, but this should be entered into the calculator without any spacing. Code: Main Body RE: (EL-5030) Prime Factors - Jlouis - 04-22-2022 02:02 AM Very interesting. Thanks RE: (EL-5030) Prime Factors - Didier Lachieze - 04-22-2022 04:17 PM Nice program! I've entered it on my EL-5030 but it returns 0 for any input. I double checked the program in my EL-5030 vs. your listing and I don't see any difference. However I'm wondering if the following sequence is correct: Code: =N=>[ RE: (EL-5030) Prime Factors - Dave Britten - 04-22-2022 04:27 PM (04-22-2022 04:17 PM)Didier Lachieze Wrote: Nice program! I've entered it on my EL-5030 but it returns 0 for any input. I just double-checked the listing to make sure I didn't fat-finger anything when typing it in, and the listing looks okay. The comma acts as "stop and display the result of the previous expression", so "C," is basically "PRINT C". In this program, C is the trial divisor, and if X<>INT (X/C)*C is false, that means C is a factor of X, so the program displays C, stores X/C into X, then repeats the trial division loop with the same value of C. RE: (EL-5030) Prime Factors - C.Ret - 04-22-2022 06:48 PM If we represent the Dave's nice AER program based on 3-loops and 3-conditionals by the following "inline-graphic": [attachment=10627] Where the purple part is an outlaw AER syntax deliberately used for clarity by avoiding the element by element long list of A[..] affectations . Code: ┌────────────────────────────────────────────────────────────────────────────────────────◄┐ Then, we may consider this close related but shorter and faster AER code using only 2-loops and 2-conditionals : [attachment=10628] Code: ┌─────────────────────────────────────────────────────────────────────────────────────────────────◄┐ Please fill free to test and correct my code, I (still) have no SHARP EAR hardware... ... but expecting one in a near future RE: (EL-5030) Prime Factors - Dave Britten - 04-22-2022 07:02 PM (04-22-2022 06:48 PM)C.Ret Wrote: If we represent the Dave's nice AER program based on 3-loops and 3-conditionals by the following "inline-graphic": Thanks, your graphical representation of the program looks good. Aside from the deliberate liberty taken on the array initialization, of course - would be nice if the calculator had a less-verbose method like that! In the Casio version that I based this on, I do 2->O~Z to initialize the whole array with 2 in one shot, then individually store the 6 elements that aren't 2, so it's a little bit shorter. (04-22-2022 06:48 PM)C.Ret Wrote: Please fill free to test and correct my code, I (still) have no SHARP EAR hardware... Clever trick with stuffing the next array index into the registers! I'll have to try keying it in later to compare the speed and size. RE: (EL-5030) Prime Factors - C.Ret - 04-22-2022 08:07 PM (04-22-2022 07:02 PM)Dave Britten Wrote: In the Casio version that I based this on, I do 2->O~Z to initialize the whole array with 2 in one shot, then individually store the 6 elements that aren't 2, so it's a little bit shorter. On the SHARP, you may try the following to short your #1 Subroutine: I found same AER listings using multiple embedded store instructions, but I don't know if it's possible on the EL 5030 ? Code: #1: 12=>L ˽ DIM A[L] ˽ 6=>A[3]=>A[1] ˽ 4=>A[8]=>A[6]=>A[4] ˽ 2=>A[L]=>A[10]=>A[9]=>A[7]=>A[5]=>A[2] ˽ 1=>A[11] ˽ 0=>C RE: (EL-5030) Prime Factors - Didier Lachieze - 04-22-2022 09:37 PM (04-22-2022 04:17 PM)Didier Lachieze Wrote: Nice program! I've entered it on my EL-5030 but it returns 0 for any input. Ok, I’ve found my mistake, I had entered a ◣ at the end of the subroutine, so the program just stopped there. After removing it it works correctly, I get the different factors until it returns -1. For 15 I get 3, 5 and -1. (04-22-2022 08:07 PM)C.Ret Wrote: On the SHARP, you may try the following to short your #1 Subroutine: I found same AER listings using multiple embedded store instructions, but I don't know if it's possible on the EL 5030 ? Yes it works on the EL-5030 (without the spaces). (04-22-2022 06:48 PM)C.Ret Wrote: Then, we may consider this close related but shorter and faster AER code using only 2-loops and 2-conditionals : This one works also with a few changes: - Replacing Q=X/F by X/F=>Q , I=1 by 1=>I and F=0 by 0=>F - Initializing individually each element of A[] For 15 I get 3 and -5 RE: (EL-5030) Prime Factors - C.Ret - 04-23-2022 04:27 AM (04-22-2022 09:37 PM)Didier Lachieze Wrote: This one works also with a few changes: Thanks for pointing out all those silly mistakes! As I don't have an AER device, I try my code on BASIC SHARP and I accidentally mixed up codes in the notepad before copying and pasting. Much better AER code here: Code: M:f(X)= #1 └►F+10*FRAC (A[I])=>F˽INT (A[I])=>I└►X/F=>Q˽F>Q =Y=>[DIM A[1]˽-X■]Q≠INT (Q)=N=>[F,Q=>X◄┐]◄┐ This code is longer than it appears on the voluntarily reduced form! I'm not sure it's shorter or faster anymore since the F>Q 'end-test' is done at each iteration; in the initial code the test X>C*C only takes place once after the 8th iteration. How much time does it save or lose? I imagine the speed improvements will greatly depend on specific values for X. Can the sequence INT (A[I])=>I be replaced by a simpler A[I]=>I ? Did the EL-5030 accept the reduced syntax INT A[I] or FRAC A[I] instead of INT (A[I]) or FRAC (A[I]) like the PC-1211 does? RE: (EL-5030) Prime Factors - Didier Lachieze - 04-23-2022 08:31 AM (04-23-2022 04:27 AM)C.Ret Wrote: Can the sequence INT (A[I])=>I be replaced by a simpler A[I]=>I ? Yes to both. So the updated code below works fine on the EL-5030: Code: M:f(X)= #1└►F+10*FRAC A[I]=>F˽A[I]=>I└►X/F=>Q˽F>Q =Y=>[DIM A[1]˽-X◣]Q≠INT Q=N=>[F,Q=>X◄┐]◄┐ RE: (EL-5030) Prime Factors - C.Ret - 04-23-2022 05:07 PM We may spare one element in matrix/vector A[..]: [attachment=10634] Code: M:f(X)=#1└►└►X/F꞊>Q˽F>Q ꞊Y꞊>[-X◣]Q≠INT Q ꞊N꞊>[F,Q꞊>X◄┐]F+10*FRAC A[I]꞊>F˽A[I]꞊>I◄┐ |