Bill Allombert on Sun, 21 Jan 2024 14:08:57 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: oeis_digits( x, {D=105} )


On Sun, Jan 21, 2024 at 01:54:18PM +0100, Ruud H.G. van Tol wrote:
> 
> oeis_digits( x, D=105) = {
>   localprec(D);
>   if("t_STR" == type(x), x=eval(x));
>   my(v=Vec(strprintf("%.*f", D, x)));
>   [[ eval(s) |s<-v[1+(x<1)..D+1+(x<1)], s!="."], if(x<1, 0, 1+logint(x,
> 10))];
> }

A different way to do the same thing:

dig_exp1(N)=localprec(N+20);digits(round(exp(1)*10^N));

? dig_exp1(100)
%14 = [2,7,1,8,2,8,1,8,2,8,4,5,9,0,4,5,2,3,5,3,6,0,2,8,7,4,7,1,3,5,2,6,6,2,4,9,7,7,5,7,2,4,7,0,9,3,6,9,9,9,5,9,5,7,4,9,6,6,9,6,7,6,2,7,7,2,4,0,7,6,6,3,0,3,5,3,5,4,7,5,9,4,5,7,1,3,8,2,1,7,8,5,2,5,1,6,6,4,2,7,4]

and more generaly,
digreal(f,N)=localprec(N+20);digits(round(f()*10^N));

? digreal(()->log(2),100)
%17 = [6,9,3,1,4,7,1,8,0,5,5,9,9,4,5,3,0,9,4,1,7,2,3,2,1,2,1,4,5,8,1,7,6,5,6,8,0,7,5,5,0,0,1,3,4,3,6,0,2,5,5,2,5,4,1,2,0,6,8,0,0,0,9,4,9,3,3,9,3,6,2,1,9,6,9,6,9,4,7,1,5,6,0,5,8,6,3,3,2,6,9,9,6,4,1,8,6,8,7,5]

Cheers,
Bill.