March 25, 2023

Determine prime numbers with a questionnaire

The classical approach to calculate the prime number works with trial division which is implemented in the programming language by choice on a modern PC. The speed depends mainly on the compiler efficiency plus some handcrafted performance improvements in the source code. The roesetta code website povides a good introduction into the subject [1].
What is missing in this classical approach from the past are heuristics which have nothing to do with programming itself but are reducing the problem space in a general way. A possible option for doing so is a questionnaire formulated in natural language. The interesting situation is, that such an approach has nothing to do with solving the original problem with computer programming but it is about reformulating the original problem. Here is an example:
1. Is the tested number greater 2?
2. Does the number ends with 0,2,4,6,8?
3. Is the number a multipie factor of the prime numbers from 2 to 100?
4. What is the Digit sum (add each single digit)?
5. Is it possible to store the prime sieve from 2 to 1000 on the computer system?
What the algorithm to determine the prime numbers has to do is to answer these questions. The answer is stored in an array in the format [yes,no,yes,26,no]
In response to a answer set the algorithm will choose a certain strategy to determine the prime number. The tool of a questionnaire allows to reference to domain specific knowledge in the context of prime number generation. There are lots of other questions available but for reason of simplicity it makes sense to start with only five of them.
The advantage of using a questionnaire to store domain knowledge is that it allows to formulate the knowledge in a machine readable and in a human friendly format at the same time. The wisdom is divided in chunks which are following the question - answer paradigm. The resulting array of answers can be processed by a computer easily.
References
[1] https://rosettacode.org/wiki/Sequence_of_primes_by_trial_division