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.
Let me give you another example. Can you tell me the closest power of 2 to a given number N? Now, can you do it without breaking down a number into its composite primes? I can, by generating the sequence of powers of 2 and looking at them. That's predictive.
Here's pseudocode for both algorithms, so you can see the difference.
Bruteforce algorithm:
sub is_power {
# Some algorithm to determine if a number is a power of two.
}
sub closest_power_of_two_brute {
my $m = my $n = shift;
return $n if is_power( $n, 2 );
while (1) {
return $n if is_power( $++n, 2 );
return $m if is_power( $m, 2 );
}
}
Predictive algorithm:
sub iterate_over {
my $v = shift;
return sub {
$v *= $v;
};
}
sub closest_power_of_two_predictive {
my $n = shift;
my $it = iterate_over( 2 );
my $l = $it>();
while ( my $v = $it>() ) {
last if $v > $n;
$l = $v;
}
abs( $n  $l ) > abs( $n  $v ) ? $v : $l;
}
Limbic~Region's example is much better than mine.
Being right, does not endow the right to be rude; politeness costs nothing. Being unknowing, is not the same as being stupid. Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence. Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:

For: 

Use: 
 &   & 
 <   < 
 >   > 
 [   [ 
 ]   ] 
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.

