Post Reply 
(34S) Prime Factors
05-30-2014, 08:58 PM
Post: #7
RE: (WP-34S) Prime Factors
(05-30-2014 08:07 PM)Dave Britten Wrote:  My hunch is that repeatedly calling NEXTP like that causes a ton of duplicated work. I don't imagine there's any sophisticated caching going on with the limited RAM in the 30b hardware. (See: Schlemiel the Painter)

If that's the case, using it in a prime factoring algorithm is probably taking it to O(N * log N) complexity at best as the input argument grows, whereas the MOD 30 loop keeps it O(N) (even if it's not as fully optimal as it could be).

The important thing is: we don't need to know whether a factor is prime or not to figure out if it divides the number. What ever the complexity of PRIME? may be (O(k log3n) according to Wikipedia), it can't be faster than a simple division. Thus if NEXTP has to test all the next odd numbers we don't gain anything.
Using the MOD 30 loop you even gain a factor 1.875 compared to the minimal routine using only odd numbers.
How does your program compare to the built-in program PF?

Kind regards
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(34S) Prime Factors - Dave Britten - 05-30-2014, 01:53 AM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 03:30 AM
RE: (WP-34S) Prime Factors - Dave Britten - 05-30-2014, 03:54 AM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 08:24 AM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 07:06 PM
RE: (WP-34S) Prime Factors - Dave Britten - 05-30-2014, 08:07 PM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014 08:58 PM
RE: (WP-34S) Prime Factors - Dave Britten - 05-30-2014, 09:42 PM
RE: (WP-34S) Prime Factors - Thomas Klemm - 05-30-2014, 10:57 PM
RE: (WP-34S) Prime Factors - Dave Britten - 05-30-2014, 11:58 PM
RE: (WP-34S) Prime Factors - Dave Britten - 05-31-2014, 01:09 AM
RE: (WP-34S) Prime Factors - Dave Britten - 06-01-2014, 06:11 PM



User(s) browsing this thread: 1 Guest(s)