The Mathematica® Journal

Bernd Thaller

Institute of Mathematics

University of Graz

Heinrichstr. 36

A-8010 Graz

Austria

bernd.thaller@kfunigraz.ac.at

http://www.kfunigraz.ac.at/imawww/thaller/

Functions of two variables with values in the field of complex numbers (e.g., analytic functions) are often considered abstract mathematical objects which are difficult to visualize. Indeed, the graph of such a function would have to be drawn in a four-dimensional space with coordinates, which cannot be easily done on a sheet of paper. Therefore, several aids for visualizing complex functions have been developed. For example, the standard package ComplexMap.m by Roman Maeder illustrates how the function transforms and distorts the complex plane. Another method uses colors for the visualization of complex values. The standard package ArgColors.m specifies colors to describe the argument of complex numbers. This color map is also used in Kevin McIsaac's package ComplexPlot3D.m [McIsaac 1994].

Here we propose a refined color map of the complex plane. The color map is continuous and one-to-one from the complex plane onto the surface of the color manifold. In addition to describing the argument of a complex number by the hue of the color, the color map uses the lightness of the color to represent the absolute value. Thus the color map is suitable for colored density plots of complex functions. The package ComplexPlot.m provides commands for producing intuitive pictures of complex-valued functions, including density plots and surface plots. Since the human eye usually cannot recognize the precise color-values, our method is not suited for a quantitative representation. However, our method is useful for giving a quick impression of the most important qualitative properties of the complex function, such as the position and order of poles and zeros. The method is particularly useful for the visualization of quantum mechanical wave functions [Pauschenwein and Thaller 1996].

The complex numbers form a two-dimensional manifold which is usually described as a plane with coordinates and . Sometimes cylindrical coordinates and are also used to represent points in the complex plane. For our purpose, the representation of complex numbers as points on a sphere is more suitable. This representation is given by the method of stereographic projection. Consider a sphere of radius centered at the origin of the three-dimensional space. Let us interpret the plane as the complex plane. From a point corresponding to , we draw a straight line to the north pole of the sphere. The intersection of the line with the surface of the sphere maps each point of the complex plane to a point on the surface in a one-to-one manner. Using spherical coordinates , we find that the azimuthal angle is just the phase , while the polar angle depends only on and on as follows:

The origin of the complex plane is mapped to the south pole . The north pole is the image of a complex "number" which has an undefined phase (like the origin) and has an infinite absolute value. *Mathematica* uses the symbol ComplexInfinity (which is the same as DirectedInfinity[]) to represent this object. The complex numbers with are represented by the equator of the sphere. All complex numbers with absolute values bigger than are mapped to the northern hemisphere, the points with are mapped onto the southern hemisphere.

The manifold of colors that can be represented in a computer is three-dimensional. In the most frequently used RGB system, the colors are described by coordinates which give the intensities of the "primary" colors: red, green, and blue. The graphics directive RGBColor[R,G,B] accepts arguments in the range [0,1]. Thus, in *Mathematica* the color manifold is represented by the three-dimensional unit cube. The corners of the cube represent the additive primary colors red , green , blue , and the subtractive primary colors yellow , cyan , magenta . The remaining corners are black and white . All shades of gray are on the main diagonal from black to white.

A color code for complex numbers can be obtained by defining an arbitrary one-to-one mapping from the surface of the sphere into the manifold of colors. To do this in a natural way, it is useful to have a short look at some less familiar coordinate systems for colors. (For more information on color systems, see [Smith and Blachman 1995].)

The distance of a color from the origin measured in the maximum metric is called the brightness, . The distance from a gray point with the same brightness is called saturation, . Note that the possible values of the brightness are between 0 and 1, and for each value of the saturation varies between 0 (gray) and . The set of all colors with constant saturation and brightness is hence a closed polygonal curve with length , which is formed by edges of a cube, each of length .

Figure 1. The RGB color cube.

The *hue* of a color is , where is the length of the part of between and the red corner of (the corner with maximal red component) in the positive direction (counter-clockwise, if viewed from the white corner). That means and both correspond to the red corner, and it is most natural to define the hue as a cyclic variable modulo 1. Hence the colors at the corners of (which are red, yellow, green, cyan, blue, and magenta with saturation and brightness ) have the hue values . The built-in color directive Hue[h,s,b] defines a color in terms of its hue , the (scaled) saturation , and brightness (the HSB color system). The saturation is scaled so that its values at a given brightness range between 0 and 1. In terms of the unscaled coordinates , the color manifold is most naturally represented as a cone.

Figure 2. The HSB color cone.

It is sometimes considered a drawback of the HSB system that the "pure" red, yellow, green, and so on (the corners of the RGB cube) by definition have the same brightness as white (). The definition of the *lightness* is designed to give a quantity that describes the human perception more accurately.

For any color the lightness is defined as the average of the maximal and the minimal component, = = . We have . At a given lightness , the brightness ranges in . Hence lightness denotes black, and (that is, , ) is white. The maximal saturation at a given lightness is for and for .

