This commit is contained in:
Miloslav Ciz 2024-03-14 23:30:14 +01:00
parent 6ac96e5e81
commit a8a438148b
33 changed files with 1816 additions and 1753 deletions

View file

@ -1,6 +1,6 @@
# Prime Number
Prime number (or just *prime*) is a [whole](integer.md) positive [number](number.md) only divisible by 1 and itself, except for the number [1](one.md). I.e. prime numbers are 2, 3, 5, 7, 11, 13, 17 etc. Non-prime numbers are called *composite numbers*. Prime numbers are extremely important, [interesting](interesting.md) and mysterious for their properties and distribution among other numbers, they have for millennia fascinated [mathematicians](math.md), nowadays they are studied in the math subfield called [number theory](number_theory.md). Primes are for example essential in [asymmetric cryptography](asymmetric_cryptography.md). Primes can be seen as the opposite of [highly composite numbers](highly_composite_number.md) (also antiprimes, numbers that have more divisors than any lower number).
Prime number (or just *prime*) is a [whole](integer.md) positive [number](number.md) only divisible by 1 and itself, except for the number [1](one.md). I.e. prime numbers are 2, 3, 5, 7, 11, 13, 17 etc. Non-prime numbers are called *composite numbers*. Ask any mathematician and you'll learn that prime numbers are more than just highly important, they are [interesting](interesting.md) and mysterious for their intricate properties and distribution among other numbers, they have for millennia fascinated [mathematicians](math.md); nowadays they are studied in the math subfield called [number theory](number_theory.md). Primes are also of practical use, for example in [asymmetric cryptography](asymmetric_cryptography.md). Primes can be seen as the opposite of [highly composite numbers](highly_composite_number.md) (also antiprimes, numbers that have more divisors than any lower number). Numbers of comparable status and similarly mysterious properties to prime numbers are for example [perfect numbers](perfect_number.md), whose importance is however a bit diminished by current lack of practical use.
```
.##.#.#...#.#...#.#...#.....#.#.....#...#.#...#.....#.....#.#.....#...
@ -8,7 +8,6 @@ Prime number (or just *prime*) is a [whole](integer.md) positive [number](number
*Prime number positions up to 70.*
The largest known prime number as of 2022 is 2^82589933 - 1 (it is so called [Mersenne prime](mersenne_prime.md), i.e. a prime of form 2^N - 1).
Every natural number greater than 1 has a unique **prime factorization**, i.e. a [set](set.md) of prime numbers whose product it is. For example 75 is a product of three primes: 3 * 5 * 5. This is called the *fundamental theorem of arithmetic*. Naturally, each prime has a factorization consisting of a single number -- itself -- while factorizations of non-primes consist of at least two primes. To mathematicians prime numbers are what chemical elements are to chemists -- a kind of basic building blocks.
@ -86,6 +85,10 @@ There also exists a term **pseudoprime** -- it stands for a number which is not
**[Fun](fun.md) with primes**: thanks to their interesting, mysterious and [random](randomness.md) nature, primes can be played around -- of course, you can examine them mathematically, which is always fun, but you can also play sort of [games](game.md) with them. For example the prime race: you make two teams of primes, one that gives 1 modulo 4, the other one that gives 3; then you go prime by prime and add points to each team depending on which one the prime falls in; the interesting thing is that team 3 is almost always in lead just by a tiny amount (this is known as Chebyshev bias, only after 2946 primes team 1 gets in the lead for a while, then at 50378 etc.). Similar thing can be done by evaluating the Mobius function: set total sum to 0, then go number by number and if it only has unique prime factors, add 1 if the number of those factors is even, otherwise subtract 1 -- see how the function behaves. Of course you can go crazy, make primes paint pictures or compose [music](music.md) -- people also like to do this with digits of numbers, e.g. those of [pi](pi.md) or [e](e.md).
**Can we generalize the concept of prime numbers?** Yeah, sure, why not? The ways are many, we'll rather run into the issue of analysis paralysis -- choosing the interesting generalization of out of the many possible ways. The above mentioned pseudoprimes, superprimes and twin primes are examples of generalizing primes, another one is e.g. defining so called **almost primes** -- a number is *n*-almost-prime if it has *n* prime factors, so 1-almost-primes are just regular primes (they have 1 prime divisor -- themselves) but then there are 2 almost primes like 9 or 15 that are kind of closer to being primes than let's say 5-almost-primes such as 48 or 80. I.e. we took the idea of numbers having either none (primes) or some (non-primes) divisors and generalized it by says a number is more prime like if it has fewer divisors. Similarly we may try to play on this observation: a non-prime is a number that is divisible by something, i.e. there is some number that when dividing the original number gives remainder after division zero; primes are those for which no number gives remainder zero, but some primes might be considered "weaker" by giving very low or very high remainder such as 1, i.e. being "not quite but almost" divisible by something (of course we have to somehow account for the fact that low divisors can only ever give low remainders) -- ideal prime would have remainders after division near the half of the dividing number (it would dodge multiples of other numbers with some margin), which we can formalize and define kind of "prime strength".
TODO: generalization to non integers? does it exist?
## Algorithms
**Primality test**: testing whether a number is a prime is quite easy and not computationally difficult (unlike factoring the number). A [naive](naive.md) algorithm is called *trial division* and it tests whether any number from 2 up to the tested number divides the tested number (if so, then the number is not a prime, otherwise it is). This can be [optimized](optimization.md) by only testing numbers up to the [square root](sqrt.md) (including) of the tested number (if there is a factor greater than the square root, there is also another smaller than it which would already have been tested). A further simple optimization is to to test division by 2, 3 and then only numbers of the form 6q +- 1 (other forms are divisible by either 2 or 3, e.g 6q + 4 is always divisible by 2). Further optimizations exist and for maximum speed a [look up table](lut.md) may be used for smaller primes. A simple [C](c.md) function for primality test may look e.g. like this:
@ -122,4 +125,5 @@ Prime generation: TODO
## See Also
- [perfect number](perfect_number.md)
- [happy number](happy_number.md)