16
$\begingroup$

I am not looking for an efficient way to find primes (which of course is a solved problem). This is more of a "what if" question.

So, in theory: Could you train a neural network to predict whether or not a given number n is composite or prime? How would such a network be laid out?

$\endgroup$
  • 1
    $\begingroup$ Take a look at cs.indstate.edu/~legri/prime06.pdf $\endgroup$ – VividD May 28 '17 at 13:56
  • 2
    $\begingroup$ If the primes follow a pattern and someone just happens to train a neural network with enough hidden nodes in order to define the classification boundary, I suppose it would work. However, we don't know if that classification exists and even if it did, we would have to prove what the boundary is in order to prove that the neural network did indeed find the correct pattern. $\endgroup$ – quintumnia Jun 5 '17 at 7:31
8
$\begingroup$

Early success on prime number testing via artificial networks is presented in A Compositional Neural-network Solution to Prime-number Testing, László Egri, Thomas R. Shultz, 2006. The knowledge-based cascade-correlation (KBCC) network approach showed the most promise, although the practicality of this approach is eclipsed by other prime detection algorithms that usually begin by checking the least significant bit, immediately reducing the search by half, and then searching based other theorems and heuristics up to $floor(\sqrt{x})$. However the work was continued with Knowledge Based Learning with KBCC, Shultz et. al. 2006

There are actually multiple sub-questions in this question. First, let's write a more formal version of the question: "Can an artificial network of some type converge during training to a behavior that will accurately test whether the input ranging from $0$ to $2^n-1$, where $n$ is the number of bits in the integer representation, represents a prime number?"

  1. Can it by simply memorizing the primes over the range of integers?
  2. Can it by learning to factor and apply the definition of a prime?
  3. Can it by learning a known algorithm?
  4. Can it by developing a novel algorithm of its own during training?

The direct answer is yes, and it has already been done according to 1. above, but it was done by over-fitting, not learning a prime number detection method. We know the human brain contains a neural network that can accomplish 2., 3., and 4., so if artificial networks are developed to the degree most think they can be, then the answer is yes for those. There exists no counter-proof to exclude any of them from the range of possibilities as of this answer's writing.

It is not surprising that work has been done to train artificial networks on prime number testing because of the importance of primes in discrete mathematics, its application to cryptography, and, more specifically, to cryptanalysis. We can identify the importance of digital network detection of prime numbers in the research and development of intelligent digital security in works like A First Study of the Neural Network Approach in the RSA Cryptosystem, G.c. Meletius et. al., 2002. The tie of cryptography to the security of our respective nations is also the reason why not all of the current research in this area will be public. Those of us that may have the clearance and exposure can only speak of what is not classified.

On the civilian end, ongoing work in what is called novelty detection is an important direction of research. Those like Markos Markou and Sameer Singh are approaching novelty detection from the signal processing side, and it is obvious to those that understand that artificial networks are essentially digital signal processors that have multi-point self tuning capabilities can see how their work applies directly to this question. Markou and Singh write, "There are a multitude of applications where novelty detection is extremely important including signal processing, computer vision, pattern recognition, data mining, and robotics."

On the cognitive mathematics side, the development of a mathematics of surprise, such as Learning with Surprise: Theory and Applications (thesis), Mohammadjavad Faraji, 2016 may further what Ergi and Shultz began.

$\endgroup$
1
$\begingroup$

In theory, a neural network can map any given function (source).

However, if you train a network with the numbers 0 to N, you cannot guarantee that the network will classify numbers outside that range correctly (n > N).

Such a network would be a regular feed forward network (MLP) as recurrency does not add anything to the classification of the given input. The amount of layers & nodes can only be found through trial and error.

$\endgroup$
  • 1
    $\begingroup$ Universal theorems applies to continuous functions on compact subsets. Prime/not prime is not such kind of function. $\endgroup$ – pasaba por aqui Aug 17 '18 at 10:59
  • 1
    $\begingroup$ @pasabaporaqui: In this case the primeness function can be approximated well enough by a continuous function with peaks at the values of primes. So the NN might output 90% chance of being a prime for 6.93 - that is clearly nonsense, but if you discretised the inputs and outputs, you don't really care about what the NN would predict for non-integers. I think this answer is basically correct. $\endgroup$ – Neil Slater Aug 27 '18 at 9:00
-1
$\begingroup$

yes it is feasible, but consider that integer factorization problem is an NP-something problem and BQP problem.

because of this, it is impossible that a neural network purely based on classical computing finds prime number with 100% accuracy, unless P=NP.

$\endgroup$
  • $\begingroup$ As the question explains, check if a number is prime is not a NP problem. $\endgroup$ – pasaba por aqui Aug 17 '18 at 10:52

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.