The set of color points which have the maximal saturation with respect to their lightness is just the surface of the RGB color cube. On the surface, the brightness is also maximal, so that for and for . Thus the pure colors have lightness 1/2 and maximal saturation. The standard package Color.m defines the color directive HLSColor[h,l,s] which describes a color in terms of hue , lightness and saturation , where this time the saturation has been scaled so that its values at a given lightness range between 0 and 1. Hence the colors at the surface of the color manifold are described by HLSColor[h,l,1] or equivalently by Hue[h,1,2l] for and Hue[h,2-2l,1] for .

Figure 3. The HLS double cone.

In the HLS system, the colors on the surface of the color manifold have maximal saturation and can therefore be distinguished most easily. It is therefore most natural to color the sphere by defining a continuous mapping from the points of the sphere onto the surface of the color manifold. This can be done most easily in the HLS color system.

Our color map associates the point on the sphere to a color given by . We have chosen a linear dependence of the lightness on the polar angle such that the south pole has lightness 0 (black), and the north pole appears with lightness 1 (white). The colors on the sphere have maximal saturation 1 in the HLS system and thus have maximal contrast. The cyclic variable hue is most naturally associated to the azimuthal angle , which corresponds to the argument of the complex number . The pure colors red, yellow, green, and so on are on the equator of the sphere. They correspond to complex numbers with . The points more to the north appear lighter, and the points on the southern hemisphere are darker. The following sequence of commands produces a visualization of the color map of the sphere. The color map of the complex plane will be shown in Section 4.

Finally, our color map for complex numbers (given in cylindrical coordinates and ) can be defined as

The color map defined in the previous section makes it easy to produce surface plots of complex-valued functions.

Here the height of the surface shows the absolute value of a complex number , while the color is defined according to ComplexToColorMap.

Finer details or rapid oscillations of complex functions would be better represented in a sort of density plot. Unfortunately, the command DensityPlot can use only color functions which depend on a single real variable (the value of the real function to be plotted). Therefore, ComplexToColorMap cannot be used with the option ColorFunction. However, we can use the graphics primitive RasterArray to define a two-dimensional array of rectangles which are colored according to our convention.

The following command plots a "density graphic" of an array of complex numbers:

For this array of complex values,

the plot clearly shows the zeroes (black) and poles (white) of the complex function Tan[z].

The package ComplexPlot.m is based on the ideas and definitions described above.

The main goal in designing the package has been to define a command ComplexDensityPlot that behaves like the built-in DensityPlot. Moreover, the package contains commands for colored surface plots and contour plots of complex functions. If the package and its documentation are placed in a subdirectory Graphics of the AddOns/Applications directory, it can be loaded with the command:

