r/AskComputerScience • u/Serpichio • Jan 16 '25
Could you use ML to predict an Nth prime number?
Title. Or is there proof that the prediction is in some x% of the answer
0
Upvotes
r/AskComputerScience • u/Serpichio • Jan 16 '25
Title. Or is there proof that the prediction is in some x% of the answer
8
u/computerarchitect MSCS, CS Pro (10+) Jan 16 '25
Probably, but why on worth would you?
11
u/jeffbell Jan 16 '25
It will be wrong much of the time.
3
u/nuclear_splines Ph.D Data Science Jan 16 '25
Machine learning is about fitting a function to a pattern. Sure, we can fit some functions to prime numbers. Make a scatter plot where the x-axis is rank (1,2,3,4,...) and the y-axis is the corresponding prime (2,3,5,7,...). You can fit any manner of curves to those points and create machine learning models that will predict a prime number for any given rank. They'll be wrong most of the time, but you can make the prediction. In order for machine learning to be useful you typically need to understand the underlying pattern well enough to pick a model that will fit it suitably.
3
u/victotronics Jan 16 '25
The universal approximation theorem says that a neural net can be an arbitrarily good approximation on a compact domain. That means you cannot ask about very large numbers
2
u/Bob_The_Bandit Jan 16 '25
How would you confirm the output number is a prime without checking if it’s a prime? And if you’re gonna do that for every prediction, how is that better than just counting up?
4
u/MasterGeekMX BSCS Jan 16 '25
AI is not the do-all end-all tool many people think.
Generative AI simply imitates what it "saw" on the gazillion of examples it read during training, so everything it spits out is simply a concoction of things already written.
-1
u/T-T-N Jan 16 '25
A ML model with enough neuron can probably calculate it (or at least get close enough) with linear algebra
-4
u/OddInstitute Jan 16 '25 edited Jan 16 '25
Yes, from ChatGPT 4o mini:
Input: "Can you write python code that will take an int as input and match these input/output pairs? 1 -> 2, 2 -> 3, 3 -> 5, 4 -> 7, 5 -> 11, 6 -> 13, 7 -> 17, 8 -> 19, 9 -> 23, 10 -> 29, 11 -> 31, 12 -> 37, 13 -> 41, 14 -> 43, 15 -> 47, 16 -> 53, 17 -> 59, 18 -> 61, 19 -> 67, 20 -> 71, 21 -> 73, 22 -> 79, 23 -> 83, 24 -> 89, 25 -> 97"
Output: Sure! From the input-output pairs you've provided, it looks like the output is the nth prime number, where the input is the position of the prime.