1 Billion digit prime

For other topics related to the FreeBASIC project or its community.
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: 1 Billion digit prime

Postby owen » Apr 16, 2014 9:07

@ srvaldez
Wow thanks for explaining the gmp bi, dll info and for pointing out MichaelW's post.
frisian
Posts: 249
Joined: Oct 08, 2009 17:25

Re: 1 Billion digit prime

Postby frisian » Apr 21, 2014 19:28

TESLACOIL wrote:As of January 2014, the largest known prime number is 257,885,161 − 1,[1] a number with 17,425,170 digits.
http://en.wikipedia.org/wiki/Largest_known_prime_number

That should be 2^257,885,161 − 1

owen wrote:Hi frisian, I'm home now and anxious to test your code. If possible can you help walk me through the install of MPIR. Please feel free to communicate with me via this forum, email or phone. My email is opreese@gmail.com and cell# is 407-655-8537. Thanks Owen P. Reese.


Sorry for the late response, phone call's are somewhat to expenses for me so, also there is a time difference because I am a the other side of that massive expands of water.

I have some older version of GMP and MPIR, so it seemed a good idea to make new with the most recent version of both. I also installed a new MINGW distro. Complete disaster, most of the time they failed to compile. I tried different MINGW distro / settings, no luck. I installed a slightly older distro, and after having replaced two programs by other versions I finally got a 32bit static GMP/MPIR file. The MPIR file passed all the chechk and it was possible to make Tuneup (needed to make a tuned version of the file). The GMP file on the other hand passed all the checks but failed to produce Tuneup. Timing for the the new GMP version it almost equal to the old version. The new MPIR file is about 1200 seconds slower than the old one (It's a fourth alpha so that could change). For now I will use the old version.

I also managed to make a 64 bit GMP version (needs the FreeBasic 64bit GCC version to run), it is faster than the 32 bit version. The 64bit MPIR failed to compile.

About your memory problem I had something similar it seems that GMP uses more memory than MPIR in the same situation but it's possible that has changed (or will in the future).
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: 1 Billion digit prime

Postby owen » Apr 28, 2014 19:13

In an effort to verify the billion digit primorial:

Code: Select all

#Include once "gmp.bi"
Dim As mpz_t p
mpz_init_set_ui(@p,1)
Dim as ZString ptr s
mpz_primorial_ui(@p,2302630117)
s = mpz_get_str( 0, 10, @p)
Print "primorial calculated"' *s
Open "primorial.txt" For Output As #1
Print #1,*s
Close #1
mpz_clear(@p)
Print "primorial has been saved in file: primorial.txt"
Sleep
End
owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: 1 Billion digit prime

Postby owen » May 04, 2014 19:13

Here's another effort to verify the primorial... but it keeps crashing.... probably a memory leak.
d1.txt is the primorial (1 gig file)
program divides the primorial by primes starting at 2 up to and including 2302630117.
saves the quotient in d2.txt checking for a remainder of zero each time.
if the remainder is zero d2.txt is copied to d1.txt and next prime is used.
when the program crashes, all i need to do is restart it.
final result should be 1 (one).

Code: Select all

#Include once "gmp.bi"
'2302630117
Dim As mpz_t n
Dim As mpz_t q
Dim As mpz_t r
Dim As mpz_t p

mpz_init_set_ui(@n,1)
mpz_init_set_ui(@q,1)
mpz_init_set_ui(@r,1)
mpz_init_set_ui(@p,1)
Dim ns As String * 100000
Dim As String nst,rst,np
Dim as ZString ptr s
Dim As Integer c,last
last=0

Do
   Print Time$
   
   Open "nextprime.txt" For Input As #1
   Input #1,np
   Close #1
   mpz_set_str(@p,np,10)
   Print "2302630117"
   mpz_nextprime(@p,@p)
   s = mpz_get_str( 0, 10, @p)
   Print *s
   np=*s
   If *s="2302630117" Then
      last=1
      Print "last one"
   EndIf
   rst=""
   Open "d1.txt" For Binary As #1
   Open "d2.txt" For Output As #2
   Do While Not Eof(1)
      Get #1,,ns
      If rst<>"0" Then
         nst=rst+RTrim(LTrim(ns))
      Else
            nst=RTrim(LTrim(ns))
      EndIf
      mpz_set_str(@n,nst,10)
      mpz_fdiv_q(@q,@n,@p)
      s = mpz_get_str( 0, 10, @q)
      Print #2,*s;
      mpz_fdiv_r(@r,@n,@p)
      s = mpz_get_str( 0, 10, @r)
      rst=*s
      mpz_clear(@n)
      mpz_clear(@q)
      mpz_clear(@r)
      mpz_clear(@p)
      mpz_init_set_ui(@n,1)
      mpz_init_set_ui(@q,1)
      mpz_init_set_ui(@r,1)
      mpz_init_set_ui(@p,1)

   Loop
   Print #2,""
   Close #1
   Close #2
   Print "remainder=";rst
   If rst<>"0" Then
      Print "oops remainder = ";rst
      Exit Do
   EndIf
   If last=1 Then Exit Do
   Shell("copy d2.txt d1.txt")
   Open "nextprime.txt" For Output As #1
   Print #1,np
   Close #1

Loop
mpz_clear(@n)
mpz_clear(@q)
mpz_clear(@r)
mpz_clear(@p)

Print "done"
Sleep

End

owen
Posts: 555
Joined: Apr 19, 2006 10:55
Location: Kissimmee, FL
Contact:

Re: 1 Billion digit prime

Postby owen » May 04, 2014 20:09

the primorial i calculated using frisian's code is online
[url]fbcadcam.com/prime/primorial.rar[/url]

Return to “Community Discussion”

Who is online

Users browsing this forum: dodicat, jj2007 and 10 guests