# Why Mathematica does strange thing with complex numbers [duplicate]

For example, compare the two commands below.

ContourPlot[
Abs[(Exp[I p] - 1) (Exp[I q] - 1)] == 0, {p, 0, 2 Pi}, {q, 0, 2 Pi}]
ContourPlot[
Abs[(Exp[I p] - 1) (Exp[I q] - 1)] == 10^-10, {p, 0, 2 Pi}, {q, 0,
2 Pi}]


Obvisouly, $$|(e^{ip}-1)(e^{iq}-1)|=0$$ is only possible on the square boundary $$p,q=0,2\pi$$, but on my computer, Mathematica produces two entirely different graphs below.

Mathematica cannot give the correct result for the first command, while it does if we change $$0$$ to $$10^{-10}$$. I think it has something to do with how Mathematica manages errors with complex numbers.

I need to work with something much more complicated than this complex function, but I really don't know how to proceed if I can't make Mathematica correctly do this basic one.

• From help, under possible issues it says Contours f(x,y)==0 for functions where f(x,y)>=0 are always poorly detected:  may be this is why? ref/ContourPlot Nov 4 '21 at 21:56
• @yarchik Thank you! I think this is a similar topic. Nov 4 '21 at 22:00
• @Nasser But it doesn't tell exactly why and how to solve. LOL. Nov 4 '21 at 22:01
• well, it says right after that Giving a value in between allows for easy contouring: may be this is meant to to be how to solve it. This explains why giving some value above zero makes it show up? I guess the lesson for us today, is to avoid using Contours f(x,y)==0 for functions where f(x,y)>=0 Nov 4 '21 at 22:08
• I don't know exactly what Mathematica does, but a common contour plotting method is to sample the function on a grid and draw contours between adjacent grid points whose values straddle the intended contour levels. If the region within the contour is so narrow that no grid point samples it, you get no contour. Nov 4 '21 at 22:34

For this critical case f[x,y]>=0 use RegionPlot as simple workaround:
RegionPlot[Abs[(Exp[I p] - 1) (Exp[I q] - 1)] <= .00001, {p, 0,2Pi}, {q, 0,2 Pi}]

• @MichaelE2 Sorry I meant f[x,y]>=0. Yes it's quite similar, but my experience shows that RegionPlot evaluates more reliable in this case. Nov 5 '21 at 11:59
• I see what you mean: that RegionPlot seems more reliable than ContourPlot when comparing f[x,y] to a small number, not that it handles the case when comparing to exactly zero. Nov 5 '21 at 12:02