See following three snippet code:

(*can compile*)
range = Range[-2, 2, 0.005];
   With[{r = range}, Table[ArcTan[x, y], {x, r}, {y, r}]]][];

(*can compile*)
   With[{r = Range[-2, 2, 0.005 - 10^-8]}, Table[ArcTan[x, y], {x, r}, {y, r}]]][];

(*can't compile*)
   With[{r = Range[-2, 2, 0.005]}, Table[ArcTan[x, y], {x, r}, {y, r}]]][];

Why the last code can't be compiled? I used Mathematica 9.0.1.

  • $\begingroup$ Your first "can compiled" doesn't compile in V.9.0.1. Gives the errors: "CompiledFunction::cfn: Numerical error encountered at instruction 12; proceeding with uncompiled evaluation. >>" and "ArcTan::indet: Indeterminate expression ArcTan[0.,0.] encountered. >>". $\endgroup$
    – m_goldberg
    Sep 6, 2013 at 17:54

2 Answers 2


In addition to Mr. Wizard's analysis, one can also avoid the indeterminacy by replacing ArcTan as follows:

   With[{r = Range[-2, 2, 0.005]}, 
    Table[Arg[Complex[x, y]], {x, r}, {y, r}]]][];

The fact that ArcTan[0,0] is undefined is a real nuisance, and I never saw the point of it because that form of the function is mainly used for practical applications such as plotting, where the purely mathematical reasons against defining that special value don't really bother anyone.

  • $\begingroup$ I didn't know of this workaround. Nice. +1 $\endgroup$
    – Mr.Wizard
    Sep 6, 2013 at 17:53
  • $\begingroup$ @AndreasLauschke Could you explain what the links above are intended for? $\endgroup$
    – Jens
    Sep 6, 2013 at 18:43
  • $\begingroup$ @AndreasLauschke I'm guessing you want to confirm the equivalence of the Arg and ArcTan methods. But the links don't seem to address the discrepancy between the definitions at the origin. $\endgroup$
    – Jens
    Sep 6, 2013 at 18:51
  • $\begingroup$ @Jens: indeed, just the equivalence of the two functions. I'd be glad to remove my comments if you think it's more misleading than helpful. $\endgroup$ Sep 6, 2013 at 19:01

The warning messages tell you:

CompiledFunction::cfn: Numerical error encountered at instruction 33; proceeding with uncompiled evaluation. >>

ArcTan::indet: Indeterminate expression ArcTan[0.,0.] encountered. >>

By using an offset of 10^-8 you avoid having exactly zero in the list, and avoid the error.

The first version does not compile in version 7 so I can't tell you about that one.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.