Visualizing (Number Theoretic) Functions with Portraits
Year: 2020 Authors: Donald Spector
Core claim
Applying functions to image pixels and comparing the transformed images across gray levels can reveal monotonicity, fluctuation, and growth behavior of number theoretic functions.
Topics
image transformation, number theoretic functions, visual pattern recognition, pixel-by-pixel analysis
Domains
number theory, arithmetic functions, analytic number theory, digital imaging, visualization, photographic portraits, halftoning
Methods
pixel-wise function mapping, grayscale binning, rescaling normalization, visual comparison across N_H
Media
grayscale photographs, color photographs, digital pixel arrays, RGB and CMYK channels
Paper text
The text below is the locally extracted OCR/Markdown version of the paper. Raw PDF files remain local and are not published here.
Bridges 2020 Conference Proceedings
Visualizing (Number Theoretic) Functions with Portraits
Donald Spector
Dept. of Physics, Hobart and William Smith Colleges, Geneva, NY, USA; spector@hws.edu
Abstract
I offer a way to determine properties of mathematical functions through a new visualization method that takes advantage of human perception of images. Since the digitization of images turns images into arrays of numbers, one can apply mathematical functions to images on a pixel-by-pixel basis. Thanks to the pattern recognition skills of humans, the form of the transformed images can give ready insight into the behavior of those mathematical functions. I explain the method and give some examples here, with a particular focus on number theoretic functions.
Introduction
Developing an understanding of the behavior of mathematical functions takes time and experience, often dependent on possessing a certain degree of comfort with translating abstract results into broadly conceptualized properties. This can be particularly true of arithmetic functions in number theory, for which continuity arguments are not generally available.
Here, I offer a novel technique to understand the behavior of functions: are they monotonic? do they fluctuate? how rapidly do they grow or fluctuate? My initial motivation was to obtain an effective way to visualize certain aspects of the behavior of number theoretic functions, but the method is perfectly general. The fundamental idea is that when mathematical functions are applied in a particular way to images, visual comparison of the transformed images to the original can readily reveal aspects of the behavior of the function. In this paper, I first describe the technique and then give a variety of examples of how it works in practice.
Generating and transforming images
Consider a grayscale image. A standard way to represent such an image digitally is as a rectangular array of real numbers, each in the interval [0, 1], one number assigned to each pixel. These real numbers represent how dark that pixel is; a black pixel is assigned 0, a white pixel is assigned 1, and the numbers in between represent the various shades of gray, with the smaller values darker than the larger values.
For our purposes, it is better to represent these grays using integers from 0 to , rather than real numbers, binning the various shades of gray into distinct hues through a linear scaling. Representing images this way is valuable for two reasons. First, because we will frequently be considering functions (from number theory) defined on integers, we will need to represent the images using integers. Second, being able to vary will allow us to study the variation of functions in an important way. We call the image represented using real numbers , and the one represented using integers (which is, of course, a function of ).
Given an image , we consider what happens when we transform it according to some function applied pixel by pixel. We thus take an input image with pixels , each of which is an integer anywhere from 0 to , and convert this to an array with pixels . We restrict the allowed functions to be non-negative. Depending on the function, there is no guarantee that the output pixels will still fall in the range from 0 to , or even that they will be integer-valued in some cases. Consequently, we rescale the pixel values so the image can easily be rendered. Let to be the maximum value of any of the , . Then construct the array defined by . The entries are real numbers in the interval [0, 1], and so we can render the array as a grayscale image, which we call .
Spector
We find that by a simple visual comparison of the transformed images to the original images at varying values of , one can readily determine mathematical properties of the transformation function. Before demonstrating this through a number of examples in the subsequent section, we address some technical features. First, because of the final rescaling, in the output image, the brightest pixel must be fully white. There is not a similar constraint on the black side; for most images of interest, with a broad range of brightnesses, this asymmetry is not significant. However, it is worth noting that a simple identity transformation applied to can yield an that is (slightly) brighter than , if no pixels in are fully saturated white. Second, to study a function that can only be evaluated on positive inputs, we increment each pixel value to before applying the function to get the array . Third, the method works with color images, too; one separates the color image into separate channels (e.g., using RGB or CMYK), transforms each channel individually, and then reassembles the output images using the same color model used to separate the original image.
Understanding functions by their action on images
For this paper, we will take two images, each of which we will transform in a variety of ways. Comparing different transformations on the same images will help highlight the insights our methodology yields. The images are two photographs: one of Handmann’s portrait of 18th century Swiss mathematician Leonhard Euler [1], and one of 20th century American mathematician Dorothy Vaughan [2].
Figure 1: Images of Leonhard Euler, in color and in grayscale, and of Dorothy Vaughan, in grayscale.
To begin, let us transform both grayscale images using the Euler totient function . Given a natural number , is the number of positive integers less than relatively prime to [3]; for ease, here we set . (As an example, , as 1 and 5 have no factors in common with 6, while 2, 3, and 4 do.) In Figure 2, we see the totient transforms of both images, each first with , and then with . From these transformed images, we can discern aspects of the behavior of . On average, is larger for
Figure 2: Totient transforms at and of the grayscale Euler and Vaughan images.
larger , but fluctuates quite dramatically. If were strictly monotonically increasing, the output images
Visualizing (Number Theoretic) Functions with Portraits
would retain the relative darkness of each pixel, but here they only do so on average; regions such as Euler’s cheeks or the background in Vaughan’s photo, quite uniform in the original, become sets of fluctuating lighter and darker grays. Still, because of the tendency of to increase on average, these fluctuations create an effect akin to halftoning [4], which becomes better at higher , with more different gray shades available to be averaged by the observer in sections where the hue does not change dramatically. The key point is this: we can infer these aspects of the totient function’s behavior simply from looking at these images.
Next, we transform the images using the Möbius inversion function , which is defined on positive integers as follows: if is divisible by a perfect square, ; if is squarefree, then is or if has an even or odd number of prime factors, respectively. For simplicity, we take . To get our transformed images, rather than using , we use , so the outputs are , or . Taking the transform with the increasing number of gray hues, we get the images in Figure 3. Since the Möbius inversion function
Figure 3: Möbius inversion function transforms of the grayscale Euler image, , 300, 500, & 1050.
yields only three values, these images contain only white, middle gray, and black pixels. While at the low value of , gross features of the original image are still apparent, this is primarily an artifact of the limited number of gray hues into which the original picture was divided. For the larger , the resulting images seem essentially random. There are faint hints of the original image, but without the original image to compare to, they would be easy to miss. In short, these images indicate that, as the input increases, the Möbius inversion function goes among its three possible outputs in a way barely distinguishable from random variation.
We now compare two different transforms of the Vaughan image in Figure 4. In the first image, we replace each pixel value by the closest prime greater than the pixel value. In the other three, we replace each pixel value by the interval to the next prime (thus if the first prime greater than is , ), at three values. Replacing each pixel value by the next prime preserves the ordering of hues from dark to light,
Figure 4: Image of Vaughan with pixel values transformed to the next prime, ; and to the gap to the next prime, , 200, and 2000.
albeit reducing the number of grays used, so the output is much like the original image. The other images
Spector
show that the distance to the next prime fluctuates, producing a jumble of light and dark in the output. Not only does the gap to the next prime fluctuate, the average gap tends to increase as the input does; this is why as increases, the output images become so much darker. Everything is normalized such that the brightest output pixel is fully white. Consequently, one large value will suppress the rest, producing a darker image. Of course, the distribution of primes has been much studied [3], but it is striking to see the behavior determined analytically to be so apparent via these image transforms.
To close, we consider three different transforms of the Euler image: one in which each pixel with value is replaced by the harmonic number, ; one in which the transforming function is the number of partitions of (how many ways can be written as a sum of positive integers); and lastly where the transform is to take the square of the sine of each pixel value. The results are shown in Figure 5. In the first, we see
Figure 5: Euler image transforms: Harmonic number and partitions at ; at & 100.
that the image is washed out and pushed towards the white end, without losing the basic form of the picture, showing that the harmonic numbers grow monotonically, but much less than linearly (logarithmically, in fact). In the second, since the number of partitions of grows extremely quickly, and the grays in final images are scaled relative to the largest output value, very few pixels wind up distinguishable from black. The last two images arise from computing , where is the pixel value, for and . The picture appears recognizable in the first case, due to the limited bins into which hues are placed, but at , we see an apparently random blur; as the period of is incommensurate with 1, the original gray hues are mapped to seemingly random new gray hues, leading to a result that looks like static on an old television.
Conclusion
This paper presents a novel method for gaining an insight into the behavior of a variety of functions, focusing on number theoretic functions. Having such a concise visual representation of how a function behaves is an interesting case of feedback, using images to provide insights into mathematics, but relying on having a mathematical representation of images. The examples given here are but a small sampling of what I have explored, including a range of other functions and the results of using this method on color images in both RGB and CMYK formulations. I also anticipate experimenting with using this approach pedagogically.
References
[1] E. Handmann. Portrait of Leonhard Euler. 1753. Kunstmuseum Basel. Online collection accessed 1 March 2020. [2] Photograph of Dorothy Vaughan. NASA. Link accessed 1 March 2020: https://www.nasa.gov/langley/hall-of-honor/dorothy-j-vaughan [3] T.M. Apostol. Introduction to Analytic Number Theory. Springer-Verlag, 1976. [4] D.C. Stulik and A. Kaplan. Halftone. Getty Conservation Institute, 2013. Link accessed 1 March 2020: https://www.getty.edu/conservation/publications_resources/pdf_publications/pdf/atlas_halftone.pdf