Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.