more wikipedia
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
I read an article from [Quanta Magazine](https://www.quantamagazine.org/how-randomness-improves-algorithms-20230403/) that had this very interesting piece of information:
|
||||
|
||||
> The basic idea goes back to a result from the 17th-century French mathematician Pierre de Fermat, known as his "little theorem." Fermat considered two integers — call them `N` and `x`. He proved that if `N` is a prime number, then `x\^N − x` is always a multiple of `N`, regardless of the value of `x`. Equivalently, if `x\^N − x` is not a multiple of `N`, then `N` can't be a prime number. But the inverse statement isn't always true: If `x\^N − x` is a multiple of `N`, then `N` is usually but not always prime.
|
||||
> To turn Fermat's little theorem into a primality test, just take the `N` that you're interested in, choose `x` at random, and plug the two numbers into `x\^N − x`. If the result is not a multiple of `N`, then you're done: You know that `N` is definitely composite. If the result is a multiple of N, then `N` is probably prime. Now pick another random `x` and try again. In most cases, after a few dozen tries, you can conclude with near certainty that `N` is a prime number. "You do this a small number of times," Blais said, "and somehow now your probability of having an error is less than the probability of an asteroid hitting the Earth between now and when you look at the answer."
|
||||
> The basic idea goes back to a result from the 17th-century French mathematician Pierre de Fermat, known as his "little theorem." Fermat considered two integers — call them `N` and `x`. He proved that if `N` is a prime number, then `x\^N - x` is always a multiple of `N`, regardless of the value of `x`. Equivalently, if `x\^N - x` is not a multiple of `N`, then `N` can't be a prime number. But the inverse statement isn't always true: If `x\^N - x` is a multiple of `N`, then `N` is usually but not always prime.
|
||||
> To turn Fermat's little theorem into a primality test, just take the `N` that you're interested in, choose `x` at random, and plug the two numbers into `x\^N - x`. If the result is not a multiple of `N`, then you're done: You know that `N` is definitely composite. If the result is a multiple of N, then `N` is probably prime. Now pick another random `x` and try again. In most cases, after a few dozen tries, you can conclude with near certainty that `N` is a prime number. "You do this a small number of times," Blais said, "and somehow now your probability of having an error is less than the probability of an asteroid hitting the Earth between now and when you look at the answer."
|
||||
|
||||
It reminded me a little of zero knowledge proofs.
|
||||
|
||||
Anyways, using Fermat's Little Theorem, I wanted to create a little function that could see whether a number was a prime number or not. First, we had to have a number to check as one of the inputs. And since I was using Javascript, it probably should be a `BigInt`, so big inputs don't lose any precision. We probably also want to optionally let the caller specify how many checks to do.
|
||||
|
||||
Then, for each check, we can generate a random `x`, calculate `x\^N − x`. If we call that, say, `m`, then we can do `m % N`, where `%` means modulo. If `m % N` is zero, that means `m` is a multiple of `N`, so we continue. If not, then we know the input is **not** a prime number, and can end it there. If we generate `x` many times, and `m % N` is always `0`, we can conclude with high probability that the input is a prime.
|
||||
Then, for each check, we can generate a random `x`, calculate `x\^N - x`. If we call that, say, `m`, then we can do `m % N`, where `%` means modulo. If `m % N` is zero, that means `m` is a multiple of `N`, so we continue. If not, then we know the input is **not** a prime number, and can end it there. If we generate `x` many times, and `m % N` is always `0`, we can conclude with high probability that the input is a prime.
|
||||
|
||||
At first, I mistakenly did `N % m`, but that means `m` is a factor (not a *multiple*) of `N`, and `N` would be by definition, not a prime number (only factors of a prime number are itself and 1). I realised the problem pretty quickly.
|
||||
|
||||
@@ -30,6 +30,6 @@ I tested a random few of the [first 1000 prime numbers](https://en.wikipedia.org
|
||||
|
||||
Just to see if it worked, I tried putting in the very large prime number "531137992816767098689588206552468627329593117727031923199444138200403559860852242739162502265229285668889329486246501015346579337652707239409519978766587351943831270835393219031728127" as a test. And:
|
||||
|
||||

|
||||

|
||||
|
||||
...fair enough.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
After 4 ([1](https://github.com/jetstream0/hedgeblog/commit/ccb848a9afdb7405d1cf6018c537aae803fe4199) [2](https://github.com/jetstream0/hedgeblog/commit/500cbd6f0217095541e5462d76282d8a40f116a9) [3](https://github.com/jetstream0/hedgeblog/commit/64889b8fae77199a4bad0c0e7915bc9f7a9f5fa9) [4](https://github.com/jetstream0/hedgeblog/commit/2a1ca739369ff2a364116510c207d5531b915b07)) painful commits, the RSS feed is up and running! And this post should confirm that, hopefully.
|
||||
After 4 ([1](https://github.com/jetstream0/hedgeblog/commit/ccb848a9afdb7405d1cf6018c537aae803fe4199), [2](https://github.com/jetstream0/hedgeblog/commit/500cbd6f0217095541e5462d76282d8a40f116a9), [3](https://github.com/jetstream0/hedgeblog/commit/64889b8fae77199a4bad0c0e7915bc9f7a9f5fa9), [4](https://github.com/jetstream0/hedgeblog/commit/2a1ca739369ff2a364116510c207d5531b915b07)) painful commits, the RSS feed is up and running! And this post should confirm that, hopefully.
|
||||
|
||||
I used [Planet KDE's RSS Feed](https://planet.kde.org/global/atom.xml) and W3C's [explanation of Atom](https://validator.w3.org/feed/docs/atom.html) for reference. W3C's [validator](https://validator.w3.org/feed/#validate_by_input) and Firefox's XML parsing thing were helpful in figuring out what exactly was wrong with the RSS feed during my testing and first three miserable commits, since Akregator (my RSS client), just told me it was invalid, with no error explanation or real error message.
|
||||
|
||||
|
||||
@@ -61,9 +61,35 @@ Here's a very incomplete (and maybe actively updated) list of ones that led to m
|
||||
- [Mongol Invasions of Japan](https://en.wikipedia.org/wiki/Mongol_invasions_of_Japan)
|
||||
- [Language Isolate](https://en.wikipedia.org/wiki/Language_isolate), languages that aren't classified as part of larger [language families](https://en.wikipedia.org/wiki/Language_family)
|
||||
- [Jiajing Wokou Raids](https://en.wikipedia.org/wiki/Jiajing_wokou_raids), pirates
|
||||
- [Word (computer_architecture)](https://en.wikipedia.org/wiki/Word_%28computer_architecture%29)
|
||||
- [Word (computer architecture)](https://en.wikipedia.org/wiki/Word_%28computer_architecture%29)
|
||||
- [Transition from Ming to Qing](https://en.wikipedia.org/wiki/Transition_from_Ming_to_Qing)
|
||||
- [Eighty Years' War](https://en.wikipedia.org/wiki/Eighty_Years%27_War), Dutch independence from Spain
|
||||
- [Abbasid Revolution](https://en.wikipedia.org/wiki/Abbasid_Revolution), the [Umayyad Caliphate](https://en.wikipedia.org/wiki/Umayyad_Caliphate) is overthrown and replaced by the Abbasid Caliphate
|
||||
- [Operation Motorman](https://en.wikipedia.org/wiki/Operation_Motorman), British military operation in Northern Ireland
|
||||
- [Green Armies](https://en.wikipedia.org/wiki/Green_armies) in the Russian Civil War
|
||||
- [Recusants](https://en.wikipedia.org/wiki/Recusancy) are those that did not support the Church of England after the English Reformation
|
||||
- [Terrorism Act 2000](https://en.wikipedia.org/wiki/Terrorism_Act_2000)
|
||||
- [Pontoon bridge](https://en.wikipedia.org/wiki/Pontoon_bridge)
|
||||
- [Francisco Macías Nguema](https://en.wikipedia.org/wiki/Francisco_Mac%C3%ADas_Nguema), completely insane dictator of Equatorial Guinea
|
||||
- [Yazidism](https://en.wikipedia.org/wiki/Yazidism)
|
||||
- [Göbekli Tepe](https://en.wikipedia.org/wiki/G%C3%B6bekli_Tepe), Neolithic archaeological site
|
||||
- [List of unsolved problems in mathematics](https://en.wikipedia.org/wiki/List_of_unsolved_problems_in_mathematics)
|
||||
- [Hartal](https://en.wikipedia.org/wiki/Hartal), Indian strike action
|
||||
- [Achaemenid Empire](https://en.wikipedia.org/wiki/Achaemenid_Empire), very big, pretty cool
|
||||
- [The Camden 28](https://en.wikipedia.org/wiki/The_Camden_28), anti-Vietnam War activists
|
||||
- [Howard Zinn](https://en.wikipedia.org/wiki/Howard_Zinn), controversial historian
|
||||
- [Gnosticism](https://en.wikipedia.org/wiki/Gnosticism) was a set of early Christian beliefs
|
||||
- [TempleOS](https://en.wikipedia.org/wiki/TempleOS)
|
||||
- [Grendel's mother](https://en.wikipedia.org/wiki/Grendel's_mother), an antagonist in the Old English epic poem, Beowulf, who scholars debate whether is a monster or just a female warrior
|
||||
- [Epic of Gilgamesh](https://en.wikipedia.org/wiki/Epic_of_Gilgamesh), Sumerian epic poem
|
||||
- [An Lushan Rebellion](https://en.wikipedia.org/wiki/An_Lushan_Rebellion), An Lushan rebels, greatly weakened the Tang Dynasty
|
||||
- [Bahmani Sultanate](https://en.wikipedia.org/wiki/Bahmani_Sultanate), South Indian empire
|
||||
- [Pagan Empire](https://en.wikipedia.org/wiki/Pagan_Kingdom), the first Burmese kingdom
|
||||
- [warsaw Uprising](https://en.wikipedia.org/wiki/Warsaw_Uprising)
|
||||
- [Polish-Lithuanian Commonwealth](https://en.wikipedia.org/wiki/Polish%E2%80%93Lithuanian_Commonwealth)
|
||||
- [Atoll](https://en.wikipedia.org/wiki/Atoll)
|
||||
- [Chambre introuvable](https://en.wikipedia.org/wiki/Chambre_introuvable), ultra-royalists Chamber of Deputies elected after the Second Bourbon Restoration
|
||||
- [Fedayeen](https://en.wikipedia.org/wiki/Fedayeen)
|
||||
- [Battle of Nagashino](https://en.wikipedia.org/wiki/Battle_of_Nagashino), where Takeda Katsuyori learns it is not a good idea to cavalry charge into gunfire
|
||||
- [Twenty-Four Generals of Takeda Shingen](https://en.wikipedia.org/wiki/Twenty-Four_Generals_of_Takeda_Shingen), related to the Battle of Nagashino above, but too interesting to leave out
|
||||
- [Battle of Bannockburn](https://en.wikipedia.org/wiki/Battle_of_Bannockburn), decisive Scottish victory in the First War of Scottish Independence
|
||||
|
||||
Reference in New Issue
Block a user