4

Do we have any theory stating a relation between primes in binary system. I mean, in decimal system we have a pattern stating that "a number which is divided by 1 and itself is a prime".

This was learned in my school when i was kid. But modern computation is performed on bits, in sense they are 1's and 0's. But we calculate the prime nature based on our school knowledge. It works fine when the numbers are small. But questions calculating largest prime in integers, this logic doesn't make sense.

So if there exists any theory(may be already existing) stating a relation among primes in binary represention, then we can save lot of computing power. For ex, starting with a binary representation of prime, changing or adding bits yields next prime number saves lot of computational power.

This might not make sense. But these were my thoughts from last night. Please correct me if I am wrong or it doesn't make a sense at all.

digEmAll
  • 56,430
  • 9
  • 115
  • 140
  • 2
    "... an _integer greater than one_ which is divided by _only_ 1 and itself, is a prime." I'm pretty certain _all_ numbers are divisible by one and themselves, regardless of the chosen domain. – paxdiablo Jul 05 '12 at 08:53
  • 3
    @paxdiablo Zero is not divisible by itself. But, I'm just being an ass ;v) – Potatoswatter Jul 05 '12 at 08:56
  • @Potatoswatter: no, that's fine. Serves me right for being a pedantic PITA :-) – paxdiablo Jul 05 '12 at 08:57
  • The only guarantee you have is that all primes excluding 2 will have its least significant bit set to 1. – leppie Jul 05 '12 at 09:45
  • 1
    @Potatoswatter a being divisible by b in this case (ring algebra) means that there is a number c so that a = bc. So 0 *is* divisible by itself. It doesn't matter that the result of the division is undefined because you can use any number for c. One of the advantages is that the divisibility order is reflexive, with 0 as the top element. – starblue Jul 05 '12 at 11:37
  • @starblue Hmm, so the definition needs to be adjusted to "only itself, 1, 0, -1, and its additive inverse." Or just restrict everything to the positive integers. – Potatoswatter Jul 06 '12 at 02:44
  • @Potatoswatter No, you don't need to exclude 0 explicitly. Since 0 is divisible by any number it is as composite as it gets and certainly doesn't satisfy the "only" in the definition of prime. – starblue Jul 06 '12 at 07:49
  • @Potatoswatter No, the only number divisible by 0 is 0 itself. – starblue Jul 06 '12 at 08:27
  • @starblue Have you just written three replies to the first thing I wrote in this thread? Thanks for the refresher… but please stop. – Potatoswatter Jul 06 '12 at 08:30

6 Answers6

4

Binary is just writing numbers as a sum of powers of two. It's not significantly different from decimal in a mathematical sense. So no, there will not be any theorems in binary that don't have some parallel in decimal.

In decimal, no number ending in an even numeral or 5 can be prime, except 2 and 5. In binary, no number ending in 0 can be prime, except 10 (which is 2).

EDIT: See this answer I wrote a couple years ago for an example of how to quickly generate primes using binary arithmetic optimizations, not advanced math. It's just a sieve of Erastosthenes, but thousands-of-years-old math, predating even the decimal system, is still amenable to SSE vectorization.

Community
  • 1
  • 1
Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
  • if a question asked like this, whats next in the series, 10,11,101,111,1011,1101,10001, can only be found converting back them to decimal and finding the pattern relation? What could be a computational logic or program behind this if not asked to do in human way? – facebook-1800001831 Jul 05 '12 at 09:33
  • @facebook-1800001831 The number system doesn't make a difference. Any relevant algorithms don't depend very much on the radix base of computation, the same steps are performed by a human or a computer. – Potatoswatter Jul 05 '12 at 09:36
  • Computers do it in binary and only convert it to decimal for display. – starblue Jul 05 '12 at 11:44
  • so whats the point @starblue? are you saying that my hypothesis exist? @Potatoswatter, if in the case, its not a point of representing data in 1's and 0's. This system was invented for data representation in digital form. So, to make the computer understable whatever input we are throwing, it should shift the computational universe from digital to binary. – facebook-1800001831 Jul 05 '12 at 11:54
  • My point is poor or easy program would make computer hard to compute the given input. that makes some sense if we go other way. I mean, very much computable instructions makes cpu job easy. THERE MUST BE A WAY!..THERE MUST BE A WAY!.. – facebook-1800001831 Jul 05 '12 at 11:56
  • There is nothing special about binary or decimal numbers for computing primes. In either case you first define the arithmetic operations for the representation, and then you use these to test numbers for primality. So no, there seems to be no easy algorithm to find the next prime (or even some infinite sequence of primes), though AFAIK nobody can prove this rigorously. – starblue Jul 05 '12 at 12:21
  • point to be noted, if we use binary representation we use logical operators, shift operators but not airthmetic operators. that is the missing logic. decimal system need airthmetic relations among them and the same numbers in binary representation need logical relations. – facebook-1800001831 Jul 05 '12 at 12:59
4

Mersenne primes are interesting prime numbers whose binary representation doesn't include any 0 (so there are only 1s)

