Talk:Sieve of Eratosthenes#Symbolic formulas: a recap

{{WikiProject banner shell|class=C|vital=yes|1=

{{WikiProject Greece|importance=Mid}}

{{WikiProject Classical Greece and Rome|importance=Mid}}

{{WikiProject Computer science|importance=Mid}}

{{WikiProject Mathematics|importance=Mid}}

}}

{{User:MiszaBot/config

| algo = old(365d)

| archive = Talk:Sieve of Eratosthenes/Archive %(counter)d

| counter = 3

| maxarchivesize = 150K

| archiveheader = {{Automatic archive navigator}}

| minthreadstoarchive = 1

| minthreadsleft = 10

}}

{{Archive box |search=yes |bot=Lowercase sigmabot III |age=12 |units=months |auto=yes }}

Visual layout

While improving greatly on various aspects of typographic style (thank you for that!), [https://en.wikipedia.org/w/index.php?title=Sieve_of_Eratosthenes&diff=next&oldid=757647493 a recent edit by an IP user 81.129.155.32] also destroyed the carefully created visual layout of pseudocode snippets and examples throughout the whole article.

Please don't do that without discussing it here and reaching a consensus first. Thanks. WillNess (talk) 10:12, 24 January 2017 (UTC)

''(Undo good faith edit that doesn't belong in this subsection. Complexity is already discussed elsewhere in the article. Passing mention of another incremental algo is enough, no need for _its_ deep analysis.)''

A recent revert has the above as its edit summary. While this might be true, it is discouraging to new editors. Too many of those, and someone will stop trying. Is it possible to put somewhere else in the article? Or change such that it does make a useful addition? It looks like someone who really does understand the subject, not a random, inappropriate, edit. Gah4 (talk) 20:44, 6 April 2017 (UTC)

Animation inconsistent : Does not mark 6 in green when marking multiples of 3

When the animation marks multiples of 3 in green, it doesn't mark the number 6 in green. You could argue this is because 6 is already marked red as a multiple of 2. But the animation then marks other multiples of 3 in green even when they have already been marked in red as a multiple of 2 (e.g. 18, 48, 54, 96). It feels like the animation should mark 6 in green when marking multiples of 3. — Preceding unsigned comment added by 62.190.148.115 (talk) 18:24, 18 September 2017 (UTC)

:The caption says "including optimization of starting from prime's square". That means the multiples of 2 are marked from 22 = 4 (which makes no difference), multiples of 3 are marked starting from 32 = 9, multiples of 5 are marked from 52 = 25, and multiples of 7 from 72 = 49. Multiples below the square have always been marked by a smaller factor. Clicking the image leads to :File:Sieve of Eratosthenes animation.gif which also explains it. PrimeHunter (talk) 18:46, 18 September 2017 (UTC)

::You probably meant "Multiples below the square have already been marked by a smaller factor." Just pointing this out for the benefit of future readers here. WillNess (talk) 17:51, 29 April 2018 (UTC)

Correction in Segmented Sieve

Hi,

It says in the segmented sieve section that the segment size delta should be chosen less than or equal to sqrt(n). The issue is that then the sieve doesn't find prime factors between delta and sqrt(n) in later segments. Shouldn't it be greater than sqrt(n) instead? — Preceding unsigned comment added by Ovinus Real (talkcontribs) 06:29, 13 July 2020 (UTC)

:If \Delta\ge \sqrt n, all primes whose multiples must be considered belong to the first segment. Otherwise, primes in other segments must be included in "found so far". I have edited the article for clarifying this. D.Lazard (talk) 10:02, 13 July 2020 (UTC)

The tables in Computational analysis and Algorithmic complexity make no sense

It is unclear what the tables are trying to show in Computational analysis and Algorithmic Complexity. "following is a table showing the actually measured number of operations for a practical implementation of the sieve of Eratosthenes as compared to the number of operations predicted from the above expression" so it doesn't even show the implementation? How exactly is wheel factorization used to optimize the sieve?

--Abstractsail (talk) 07:08, 3 September 2020 (UTC)

Naming of linear sieve as "Euler sieve"

I skimmed the given reference http://research.cs.wisc.edu/techreports/1990/TR909.pdf and it don't see any mention of Euler. Anyhow clearly Euler used the techniques for proofs and not as a computer algorithm to generate primes in linear time (I don't think time complexity was ever his concern in a math proof). So I don't know where the name actually comes from. Wqwt (talk) 20:27, 29 October 2021 (UTC)

: this used to be called someth like "the version of sieve in Euler's proof of zeta function", and then some editor just shortened it. There was much discussion of this version in haskell-cafe around 2010 where that short name was explicitly used, if that counts for anything. (apologies for the typos, if any) -- WillNess (talk)

(and the date is: ) WillNess (talk) 15:14, 28 May 2022 (UTC)

Turns out I misremembered this thing entirely, sorry for that. It was introduced as such right away. Here's the first version of the article where that section appeared: https://en.m.wikipedia.org/w/index.php?title=Sieve_of_Eratosthenes&oldid=282870717 -- WillNess (talk) 15:25, 28 May 2022 (UTC)

:This line is indeed edited many times since it was originally introduced in the version linked from 2009. However although the version from 2009 introduces the claim that the linear sieve is based on a proof idea from Euler, it does not include the currently referenced work of Sorenson as a source yet. This was added (by you) 4 years later in 2013 https://en.wikipedia.org/w/index.php?title=Sieve_of_Eratosthenes&diff=prev&oldid=584496363.

:Could you clarify why this was added as a source (maybe it was by mistake?), because I also could not find anything in Sorenson's article attributing the linear sieve to Euler. Fireline11 (talk) 10:42, 31 May 2025 (UTC)

Missed optimization in animation and pseudo code

Both the animation and pseudo code mention that they include optimization (starting from prime squares). The argument there being all number smaller than prime squared have already been marked. It then goes and marks prime^2, prime^2 + prime, prime^2 + 2 * prime, ... but half of those numbers are even. Another common optimization is therefore to mark only prime^2, prime^2 + 2 * prime, prime^2 + 4 * prime, ... for any prime > 2. Taking this one step further is to exclude all even numbers from the array of booleans in the first place:

algorithm Sieve of Eratosthenes is

input: an integer n > 1.

output: all prime numbers from 2 through n.

let A be an array of Boolean values, indexed by integers 1 to n / 2,

initially all set to true.

for i = 3, 5, 7, 9, ..., not exceeding {{math|{{sqrt|n}}}} do

if A[i / 2] is true

for j = i2, i2+2i, i2+4i, i2+6i, ..., not exceeding n do

A[j / 2] := false

return all i <= n such that i == 2 or i is odd and A[i / 2] is true.

Apart from saving the time to mark all even numbers it also saves half the memory and is therefore a common optimization too.

: yes this is mentioned in the article. But we also must keep it simple. So it's a balancing act. -- WillNess (talk)

(here's the sig with the date, IIRC how to do it) WillNess (talk) 15:13, 28 May 2022 (UTC)

:That's a good optimization. You can just mention sieving by skipping evens. Further simple optimizations are mentioned at https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html#sieving-by-the-odd-numbers-only Wqwt (talk) 05:10, 25 August 2022 (UTC)

::it is mentioned, in Overview. WillNess (talk) 14:52, 3 October 2022 (UTC)

Sieve of Sorenson?

Are we married to mentioning Sorenson's work? Maybe we should say something else along the lines of '...the space-saving sieve as attributed to Dunten, Jones and Sorenson...'. The citation is also broken, but this one is not; https://doi.org/10.1016/0020-0190(96)00099-3.

I'm not even sure that is the correct author/paper the contributor was referring to, but there appears to be nothing commonly referred to as the Sieve of Sorensen. 69.162.230.42 (talk) 00:34, 15 August 2024 (UTC)

:I found a not-so-broken link to the same paper. I updated the text to refer to the actual name of the Sieve from the paper, but also left an attribution to J. Sorenson, this maintains an attribution with a more correct name. I also updated the citation to a living-link. I think until the Pseudosquares Prime Sieve is commonly referred to as the Sorenson Sieve we should refrain from forcing a name.

:I kind of wonder if a student of his added this while reviewing material. 69.162.230.42 (talk) 00:52, 15 August 2024 (UTC)

Segmented sieve motivation is worded too strongly

The section on the segmented version gives the following motivation in the second sentence.

"For large n, the range of primes may not fit in memory; worse, even for moderate n, its cache use is highly suboptimal. The algorithm walks through the entire array A, exhibiting almost no locality of reference."

I think this sentence is worded too strongly. Locality of reference of the pseudocode given in the section above is actually not terrible and memory accesses are very regular. Therefore, I propose we rewrite it to

"For large n, the range to be sieved may not fit in memory and even for moderate n, its cache use is not optimal."

This way we refrain from justifying the segmented sieve (which is a more niche topic) by making strong statements about problems with the basic implementation, but we touch on the two main things it helps with.

1. Sieving up to a higher limit N

2. Better usage of CPU caches.

Happy to discuss if there is disagreement. I saw there was already quite a lot of discussion on the segmented sieves so I do not want to step on anyone's toes here. Fireline11 (talk) 12:06, 31 May 2025 (UTC)