Any idea how to quickly find the order of magnitude needed for the left argument to ": for this approach?
Thanks, -- Raul On Thu, Jul 25, 2019 at 11:38 AM Devon McCormick <[email protected]> wrote: > > In case it's not clear from the J code, I'm evaluating this continued > fraction: > e = 3 + _1 > -------------- > 4 + _2 > ---------- > 5 + _3 > ------- > 6 + _4 > ---- > 7 + ... > > On Thu, Jul 25, 2019 at 11:32 AM Devon McCormick <[email protected]> wrote: > > > I recently posted something about using a (Ramanujan-like) continued > > fraction for calculating e: > > ramaE=: ([: +`%`:3 [: , [: x: (3 + i.) ,. [: - [: >: i.)"0 > > ramaE 10 > > 9864101r3628800 > > 50j48 ": ramaE 10 NB. Format as decimal > > 2.718281801146384479717813051146384479717813051146 > > 50j48 ": ramaE 20 NB. More precision... > > 2.718281828459045235339784490666415886146403434540 > > 50j48 ": ramaE 50 NB. Even more precision... > > 2.718281828459045235360287471352662497757247093700 > > 50j48 ": ramaE 80 NB. More than 48 digits? > > 2.718281828459045235360287471352662497757247093700 > > 102j100 ": ramaE 80 NB. Yes - more than 48 digits? > > > > 2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274 > > > > This appears to add more digits quickly as you increase the argument. You > > can tell how many digits are good by comparing a given run with one using a > > higher value: > > try2=. ramaE 80 90 > > try2 > > 194545954561539067326581042506243811231423891946873480598031074615399345559765318585225493549256921092507319165187339201r71569457046263802294811533723186532165584657342365752577109445058227039255480148842668944867280814080000000000000000000 > > 119434520557937... > > =/102j100":&>try2 > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > > =/202j200":&>try2 > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > > 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 ... > > 0 i.~ =/202j200":&>try2 > > 122 > > So "ramaE 80" gives us e to 122 digits (120 decimal digits). > > > > > > > > On Thu, Jul 25, 2019 at 11:04 AM Ulrich Vollert <[email protected]> wrote: > > > >> Hello, > >> > >> I came across ’The Google Test’ by Eugene McDonnell ( > >> https://www.jsoftware.com/papers/play211.htm < > >> https://www.jsoftware.com/papers/play211.htm>) and was wondering how to > >> calculate many digits of Euler’s number e. > >> > >> I found an (ancient) article "The calculation of e to many significant > >> digits" by A. H. J. Sale in The Computer Journal 11(2) · August 1968 ( > >> https://www.researchgate.net/publication/266281843_The_Calculation_of_e_to_Many_Significant_Digits > >> < > >> https://www.researchgate.net/publication/266281843_The_Calculation_of_e_to_Many_Significant_Digits>) > >> which uses a clever algorithm implemented in Algol 60 (!) to calculate e > >> digit by digit and using only integer arithmetic. > >> > >> With this algorithm in J (see below) I could calculate as many digits of > >> e as I want (I used 140 digits) and solved the Google Test which asks for: > >> > >> 1. First 10-digit prime found in consecutive digits of e. > >> > >> 2. The number F(5) which follows > >> > >> F(1)= 7182818284 > >> F(2)= 8182845904 > >> F(3)= 8747135266 > >> F(4)= 7427466391 > >> F(5)=__________ > >> > >> (BTW In the article of Eugene McDonell the second number F(2) contains > >> transposed digits 9 and 0.) > >> > >> Here is my question: > >> > >> How would you calculate many significant digits of e in J? > >> > >> Regards, > >> Ulrich > >> > >> > >> NB. *** problem 1 *** > >> > >> NB. value to check m > >> checkm =: 3 : 0 > >> r =. -: ^. 6.2831852 * y > >> r + y * (^. y) - 1 > >> ) > >> > >> NB. given the number of digits of e which are wanted, > >> NB. calculate the number of required terms > >> number_of_terms =: 3 : 0 > >> test =. 2.30258509 * >: y > >> (>: ^: (test&>: @: checkm) ^:_) 4 > >> ) > >> > >> NB. from JforC > >> LoopWithInitial =: 2 : 'u&.>/\.&.(,&(<v))&.|.&.(<"_1)' > >> > >> NB. x is coeff and y is j, carry, follwed by the coeffs so far > >> NB. answer are the next j and carry, the new coeff, and old coeffs > >> term =: 4 : 0 > >> j =. {. y > >> carry =. 1 { y > >> coeffs =. 2 }. y > >> temp =. carry + 10 * x > >> (<: j), ((0, j) #: temp), coeffs > >> ) > >> > >> NB. initialise with m > >> init =: 3 : 0 > >> term LoopWithInitial (y, 0) (<: y) $ 1 > >> ) > >> > >> NB. given is an output of term LoopWithInitial > >> NB. find next output > >> next =: 3 : 0 > >> NB. take last row of output of term LoopWithInitial > >> NB. the row contains: j carry coeffs > >> last =. {: y > >> NB. carry is the next digit of e, forget j > >> ee =: ee , ": 1 { last > >> term LoopWithInitial ((<: #last), 0) |. 2 }. last > >> ) > >> > >> NB. calculate the number of digits of e > >> NB. the digits are collected in a global variable ee > >> calc_e =: 3 : 0 > >> ee =: '' > >> next^:y init number_of_terms y > >> ee > >> ) > >> > >> digits_e =: ". 10 ]\ calc_e 140 > >> > >> solution1 =: {. (I. 1 p: digits_e) { digits_e > >> NB. -> 7427466391 > >> > >> NB. *** problem 2 *** > >> > >> NB. cross sum of a number > >> csum =: 3 : '+/ "."0 ": y' > >> > >> NB. the given numbers have all the same cross sum of 49 > >> NB. csum"0 (7182818284 8182845904 8747135266 7427466391) -> 49 49 49 49 > >> > >> NB. find the next number in the digits of e with a cross sum of 49 > >> solution2 =: 4 }. (] {~ [: I. 49 = csum"0) digits_e > >> NB. -> 5966290435 > >> > >> > >> > >> > >> ---------------------------------------------------------------------- > >> For information about J forums see http://www.jsoftware.com/forums.htm > >> > > > > > > -- > > > > Devon McCormick, CFA > > > > Quantitative Consultant > > > > > > -- > > Devon McCormick, CFA > > Quantitative Consultant > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
