Add primes

master
Miloslav Ciz 2 years ago
parent 80b9b75a58
commit ccda82a491

@ -4,4 +4,4 @@
For us the most important part of 4chan is the technology board known as /g/ (for technoloGEE). Browsing /g/ can bring all kinds of emotion, it's a place of relative freedom and somewhat beautiful chaos where all people from absolute retards to geniuses argue about important and unimportant things, brands, tech news and memes, and constantly advise each other to kill themselves. Sometimes the place is pretty toxic and not good for mental health.
2022 update: abandon ship, /g is officially unusable, a bunch of capitalist children arguing about brands, [productivity cult](productivity_cult.md), crypto, consumerism, "open soars", no trace of [free software](free_software.md). Not worth it anymore.
2022 update: abandon ship, /g is officially unusable, a bunch of capitalist children arguing about brands, [productivity cult](productivity_cult.md), crypto, consumerism, "open soars", no trace of [free software](free_software.md). Not worth it anymore. You can still read very old thread on archives such as https://desuarchive.org/g/page/280004/.

@ -0,0 +1,82 @@
# Function
Function is a very basic term in [mathematics](math.md) and [programming](programming.md) with a slightly different meanings in each: mathematical function maps numbers to other numbers, a function in programming is a subprograms to which we divide a bigger program. Well, that's pretty simplified but those are the basic ideas. A more detailed explanation will follow.
## Mathematical Functions
In mathematics functions can be defined and viewed from different angles but a function is basically anything that assigns each member of some set *A* (so called *domain*) exactly one member of a potentially different set *B* (so called *codomain*). A typical example of a function is an equation that from one "input number" computes another number, for example:
*f(x) = x / 2*
Here we call the function *f* and say it takes one [parameter](parameter.md) (the "input number") called *x*. The "output number" is defined by the right side of the equation, *x / 2*, i.e. the number output by the function will be half of the parameter (*x*). The domain of this function (the set of all possible numbers that can be taken as input) is the set of [real numbers](real_number.md) and the codomain is also the set of real numbers. This equation assigns each real number *x* another real number *x / 2*, therefore it is a function.
{ I always imagined functions as kind of little boxes into which we throw a number and another number falls out. ~drummyfish }
Now consider a function *f2(x) = 1 - 1 / x*. Note that in this case the domain is the set of real number minus [zero](zero.md); the function can't take zero as an input because we can't divide by zero. The codomain is the set of real numbers minus one because we can't ever get one as a result.
Another common example of a function is the [sine](sin.md) function that we write as *sin(x)*. It can be defined in several ways, commonly e.g. as follows: considering a [right triangle](right_triangle.md) with one of its angles equal to *x* [radians](radian.md), *sin(x)* is equal to the ratio of the side opposing this angle to the triangle [hypotenuse](hypotenuse.md). For example *sin(pi / 2) = sin(45 degrees) = 1 / sqrt(2) ~= 0.71*. The domain of sine function is again the set of real number but its codomain is only the set of real numbers between 0 and 1 because the ratio of said triangle sides can never be negative or greater than 1, i.e. sine function will never yield a number outside the interval <0,1>.
Note that these functions have to satisfy a few conditions to really be functions. Firstly each number from the domain must be assigned exactly one number (although this can be "cheated" by e.g. using a set of couples as a codomain), even though multiple input numbers can give the same result number. Also importantly **the function result must only depend on the function's parameter**, i.e. the function mustn't have any memory or inside state and it mustn't depend on any external factors (such as current time) or use any randomness (such as a dice roll) in its calculation. For a certain [argument](argument.md) (input number) a function must give the same result every time. For this reason not everything that transforms numbers to other numbers can be considered a function.
Functions can have multiple parameters, for example:
*g(x,y) = (x + y) / 2*
The function *g* computes the average of its two parameters, *x* and *y*. Formally we can see this as a function that maps elements from a set of couples of real numbers to the set of real numbers.
Of course function may also work with just [whole numbers](whole_number.md), also [complex numbers](complex_number.md), [quaternions](quaternion.md) and theoretically just anything crazy like e.g. the set of animals :) However in these "weird" cases we generally no longer use the word *function* but rather something like a *[map](map.md)*. In mathematical terminology we may hear things such as a *real function of a complex parameter* which means a function that takes a complex number as an input and gives a real number result.
To get better overview of a certain function we may try to represent it graphically, most commonly we make function **[plots](plot.md)** also called **graphs**. For a function of a single parameter we draw graphs onto a grid where the horizontal axis represents number line of the parameter (input) and the vertical axis represents the result. For example plotting a function *f(x) = ((x - 1) / 4)^2 + 0.8* may look like this:
```
|f(x)
2+
'.._ |
''--1+.____...--'
___,__,__|__,__,_____x
-2 -1 |0 1 2
-1+
|
-2+
|
```
This is of course done by plotting various points [*x*,*f(x)*] and connecting them by a line.
Plotting functions of multiple parameters is more difficult because we need more axes and get to higher [dimensions](dimension.md). For functions of 2 parameters we can draw e.g. a [heightmap](heightmap.md) or create a [3D model](3d_model.md) of the surface which the function defines. 3D functions may in theory be displayed like 2D functions with added time dimension (animated) or as 3D density clouds. For higher dimensions we usually resort to some kind of cross-section or [projection](projection.md) to lower dimensions.
Functions can have certain properties such as:
- being **[bijective](bijection.md)**: A bijective function pairs exactly one element from the domain with one element from codomain and vice versa, i.e. for every result (element of codomain) of the function it is possible to unambiguously say which input created it. For bijective functions we can create **[inverse functions](inverse_function.md)** that reverse the mapping (e.g. [arcus sine](asin.md) is the inverse of a [sin](sin.md) function that's limited to the interval where it is bijective). For example *f(x) = 2 * x* is bijective with its inverse function being *f^(-1)(x) = x / 2*, but *f2(x) = x^2* is not bijective because e.g. both 1 and -1 give the result of 1.
- being an **[even function](even_function.md)**: For this function it holds that *f(x) = f(-x)*, i.e. the plotted function is symmetric by the vertical axis. Example is the [cosine](cos.md) function.
- being an **[odd function](odd_function.md)**: For this function it holds that *-f(x) = f(-x)*, i.e. the plotted function is symmetric by the center point [0,0]. Example is the [sine](sin.md) function.
In context of functions we may encounter the term [composition](composition.md) which simply means chaining the functions. E.g. the composition of functions *f(x)* and *g(x)* is written as *(f o g)(x)* which is the same as *f(g(x))*.
[Calculus](calculus.md) is an important mathematical field that studies changes of continuous functions. It can tell us how quickly functions grow, where they have maximum and minimum values, what's the area under the line in their plot and many other things.
## Programming Functions
In programming the definition of a function is less strict, even though some languages, namely [functional](functional.md) ones, are built around purely mathematical functions -- for distinction we call these strictly mathematical functions **pure**. In traditional languages functions may or may not be pure, a function here normally means a **subprogram** which can take parameters and return a value, just as a mathematical function, but it can further break some of the rules of mathematical functions -- for example it may have so called **[side effects](side_effect.md)**, i.e. performing additional actions besides just returning a number (such as modifying data in memory, printing something to the screen etc.), or use randomness and internal states, i.e. potentially returning different numbers when invoked (called) multiple times with exactly the same parameters. These functions are called **impure**; in programming a *function* without an adjective is implicitly expected to be impure. Thanks to allowing side effects these functions don't have to actually return any value, their purpose may be to just invoke some behavior such as writing something to the screen, initializing some hardware etc. The following piece of code demonstrates this in [C](c.md):
```
int max(int a, int b, int c) // pure function
{
return (a > b) ? (a > c ? a : c) : (b > c ? b : c);
}
unsigned int lastPresudorandomValue = 0;
unsigned int pseudoRandom(unsigned int maxValue) // impure function
{
lastPresudorandomValue = // side effect: working with global variable
lastPresudorandomValue * 7907 + 7;
return (lastPresudorandomValue >> 2) % (maxValue + 1);
}
```
In older languages functions were also called *[procedures](procedure.md)* or *[routines](routine.md)*. Sometimes there was some distinction between them, e.g. in [Pascal](pascal.md) functions returned a value while procedures didn't.

@ -2,6 +2,8 @@
Homosexuality is a disorder/disease which makes individuals sexually attracted primarily to the same sex. A homosexual individual is called gay, homo or faggot ([females](woman.md) are called lesbians).
Even though homosexuality is largely genetically determined, it is also to a great extent a **choice**, sometimes a choice that's not of the person in question. Most people are actually [bisexual](bi.md) to a considerable degree, with a *preference* of certain sex. That is there is a certain probability in each individual of choosing one or the other sex for a sexual/life partner. However culture and social pressure can push these probabilities in either way. If a child grows up in a major influence of YouTubers and other celebrities that openly are gay, or promote gayness as something extremely cool and fashionable, if the culture constantly pains being homosexual as being more interesting and somehow "brave" and if the [competition](competition.md) of sexes fueled e.g. by the [feminist](feminism.md) propaganda paints the opposite sex as literal [Hitler](hitler.md), the child has a greater probability of (maybe involuntarily) choosing the gay side of his sexual personality.
There is a terrorist fascist organization called [LGBT](lgbt.md) aiming to make gays superior to other people.
Of course, [we](lrs.md) have nothing against gay people as we don't have anything against people with any other disorder -- we love all people. But we do have an issue with any kind of terrorist organization, so while we are okay with gays, we are not okay with LGBT.

@ -4,6 +4,12 @@ Technological minimalism is a philosophy of designing technology to be as simple
There is a so called *[airplane rule](airplane_rule.md)* that states a plane with two engines has twice as many engine problems than a plane with a single engine.
Up until recently in history every engineer would tell you that *the better machine is that with fewer moving parts*. This still seems to hold in mathematics, an area inhabited by the smartest people, where there is a tendency to look for the most minimal equations -- such equations are considered [beautiful](beauty.md). Science also knows this rule as the Occam's razor. In technology invaded by aggressive commercialization the situation is different, minimalism lives only in the underground as part of such philosophies as [suckless](suckless.md), [Unix](unix_philosophy.md), [KISS](kiss.md), countercomplex and, of course, [less retarded software](lrs.md). This is bad.
Up until recently in history every engineer would tell you that *the better machine is that with fewer moving parts*. This still seems to hold in mathematics, an area inhabited by the smartest people, where there is a tendency to look for the most minimal equations -- such equations are considered [beautiful](beauty.md). Science also knows this rule as the Occam's razor. In technology invaded by aggressive commercialization the situation is different, minimalism lives only in the underground and is ridiculed by the mainstream propaganda. Some of the minimalist movements, terms and concepts include:
- [suckless](suckless.md)
- [Unix philosophy](unix_philosophy.md)
- [KISS](kiss.md)
- [countercomplex](countercomplex.md)
- [less retarded software](lrs.md)
Under [capitalism](capitalism.md) technological minimalism dies with possibly only the "shallow" kind of minimalism ([pseudominimalism](pseudominimalism.md)) surviving. This so called "minimalism" tries to make things look minimal only aesthetically and hides ugly overcomplicated internals under this facade. [Apple](apple.md) is known for this [shit](shit.md).

@ -0,0 +1,102 @@
# 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. 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 [assymetric cryptography](assymetric_cryptography.md).
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.
**Why is 1 not a prime?** Out of convenience -- if 1 was a prime, the fundamental theorem of arithmetic would not hold because 75's factorization could be 3 * 5 * 5 but also 1 * 3 * 5 * 5, 1 * 1 * 3 * 5 * 5 etc.
The unique factorization can also nicely be used to encode [multisets](multiset.md) as numbers. We can assign each prime number its sequential number (2 is 0, 3 is 1, 5 is 2, 7 is 3 etc.), then any number encodes a set of numbers (i.e. just their presence, without specifying their order) in its factorization. E.g. 75 = 3 * 5 * 5 encodes a multiset {1, 2, 2}. This can be exploited in cool ways in some [cyphers](cypher.md) etc.
**There are infinitely many prime numbers**. The proof is pretty simple (shown below), however it's pretty interesting that it has still not been proven whether there are infinitely many [twin primes](twin_prime.md) (primes that differ by 2), that seems to be an extremely difficult question.
Euklid's [proof](proof.md) shows there are infinitely many primes, it is done by contradiction and goes as follows: suppose there are finitely many primes *p1*, *p2*, ... *pn*. Now let's consider a number *s* = *p1* * *p2* * ... * *pn* + 1. This means *s* - 1 is divisible by each prime *p1*, *p2*, ... *pn*, but *s* itself is not divisible by any of them (as it is just 1 greater than *s* and multiples of some number *q* greater than 1 have to be spaced by *q*, i.e. more than 1). If *s* isn't divisible by any of the considered primes, it itself has to be a prime. However that is in contradiction with the original assumption that *p1*, *p2*, ... *pn* are all existing primes. Therefore a finite list of primes cannot exist, there have to be infinitely many of them.
**Distribution and occurrence of primes**: the occurrence of primes seems kind of """[random](random.md)""" (kind of like digits of [decimal](decimal.md) representation of [pi](pi.md)), without a simple pattern, however hints of patterns appear such as the [Ulam spiral](ulam_spiral.d) -- if we plot natural numbers in a square spiral and mark the primes, we can visually distinguish dimly appearing 45 degree diagonals as well as horizontal and vertical lines. Furthermore the **density of primes decreases** the further away we go from 0. The *prime number theorem* states that a number randomly chosen between 0 and *N* (for large *N*) has approximately 1/log(N) probability of being a prime. **Prime counting function** is a function for *N* tells the number of primes smaller or equal to *N*. While there are 25 primes under 100 (25%), there are 9592 under 100000 (~9.5%) and only 50847534 under 1000000000 (~5%).
```
, , , ', ' ,' , , '
',', ' , ' ', ' ',
,, , ,' ' ', ,' ,' , ' '
, , ', , ' ,' ', ,' ' ,', ,
' ',', , , ', ',
, , , ,' ,' ' ', , , '
,', ,', ' , , ,' ' , ' ,
, ', ' ', , ,' , ', ' ' ' ,
',', , ,' ' , ,' ' ' ,',' ', , ,
' ' ' ', , , , ', , ', ,
' ' ' ' ' ', , ,' ' ' ',
' ', ', , , ,', ,',', ,' ' ' , ' ' ' , ,
, , ,',;,', , , , ,', ,
' ' ' ',' ',
,,' ' , ' ,' ', ',' ', ' ', ,' ,' ' ',
, , , , ' , , ,' , , '
' ', ', ' , , , ' ' '
,, , , , , ' ' ,', ', ' , ,' ,','
, , ,', ' , , ',', , ,
', ' ' ', , , ,' ', ',
, ', , ,' ', ' ' , ' '
, ' ' ' ' ', ', ,
, ' ' ' ' ,' , , ,' ',
,' ', , ,', , ' , , ' '
, ', , , , , ,' ',
```
*Ulam spiral: the center of the image is the number 1, the number line continues counter clockwise, each point represents a prime.*
Here are prime numbers under 1000: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997.
```
______/
/ /
_____ ______/_ /
____ / X /__\ /
___ / \/__ / \ /__ \/
/ \ / /\ \ / \ / \ /\
--2--3--/--5--X--7--/--\--X--11-X--13-X--\--
\__\/ \ \/ \__\/ \ \/ \__\/ \ \/ \__\/
\__\_/\ \ /\ \ /\__\_/\ \ /\ \ /\
\__\__X \ X \ X \ X__\__X
\__\__\/ \ \/ \ \/ \ \/ \
\__\__\_/\ \ /\ \ /\ \
```
## 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 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:
```
int isPrime(int n)
{
if (n < 4)
return n > 1;
if (n % 2 == 0 || n % 3 == 0)
return 0;
int test = 6;
while (test <= n / 2) // replace n / 2 by sqrt(n) if available
{
if (n % (test + 1) == 0 || n % (test - 1) == 0)
return 0;
test *= 6;
}
return 1;
}
```
[Sieve of Eratosthenes](sieve_of_eratosthenes.md) is a simple algorithm to find prime numbers up to a certain bound *N*. The idea of it is following: create a list of numbers up to *N* and then iteratively mark multiples of whole numbers as non-primes. At the end all remaining (non-marked) numbers are primes. If we need to find all primes under *N*, this algorithm is more efficient than testing each number under *N* for primality separately (we're making use of a kind of [dynamic programming](dynamic_programming.md) approach).
Prime factorization: TODO
Prime generation: TODO
## See Also
- [happy number](happy_number.md)

@ -1,7 +1,9 @@
# USA
United States of America (USA, US or just "murika") is a [dystopian](dystopia.md) country of fat, stupid fascist people enslaved by [capitalism](capitalism.md), people endlessly obsessed with money and wars. USA consists of 50 states located in North America, a continent that ancestors of Americans invaded and have stolen from Indians, the natives whom Americans murdered.
United States of America (USA, US or just "murika") is a [dystopian](dystopia.md) country of fat, stupid fascist people enslaved by [capitalism](capitalism.md), people endlessly obsessed with money and wars. USA consists of 50 states located in North America, a continent that ancestors of Americans invaded and have stolen from Indians, the natives whom Americans mass murdered.
USA is very similar to [North Korea](north_korea.md): in both countries the people are successfully led to believe their country is the best. North Korea is ruled by a single political party, US is ruled by two practically same militant capitalist parties (democrats and republicans), i.e. de-facto one party as well. Both countries are obsessed with weapons and their military, both are highly and openly [fascist](fascism.md) (nationalist). Both countries are full of extreme [propaganda](propaganda.md), [censorship](censorship.md) and greatly support cult of personality, people worship dictators such as Kim Jong-un or [Steve Jobs](steve_jobs.md). US is even worse than North Korea because it exports its toxic culture over the whole world, it is destroying all other cultures and leads the whole world to doom and destruction of all life.
USA is very similar to [North Korea](north_korea.md): in both countries the people are successfully led to believe their country is the best. North Korea is ruled by a single political party, US is ruled by two practically same militant capitalist imperialist parties (democrats and republicans), i.e. de-facto one party as well. Both countries are obsessed with weapons and their military, both are highly and openly [fascist](fascism.md) (nationalist). Both countries are full of extreme [propaganda](propaganda.md), [censorship](censorship.md) and greatly support cult of personality, people worship dictators such as Kim Jong-un or [Steve Jobs](steve_jobs.md). US is even worse than North Korea because it exports its toxic culture over the whole world and constantly invades other countries, it is destroying all other cultures and leads the whole world to doom and destruction of all life.
In US mainstream [politics](politics.md) there exists no true left, only [right](left_right.md) and [pseudoleft](pseudoleft.md). It is only in extreme underground, out of the sight of most people, where occasionally something good comes into existence as an exception to a general rule that nothing good comes from the US. One of these exceptions is [free software](free_software.md) (established by [Richard Stallman](rms.md)) which was however quickly smothered by the capitalist [open source](open_source.md) counter movement.
In US mainstream [politics](politics.md) there exists no true left, only [right](left_right.md) and [pseudoleft](pseudoleft.md). It is only in extreme underground, out of the sight of most people, where occasionally something good comes into existence as an exception to a general rule that nothing good comes from the US. One of these exceptions is [free software](free_software.md) (established by [Richard Stallman](rms.md)) which was however quickly smothered by the capitalist [open source](open_source.md) counter movement.
On 6th and 9th August 1945 USA casually killed about 200000 civilians, most of whom were innocent men, women and children, by throwing atomic bombs on Japanese cities Hiroshima and Nagasaki. The men who threw the bombs and ordered the bombing were never put on trial, actually most Americans accepted it as a good thing to do lol.

@ -0,0 +1,7 @@
# World Of Warcraft
World of Warcraft (WoW) is a [proprietary](proprietary.md) [game](game.md) released in [2004](2004.md) by [Blizzard](blizzard.md) that was one of the most successful and influencing games among [MMORPGs](mmorpg.md).
There is a [FOSS](foss.md) implementation of WoW server called [MaNGOS](mangos.md) that's used to make private servers. The client is of course proprietary and if you dare make a popular server Blizzard will kill your grandmother and rape your children.
{ The classic WoW (some time until the end of WOTLK) lied somewhere in the middle between good old and shitty [modern](modern.md) games (the WoW of today is 100% shit of course). For me the peak of Warcraft was [Warcraft III:TFT](warcraft.md), it was perfect in every way (except for being proprietary and bloated of course). As a great fan of Warcraft III, seeing WoW in screenshots my fantasy made it the best game possible to be created. When I actually got to playing it it was really good -- some of my best memories come from that time -- nevertheless I also remember being disappointed in many ways. Especially with limitation of freedom (soulbound items, forced grinding, effective linearity of leveling, GMs preventing hacking the game in fun ways etc.) and here and there a lack of polish (there were literally visible unfinished parts of the map, also visual transitions between zones too fast and ugly and the overall world design felt kind of bad), laziness and repetitiveness of the design. I knew how the game could be fixed, however I also knew it would never be fixed as it was in hands of a corporation that had other plans with it. That was the time I slowly started to see things not being ideal and the possibility of a great thing going to shit. ~drummyfish }
Loading…
Cancel
Save