[quote=alexhiggins732;211298]So being the crank I am, I did what any selfrespecting crank would do, I rewrote it in VB.NET...
[/quote] That's a pretty ambitious spurofthemoment undertaking. I have no idea if its possible (I don't know much VB.NET so I won't be of any use in helping you with your port). As you've seen, pointers are used abundantly and I employ all sorts of C hacks like casting void pointers and adding pointer values. Not sure if equivalent code is possible in VB. It may have been easier to package the existing C code as a .dll library for use in a VB program. 
[quote=bsquared;211309]That's a pretty ambitious spurofthemoment undertaking. I have no idea if its possible (I don't know much VB.NET so I won't be of any use in helping you with your port).
As you've seen, pointers are used abundantly and I employ all sorts of C hacks like casting void pointers and adding pointer values. Not sure if equivalent code is possible in VB. It may have been easier to package the existing C code as a .dll library for use in a VB program.[/quote] Yeah tell me about it. That is nothing like my "sliding window" sieve or even the seo. In fact Atkins and Euler have sieve named after them and and made only simple modifications. [B]YOUR SIEVE IS A BEAST:smile: I NOMINATE THE NAME THE SIEVE OF BUHROW[/B] COM Interop on windows is quite a drag on performance. I current use a LIBGMP wrapper and just for i=0 to 100000000 takes several minutes. Actually comparing c/c++/vb performance is quite comparable when dealing with 32 bit words. 16 and 64 may be slightly slower and perhaps the bounds checking performed under the hood would be another performance hit, but nothing compared to the cost of com calls. Hopefully someone with VS will take a look and give it a shot. I can upload and entire project file. It would simply be a matter of stepping though each program. I mean their almost exact line for line. FYI, tiny_soe works perfect but then again that is a pretty simple implementation. spSOE fails, first reporting 121 as prime. 
[QUOTE=alexhiggins732;211311]Yeah tell me about it. That is nothing like my "sliding window" sieve or even the seo. In fact Atkins and Euler have sieve named after them and and made only simple modifications. [/QUOTE]
You think the Sieve of Atkin is a simple modification? 
[quote=alexhiggins732;211311]Yeah tell me about it. That is nothing like my "sliding window" sieve or even the seo. In fact Atkins and Euler have sieve named after them and and made only simple modifications.
[B]YOUR SIEVE IS A BEAST:smile: I NOMINATE THE NAME THE SIEVE OF BUHROW[/B] [/quote] I'm flattered :smile:, but at the end of the day its just another sieve of Eratosthenes. The best that can be said about it is that it uses some optimizations that perhaps haven't been implemented before. Even so, in all but very special cases it isn't even the fastest SOE... ecprime fills those shoes. 
[quote=CRGreathouse;211315]You think the Sieve of Atkin is a simple modification?[/quote]
While it may be entirely more effecient for larger input and the theory behind it can be quite complex, it is indeed a relatively simple modification compared to the one implement in Yafu. Compare this mutlithreaded sieve to the code in the previous thread [code] Private Shared Sub ParralleSieve(x as Integer) Dim xx = x * x For y As Integer = 1 To sqrt Dim yy = y * y Dim n = 4 * xx + yy If n <= max AndAlso (n Mod 12 = 1 OrElse n Mod 12 = 5) Then isPrime(n) = Not isPrime(n) End If n = 3 * xx + yy If n <= max AndAlso n Mod 12 = 7 Then isPrime(n) = Not isPrime(n) End If n = 3 * xx  yy If x > y AndAlso n <= max AndAlso n Mod 12 = 11 Then isPrime(n) = Not isPrime(n) End If Next End Sub Private Shared Function SieveOfAtkins(ByVal max As Integer) As List(Of Integer) Dim isPrime = New BitArray(CInt(max) + 1, False) Dim sqrt = CInt(Math.Sqrt(max)) Parallel.[For](1, sqrt, AddressOf ParrallelSieve) Dim primes = New List(Of Integer)() For n As Integer = 5 To sqrt If isPrime(n) Then primes.Add(n) Dim nn As Integer = n * n Dim k As Integer = nn While k <= max isPrime(k) = False k += nn End While End If Next For n As Integer = sqrt + 1 To max If isPrime(n) Then primes.Add(n) End If Next Return primes End Function [/code] 
[QUOTE=alexhiggins732;211323]While it may be entirely more effecient for larger input and the theory behind it can be quite complex, it is indeed a relatively simple modification compared to the one implement in Yafu.[/QUOTE]
[QUOTE=alexhiggins732;211323]Compare this mutlithreaded sieve to the code in the previous thread [code] Private Shared Sub ParralleSieve(x as Integer) Dim xx = x * x For y As Integer = 1 To sqrt Dim yy = y * y Dim n = 4 * xx + yy If n <= max AndAlso (n Mod 12 = 1 OrElse n Mod 12 = 5) Then isPrime(n) = Not isPrime(n) End If n = 3 * xx + yy If n <= max AndAlso n Mod 12 = 7 Then isPrime(n) = Not isPrime(n) End If n = 3 * xx  yy If x > y AndAlso n <= max AndAlso n Mod 12 = 11 Then isPrime(n) = Not isPrime(n) End If Next End Sub Private Shared Function SieveOfAtkins(ByVal max As Integer) As List(Of Integer) Dim isPrime = New BitArray(CInt(max) + 1, False) Dim sqrt = CInt(Math.Sqrt(max)) Parallel.[For](1, sqrt, AddressOf ParrallelSieve) Dim primes = New List(Of Integer)() For n As Integer = 5 To sqrt If isPrime(n) Then primes.Add(n) Dim nn As Integer = n * n Dim k As Integer = nn While k <= max isPrime(k) = False k += nn End While End If Next For n As Integer = sqrt + 1 To max If isPrime(n) Then primes.Add(n) End If Next Return primes End Function [/code][/QUOTE] As far as I can tell, this is wrong. But even if it works (I can't get it to give correct answers), it's not more than a pale reflection of the sieve. This takes at least [TEX]n(\log n)^{1+\varepsilon}[/TEX] time, while the 'true' Sieve of Atkin takes only [TEX]O(n/\log\log n)[/TEX] time. Similarly, yours takes about [TEX]n[/TEX] bits of memory, while the real one takes [TEX]n^{0.5+\varepsilon}[/TEX] bits. The second is not difficult, but the first one takes real magic. By omitting that part you do a great disservice to the inventors of the sieve, Bernstein and Atkin. But if you think that implementation tricks are what make the algorithm, then you should see [url=http://cr.yp.to/primegen.html]Bernstein's implementation[/url]. Also: the name is Atkin, not Atkins. 
I concur, it is indeed a great sieve indeed and there are many implementations of it out there. For those interested here is the theory behind it and other sieves.
[url]http://cr.yp.to/papers/primesieves.pdf[/url] 
[QUOTE=CRGreathouse;211325]
Also: the name is Atkin, not Atkins.[/QUOTE] I guess Atkin is often mistaken for the diet :smile: 
I've now completed the sum of each sequence (primes, prime squares, and prime cubes) up to 1e14, and found the 12th member of the cube sequence:
[CODE]**** 1000000000000 divides prime cube sum up to 33777547344991, sum is 10532010356822624092227361649102207021134000000000000 ****[/CODE] 
[quote=flouran;211328]I guess Atkin is often mistaken for the diet :smile:[/quote]Well, the diet is a sieve, screening out certain types of calories, isn't it? :smile:

I thought a calory was 4.2 Joule, but nutritionists use
the term to refer to a kilocalory. I don't think there are different types for different foods. Even the "type of energy" it measures is the same for everything. David 
All times are UTC. The time now is 08:14. 
Powered by vBulletin® Version 3.8.11
Copyright ©2000  2021, Jelsoft Enterprises Ltd.