(EL5030) Prime Factors

04212022, 03:01 PM
Post: #1




(EL5030) Prime Factors
I got one of these odd little programmable Sharp calculators recently, and worked out how to do the typical mod30 factor finder with its somewhatlimited "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 : Reversevideo 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....25&lang=en I couldn't find a manual for the EL5030 anywhere, but the EL9000 manual is sufficient. The EL5030 is largely equivalent to the AER I mode of the EL9000. 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 

04222022, 02:02 AM
Post: #2




RE: (EL5030) Prime Factors
Very interesting.
Thanks 

04222022, 04:17 PM
Post: #3




RE: (EL5030) Prime Factors
Nice program! I've entered it on my EL5030 but it returns 0 for any input.
I double checked the program in my EL5030 vs. your listing and I don't see any difference. However I'm wondering if the following sequence is correct: Code: =N=>[ 

04222022, 04:27 PM
Post: #4




RE: (EL5030) Prime Factors
(04222022 04:17 PM)Didier Lachieze Wrote: Nice program! I've entered it on my EL5030 but it returns 0 for any input. I just doublechecked the listing to make sure I didn't fatfinger 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. 

04222022, 06:48 PM
(This post was last modified: 04222022 08:21 PM by C.Ret.)
Post: #5




RE: (EL5030) Prime Factors
If we represent the Dave's nice AER program based on 3loops and 3conditionals by the following "inlinegraphic":
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 2loops and 2conditionals : Code: ┌─────────────────────────────────────────────────────────────────────────────────────────────────◄┐ Please fill free to test and correct my code, I (still) have no SHARP EAR hardware... ... but expecting one in a near future 

04222022, 07:02 PM
Post: #6




RE: (EL5030) Prime Factors
(04222022 06:48 PM)C.Ret Wrote: If we represent the Dave's nice AER program based on 3loops and 3conditionals by the following "inlinegraphic": 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 lessverbose 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. (04222022 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. 

04222022, 08:07 PM
(This post was last modified: 04222022 08:12 PM by C.Ret.)
Post: #7




RE: (EL5030) Prime Factors
(04222022 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 

04222022, 09:37 PM
Post: #8




RE: (EL5030) Prime Factors
(04222022 04:17 PM)Didier Lachieze Wrote: Nice program! I've entered it on my EL5030 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. (04222022 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 EL5030 (without the spaces). (04222022 06:48 PM)C.Ret Wrote: Then, we may consider this close related but shorter and faster AER code using only 2loops and 2conditionals : 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 

04232022, 04:27 AM
(This post was last modified: 04232022 09:45 AM by C.Ret.)
Post: #9




RE: (EL5030) Prime Factors
(04222022 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 'endtest' 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 EL5030 accept the reduced syntax INT A[I] or FRAC A[I] instead of INT (A[I]) or FRAC (A[I]) like the PC1211 does? 

04232022, 08:31 AM
Post: #10




RE: (EL5030) Prime Factors
(04232022 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 EL5030: 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◄┐]◄┐ 

04232022, 05:07 PM
(This post was last modified: 04232022 05:43 PM by C.Ret.)
Post: #11




RE: (EL5030) Prime Factors  
« Next Oldest  Next Newest »

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