Results 1 to 6 of 6

Math Help - Table the firts 50 twin primes in Mathematica

  1. #1
    Newbie
    Joined
    Jan 2008
    Posts
    2

    Table the firts 50 twin primes in Mathematica

    I want to know how I find, calculate (make a list in Mathematica) for the firts 50 twin primes. If p is a prime and p+2 is a prime they called twin primes. Anybody who can tell me to programing the program Wolfram Mathematica?

    I have come this far, so long:

    1) I make a new empty list, that I'm calling "twins"

    twins = {}

    {}

    2) I know that the first twins is 3, 5 and put the element to the list:

    AppendTo[twins, {3, 5}]

    {{3, 5}}

    twins

    {{3, 5}}

    Ok!

    3) I'm checking if the next prime 3+2=5 have a twin and use my conditions:

    n = 5

    5

    If[PrimeQ[n] && PrimeQ[n + 2], AppendTo[twins, {n, n + 2}]]


    {{3, 5}, {5, 7}}

    Ok!

    4) Then I'm checking the lengt of my list:

    Length[twins]

    2

    I's ok!

    4) It's ok, but the last thing I want to tell Mathematica is to use the comand "While" and do this:



    As long as "twins" has less than 50 elements:
    Test if both n and n+2 are primes.
    If it is so: put {n,n+2} to the list "twins", then increse
    n whith 2 and then return the list "twins".



    If you can help you can also send me a Mathematica-file whith the solution (nb-file). to anders.skoog@vaxjofria.se or anders.k.m.skoog@home.se , or just write it down here at the forum. Thanks.
    Last edited by Bigas; February 2nd 2008 at 01:53 AM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    GAMMA Mathematics
    colby2152's Avatar
    Joined
    Nov 2007
    From
    Alexandria, VA
    Posts
    1,172
    Awards
    1
    Quote Originally Posted by Bigas View Post
    I want to know how I find (make a table or a list in Mathematica) for the firts 50 twin primes. If p is a prime and p+2 is aprime they called twin primes. Anybody who can tell me to find the first 50 in the program Wolfram Mathematica?
    Use Excel, but make sure you have enough memory. I got the first 20 twin primes...


    3/5

    5/7





    11/13





    17/19











    29/31











    41/43

















    59/61











    71/73





























    101/103





    107/109





























    137/139











    149/151





























    179/181











    191/193





    197/199





























    227/229











    239/241





























    269/271











    281/283
    Follow Math Help Forum on Facebook and Google+

  3. #3
    GAMMA Mathematics
    colby2152's Avatar
    Joined
    Nov 2007
    From
    Alexandria, VA
    Posts
    1,172
    Awards
    1
    Sorry for those gaps, I copied it straight out of Excel.. Here are the top 35 twin primes: Twin prime - Wikipedia, the free encyclopedia
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Jan 2008
    Posts
    2
    Quote Originally Posted by colby2152 View Post
    Sorry for those gaps, I copied it straight out of Excel.. Here are the top 35 twin primes: Twin prime - Wikipedia, the free encyclopedia


    I think you misunderstod me. I have to calculate the first 50 prime twins i Mathematica. Anybody who can help me how to do?
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Senior Member
    Joined
    Nov 2007
    Posts
    329
    Hey! Why don't you use the Help in Mathematica?? If you had typed "twin prime" in the search you would have probably found the command you need:
    Code:
    Select[Range[1000], PrimeQ[#] && NextPrime[#] == 2 + # &]
    And if you want the first 50 twin primes then choose a big enough number instead of 1000 for example 100000 and modify a little bit in the Select command to display only the first 50 numbers:
    Code:
    Select[Range[100000], PrimeQ[#] && NextPrime[#] == 2 + # &, 50]
    Follow Math Help Forum on Facebook and Google+

  6. #6
    GAMMA Mathematics
    colby2152's Avatar
    Joined
    Nov 2007
    From
    Alexandria, VA
    Posts
    1,172
    Awards
    1
    Quote Originally Posted by Bigas View Post
    I think you misunderstod me. I have to calculate the first 50 prime twins i Mathematica. Anybody who can help me how to do?
    I am not familiar with Mathematica. I am not sure if what I did in Excel could help you out, but you could do an if/then/while/for (whatever) loop starting at n=2, going from i=2 to i=n-1, and compare n/i - integer(n/i) and use that to see if any numbers are prime. They will be prime if none of those calculations come up as an integer. Then you can do another loop looking at a prime and the number two ahead of it.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Mathematica Table Column Lables and grid lines
    Posted in the Math Software Forum
    Replies: 2
    Last Post: February 6th 2010, 07:01 AM
  2. twin primes
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: December 13th 2009, 12:59 PM
  3. Twin Primes Problem
    Posted in the Number Theory Forum
    Replies: 2
    Last Post: July 11th 2009, 07:34 AM
  4. Porve the sum of twin primes is divisible by 12
    Posted in the Number Theory Forum
    Replies: 1
    Last Post: February 4th 2008, 03:15 PM
  5. Consecutive Twin Primes Proof
    Posted in the Number Theory Forum
    Replies: 2
    Last Post: December 18th 2005, 05:18 AM

Search Tags


/mathhelpforum @mathhelpforum