Karlotcha Hoa
  • 284
  • 3
  • 11
1

If you want to cut down on CPU cycles to establish primality of a number, you should look into Factorization using the eliptical curve method. I don't know exactly how it works, but it is very quick.

But, I am in agreement with all the comments. There is no advantage to manipulating the bits in a binary representation to establishing whether a number is prime or not.

You can also run prime factorization in Emacs with

  • M-x calc
  • put in a large number
  • k f
dadinck
  • 1,118
  • 1
  • 7
  • 8
  • If you want to cut down on the number of tests in a brute force method, you use only prime numbers for a test (if 7 isn't a factor, then 21 or 49 will also not be factors) and the end test will be the square root of the number. Of course, it might be easier just to use all odd numbers than to test if the trial number is prime. – dadinck Jul 06 '12 at 20:13
  • see the link in the edit to my answer for an example of that kind of optimization, taken to the extreme. – Potatoswatter Jul 06 '12 at 20:15
0

I dont know if it makes any sense to start this topic again but I couldnt find similar approaches to mine. So i tought lets think out of the box and in patterns. So i started to search for paterns in binary represenation of prime numbers. The first thing i found out was about the leading 0 for non prime numbers(except for 2) the next thing I found out was that primes below 100 start and end with 1 and few other interesting patterns. But there does not seem to be a consistant pattern or a set of patterns for all prime numbers. I guess if there would be one, some other computer scientist would find it out. It would be preharps easier to apply these patterns if they would exist to find larger primes which would make the decryption much faster and some authentifications much more insecure.

Does somebody also do research about binary primes or is it just me thinking too much out of the box?

0

One interesting aspect of the binary representation of prime numbers is that there are a few patterns, Take this code for example at the bottom. Every True (which is odd) is followed by a number that ends with the same number. For example, this prime 13, is an odd binary number, followed by 3 numbers that end with 0 before the next Prime(True). All of the binary path follows this pattern. Only Primes are odd in there binary representation, and the between numbers that follow them to the next true all END in the same number until the next prime, which is always even, until the next odd prime! Another interesting pattern. All 5's are always followed by numbers that end with 0! All 3's are followed by numbers ending in 8's! And so forth! 7's are followed by numbers ending with 2's. etc. I'm sure there is more patterns but this is very interesting and shows that there is some kind of underlying pattern to the binary number that represents all primes.

It get's even more interesting. When an even path ends, it's next number is always ending in the same number ending in odd. For example, when the 0 ending numbers path ends, the next prime ends with 1. And this is true for all the numbers, they all have a pair they connect with! When the numbers ending with 8's run end, the next number always ends in 9! And so forth

13 1103823372545 True
14 17661173960720 False
15 282578783371520 False
16 4521260533944320 False
17 72340168543109121 True

ss = ""
for x in range(3,100):
   if isprime(x):
      ss += "1"
   else:
      ss += "0"
   print(x, int(ss,16), isprime(x))

3 1 True
4 16 False
5 257 True
6 4112 False
7 65793 True
8 1052688 False
9 16843008 False
10 269488128 False
11 4311810049 True
12 68988960784 False
13 1103823372545 True
14 17661173960720 False
15 282578783371520 False
16 4521260533944320 False
17 72340168543109121 True
18 1157442696689745936 False
19 18519083147035934977 True
20 296305330352574959632 False
21 4740885285641199354112 False
22 75854164570259189665792 False
23 1213666633124147034652673 True
24 19418666129986352554442768 False
25 310698658079781640871084288 False
26 4971178529276506253937348608 False
27 79538856468424100062997577728 False
28 1272621703494785601007961243648 False
29 20361947255916569616127379898369 True
30 325791156094665113858038078373904 False
31 5212658497514641821728609253982465 True
32 83402535960234269147657748063719440 False
33 1334440575363748306362523969019511040 False
34 21351049205819972901800383504312176640 False
35 341616787293119566428806136068994826240 False
36 5465868596689913062860898177103917219840 False
37 87453897547038609005774370833662675517441 True
38 1399262360752617744092389933338602808279056 False
39 22388197772041883905478238933417644932464896 False
40 358211164352670142487651822934682318919438336 False
41 5731378629642722279802429166954917102711013377 True
42 91702058074283556476838866671278673643376214032 False
43 1467232929188536903629421866740458778294019424513 True
44 23475726867016590458070749867847340452704310792208 False
45 375611629872265447329131997885557447243268972675328 False
46 6009786077956247157266111966168919155892303562805248 False
47 96156577247299954516257791458702706494276857004883969 True
48 1538505235956799272260124663339243303908429712078143504 False
49 24616083775308788356161994613427892862534875393250296064 False
50 393857340404940613698591913814846285800558006292004737024 False
51 6301717446479049819177470621037540572808928100672075792384 False
52 100827479143664797106839529936600649164942849610753212678144 False
53 1613239666298636753709432478985610386639085593772051402850305 True
54 25811834660778188059350919663769766186225369500352822445604880 False
55 412989354572451008949614714620316258979605912005645159129678080 False
56 6607829673159216143193835433925060143673694592090322546074849280 False
57 105725274770547458291101366942800962298779113473445160737197588480 False
58 1691604396328759332657621871084815396780465815575122571795161415680 False
59 27065670341260149322521949937357046348487453049201961148722582650881 True
60 433050725460162389160351198997712741575799248787231378379561322414096 False
61 6928811607362598226565619183963403865212787980595702054072981158625537 True
62 110860985717801571625049906943414461843404607689531232865167698538008592 False
63 1773775771484825146000798511094631389494473723032499725842683176608137472 False
64 28380412343757202336012776177514102231911579568519995613482930825730199552 False
65 454086597500115237376204418840225635710585273096319929815726893211683192832 False
66 7265385560001843798019270701443610171369364369541118877051630291386931085312 False
67 116246168960029500768308331223097762741909829912657902032826084662190897364993 True
68 1859938703360472012292933299569564203870557278602526432525217354595054357839888 False
69 29759019253767552196686932793113027261928916457640422920403477673520869725438208 False
70 476144308060280835146990924689808436190862663322246766726455642776333915607011328 False
71 7618308928964493362351854795036934979053802613155948267623290284421342649712181249 True
72 121892942863431893797629676720590959664860841810495172281972644550741482395394899984 False
73 1950287085814910300762074827529455354637773468967922756511562312811863718326318399745 True
74 31204593373038564812193197240471285674204375503486764104184997004989819493221094395920 False
75 499273493968617036995091155847540570787270008055788225666959952079837111891537510334720 False
76 7988375903497872591921458493560649132596320128892611610671359233277393790264600165355520 False
77 127814014455965961470743335896970386121541122062281785770741747732438300644233602645688320 False
78 2045024231295455383531893374351526177944657952996508572331867963719012810307737642331013120 False
79 32720387700727286136510293989624418847114527247944137157309887419504204964923802277296209921 True
80 523526203211636578184164703833990701553832435967106194516958198712067279438780836436739358736 False
81 8376419251386185250946635261343851224861318975473699112271331179393076471020493382987829739776 False
82 134022708022178964015146164181501619597781103607579185796341298870289223536327894127805275836416 False
83 2144363328354863424242338626904025913564497657721266972741460781924627576581246306044884413382657 True
84 34309813253677814787877418030464414617031962523540271563863372510794041225299940896718150614122512 False
85 548957012058845036606038688487430633872511400376644345021813960172704659604799054347490409825960192 False
86 8783312192941520585696619015798890141960182406026309520349023362763274553676784869559846557215363072 False
87 140532995087064329371145904252782242271362918496420952325584373804212392858828557912957544915445809152 False
88 2248527921393029269938334468044515876341806695942735237209349980867398285741256926607320718647132946432 False
89 35976446742288468319013351488712254021468907135083763795349599693878372571860110825717131498354127142913 True
90 575623147876615493104213623819396064343502514161340220725593595102053961149761773211474103973666034286608 False
91 9209970366025847889667417981110337029496040226581443531609497521632863378396188371383585663578656548585728 False
92 147359525856413566234678687697765392471936643625303096505751960346125814054339013942137370617258504777371648 False
93 2357752413702617059754859003164246279550986298004849544092031365538013024869424223074197929876136076437946368 False
94 37724038619241872956077744050627940472815780768077592705472501848608208397910787569187166878018177223007141888 False
95 603584617907869967297243904810047047565052492289241483287560029577731334366572601106994670048290835568114270208 False
96 9657353886525919476755902476960752761040839876627863732600960473243701349865161617711914720772653369089828323328 False
97 154517662184414711628094439631372044176653438026045819721615367571899221597842585883390635532362453905437253173249 True
98 2472282594950635386049511034101952706826455008416733115545845881150387545565481374134250168517799262486996050771984 False
99 39556521519210166176792176545631243309223280134667729848733534098406200729047701986148002696284788199791936812351744 False
oppressionslayer
  • 6,942
  • 2
  • 7
  • 24
  • Oh no, don't say that, it was autogenerated. Now i'm going to have to change it! BTW, did you like the patterns i found with the ending numbers? – oppressionslayer Jun 20 '20 at 13:05
  • 1
    I will upload a picture later today. The pattern is that you always know what ending number will be next once you know the pattern. Looking at the ending numbers only. Like 8 is always followed by 9. 1 is always followed by 6. You can guess the next ending number once you know the pattern. 4 always follows 9. etc. There;s no randomness to it, you actually know the next ending number once you have the pattern, the only thing you don't know is how often those ending numbers repeat. – oppressionslayer Jun 20 '20 at 13:12
0

I found the following information interesting regarding this subject. George Spelvin wrote the following in an email thread.

One thing I note is that the advice in the comments to choose a prime number is misquoting Knuth! Knuth says (vol. 3 section 6.4) the number should be relatively prime to the word size, which for binary computers simply means odd.

https://lwn.net/Articles/687494/

Clay Risser
  • 3,272
  • 1
  • 25
  • 28