Share this post

Link to post

Share on other sites

jchd 930

jchd 930

AutoIt strength clearly isn't computational speed, hence traditional primality or compositness tests aren't guaranteed to be any faster than trial divide. Also and since no efficient arbitrary-size integer arithmetic operation is built-in, the usefulness of AutoIt in number theory is irrevocably close to zero.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

I'd say this is considerably slower than your script lol its actually still running. But id definitely say this is a situation where processing power would make a difference. I'm using a laptop that is a few years old and its using the cpu at 100%. its been a few minutes and its only into like the 10000's lol but at least it works. i guess i can make it so that if $y > 3 then exitloop would prolly speed it up

Edited December 16, 2013 by markyrocks

Share this post

Link to post

Share on other sites

Rogue5099 16

Rogue5099 16

well I been playing around with this for shitz an giggles this is what i've come up with

I'd say this is considerably slower than your script lol its actually still running. But id definitely say this is a situation where processing power would make a difference. I'm using a laptop that is a few years old and its using the cpu at 100%. its been a few minutes and its only into like the 10000's lol but at least it works. i guess i can make it so that if $y > 3 then exitloop would prolly speed it up

Array's and ReDim would slow it up a bit and Array's do have a limit so I was trying to stay away from them,

Also while writing what I did I eliminated a lot of checks by (even numbers and being divisible by 5). Also using the square root as the max number to divide by because once you go past the square root of the number you are just doing double checks.

Share this post

Link to post

Share on other sites

markyrocks 10

markyrocks 10

the redim is redundant after i set it to exitloop after y>=3 still taking forever tho. hence the $y will never be greater then ubound($temp). I just wrote that as a learning exercise. its been like 20 min and its still not past like 70000. I think the point here is the Mod() isn't anyfaster.

Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.

Share this post

Link to post

Share on other sites

czardas 1,116

czardas 1,116

I like this style as well! Only thing I noticed was that you have 1 as a prime number which the first prime number is 2. These 2 lines also exempt negative numbers and number 1.

If $number = 2 Or $number = 5 Then Return True

If $number < 0 Then Return False

Thanks. I agree the code needs some tweaking for negative primes (using Abs) and error checks also need adding. It was the method that interested me the most. As far as the number 1 is concerned, I was a little surprised to see people excluding it from the list. I always interpreted a prime as being any whole number which only divides by 1 and itself. This is the definition we were taught in school, and this would mean the number 1 does qualify as a prime. I need to check my sources.

Zero definately needs removing though. If the code is useful to you, then tweak it any way you wish.

Edit

I'm getting somewhere researching this. The number one was originally considered a prime number, until they redefined the meaning of the word. I'm not exactly sure why they did this yet. It is entirely a question of semantics. It reminds me a bit of Pluto no longer being classified as a planet. Funny old world.

Share this post

Link to post

Share on other sites

jchd 930

jchd 930

Divisibility by the unit is a triviality. Also if 1 is considered prime the fundamental theorem of arithmetic no longer holds: decomposition into primes is no longer unique. That would need rephrasing most results in number theory. It's therefore more natural to exclude 1 from PRIMES.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post

Share on other sites

czardas 1,116

czardas 1,116

I understand the reasons for the change, as explained in the video. The redefinition makes things easier by not having to constantly exclude the unique exception to the rule - unity. it's nothing more than semantics, and has no deeper significance beyond the convenience factor - it doesn't really matter what you call it. Quite interesting though.

I would have said all primes greater than one are a subset of all primes greater than zero, rather than turning 2000+ years of established definition on its head.

Rewording the theory won't break anything. It's clearly too late to go down that path now though. The historians will have to struggle with it instead.

Share this post

Link to post

Share on other sites

lark 1

lark 1

I'm surprised no one has mentioned prime sieves yet. Prime sieves work by filtering out non-primes, instead of checking whether each number is prime. The fastest sieve I've heard of is the sieve of atkin, which uses quadratics to determine prime numbers. Pseudo code on the wikipedia page is here: http://en.wikipedia.org/wiki/Sieve_of_Atkin

Another popular prime sieve is the sieve of eratosthenes- its much simpler, but not quite as fast.

Share this post

Link to post

Share on other sites

czardas 1,116

czardas 1,116

That looks good. I knew there were faster methods but I need to study the sieve methods to understand them. Thanks for posting this. Ah that pseudo code on wiki seems easy to read.

The prime number generation code I wrote above was really only to test the function for testing primes rather than specifically generate them. I imagine there will be some short cuts for that too which I don't know about. Your post has given me some new ideas already.

Share this post

Link to post

Share on other sites

czardas 1,116

czardas 1,116

I just looked at this in a bit more depth. The code above only produces 9591 primes (not 100,000) so the timing comparison is out by quite a large factor. The AutoIt limitation of 16 million array elements imposes a restriction of primes up to 8 digits using the method as it is coded right now. It's a facinating algorithm though. I imagine it can be tweaked - needs some thought.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)