Message Boards Message Boards

2
|
4045 Views
|
5 Replies
|
8 Total Likes
View groups...
Share
Share this post:

NextPrime with a prime as its first argument

NextPrime[5, {-1, 2, 1, 0}]
NextPrime[5, {-1, 2, 1}]
Have a look at the results. It seems NextPrime produces strange results if its first argument is a prime number and the second argumetn is a list of both positive and negative integers
POSTED BY: Gregory Fridman
5 Replies
NextPrime[5, {-1, 2, 1}]

This one giving {3,7,5} is a clear problem. Will investigate like, right now.
POSTED BY: Daniel Lichtblau
Posted 11 years ago
I agree with Gregory Fridman, the behaviour with a list is not consistent with NextPrime[n,#]&/@list.

To be specific:
NextPrime[5, {-1, 2, 1, 0}]
yields: {3, 11, 7, 5}

However:
NextPrime[5, {-1, 2, 1}]
yields: {3,7,5} where {3, 11,7} would be expected if the function was mapped to each list member or if it was recursive (e,g, Rest@FoldList[NextPrime[#1, #2] &, 5, {-1, 2, 1}]) viz nested {3,7,11}.
Similarly:
NextPrime[5, {-1, 1, 1, 1}]
yields: {3, 5, 5, 5} instead of the expected {3,7,7,7}.

I guess it does not handle list as second argument but also does not throw out.
POSTED BY: Mark Dooris
Bill, the point is that the next cell gives different results. Have a look
POSTED BY: Gregory Fridman
Thank you for the prompt reply
POSTED BY: Gregory Fridman
Posted 11 years ago
Even though the help pages don't seem to mention it, the second argument to NextPrime can be a list. If a positive integer in that list is n then Next prime finds the n'th prime after the first argument, if it is negative then it finds the n'th prime before the first argument. So for your first example it finds the first prime before 5 = 3, the second prime after 5 = 11, the first prime after 5 = 7 and the zeroth prime after 5 = 5.

Is there anything wrong with this description or the help page description?
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract