50g User RPL Micro-Challenge: Fraction to a Power
10-09-2017, 10:26 AM
Post: #1
 Joe Horn Senior Member Posts: 1,347 Joined: Dec 2013
50g User RPL Micro-Challenge: Fraction to a Power
The 50g in exact mode takes a very long time to raise a fraction (ratio of integers) to integer powers. Example: 11/12 to the 115th power:

11/12
115
<< ^ EVAL >>

Micro-Challenge: Generate that same answer in less than 1 second, using only vanilla User RPL (no System RPL or SYSEVALs or FLASHEVALs etc). The fastest program wins.

X<> c
-Joe-
10-09-2017, 11:16 AM (This post was last modified: 10-09-2017 11:17 AM by Gerald H.)
Post: #2
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
My suggestion:

0.2197s

Code:
« SWAP OBJ→ 5. ROLLD DROP SWAP PICK3 ^ SWAP ROT ^ ROT 3. →ALG »
10-09-2017, 11:20 AM (This post was last modified: 10-09-2017 11:54 AM by Werner.)
Post: #3
 Werner Senior Member Posts: 329 Joined: Dec 2013
RE: 50g User RPL Micro-Challenge: Fraction to a Power
The date on my IPOW.RPL file reads 2006 ;-)
Edit: but it can't get it done in less than 1 second, so Gerald's idea is the way to go!
Werner
10-09-2017, 12:15 PM (This post was last modified: 10-09-2017 02:11 PM by John Keith.)
Post: #4
 John Keith Member Posts: 250 Joined: Dec 2013
RE: 50g User RPL Micro-Challenge: Fraction to a Power
While Gerald H's program is probably unbeatable, I'm guessing this

Code:
\<<SWAP OBJ\-> DROP2 UNROT OVER ^ UNROT ^ / \>>

is closer to what Joe has in mind, since it takes around 945ms on my HP 50.

John
10-09-2017, 12:46 PM (This post was last modified: 10-09-2017 12:50 PM by Gerald H.)
Post: #5
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
With John's better stack manipulation:

: .2186

Code:
« SWAP OBJ→ 5. ROLLD DROP UNROT OVER ^ UNROT ^ ROT 3. →ALG »
10-09-2017, 12:48 PM
Post: #6
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
I don't know where the face came from - I entered ":s:" without quotes.
10-09-2017, 01:17 PM
Post: #7
 Gerson W. Barbosa Senior Member Posts: 1,056 Joined: Dec 2013
RE: 50g User RPL Micro-Challenge: Fraction to a Power
(10-09-2017 12:48 PM)Gerald H Wrote:  I don't know where the face came from - I entered ":s:" without quotes.

Just check “Disable Smilies” in the Post Options.

:s:
10-09-2017, 02:34 PM
Post: #8
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
Faster:

:s: .1831

Code:
« SWAP COMP→ 5. ROLLD 5. ROLLD UNROT OVER ^ UNROT ^ 4. ROLL 4. ROLL →ALG »
10-09-2017, 02:35 PM
Post: #9
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
Thank you, Gerson, it worked.
10-09-2017, 02:46 PM (This post was last modified: 10-09-2017 02:47 PM by Gerald H.)
Post: #10
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
Faster?

:s: .1825

Code:
« SWAP COMP→ 5. ROLLD 4. ROLLD UNROT OVER ^ UNROT ^ ROT 4. ROLL →ALG »
10-09-2017, 03:22 PM (This post was last modified: 10-09-2017 03:24 PM by Gilles59.)
Post: #11
 Gilles59 Member Posts: 136 Joined: Jan 2017
RE: 50g User RPL Micro-Challenge: Fraction to a Power
Code:
 << SWAP FXND UNROT OVER ^ UNROT ^ / >>

0.9282s

Gerald solution is very fast ! (but needs development Library ;D ) I wonder why it s so fast ?
10-09-2017, 03:30 PM
Post: #12
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
It's the division that's so slow.
10-09-2017, 03:34 PM
Post: #13
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
This version is about as fast as my last try:

