HP Forums

Full Version: 50g User RPL Micro-Challenge: Fraction to a Power
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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 >>

takes about 40 seconds to return the exact answer.

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.
My suggestion:

0.2197s

Code:
« SWAP OBJ→ 5.
ROLLD DROP SWAP
PICK3 ^ SWAP ROT ^
ROT 3. →ALG
»
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
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
With John's better stack manipulation:

Confused: .2186

Code:
« SWAP OBJ→ 5.
ROLLD DROP UNROT
OVER ^ UNROT ^ ROT
3. →ALG
»
I don't know where the face came from - I entered ":s:" without quotes.
(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:
Faster:

:s: .1831

Code:
« SWAP COMP→ 5.
ROLLD 5. ROLLD
UNROT OVER ^ UNROT
^ 4. ROLL 4. ROLL
→ALG
»
Thank you, Gerson, it worked.
Faster?

:s: .1825

Code:
« SWAP COMP→ 5.
ROLLD 4. ROLLD
UNROT OVER ^ UNROT
^ ROT 4. ROLL →ALG
»
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 ?
It's the division that's so slow.
This version is about as fast as my last try:

Code:
« SWAP FXND UNROT
OVER ^ UNROT ^ { /
} OBJ→ DROP 3. →ALG
»
(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 ?
Average over 100 runs

.182s

Code:
« SWAP COMP→ DROP 4
ROLLD UNROT OVER ^
UNROT ^ ROT 3. →ALG
»
Replacing ->ALG by EVAL increases the time my program Needs (.2163s) to .9723s.
Arno
(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.
(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 >>

takes about 40 seconds to return the exact answer.

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)
I tried

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

which took 2.5 sec. Seems like a lack of optimization in the expression parser.
(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 >>

takes about 40 seconds to return the exact answer.

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.
Pages: 1 2
Reference URL's