Some useful working procedures

The following simple procedure is easily built upon the above:

> egypt := proc(R)
local r, n, k;
r[0] := R:
n[1] := ceil(1/r[0]):
for k while type(1/r[k-1], integer) = false do
r[k] := r[k-1] - 1/n[k]:
n[k+1] := ceil(1/r[k]):
od:
seq(1/n[m], m=1..k);
end:

> egypt(1/7);

1/7

> egypt(3/15); # here '3/15' is already a unit fraction

1/5

> egypt(3/5);

1/2, 1/10

> egypt(17/39);

1/3, 1/10, 1/390

> egypt(171/3391); # the original example

1/20, 1/2339, 1/14420999, 1/254179689327669, 1/5814...

A dramatic example due to Stan Wagon is 31/311 (which I'm not executing for printing):

> # egypt(31/311);

>

A way of checking (if you wish) is to make the output into a List, and then add the elements of that list:

> L := [egypt(17/39)];
add(x, x = L);

L := [1/3, 1/10, 1/390]

17/39

> a := ithprime(100);
b := ithprime(200);
egypt(a/b);

a := 541

b := 1223

1/3, 1/10, 1/111, 1/79855, 1/21681111630

> a := 9!+1:
b := 10!+1:
egypt(a/b);

1/10, 1/4032002, 1/18289166112003, 1/66898719414485...

Here's a simple variation which will allow us to see the decreasing numerators (the last of which will always be '1', for we have arrived at a terminating unit fraction):

> stages := proc(R)
local r, n, k, m;
r[0] := R:
n[1] := ceil(1/r[0]):
for k while type(1/r[k-1], integer) = false do
r[k] := r[k-1] - 1/n[k]:
n[k+1] := ceil(1/r[k]):
od:
print(seq(1/n[m], m=1..k));
lprint(`Decreasing numerators:`);
seq(numer(r[m]), m=0..k-1);
end:

>

> stages(4/17);

1/5, 1/29, 1/1233, 1/3039345

`Decreasing numerators:`

4, 3, 2, 1

>

The '3, 2, 1' in the output are last three numerators on the RHS in:

4/17 = 1/5+3/85
3/85 = 1/29+2/2465
2/2465 = 1/1233+1/3039345

>

> a := ithprime(100);
b := ithprime(200);
stages(a/b);

a := 541

b := 1223

1/3, 1/10, 1/111, 1/79855, 1/21681111630

`Decreasing numerators:`

541, 400, 331, 17, 1

> a := 9!+1:
b := 10!+1:
stages(a/b);

1/10, 1/4032002, 1/18289166112003, 1/66898719414485...

`Decreasing numerators:`

362881, 9, 2, 1

>

If we wanted only to see how many steps there were when the greedy algorithm was applied, we could do something like this:

> howmany := proc(R) local r, n, k, m;
r[0] := R: n[1] := ceil(1/r[0]):
for k while type(1/r[k-1], integer) = false do
r[k] := r[k-1] - 1/n[k]:
n[k+1] := ceil(1/r[k]):
od: k; end:

>

> howmany(4/19);

2

> howmany(4/17); # the maximum number with numerator '4':

4

>

Contact details 

After August 31st 2007 please use the following Gmail address: jbcosgrave at gmail.com


This page was last updated 18 February 2005 15:07:06 -0000