Code:
« SWAP FXND UNROT OVER ^ UNROT ^ { / } OBJ→ DROP 3. →ALG »
10-09-2017, 03:44 PM (This post was last modified: 10-09-2017 03:50 PM by Gilles59.)
Post: #14
 Gilles59 Member Posts: 136 Joined: Jan 2017
RE: 50g User RPL Micro-Challenge: Fraction to a Power
(10-09-2017 03:30 PM)Gerald H Wrote:  It's the division that's so slow.

Because a direct '/' tries to simplify the fraction?
and ->ALG does not try ?
10-09-2017, 06:24 PM
Post: #15
 Gerald H Senior Member Posts: 1,361 Joined: May 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
Average over 100 runs

.182s

Code:
« SWAP COMP→ DROP 4 ROLLD UNROT OVER ^ UNROT ^ ROT 3. →ALG »
10-09-2017, 09:39 PM
Post: #16
 Arno K Senior Member Posts: 430 Joined: Mar 2015
RE: 50g User RPL Micro-Challenge: Fraction to a Power
Replacing ->ALG by EVAL increases the time my program Needs (.2163s) to .9723s.
Arno
10-09-2017, 10:01 PM
Post: #17
 Joe Horn Senior Member Posts: 1,347 Joined: Dec 2013
RE: 50g User RPL Micro-Challenge: Fraction to a Power
(10-09-2017 12:15 PM)John Keith Wrote:  While Gerald H's program is probably unbeatable, I'm guessing this

Code:
\<<SWAP OBJ\-> DROP2 UNROT OVER ^ UNROT ^ / \>>

is closer to what Joe has in mind, since it takes around 945ms on my HP 50.

John

I had these two in mind (both contain 8 commands):

<< SWAP OBJ-> DROP ->LIST SWAP ^ EVAL / >>

<< SWAP FXND UNROT OVER ^ UNROT ^ / >>

... but both suffer from the division at the end (yes, Gilles, division simplifies fractions, which isn't needed here). That's why Gerald's program is so fast.

X<> c
-Joe-
10-09-2017, 10:37 PM
Post: #18
 brickviking Member Posts: 289 Joined: Dec 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
(10-09-2017 10:26 AM)Joe Horn Wrote:  The 50g in exact mode takes a very long time to raise a fraction (ratio of integers) to integer powers. Example: 11/12 to the 115th power:

11/12
115
<< ^ EVAL >>

Micro-Challenge: Generate that same answer in less than 1 second, using only vanilla User RPL (no System RPL or SYSEVALs or FLASHEVALs etc). The fastest program wins.

On my calculator, putting that onto the stack and using this: [RSHIFT] →NUM gives me the answer in less than a second.
(Although in saying that, if I hit EVAL instead, that takes a while, and gives me a fraction with really REALLY long numbers.)

I don't know if my answer counts as RPL or not.

(whistles innocently)

(Post 113)

Regards, BrickViking
HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a)
10-10-2017, 01:20 AM
Post: #19
 ttw Member Posts: 133 Joined: Jun 2014
RE: 50g User RPL Micro-Challenge: Fraction to a Power
I tried

<< (11^115)/(12^115) EVAL>> TEVAL

which took 2.5 sec. Seems like a lack of optimization in the expression parser.
10-10-2017, 04:12 AM
Post: #20
 Joe Horn Senior Member Posts: 1,347 Joined: Dec 2013
RE: 50g User RPL Micro-Challenge: Fraction to a Power
(10-09-2017 10:37 PM)brickviking Wrote:
(10-09-2017 10:26 AM)Joe Horn Wrote:  The 50g in exact mode takes a very long time to raise a fraction (ratio of integers) to integer powers. Example: 11/12 to the 115th power:

11/12
115
<< ^ EVAL >>

Micro-Challenge: Generate that same answer in less than 1 second, using only vanilla User RPL (no System RPL or SYSEVALs or FLASHEVALs etc). The fastest program wins.

On my calculator, putting that onto the stack and using this: [RSHIFT] →NUM gives me the answer in less than a second.

Not the exact answer, which is what was specified.

X<> c
-Joe-
 « Next Oldest | Next Newest »

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