mersenneforum.org Semiprime Squared Prime Test ¿
 Register FAQ Search Today's Posts Mark Forums Read

 2020-12-05, 01:58 #1 ONeil   Dec 2017 24×3×5 Posts Semiprime Squared Prime Test ¿ If you guys don't like this than you all must hate primes and I'm leaving. This little puppy code produces primes up the ying yang and if you know how to code then you can remove the prime checker and see if the outputs for Huge primes produce too and I feel they do! Code: print('''SemiPrime Squared Prime test, Good for 5 digits and a little more on input!''') import time while True: start_time = time.time() p = int(input("Enter a prime number: ")) a = (((p*5)**2)-2) c = (((p*2)**2)+1) e = (((p*3)**2)-2) g = (((p*7)**2)-2) i = (((p*11)**2)-20) k = (((p*13)**2)-2) b = (p*5) d = (p*2) f = (p*3) h = (p*7) j = (p*11) l = (p*13) def isPrime(n) : # Corner cases if (n <= 1) : return False if (n <= 3) : return True # This is checked so that we can skip # middle five numbers in below loop if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True # Driver Program if (isPrime(a)) : print("|a| PRIME!",a,'|a|') else : print("|a| false",a,'|a|') if(isPrime(a)) : print("|a| PRIME!",a,'|a|') else : print("|a| false",a,'|a|') print(b,'|b|Semiprime product always of Five') if (isPrime(c)) : print("|c| PRIME!",c,'|c|') else : print("|c| false",c,'|c|') if(isPrime(c)) : print("|c| PRIME!",c,'|c|') else : print("|c| false",c,'|c|') print(d,'|d|Semiprime product always of Two') if (isPrime(e)) : print("|e| PRIME!",e,'|e|') else : print("|e| false",e,'|e|') if(isPrime(e)) : print("|e| PRIME!",e,'|e|') else : print("|e| false",e,'|e|') print(f,'|f|Semiprime product always of Three') if (isPrime(g)) : print("|g| PRIME!",g,'|g|') else : print("|g| false",g,'|g|') if(isPrime(g)) : print("|g| PRIME!",g,'|g|') else : print("|g| false",g,'|g|') print(h,'|h|Semiprime product always of Seven') if (isPrime(i)) : print("|i| PRIME!",i,'|i|') else : print("|i| false",i,'|i|') if(isPrime(i)) : print("|i| PRIME!",i,'|i|') else : print("|i| false",i,'|i|') print(j,'|j|Semiprime product always of Eleven') if (isPrime(k)) : print("|k| PRIME!",k,'|k|') else : print("|k| false",k,'|k|') if(isPrime(i)) : print("|k| PRIME!",k,'|k|') else : print("|k| false",k,'|k|') print(l,'|l|Semiprime product always of Thirteen') print('If Top Prime and Bottom false, than its Prime') e = int(time.time() - start_time) print('{:02d}:{:02d}:{:02d}'.format(e // 3600, (e % 3600 // 60), e % 60))
2020-12-05, 03:17   #2
retina
Undefined

"The unspeakable one"
Jun 2006
My evil lair

32×23×29 Posts

Quote:
 Originally Posted by ONeil If you guys don't like this than you all must hate primes ...
What are you trying to achieve with that statement?

The conclusion doesn't follow from the premise.

 2020-12-05, 04:21 #3 ONeil   Dec 2017 24×3×5 Posts I just spotted something about this code. Test any number one before a Twin Prime and the middle of twins and just one after the Twins and don't forget to test the Twins you often always get a Prime output and for some odd reason you don't the next prime produces a prime.
2020-12-05, 07:54   #4
swishzzz

Jan 2012

22·13 Posts

Quote:
 if you know how to code
We should be the ones asking you this rather than the other way around. Evidently it seems like you have learned nothing since the last pointless Python script you produced. So before you post anything else on this forum why don't you sit down with a Python textbook (Think Python: How to Think Like a Computer Scientist is a good one, as are many other ones you can find with simple google search) and learn more on how to actually generate good code with good style - e.g.
• No useless print statements scattered all over the place (some are even copy pasted instances right next to each other in execution order)
• 4 spaces per indent level (not 8)
• No unnecessary brackets like (((p*3)**2)-2)
• Variable names that are descriptive rather than one letter long. Or at least put comments in the code so a reader can figure out what the hell you're trying to do. Why did you define so many random values of the form (x*n)**2 - k in the first place?
• Actually show an example input, what the output is, and why that's important. While we're at it you should do some simple tests on your functions, so that your function isPrime doesn't report 2 as composite, for example.
• This will be a harder one, but do you have any idea how long this will take for an input p of say 20 digits? 100 digits? Those are not "huge primes" by any standards.

