From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109d8a,9fee389daa016b1b X-Google-Attributes: gid109d8a,public X-Google-Thread: 103376,c26e060278deff34,start X-Google-Attributes: gid103376,public From: nabbasi@pacbell.net Subject: Re: Factorial Base - e Date: 1999/02/18 Message-ID: <7ai90l$eod@drn.newsguy.com> X-Deja-AN: 445902919 References: <19990215100437.15893.00002176@ng-fp1.aol.com> <7ac66f$oen$2@sun500.nas.nasa.gov> Organization: Newsguy News Service [http://www.newsguy.com] Newsgroups: sci.math,comp.lang.ada Date: 1999-02-18T00:00:00+00:00 List-Id: In article <7ac66f$oen$2@sun500.nas.nasa.gov>, hook@nas.nasa.gov says... > > I'm not familiar with this program, but I _do_ have an implementation > of the "spigot" algorithm for computing the decimal representation of > e that sounds like much the same thing. I first learned about this > approach from an article in the American Mathematical Monthly, which > is (sort of) referenced in the comments given in the source code that > I include below. > -- -- This is an Ada implementation of decimal representation of 'e' -- based on SPIGOT algorithm for \pi by -- S. Rabinowitz & S. Wagon, _The_American_Mathematical_Monthly_, March 1995 -- -- A C implementation of the above was posted on the net by -- Ed Hook -- MRJ Technology Solutions, Inc. -- NAS, NASA Ames Research Center -- Internet: hook@nas.nasa.gov -- -- This is an Ada implementation of the Ed Hook program but using GNAT -- (gnu Ada compiler), with the added small feature is that it -- computes the frequency of each digit in e. -- -- the following table is the result. my PC is still running trying to find the -- frequency for 200,000 digits and more for e, and it's been several days -- and not finished. So this is a partial results. (PC is 200 MHz pentium, -- running Linux 2.0.36, and compiler is GNAT 3.11p -- -- offcourse as number of digits of e goes very large, each digit is expected -- to show as often as any other digit. -- -- Nasser Abbasi nabbasi@pacbell.net -- -- results: -- this is distributions of digits in e as function of number of digits. -- for example, when looking at 5000 digits of e, we find 497 0's, -- 478 1's, etc.. (this is for digits after the decimal point of e) -- -- -- #digits in e -- -------------------------------------------------------------- -- 500 5,000 20,000 50,000 200,000 1,000,000 5,000,000 -- --------------------------------------------------------------- --how many 0's 51 497 1,949 4,948 --how many 1's 43 478 2,010 5,055 --how many 2's 50 492 2,020 4,969 --how many 3's 53 514 2,080 5,026 STILL IN PROGRESS FOR 3 DAYS --how many 4's 52 470 1,989 4,966 NEED TO BOOT PC :( --how many 5's 44 478 1,979 5,046 --how many 6's 51 545 2,057 5,133 --how many 7's 60 525 1,977 4,959 --how many 8's 40 509 1,966 4,972 --how many 9's 56 492 1,974 4,926 -- ------------------------------------------------------------------------ --most occuring '7' '7' '3' '6' ------------------------------------------------------------------------ --least occuring '8' '4' '0' '9' ------------------------------------------------------------------------ --difference --between largest 20 55 131 207 --and smallest --in frequency ------------------------------------------------------------------------ --difference --between largest 4% 1.1% 0.655% 0.414% --and smallest --frequency in % -- -- --Compiler: GNAT 3.11p , see http://www.adahome.com to download --To compile: save this file as dist_e_final.adb and type -- gnatmake dist_e_final.adb --system: Linux 2.0.36 --Date: feb. 17, 1999 --To Run: ./dist_e_final -- For example, to see e for 70 digits do: -- -- /home/nabbasi/my_ada $./dist_e_final 70 -- 2.7182818284590452353602874713526624977572470936999595749669676277240766 -- frequency of 0 is 4 -- frequency of 1 is 3 -- frequency of 2 is 9 -- frequency of 3 is 4 -- frequency of 4 is 7 -- frequency of 5 is 7 -- frequency of 6 is 10 -- frequency of 7 is 12 -- frequency of 8 is 5 -- frequency of 9 is 9 -- with Ada.Text_Io; use Ada.Text_Io; with ada.command_line; use ada.command_line; procedure Dist_E_final is type E_Type is array( Natural range <> ) of Natural; Dist : array(0..9) of Natural := (others => 0); Num_Of_Digits : Natural; begin if( Argument_Count /= 1 ) then Put_Line("usage: dist_e "); return; end if; begin Num_Of_Digits := natural'value( Argument(1)); if( Num_Of_Digits = 0 ) then Put_Line("value for number of digits must be larger than zero"); return; end if; exception when others => Put_Line("Exception. invalid value for number of digits"); return; end; declare -- the algorithm itself is in this block E: E_Type( 1 .. Num_Of_Digits+2 ) := (others=> 1); Carry : Natural; begin Put("2."); for I in E'first .. E'Last-2 loop Carry := 0; for J in reverse E'first .. E'Last loop E(J) := E(J)*10; E(J) := E(J)+Carry; Carry := E(J)/(J+1); E(J) := E(J) rem (J+1); end loop; Put(Natural'Image(Carry)(2)); -- print current digit of e Dist(Carry) := Dist(Carry) + 1; -- update this digit frequency end loop; end; New_Line; for I in Dist'Range loop Put_line("frequency of " & Natural'Image(I) & " is " & Natural'Image( Dist(I))); end loop; end Dist_E_final;