Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, I tried to compile this function but Mathematica gives "The only function arguments supported are Times, Plus, or List", I have no a way to compile this.

isPrime = Compile[{{n, _Integer}},
  And @@ (Mod[n, #] != 0 & /@ Range[2, Sqrt@N@n])
share|improve this question
You could use PrimeQ instead. – Michael E2 Jun 11 '13 at 19:27
You could rewrite it to a more procedural form, but in this case I don't see the point, you could instead use the fact that Mod is listable and look at ! MemberQ[Mod[n, Range[2, Sqrt@n]], 0] And use Divisible instead of checking result of Mod, or best use PrimeQ as Michael suggests – ssch Jun 11 '13 at 19:27
...why not isPrime = Compile[{{n, _Integer}}, FreeQ[Mod[n, Range[2, Sqrt[n]]], 0]], if you insist on your approach? – J. M. Jun 11 '13 at 19:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.