formula to calculate the nth prime

Hi,

Here is a formula to calculate the n-th prime, given the primes less than the n-th prime:

primorial(n) - (2*((EulerPhi(primorial(n)))+(EulerPhi(primorial(n))-(1/2*(primorial(n-1))))+(EulerPhi(primorial(n))-(primorial(n-1))))) = 2*primorial(n-2).

For example for x=7 and x=11 the formulas are:

2*3*5*x - (2*(((3-1)*(5-1)*(x-1)) + (((3-1)*(5-1)*(x-1))-(1/2*(2*3*5)) + (((3-1)*(5-1)*(x-1))-(2*3*5)) = 2*(2*3) x=7

2*3*5*7*x - (2*(((3-1)*(5-1)*(7-1)*(x-1)) + (((3-1)*(5-1)*(7-1)*(x-1))-(1/2*(2*3*5*7)) + (((3-1)*(5-1)*(7-1)*(x-1))-(2*3*5*7)) = 2*(2*3*5) x=11

This obviously isn't a very efficient formula but I was wondering if it is possible to find a larger prime with algebra given only smaller primes and yep it is! :D

cheers, Jamie

Reply to
Jamie M
Loading thread data ...

Whitespace Is Our Friend.

primorial(n) - (2* ( ( EulerPhi(primorial(n)) ) + ( EulerPhi(primorial(n)) - (1/2*(primorial(n-1))) ) + ( EulerPhi(primorial(n)) - (primorial(n-1)) ) ) ) = 2* primorial(n-2).

Why didn't you do some pretty obvious simplifications? I think this is a lot easier to follow:

primorial(n) - 6*EulerPhi(primorial(n)) + 3*primorial(n-1) = 2*primorial(n-2).

Further simplification:

primorial(n-1)*x -

6*EulerPhi(primorial(n-1))*(x-1) + 3*primorial(n-1) = 2*primorial(n-2).

primorial(n-1)*(x-1) -

6*EulerPhi(primorial(n-1))*(x-1) + 4*primorial(n-1) = 2*primorial(n-2).

( primorial(n-1) - 6*EulerPhi(primorial(n-1)) )*(x-1) = 2*primorial(n-2) - 4*primorial(n-1).

( 6*EulerPhi(primorial(n-1)) - primorial(n-1) )*(x-1) = 4*primorial(n-1) - 2*primorial(n-2)

( 6*((2-1)*(3-1)*(5-1)) - (2*3*5) )*(x-1) = 4*(2*3*5) - 2*(2*3)

18*(x-1) = 108, x = 7

( 6*((2-1)*(3-1)*(5-1)*(7-1)) - (2*3*5*7) )*(x-1) = 4*(2*3*5*7) - 2*(2*3*5)

78*(x-1) = 780, x = 11

( 6*((2-1)*(3-1)*(5-1)*(7-1)*(11-1)) - (2*3*5*7*11) )*(x-1) = 4*(2*3*5*7*11) - 2*(2*3*5*7)

( 6*(1*2*4*6*10) - (2330) )*(x-1) = 4*(2330) - 2*(210)

550*(x-1) = 8900

x = 17+

Okay. Now I see why you made it more complicated than necessary.

Anyway, remember that Whitespace Is Our Friend, for when you're not trolling.

Reply to
Jim Burns

Hi,

Could you simplify it an state it as x = ?

Thanks.

cheers, Jamie

Reply to
Jamie M

All odd numbers are prime:

1 - yes 3 - yes 5 - yes 7- yes 9 - no 11 - yes 13 - yes

Thus proven. 9 was just an experimental error...

-- Kevin Aylward

formatting link
- SuperSpice
formatting link

Reply to
Kevin Aylward

Hi,

Sorry wasn't meaning to troll! :) I actually didn't test it for prime 13, so just assumed it was correct, but obviously it isn't.

cheers, Jamie

Reply to
Jamie M

Hi,

"= 2*primorial(n-2)." is incorrect in the formula, It doesn't work beyond prime 11, the correct = x value is this sequence:

0,0,12,60,2400,47640,1277940,33219780,?

ie.

2*3 - (2*(((3-1)) + (((3-1))-(1/2*(2)) + (((3-1))-(2)=0 2*x - (2*(((x-1)) + (((x-1))-(1/2*(2)) + (((x-1))-(2)) =0 x=3

2*3*5 - (2*(((3-1)*(5-1)) + (((3-1)*(5-1))-(1/2*(2*3)) + (((3-1)*(5-1))-(2*3)=0

2*3*x - (2*(((3-1)*(x-1)) + (((3-1)*(x-1))-(1/2*(2*3)) + (((3-1)*(x-1))-(2*3)) =0 x=5

2*3*5*7 - (2*(((3-1)*(5-1)*(7-1)) + (((3-1)*(5-1)*(7-1))-(1/2*(2*3*5)) + (((3-1)*(5-1)*(7-1))-(2*3*5)) =12

2*3*5*x - (2*(((3-1)*(5-1)*(x-1)) + (((3-1)*(5-1)*(x-1))-(1/2*(2*3*5)) + (((3-1)*(5-1)*(x-1))-(2*3*5)) =12 x=7

2*3*5*7*x - (2*(((3-1)*(5-1)*(7-1)*(x-1)) + (((3-1)*(5-1)*(7-1)*(x-1))-(1/2*(2*3*5*7)) + (((3-1)*(5-1)*(7-1)*(x-1))-(2*3*5*7)) =60

2*3*5*7*x - (2*(((3-1)*(5-1)*(7-1)*(x-1)) + (((3-1)*(5-1)*(7-1)*(x-1))-(1/2*(2*3*5*7)) + (((3-1)*(5-1)*(7-1)*(x-1))-(2*3*5*7)) =60 x=11

2*3*5*7*11*13 - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1))-(1/2*(2*3*5*7*11)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1))-(2*3*5*7*11)) =2400

2*3*5*7*11*x - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(x-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(x-1))-(1/2*(2*3*5*7*11)) + (((3-1)*(5-1)*(7-1)*(11-1)*(x-1))-(2*3*5*7*11)) =2400 x=13

2*3*5*7*11*13*17 - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1))-(1/2*(2*3*5*7*11*13)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1))-(2*3*5*7*11*13))=47640

2*3*5*7*11*13*x - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(x-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(x-1))-(1/2*(2*3*5*7*11*13)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(x-1))-(2*3*5*7*11*13)) =47640 x=17

2*3*5*7*11*13*17*19 - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1))-(1/2*(2*3*5*7*11*13*17))

  • (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1))-(2*3*5*7*11*13*17))=1277940
2*3*5*7*11*13*17*x - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(x-1))
  • (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(x-1))-(1/2*(2*3*5*7*11*13*17))
  • (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(x-1))-(2*3*5*7*11*13*17)) =1277940 x=19

2*3*5*7*11*13*17*19*23 - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(23-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(23-1))-(1/2*(2*3*5*7*11*13*17*19))

  • (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(23-1))-(2*3*5*7*11*13*17*19))=33219780
2*3*5*7*11*13*17*19*x - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(x-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(x-1))-(1/2*(2*3*5*7*11*13*17*19))
  • (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(x-1))-(2*3*5*7*11*13*17*19)) =33219780 x=23

2*3*5*7*11*13*17*19*23*29 - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(23-1)*(29-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(23-1)*(29-1))-(1/2*(2*3*5*7*11*13*17*19*23))

  • (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(23-1)*(29-1))-(2*3*5*7*11*13*17*19*23))=33219780
2*3*5*7*11*13*17*19*x - (2*(((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(x-1)) + (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(x-1))-(1/2*(2*3*5*7*11*13*17*19))
  • (((3-1)*(5-1)*(7-1)*(11-1)*(13-1)*(17-1)*(19-1)*(x-1))-(2*3*5*7*11*13*17*19)) =33219780 x=29

I don't know the formula to find 0,0,12,60,2400,47640,1277940,33219780,? and without that this formula won't work to calculate the n-th prime...

cheers, Jamie

Reply to
Jamie M

Hi,

Try this might improve your results:

row_3 = 1,0,1,2,3,0;

For any number x that has prime(3)=5 as a factor, values on row_3 give the minimum distance to the next prime > x. ie. numbers with 5 as a factor: 5,10,15,20,25,30,35,40,45,50,55,60,.. using row3: 1,0,1,2,3,0; all numbers >5 up to 5+1 aren't prime all numbers >10 up to 10+0 aren't prime all numbers >15 up to 15+1 aren't prime all numbers >20 up to 20+2 aren't prime all numbers >25 up to 25+3 aren't prime all numbers >30 up to 30+0 aren't prime This pattern can be repeated indefinitely using the same repeating values on row3 ie: all numbers >35 up to 35+1 aren't prime all numbers >40 up to 40+0 aren't prime all numbers >45 up to 45+1 aren't prime all numbers >50 up to 50+2 aren't prime all numbers >55 up to 55+3 aren't prime all numbers >60 up to 60+0 aren't prime.

cheers, Jamie

Reply to
Jamie M

it's sitting there in front of your face!

The answer is 44!

Reply to
M Philbrook

snipped (apparently) claim of face sitting (apparently)

You should already know that the answer to everything is 42. :-)

Reply to
Long Hair

[...]

I really don't want to discourage you -- and I recognize that everyone has to start somewhere -- but you really need to improve your number theory game. Or just your playing-around-with-equations game.

I believe you if you say you're not trolling, but part of the reason that I thought you were trolling was that you had missed a very elementary simplification, something like combining 3*B + 2*B to get 5*B. It looked so obvious to me (once I had re-written your formula) that I assumed you were being intentionally obscure -- hence, trolling.

It's true that, the way you had written it, it was much harder to see than that, but part of what you need to improve is re-writing things to help you see such things. (see also: Whitespace Is Our Friend)

---- I came up with what seemed to me a considerable simplificiation ( 6*EulerPhi(primorial(n-1)) - primorial(n-1) )*(x-1) = 4*primorial(n-1) - 2*primorial(n-2) And you asked me how to solve it for x. I think you asked for x = something. That is what I mean by "solve for x".

I can do that, and I will. But this is a good example to show what I consider an essential technique for playing around with equations. I don't know if this has an official name, but I call it "chunking". One takes a big, messy part of an even bigger, messier formula and replaces it with something simple looking. You haven't really changed the formula, because the simple-looking thing still represents the big, messy thing.

Here, we can re-write ( 6*EulerPhi(primorial(n-1)) - primorial(n-1) )*(x-1) = 4*primorial(n-1) - 2*primorial(n-2) as B*(x-1) = C if we set B = ( 6*EulerPhi(primorial(n-1)) - primorial(n-1) ) and C = 4*primorial(n-1) - 2*primorial(n-2) Then we can solve for x: x = 1 + C/B and we can, if we wish, put the big messy things back: x = 1 + ( 4*primorial(n-1) - 2*primorial(n-2) ) / ( 6*EulerPhi(primorial(n-1)) - primorial(n-1) )

There might be further simplifications that can be made at this point. Or not, I haven't looked.

Chunking gets much more valuable when the same big, messy thing shows up more than once. This is something to keep in mind when you're think about how to slice apart your bigger, messier formula into chunks.

For example, in your primorial(n) - (2*((EulerPhi(primorial(n)))+(EulerPhi(primorial(n))-(1/2*(primorial(n-1))))+(EulerPhi(primorial(n))-(primorial(n-1))))) = 2*primorial(n-2) we could chunk p(n) = primorial(n) p(n-1) = primorial(n-1) p(n-2) = primorial(n-2) E(n) = EulerPhi(primorial(n)) and, doing nothing else, your formula gets much easier to understand. p(n) - (2*((E(n))+(E(n)-(1/2*(p(n-1))))+(E(n)-(p(n-1))))) = 2*p(n-2)

Of course, Whitespace is still Our Friend, though finding out how to use whitespace to help _you_ see how something big and messy is put together is something _you'll_ need to work out. p(n) - ( 2*( ( E(n) ) + ( E(n) - (1/2*(p(n-1))) ) + ( E(n) - (p(n-1)) ) ) ) = 2*p(n-2)

---- So: 1. Whitespace Is Our Friend. 2. Chunking Is Our Friend.

---- Elsethread, Kevin Aylward made a joke (an old one, but a good one) All odd numbers are prime:

1 - yes 3 - yes 5 - yes 7 - yes 9 - no 11 - yes 13 - yes

Thus proven. 9 was just an experimental error...

The point of the joke is that we don't do "experimental error" in math. If I say "all odd numbers are prime", I am taken to mean *ALL* odd numbers are prime, without exception. So, the thing said is definitely NOT proven.

The techniques that we use in order to be able to _say_ something _like_ "all odd numbers are prime" (but something else, something correct) -- to say it and be correct without exception -- are what most people refer to when they say "mathematics".

Just checking some of *ALL* is not one of those techniques. I think you can see why.

Reply to
Jim Burns

If Jamie works at this a little longer, he may rediscover the sieve of Eratosthenes

formatting link

Eratosthenes was born in 276 BC and died in 194 BC, so the idea has been around for a while.

--
Bill Sloman, Sydney
Reply to
bill.sloman

Hi,

Thanks, I tested that equation you solved for x, and got this output:

n x

0 1.4 1 1.4 2 2.5 3 4.333 4 7 5 11 6 16.47 7 26.49 8 47.69 9 149.97 10 -210.85 11 -74.14 12 -46.48 13 -35.65 14 -29.53 15 -25.41 ... 100 -7.014 (approx) 6400 -4.75 (approx) 6700 -4.73 (approx)

x slowly moves back towards 0, or else some limit close to -0 I guess, but it doesn't seem like it would go positive again. Any ideas on what that means? I had kind of expected x to just get larger.

cheers, Jamie

Reply to
Jamie M

Hi,

I added in one more thing to the formula, here is the Mathematica code, check the output seems pretty good now.

cheers, Jamie

Primorial[n_] := Times @@ Prime[Range[n]] For[abz = 123, abz < 200, abz++, n = abz; abc = Primorial[n] - (2*((EulerPhi[Primorial[n]]) + (EulerPhi[Primorial[n]] - (1/2*(Primorial[n - 1]))) + (EulerPhi[Primorial[n]] - (Primorial[n - 1])))); Print[abc/(abclast + 0.001)]; abclast = abc;

output:

1.348976534243001*10^-226 683.989 691.969 701.949 709.965 719.946 727.961 733.976 739.974 743.988 751.9526719532148 757.9668362865026 761.9805313827452 769.9465423396056 773.9759220645500 787.8960560349760 797.9261019362736 809.9097261477187 811.9825971824887 821.9213978739995 823.9780857485846 827.9612985662750 829.9734962971450 839.9139243059970 853.8843437256334 857.9533294400837 859.9650621337598 863.9491145184712 877.8786706147960 881.9454472262985 883.9568255746800 887.9413949127097 907.833398821066 911.938084265247 919.910417376421 929.896164220180 937.907559075739 941.931060152427 947.916810967374 953.915153591772 967.864550385730 971.924295456198 977.910548967700 983.908953949633 991.895549381174 997.905888215067 1009.869427857681 1013.914527503639 1019.901437135354 1021.922632944726 1031.875621586853 1033.919333053904 1039.895295864701 1049.871631980883 1051.914480626966 1061.869021523264 1063.911312845743 1069.888066778317 1087.822211432057 1091.896223536677 1093.905231913702 1097.893186005687 1103.881270893985 1109.879910759946 1117.868257590860 1123.877285719450 1129.875956749974 1151.793862928496 1153.893621256666 1163.852674711661 1171.861479189142 1181.850638283252 1187.868909918657 1193.867664277097 1201.856920631363 1213.836945399172 1217.873538177709
Reply to
Jamie M

Hi,

I don't want to discourage anyone either, with that being said here is a new example to calculate the nth prime (Mathematica code), however unfortunately it requires the nth prime, but I'd like to hope the formula can be fiddled with to take in nth-1 and give the nth prime!

Primorial[n_] := Times @@ Prime[Range[n]] For[n = 50, n < 200, n++, abczz = (Primorial[n] - (2*((EulerPhi[ Primorial[n]]) + (EulerPhi[ Primorial[n]] - (1/2*(Primorial[n - 1]))) + (EulerPhi[Primorial[n]] - (Primorial[n - 1]))))) / (Primorial[n - 1] - (2*((EulerPhi[ Primorial[n - 1]]) + (EulerPhi[ Primorial[n - 1]] - (1/2*(Primorial[n - 2]))) + (EulerPhi[Primorial[n - 1]] - (Primorial[n - 2]))))); Print[abczz + 0.001]; Print[Prime[n]]; ]

If you plug in the nth prime ie n=125, it outputs 691.97, and the nth prime is 691. So this requires to put in the same prime that it gives, not much use, but maybe it can be simplified :D

Here is the Mathematica output of running that code:

230.478 229 234.398 233 240.321 239 242.436 241 252.178 251 258.295 257 264.287 263 270.279 269 272.379 271 278.261 277 282.305 281 284.346 283 294.135 293 308.038 307 312.275 311 314.311 313 318.257 317 332.03 331 338.203 337 348.115 347 350.272 349 354.225 353 360.179 359 368.136 367 374.169 373 380.164 379 384.194 383 390.153 389 398.113 397 402.177 401 410.105 409 420.069 419 422.194 421 432.062 431 434.183 433 440.116 439 444.142 443 450.107 449 458.074 457 462.128 461 464.151 463 468.118 467 480.002 479 488.056 487 492.106 491 500.049 499 504.098 503 510.068 509 521.989 521 524.111 523 541.912 541 548.056 547 558.007 557 564.05 563 570.047 569 572.088 571 578.04 577 587.994 587 594.035 593 600.032 599 602.07 601 608.025 607 614.022 613 618.04 617 620.057 619 631.953 631 641.972 641 644.047 643 648.025 647 654.003 653 660. 659 662.035 661 673.939 673 678.011 677 683.99 683 691.97 691 701.95 701 709.966 709 719.947 719 727.962 727 733.977 733 739.975 739 743.989 743 751.954 751 757.968 757 761.982 761 769.948 769 773.977 773 787.897 787 797.927 797 809.911 809 811.984 811 821.922 821 823.979 823 827.962 827 829.974 829 839.915 839 853.885 853 857.954 857 859.966 859 863.95 863 877.88 877 881.946 881 883.958 883 887.942 887 907.834 907 911.939 911 919.911 919 929.897 929 937.909 937 941.932 941 947.918 947 953.916 953 967.866 967 971.925 971 977.912 977 983.91 983 991.897 991 997.907 997 1009.87 1009 1013.92 1013 1019.9 1019 1021.92 1021 1031.88 1031 1033.92 1033 1039.9 1039 1049.87 1049 1051.92 1051 1061.87 1061 1063.91 1063 1069.89 1069 1087.82 1087 1091.9 1091 1093.91 1093 1097.89 1097 1103.88 1103 1109.88 1109 1117.87 1117 1123.88 1123 1129.88 1129 1151.79 1151 1153.89 1153 1163.85 1163 1171.86 1171 1181.85 1181 1187.87 1187 1193.87 1193 1201.86 1201 1213.84 1213 1217.87 1217

cheers, Jamie

Reply to
Jamie M

Hi,

Could you solve this formula for x in Primorial[n]=2*3*5*7*11...*691*x ?

ie x as a prime larger than 691.

prime(n) = (Primorial[n] - (2*((EulerPhi[ Primorial[n]]) + (EulerPhi[ Primorial[n]] - (1/2*(Primorial[n - 1]))) + (EulerPhi[Primorial[n]] - (Primorial[n - 1]))))) / (Primorial[n - 1] - (2*((EulerPhi[ Primorial[n - 1]]) + (EulerPhi[ Primorial[n - 1]] - (1/2*(Primorial[n - 2]))) + (EulerPhi[Primorial[n - 1]] - (Primorial[n - 2])))));

cheers, Jamie

Reply to
Jamie M

I would substitute

Primorial[n] = Primorial[n-1]*x

EulerPhi[Primorial[n]] = EulerPhi[Primorial[n-1]]*(x-1)

and I think also prime(n) = x

then, since x only occurs as "x times some known coefficient", I'd collect all the x-multiple-terms on one side of '=' and all the constant-terms on the other.

That seems to be what you'd intended to do below, more or less, but with some x-dependent terms left on both sides.

Why do you think this will give you primes?

Reply to
Jim Burns

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.