From: Ralf Fritzsch on
Hi,

in 1999 Joe Horn posted an algorithm to convert any fraction to "Egyptian
Fractions", I just cite it here for reference:

-----
Input any fraction (e.g. '5/7') and this HP49G program will convert it
to a sum of integer reciprocals (called "Egyptian Fractions"). Be sure
exact mode is on for infinite precision. Sometimes the output is
surprising!

<< 0 SWAP
WHILE DUP FXND NIP 1 >
REPEAT DUP INV FXND IDIV2 SIGN + INV ROT OVER + UNROT - EVAL
END DROP
>>
BYTES: #8EF6h 84.0

Examples:
Input: 5/17
Output: 1/4 + 1/23 + 1/1564
EVAL: 5/17 (simplified back to the original value)

Input: 5/91
Output:
1/19 + 1/433 + 1/249553 + 1/93414800161 + 1/17452649778145716451681 (!!)
EVAL: 5/91

-Joe-

I tried it out, but unfortunately I only get ? as an answer :-(
I double-checked it via BYTES to be sure I made no typo, all was OK. Exact
mode was On, of course.


Any idea what I may have forgot?

TIA,
-------------------------------------------------------------------------
Ralf Fritzsch
Bundesanstalt fuer Wasserbau Federal Waterways Engineering and Research
Dienststelle Kueste Institute - Department Hamburg
-------------------------------------------------------------------------
Unix _IS_ user friendly - it's just selective about who its friends are.
-------------------------------------------------------------------------

From: Bart on
On May 10, 12:44 pm, Ralf.Fritz...(a)T-Online.DE (Ralf Fritzsch) wrote:
> Hi,
>
> in 1999 Joe Horn posted an algorithm to convert any fraction to "Egyptian
> Fractions", I just cite it here for reference:
>
> -----
> Input any fraction (e.g. '5/7') and this HP49G program will convert it
> to a sum of integer reciprocals (called "Egyptian Fractions").  Be sure
> exact mode is on for infinite precision.  Sometimes the output is
> surprising!
>
> << 0 SWAP
>   WHILE DUP FXND NIP 1 >
>   REPEAT DUP INV FXND IDIV2 SIGN + INV ROT OVER + UNROT - EVAL
>   END DROP
>
> BYTES: #8EF6h 84.0
>
> Examples:
> Input: 5/17
> Output: 1/4 + 1/23 + 1/1564
> EVAL: 5/17 (simplified back to the original value)
>
> Input: 5/91
> Output:
> 1/19 + 1/433 + 1/249553 + 1/93414800161 + 1/17452649778145716451681 (!!)
> EVAL: 5/91
>
> -Joe-
>
> I tried it out, but unfortunately I only get ? as an answer :-(
> I double-checked it via BYTES to be sure I made no typo, all was OK. Exact
> mode was On, of course.
>
> Any idea what I may have forgot?
>
> TIA,
> -------------------------------------------------------------------------
> Ralf Fritzsch
> Bundesanstalt fuer Wasserbau   Federal Waterways Engineering and Research
> Dienststelle Kueste            Institute  -  Department Hamburg
> -------------------------------------------------------------------------
>  Unix _IS_ user friendly - it's just selective about who its friends are.
> -------------------------------------------------------------------------


Hmmm, at some point IDIV2 results in 0 and from the AUR: "In exact
mode, the sign for argument 0 is undefined (?)"

My workaround is:
<< 0 SWAP
WHILE DUP FXND NIP 1 >
REPEAT DUP INV FXND IDIV2 DUP
IF 0 <>
THEN SIGN
END + INV ROT OVER + UNROT - EVAL
END DROP >>

Note: replace the <> after the IF with the "not equal" sign (left
shift & +/- key)

BYTES: # 6B71h 109.5

Regards,
B

Regards,
Bart
From: Joe Horn on
An alternative to Bart's workaround for the EGYPT bug is to replace
IDIV2 SIGN (in the original program) with IDIV2 NOT NOT. That will
either not work, or not not work.

-Joe-
From: Jim Horn on
> Examples:
> Input: 5/17
> Output: 1/4 + 1/23 + 1/1564
> EVAL: 5/17 (simplified back to the original value)

Or 1/4 + 1/34 + 1/68.

> Input: 5/91
> Output:
> 1/19 + 1/433 + 1/249553 + 1/93414800161 + 1/17452649778145716451681 (!!)
> EVAL: 5/91

Or, you could use 1/28 + 1/52.

But I cheated and used the calculator at:
<http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fractions/
egyptian.html>
which *doesn't* just use the greedy algorithm.

Jim
From: Ralf Fritzsch on
In article <a96101d2-ccf2-49f5-ae27-bc9316588166(a)i9g2000yqi.googlegroups.com>, bart(a)barend.plus.com says...
>
>On May 10, 12:44=A0pm, Ralf.Fritz...(a)T-Online.DE (Ralf Fritzsch) wrote:
>> ...
>> in 1999 Joe Horn posted an algorithm to convert any fraction to "Egyptian
>> Fractions", I just cite it here for reference:
>> ...
>Hmmm, at some point IDIV2 results in 0 and from the AUR: "In exact
>mode, the sign for argument 0 is undefined (?)"
>
>My workaround is:
><< 0 SWAP
> WHILE DUP FXND NIP 1 >
> REPEAT DUP INV FXND IDIV2 DUP
> IF 0 <>
> THEN SIGN
> END + INV ROT OVER + UNROT - EVAL
> END DROP >>
>
>Note: replace the <> after the IF with the "not equal" sign (left
>shift & +/- key)
>
>BYTES: # 6B71h 109.5
>
>Regards,
>B
> ...

Thank you very much, dear Bart, for your workaround! Unfortunately I was too
dumb to get it done myself :-(

Kind regards,
-------------------------------------------------------------------------
Ralf Fritzsch
Bundesanstalt fuer Wasserbau Federal Waterways Engineering and Research
Dienststelle Kueste Institute - Department Hamburg
-------------------------------------------------------------------------
Unix _IS_ user friendly - it's just selective about who its friends are.
-------------------------------------------------------------------------

 | 
Pages: 1
Prev: ROM Bank 0 layout
Next: geohp