(We don't have to restart the kernel, because the package prevents shadowing [Wagner 1996]. Note, however, that the previously defined commands ComplexPlot3D and ListComplexDensityPlot will be overwritten.)

To make the documentation accessible through the Help Browser, create the directory AddOns/Applications/Graphics/Documentation/English and put the files BrowserCategories.m, BrowserIndex.nb, ComplexPlot.nb, and CPcmds.nb in this directory. After executing the command Rebuild Help Index in the *Mathematica* front end, the new help topics should be available.

The command ComplexDensityPlot [f [x,y],{x, xmin, xmax},{y,ymin,ymax}] implements an analogue of DensityPlot for complex-valued functions. It generates a two-dimensional raster of colors which are determined from the complex values of f according to the color map discussed in the previous section. For example, the following command gives a colored density plot of the identity function, which illustrates our color map of the complex plane.

Note that red represents positive real. The complex numbers on the unit circle have maximal brightness and saturation (lightness 1/2). For on the unit circle, has the complementary color. A complex zero appears black. The warning is printed because the argument (and hence the hue) of zero is not defined. Other exceptional values producing error messages are ComplexInfinity and Indeterminate. You can turn off these messages using the command

DensityPlots are well suited for displaying fine details of functions at high resolutions. We can increase the resolution using the option PlotPoints. For plots at high resolution, we should turn off the mesh lines. The following command takes a long time on slow computers.

The bright points indicate the 5 poles of the function . One can see that the poles are of second order because all colors appear twice on a small circle around the pole.

The command ComplexDensityPlot returns a graphics object called ColorDensityGraphics, which can be transformed into other graphics objects, such as ContourGraphics, DensityGraphics, or SurfaceGraphics.

The package provides the command ComplexPlot3D for three-dimensional surface plots of complex functions. The graphics above can also be generated using the command

Here is another example:

The package also handles singularities. For the following example we turn off the compiler in order to suppress error messages. The Arg::indet warning will still be generated because the arguments of zero, ComplexInfinity, and Indeterminate are not defined. Note that Indeterminate will appear as gray at GrayLevel[0.5].

You can specify your own color map by setting the option ComplexToColorMap.

The default color map is given by the symbol $ComplexToColorMap. There are various options for modifying this built-in color map. The option SphereRadius sets the radius of the sphere used for the stereographic projection. The default value is 1. Setting SphereRadius to causes all complex numbers with to be colored with lightness 1/2 (maximal brightness and saturation). This is useful if we want to investigate complex functions in regions where the absolute value is very small or very large compared to 1.

If we are interested only in a certain range of values, we can set the option ValueRange to a range {vmin,vmax}, which displays complex numbers with absolute values larger than at maximal lightness and complex numbers with at minimal lightness. The values for maximal and minimal lightness are controlled by the LightnessRange option and are set by default to LightnessRange->{0,1}.

It is also possible to set . A plot of with ValueRange set to is the same as a plot of with the default setting of .

The ColorDensityGraphics object stores the table of colors obtained by applying the color map to the complex values. Thus, we can quickly redraw the plot with modified Graphics options, such as AspectRatio, MeshStyle, or FrameLabels. (We can't modify the options that control the color map in this way.)

Sometimes, a contour plot displays the absolute value of a function more clearly than a density plot. The package ComplexPlot.m provides a command for combining ContourPlot with ComplexDensityPlot:

Note that the option PlotRange only affects the range of the contours. You have to use the ValueRange option in order to influence the colors. In the following plot, contours are used to represent values where , and colors are used for the range .

Finally, there is a command ColorArrayPlot for plotting a two-dimensional raster of color directives. This can be used to display color images in *Mathematica*. The following auxiliary function reads a picture file in noninterleaved "raw format," a stream of bytes describing the color information without a header. Many image-editing programs (such as Adobe Photoshop) are able to save pictures in raw format. Assuming that the color information is stored in non-interleaved raw format without header, the picture can be read with the following command:

Here is an example:

We will illustrate the usefulness of the package ComplexPlot.m by investigating graphically the famous Riemann zeta-function Zeta[z], which has a rich and interesting structure [Karatsuba and Voronin 1992]. This function is defined as the analytic continuation to the whole complex plane of the function

which is initially given only for . The zeta function is meromorphic everywhere with a single pole at . The Riemann hypothesis is the conjecture that all zeros with lie on the "critical line" [Aizenberg, et.al.1997]. The only zeros with are simple zeros at the negative even integers. The Riemann zeta function plays a prominent role in number theory, because its properties are related to the distribution of prime numbers.

The function Zeta[z] has absolute values ranging over many orders of magnitude within small regions. Usually, SurfacePlots of such functions are not very useful, so we use a ColorDensityPlot for the visualization. (The following high-resolution plot takes several minutes on a Power Mac 8500. You should decrease the number of plot points on slower computers.)

We can see the pole at , and the first of the zeroes along the critical line . The phase information is hidden in the regions that are black or white, where the absolute value of Zeta[z] is very small or large compared to 1.

We can make this information visible by restricting the maximal and minimal lightness of the colors in the graphic. If we set LightnessRange->{0.5,0.5}, the information on the absolute value is totally suppressed. The following plot gives the phase information for the same region as in the plot above.

We can have a closer look at the region of for which Abs[Zeta[z]] is very small by setting SphereRadius to some small value. The following plot enlarges the black region of the first graphics and displays the values with Abs[Zeta[z]]=0.005 with maximal brightness/saturation:.

This plot shows clearly the zeros (all of first order) of the zeta function in the region under consideration. The zeros are located at the negative even numbers. The zeros at -16, -18, and -20 are already visible in the first plot. In order to look at the behavior of the zeta function near the zero at , we have to increase SphereRadius. Otherwise, the following plot would show only a tiny black point in a white field.

This is an even more extreme example:

To display the behavior near the critical line and the precise position of the zeros, a contour plot seems most appropriate.

The colors of the graphic show that the poles and zeros of the Riemann zeta function are of first order. Finally, we show a high-resolution surface plot of the zeta function in the same region.

L. Aizenberg., V. Adamchik, and V. E. Levit, "Approaching the Riemann Hypothesis with *Mathematica,*" *The Mathematica Journal*, **7 **(1) (1997).

A. A. Karatsuba and S. M. Voronin, "The Riemann Zeta-Function," *De Gruyter Expositions in Mathematics 5*. Walter de Gruyter, 1992.

K. McIsaac, ComplexPlot3D.m [*Mathematica* application package], 1998. Available: http://www.mathematica-journal.com/issue/v7i2/articles/contents/thaller/AddOns/Applications/Graphics/ComplexPlot.m

J. Pauschenwein and B. Thaller, "Visualizing quantum-mechanical wavefunctions in three dimensions with AVS," *Computers in Physics, ***10** (6) (1996), pp. 558-66.

C. Smith and N. Blachman, *The Mathematica Graphics Guidebook,* Addison-Wesley, 1995.

D. B. Wagner, "Contexts and shadowing," *The Mathematica Journal, ***10 **(6) (1996), pp. 41-51.

B. Thaller, "Visualization of complex-valued functions," [personal web site], 1997. Available: http://www.kfunigraz.ac.at/imawww/thaller/visualization/complex.html

Converted by