Note: I have restisted the temptation to reply to your node for some time for I got to the conclusion that wrt this topic we speak "two different languages", so to say. Eventually, I'm trying once more, and I only ask you to go through all this paying attention to every word, even if in the end it resulted to be rather long.
The important word in my assertion isn't mathematical, it's predict. You cannot determine the closest prime p to any number n without a primality test. Now, brute force algorithms are mathematically describable; I'm not saying they're not.
Don't misunderstand me, I understand the point you're trying to make.

However I have two remarks to make:

  1. mathematically speaking, which is appropriate in this case, "predict" is meaningless, for it belongs to the realm of astrology and the like rather than that of maths.

    You may contend that the term does appear frequently in tons of respectful mathematics text both in connection with probabilistic or approximate arguments and exact ones, but what I mean is that from a more exact, formalized point of view (of which mathematicians are aware) there is fundamentally no "onthological" difference between, say, one algorithm e.g. a "brute force one" to compute a given quantity and another one e.g. a "predictive" (whatever this may mean!) one. Of course provided that they are guaranteed to return the same quantity, in which case there is a necessary and sufficient condition asserting this.

    The difference that there can be between two such algorithms can be at most in terms of some "circumstantial" charachteristic ascribable to them, even if such "circumstantial charachteristics" may eventually turn out to be of a crucial importance in a practical application, telling wether, for example, a given number can be computed in a reasonable time or if such a computation would require 10^100 times the age of the universe.

  2. Taking into account what has been pointed out at the previous point, the OP wrote:
    If I have a certain number (eg 10) and I want to find out which are the closest prime numbers to it: (5 7 11 13).

    Please give me some ideas on how that can be accomplished.

    To which you replied:
    What have you tried? What directions are you thinking of?

    If you don't provide those items, we quite reasonably are going to consider this an attempt to get us to do your homework for you.

    To which he replied:
    I am thinking of using Math::Prime::Simple. The way with that was:
    @ranges = ( [ $myNum-100, $myNum+100 ] ); $primes = prime( @ranges );
    But this gives me ranges from -100 to +100 of $myNum. And I would have to parse through and check to see the 2 primenumbers smaller and greater than $myNum. Is there any nicer way?
    To which in turn you replied:
    There is no way of predicting what the next prime number is, given any other number. If there was, then current cryptography methods wouldn't work. All prime number generators are, for the most part, variations on brute force. The method you're looking at is probably as good as any.
    Which is the post I commented.

Now, the OP's answer in terms of Math::Prime::Simple (which BTW I do not happen to know) shows that it is already a brute force attack, but he's concerned about the fact it's far too much brute force than is really needed. I think he would have been content with a brute force attack that wouldn't have involved a brute force attack over a (fixed size) range, which has two drawbacks:

More importantly (IMHO) your claim that "there is no way of predicting what the next prime number is, given any other number" is still devoid of any mathematical significance. It's a matter of English semantics, for "to calculate the next prime brute force wise" is (a way) to "predict it".

I think you should have said something along the lines of "there is no way to find what the nearest prime to a given number that does not involve a brute force attack based on running a primality testing on its neighbours" instead.

As a minor nitpick, I would add, that there is no known way, but we do not know that there can't be, even if it appears likely that there will never be.

Also, you explicitly mentioned prime numbers generators, that is, implicitly, primality tests. But there are now relatively fast primality tests. And your claim that "if there was, then current cryptography methods wouldn't work" is plainly false, for those cryptography methods are based on the related but different problem of factorization. But really there's much we still don't know even about the latter: for example we do not know yet if it is NP complete. (But it's likely not to be, they say!)


In reply to Re^8: a close prime number by blazar
in thread a close prime number by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.