Hi Bill,
Thanks for the routine, but that is not an
iterator of primes; it is an iterator of integers. By iterating through
all the integers, your routine finds primes, but it does not iterate the
primes. The fact that you close the scope around tests for primes doesn’t
make it an iterator.
The idea behind the iterator is to produce
one new one, given the old one as a starting point. You could reformulate
the code below to do so, but it would still not iterate the primes, it would be
iterating the integers again. By the time you get to large numbers, you
can forget about the computer which will be so busy iterating integers it will
not get to the next prime for days, weeks, even years if your computer uses 64
bit numbers.
The whole point is that there is no
function that will iterate the primes directly. The code you wrote will EVENTUALLY
iterate primes as a BYPRODUCT of iterating integers and testing them, but that
code doesn’t produce each prime directly, once per iteration, without
iterating other types.
The method you are using is often called Eratosthenes’
Sieve, which is a well known method to calculate primes, but NOT to iterate
them. The difference is in what is being enumerated inside
the code.
-Rich
Sincerely,
Rich Cooper
EnglishLogicKernel.com
Rich AT EnglishLogicKernel DOT com
9 4 9 \ 5 2 5 - 5 7 1 2
From: ontolog-forum-bounces@xxxxxxxxxxxxxxxx
[mailto:ontolog-forum-bounces@xxxxxxxxxxxxxxxx] On Behalf Of Bill Andersen
Sent: Wednesday, October 13, 2010
12:52 PM
To: [ontolog-forum] ; Rich Cooper
Subject: Re: [ontolog-forum] HOL
decidability [Was: using SKOS forcontrolled values for controlledvocabulary]
On Oct 13, 2010, at 01:56 , Rich Cooper wrote:
Hi Duane, yes, iterators in software were
what I tried to convey there. There is no function that will iterate the
primes. By pairing each prime in ascending order with any other iterated
set, you create unique prime keys for each element of that set, keys that
cannot be factored.
-Rich
Hi Rich
Here's a fixed precision implementation of a prime iterator, along the
lines Chris Menzel described.
import
java.util.Iterator;
public class PrimeIterator implements
Iterator<Integer> {
public boolean hasNext() {
private boolean isPrime(Integer n) {
throw new UnsupportedOperationException();
public static void main(String[] argz) {
PrimeIterator
iter = new
PrimeIterator();
System.out.println(iter.next());
3600 O'Donnell Street, Suite 600