find_Baker := proc(n)
# finds the smallest number m of digits of the input number
# that allows us to start Baker's algorithm at step n
# and builds the table
# we start with m = n+1, if we succeed, we build the table
# else we increment m
global m, TAB, failure;
Digits := 30;
# recalculation of the convergence domain [0,A]
A := evalf(log(2));
for i from 1 to 100 do
A := A+evalf(log(1+2^(-i))) od;
# First, we build the J intervals
remainder := evalf(log(1+2^(-n)));
for i from (n+1) to 100 do
remainder := remainder+evalf(log(1+2^(-i)))
od;
for counter from 0 to (2^n-1) do
# computation of d_0, d_1, ... d_n-1
# where the d_i's are the digits of the binary representation
# of counter
decomp := counter;
for k from 1 to n do
d[n-k] := decomp mod 2;
decomp := trunc(decomp/2)
od;
Jleft[counter] := evalf(d[0]*log(2));
for i from 1 to (n-1) do
Jleft[counter] := Jleft[counter]
+ evalf(d[i]*log(1+2^(-i)))
od;
Jright[counter] := Jleft[counter]
+ remainder+evalf(log(1+2^(-n+1)));
od;
# now we try successive values of m
m := n;
failure := true;
# failure = true means that m is not large enough
while (failure) do
m := m+1;
powerof2 := 2^(m-1);
Ileft[0] := 0; Iright[0] := evalf(1/powerof2);
for counter from 1 to 2^m-1 do ;
Ileft[counter] := Iright[counter-1];
Iright[counter] := evalf((counter+1)/powerof2);
od;
# Now we must check if for each I-interval included in the
# convergence domain of the algorithm
# there exists a J-interval that
# contains it
countermax := trunc(A*2^(m-1))-1;
Jstart := 0;
failure := false;
counter := 0;
while (not failure) and (counter <= countermax) do
while Jright[Jstart] < Iright[counter] do
Jstart := Jstart+1
od;
if Jleft[Jstart] <= Ileft[counter] then
TAB[counter] := Jstart else failure := true
fi;
counter := counter+1
od;
if (failure=false)
then
print (m);
for counter from 0 to countermax do
print(counter,TAB[counter])
od
fi
od;
end;