HP Forums
50g User RPL Micro-Challenge: Fraction to a Power - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: 50g User RPL Micro-Challenge: Fraction to a Power (/thread-9261.html)

Pages: 1 2


50g User RPL Micro-Challenge: Fraction to a Power - Joe Horn - 10-09-2017 10:26 AM

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.


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 11:16 AM

My suggestion:

0.2197s

Code:
« SWAP OBJ→ 5.
ROLLD DROP SWAP
PICK3 ^ SWAP ROT ^
ROT 3. →ALG
»



RE: 50g User RPL Micro-Challenge: Fraction to a Power - Werner - 10-09-2017 11:20 AM

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


RE: 50g User RPL Micro-Challenge: Fraction to a Power - John Keith - 10-09-2017 12:15 PM

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


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 12:46 PM

With John's better stack manipulation:

Confused: .2186

Code:
« SWAP OBJ→ 5.
ROLLD DROP UNROT
OVER ^ UNROT ^ ROT
3. →ALG
»



RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 12:48 PM

I don't know where the face came from - I entered ":s:" without quotes.


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerson W. Barbosa - 10-09-2017 01:17 PM

(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:


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 02:34 PM

Faster:

:s: .1831

Code:
« SWAP COMP→ 5.
ROLLD 5. ROLLD
UNROT OVER ^ UNROT
^ 4. ROLL 4. ROLL
→ALG
»



RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 02:35 PM

Thank you, Gerson, it worked.


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 02:46 PM

Faster?

:s: .1825

Code:
« SWAP COMP→ 5.
ROLLD 4. ROLLD
UNROT OVER ^ UNROT
^ ROT 4. ROLL →ALG
»



RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gilles59 - 10-09-2017 03:22 PM

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 ?


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 03:30 PM

It's the division that's so slow.


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 03:34 PM

This version is about as fast as my last try:

Code:
« SWAP FXND UNROT
OVER ^ UNROT ^ { /
} OBJ→ DROP 3. →ALG
»



RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gilles59 - 10-09-2017 03:44 PM

(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 ?


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Gerald H - 10-09-2017 06:24 PM

Average over 100 runs

.182s

Code:
« SWAP COMP→ DROP 4
ROLLD UNROT OVER ^
UNROT ^ ROT 3. →ALG
»



RE: 50g User RPL Micro-Challenge: Fraction to a Power - Arno K - 10-09-2017 09:39 PM

Replacing ->ALG by EVAL increases the time my program Needs (.2163s) to .9723s.
Arno


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Joe Horn - 10-09-2017 10:01 PM

(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.


RE: 50g User RPL Micro-Challenge: Fraction to a Power - brickviking - 10-09-2017 10:37 PM

(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)


RE: 50g User RPL Micro-Challenge: Fraction to a Power - ttw - 10-10-2017 01:20 AM

I tried

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

which took 2.5 sec. Seems like a lack of optimization in the expression parser.


RE: 50g User RPL Micro-Challenge: Fraction to a Power - Joe Horn - 10-10-2017 04:12 AM

(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.