ontolog-forum
[Top] [All Lists]

Re: [ontolog-forum] HOL decidability [Was: using SKOS forcontrolled valu

To: "'[ontolog-forum] '" <ontolog-forum@xxxxxxxxxxxxxxxx>
From: "Rich Cooper" <rich@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 13 Oct 2010 14:39:39 -0700
Message-id: <20101013213943.B183A138D1A@xxxxxxxxxxxxxxxxx>

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.  

 

Thanks for your inputs,

-Rich

 

Hi Rich

 

Here's a fixed precision implementation of a prime iterator, along the lines Chris Menzel described.

 

Enjoy

------------

 

package foo;

 

import java.util.Iterator;

 

public class PrimeIterator implements Iterator<Integer> {

 

       private Integer n = 2;

      

       @Override

       public boolean hasNext() {

              // Thanks to Euclid :-D

              return true;

       }

      

       private boolean isPrime(Integer n) {

              Integer i = 2;

              while (i < n) {

                     if ((n % i) == 0) {

                           // divisible by i < n

                           return false;

                     }

                     i++;

              }

              return true;

       }

 

       @Override

       public Integer next() {

              while (!isPrime(n)) {

                     n++;

              }

              Integer tmp = n;

              n++;

              return tmp;

       }

 

       @Override

       public void remove() {

              throw new UnsupportedOperationException();

       }

      

       public static void main(String[] argz) {

              PrimeIterator iter = new PrimeIterator();

              while (iter.hasNext()) {

                     System.out.println(iter.next());

              }

       }

 

}

 

Bill Andersen 

Highfleet, Inc. (www.highfleet.com)

3600 O'Donnell Street, Suite 600

Baltimore, MD 21224

Office: +1.410.675.1201

Cell: +1.443.858.6444

Fax: +1.410.675.1204

 

 



 


_________________________________________________________________
Message Archives: http://ontolog.cim3.net/forum/ontolog-forum/  
Config Subscr: http://ontolog.cim3.net/mailman/listinfo/ontolog-forum/  
Unsubscribe: mailto:ontolog-forum-leave@xxxxxxxxxxxxxxxx
Shared Files: http://ontolog.cim3.net/file/
Community Wiki: http://ontolog.cim3.net/wiki/ 
To join: http://ontolog.cim3.net/cgi-bin/wiki.pl?WikiHomePage#nid1J
To Post: mailto:ontolog-forum@xxxxxxxxxxxxxxxx    (01)

<Prev in Thread] Current Thread [Next in Thread>