md`
## Motivation
Domain coloring is a technique for visualizing complex functions. Plotting a function of one variable on a two dimensional page is straightforward, but a complex function doubles the number of dimensions by mapping each complex number to another complex number—for a total of four dimensions. That's one more than we can represent with a two-dimensional heat map or contour plot, so we'll need to resort to some other tricks.
[Complex *analytic* functions](https://en.wikipedia.org/wiki/Analytic_function) are for the most part just regular functions evaluated in the complex plane and which don't resort to forbidden operations like treating the real and imaginary components separately (this is *not at all* a technical definition!). For example, ${tex`f(z) = \sqrt{z}`} is complex analytic while ${tex`f(z) = \sqrt{\mathrm{Re}(z)}`} is complex but not analytic. If our function is analytic, then the behavior constrained by the [Cauchy-Riemann](https://en.wikipedia.org/wiki/Cauchy–Riemann_equations) equations and we can take a bit more targeted approach to focus on conveying the characteristics of the complex analytic function that aid interpretation.
Roughly speaking, the rules of domain coloring are:
- Dark grid lines represent inputs ${tex `z`} with integer real or imaginary values. I'll refer to these as **rectangular grid lines**.
- Light grid lines represent the argument (a.k.a. the phase) and modulus (a.k.a. the magnitude) of the input ${tex `z`}. (Well, more precisely the *log* of the modulus, to make it scale-independent.) I'll refer to these as **polar grid lines**.
- The hue represents the complex phase, with red corresponding to a positive real value
- Values with a small modulus are dark
- Values with a large modulus are light
That's a lot to pack into one plot! There are additional tricks like indicating direction with gradients, but I find that more distracting than anything. You can [read more about domain coloring on wikipedia](https://en.wikipedia.org/wiki/Domain_coloring) (and see their version of the above plot). Though the task is straightforward, getting the coloring just right is really tricky. I've given it another shot in this notebook, but there's still room for improvement.
***Edit***: *I'm starting to second guess my take on gradients. It's just so hard to get the scaling right otherwise, especially on the GPU where it's not straightforward to calculate stats and scale the coloring by the actual range displayed. I've [tried the gradient approach here](http://rreusser.github.io/lamb-wave-dispersion/). It's not so bad as long as you aim for a bit of subtlety. Though it still seems more difficult to interpret to me.*
Let's work through this and start simple.
## Visualizing zeros
Using the domain coloring technique, the plot of ${tex `f(z) = (z^2-i)/(2z^2+2i)`} looks like this:
`