mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Blogorrhea > ONeil

Reply
 
Thread Tools
Old 2020-11-09, 07:25   #1
ONeil
 
Dec 2017

24×3×5 Posts
Minus A stab at Twin Primes, Pour on the Steak Sauce

Warning: if you wish to be a prime number theorist, then you
have to realize, as the integers grow the prime gaps increase too! So
predicting prime numbers is near impossible at the very large scale! So for
most prime number formulas, this one works best at the lower scale. User
beware. You must enter a Prime to find the twin prime!

I built this twin prime finder for speed so enjoy it kicks ass for speed I mean just check the times and you will scratch your head. Now if you must find your twin prime then input its twin ok on the lower end! It will find the higher integer Twin Prime guaranteed. Also for you seekers out there I built in a modular search for this code and when all zeros come up, check the prime window for at least a prime. For Huge prime who can guarantee it, I'm just saying







Code:
print('''Warning: if you wish to be a prime number theorist, then you
have to realize, as the integers grow the prime gaps increase too!  So
predicting prime numbers is near impossible at the very large scale!  So for
most prime number formulas, this one works best at the lower scale.  User
beware.  You must enter a Prime to find the twin prime!''')
import time
start_time = time.time()

while True:
	n = int(input("Enter a prime number: "))
	if n % 2 != 0:
		t = (((2*n)//2)) + ((3*(n+2)//3))
		ttl = (((2*n)//2)) + ((3*(n+2)//3)) + (((2*n+3))) - ((3*(n+2)//3))
		
		ta = (((2*n)//2))
		tb = ((3*(n+2)//3))
		print('____________')
		print(ttl%6,'When all Zero likely twin primes or one prime')
		
		print(t%3)
		print(t%8)
		print('____________')
		print(ta,tb,"Prime numbers show here")
		
		
		e = int(time.time() - start_time)
		print('{:02d}:{:02d}:{:02d}'.format(e // 3600, (e % 3600 // 60), e % 60))
ONeil is offline   Reply With Quote
Old 2020-11-09, 08:08   #2
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

611510 Posts
Default

It might be fast, but it is wrong.

There is no sense in driving at lightning speed when you are driving in the wrong direction.
retina is online now   Reply With Quote
Old 2020-11-09, 08:10   #3
ONeil
 
Dec 2017

F016 Posts
Default

Quote:
Originally Posted by retina View Post
It might be fast, but it is wrong.

There is no sense in driving at lightning speed when you are driving in the wrong direction.
it works for me show me the error I'm picking off many twin primes
ONeil is offline   Reply With Quote
Old 2020-11-09, 08:17   #4
ONeil
 
Dec 2017

24·3·5 Posts
Question

Quote:
Originally Posted by retina View Post
It might be fast, but it is wrong.

There is no sense in driving at lightning speed when you are driving in the wrong direction.
t = (((2*n)//2)) + ((3*(n+2)//3))

Are you suggesting I should just do this retina?

t = (( n ) + (n+2))
ONeil is offline   Reply With Quote
Old 2020-11-09, 08:36   #5
ONeil
 
Dec 2017

24×3×5 Posts
Lightbulb

Quote:
Originally Posted by retina View Post
It might be fast, but it is wrong.

There is no sense in driving at lightning speed when you are driving in the wrong direction.
Your wrong, and here is why the modular arithmetic is great for prediction and helps when its all zero so the approach is to to check when all is zero or 2 zero's and the last is a 4.
ONeil is offline   Reply With Quote
Old 2020-11-09, 10:15   #6
Viliam Furik
 
"Viliam Furík"
Jul 2018
Martin, Slovakia

2×13×17 Posts
Default

Quote:
Originally Posted by ONeil View Post
Your wrong, and here is why the modular arithmetic is great for prediction and helps when its all zero so the approach is to to check when all is zero or 2 zero's and the last is a 4.
retina was saying, that no matter how fast you make your code, it's not useful, at all...

If you have to put in the smaller of the two KNOWN twin primes, the only purpose of that code is to print out p+2. Anything more is unnecessary, as is anything less -> If you know it's the smaller twin, why even bother printing out p+2??
Viliam Furik is offline   Reply With Quote
Old 2020-11-09, 11:52   #7
mathwiz
 
Mar 2019

149 Posts
Default

What's the point of this code?

If you know p prime, it just computes p+2? (in which case... why not just add 2)?

Or is it that you know p prime, and it computes p+2 *and* tests it for primality? (in which case, why not just use any of the existing primality testing algorithms, which are actually correct?)
mathwiz is offline   Reply With Quote
Old 2020-11-09, 13:34   #8
Dr Sardonicus
 
Dr Sardonicus's Avatar
 
Feb 2017
Nowhere

444810 Posts
Default

Quote:
Originally Posted by ONeil View Post
<snip>
Code:
<snip>
		ta = (((2*n)//2))
		tb = ((3*(n+2)//3))
<snip>
Quote:
KIRK: Mister Spock, is this ship headed for Ariannus?

SPOCK: Negative, Captain. The Enterprise is now moving in a circular course.

SCOTT: And at warp ten, we're going nowhere mighty fast.
-- STAR TREK, "Let That Be Your Last Battlefield"
Dr Sardonicus is offline   Reply With Quote
Old 2020-11-13, 03:43   #9
swishzzz
 
Jan 2012
Toronto, Canada

3×19 Posts
Default

Code:
print('''Warning: if you wish to be a prime number theorist, then you
have to realize, as the integers grow the prime gaps increase too!  So
predicting prime numbers is near impossible at the very large scale!  So for
most prime number formulas, this one works best at the lower scale.  User
beware.  You must enter a Prime to find the twin prime!''')
import time
start_time = time.time()

while True:
	n = int(input("Enter a prime number: "))
	if n % 2 != 0:
		t = (((2*n)//2)) + ((3*(n+2)//3))
		ttl = (((2*n)//2)) + ((3*(n+2)//3)) + (((2*n+3))) - ((3*(n+2)//3))
		
		ta = (((2*n)//2))
		tb = ((3*(n+2)//3))
		print('____________')
		print(ttl%6,'When all Zero likely twin primes or one prime')
		
		print(t%3)
		print(t%8)
		print('____________')
		print(ta,tb,"Prime numbers show here")
		
		
		e = int(time.time() - start_time)
		print('{:02d}:{:02d}:{:02d}'.format(e // 3600, (e % 3600 // 60), e % 60))
As a python developer the formatting here drives me nuts. Disregarding the content of the actual code itself, please
  • Use 4 spaces per indent level
  • Remove the unnecessary bracketing. You should know that * and / have precedence over + and -.
  • Put spaces after operators and commas
  • Be consistent in your use of '' and "" quotes
  • Put your imports at the very top of the code
swishzzz is offline   Reply With Quote
Old 2020-11-13, 13:34   #10
Dr Sardonicus
 
Dr Sardonicus's Avatar
 
Feb 2017
Nowhere

25×139 Posts
Default

Quote:
Originally Posted by swishzzz View Post
<snip>
Disregarding the content of the actual code itself,
<snip>
Good move. If you look too hard for any content, you'll hurt your eyes.
Quote:
<snip>
  • Remove the unnecessary bracketing. You should know that * and / have precedence over + and -.
    <snip>
Being unfamiliar with Python, I had to look up // (it's "floor divide"), and has the same priority as * and /. Thus, apparently in spite of the OP's best efforts, this thread has served a constructive purpose. I've learned something!

If there is any reason for the unnecessary bracketing other than making the code harder to read, I am suffering a failure of imagination as to what it could be.

Just out of curiosity, is there a generic term for calculations specifically designed not to do anything?
Dr Sardonicus is offline   Reply With Quote
Old 2020-11-13, 14:33   #11
retina
Undefined
 
retina's Avatar
 
"The unspeakable one"
Jun 2006
My evil lair

5·1,223 Posts
Default

Quote:
Originally Posted by Dr Sardonicus View Post
Just out of curiosity, is there a generic term for calculations specifically designed not to do anything?
Yes, they are speed-up computations.

So whenever someone says it isn't fast enough, then you just remove one of them and now it is faster. It's pure genius!
retina is online now   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
find very easy twin prime in the infamy twin primes hal1se Miscellaneous Math 13 2018-11-05 16:34
Mersenne Primes p which are in a set of twin primes is finite? carpetpool Miscellaneous Math 3 2017-08-10 13:47
Twin Primes Computer Science & Computational Number Theory 171 2013-05-14 02:57
OT: Twin Primes R.D. Silverman Math 8 2005-07-15 21:56
Twin primes again Chris Card Math 1 2005-05-26 14:18

All times are UTC. The time now is 08:51.

Tue Apr 13 08:51:19 UTC 2021 up 5 days, 3:32, 1 user, load averages: 0.86, 1.33, 1.45

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.