So please do us all a favor and start educating yourself on some Python/coding/number theory basics before you make another thread on this forum. It'll make both your time and our time much more productive.

2020-12-05, 08:01   #5
retina
Undefined

"The unspeakable one"
Jun 2006
My evil lair

177316 Posts

Quote:
 Originally Posted by swishzzz [*] 4 spaces per indent level (not 8)
I use tab characters. And my tab width is 8.

You can all hate me now, I don't care. Eight is the "correct" number, always. No need for all those wasteful space-space-space-space-space-space-space-space... things, using up the precious HDD capacity.

Every byte matters.

2020-12-05, 08:15   #6
swishzzz

Jan 2012

22·13 Posts

Quote:
 Originally Posted by retina I use tab characters. And my tab width is 8.
That's actually a fair point, I think there is a heuristic for HTML pages where the ones that are written using tabs are 5-15% smaller and takes similarly less time to load. Or maybe you have a script with tens of thousands of lines where that might actually make a difference. I guess it isn't necessarily universal even among Python developers but it's in the official style guidelines (PEP 8).

Funnily I came upon this while doing a quick search...

https://stackoverflow.blog/2017/06/1...oney-use-tabs/

2020-12-05, 08:39   #7
retina
Undefined

"The unspeakable one"
Jun 2006
My evil lair

32×23×29 Posts

Quote:
 Originally Posted by swishzzz I guess it isn't necessarily universal even among Python developers but it's in the official style guidelines (PEP 8).
Quote:
 Worth noting that PEP-8 was never meant to be used for anything outside the Python standard library. There’s no reason to adhere to it in your own code, and there’s no technical rationale behind [many of] its recommendations.

2020-12-06, 00:55   #8
ONeil

Dec 2017

24010 Posts

Quote:
lol You feeling Pepy today

 2020-12-06, 06:45 #9 CRGreathouse     Aug 2006 3×1,987 Posts Let me break this down. You have 12 polynomials in p (let's suppose this is prime), six of which are quadratic and six of which are linear (constant multiples of p, in fact). But it's pretty obvious that a prime multiple of a prime will be semiprime, so that's true but trivial, and the quadratics will be less than 10% prime, less than 1% prime, less than 0.0000001% prime, ..., by sieve theory. (More can be said, conjecturally, about the relative density of the primes in each, though. Interested?) Aside: Your code really needs work; you should have a function, say "test", where you can just call test(25*p**2 - 2, '|a|') and have the appropriate things done. Or better yet, scrap the need for the second argument entirely and apply the function directly to an array, like so: Code: def test(n): # function definition goes here valuesToTest = [25*p**2-2, 4*p**2+1, 9*p**2-2, 49*p**2-2, 121*p**2-20, 169*p**2-2] results = map(test, valuesToTest) which could be simpler if you had a regular structure to the values you were using: Code: def test(n): # function definition goes here initialPrimes = [2, 3, 5, 7, 11, 13] offsets = [1, -2, -2, -2, -20, -2] valuesToTest = [ q*p for q in initialPrimes ] valuesToTest = [ k**2 for k in valuesToTest ] valuesToTest = [sum(x) for x in zip(valuesToTest, offsets)] results = map(test, valuesToTest) OK, well, conceptually simpler anyway. (My Python could no doubt be improved.) The point is, there's no reason to repeat the test code for every case.

 Similar Threads Thread Thread Starter Forum Replies Last Post ONeil ONeil 2 2020-12-01 04:14 sweety439 sweety439 11 2020-09-23 01:42 enzocreti enzocreti 3 2020-09-02 16:35 danaj Computer Science & Computational Number Theory 12 2018-10-14 03:16 siegert81 Math 6 2010-12-28 15:17

All times are UTC. The time now is 14:46.

Sat Jan 23 14:46:31 UTC 2021 up 51 days, 10:57, 0 users, load averages: 2.39, 2.26, 2.45