Mandelbrot Set in VB.NET

I finally downloaded the Express edition of Microsoft Visual Basic .NET, and started a long-overdue peek into the much-hyped .NET technology. Up till now, most of my code has been plain C++ with straight Windows API calls. I generally stay away from languages that remove the programmer from the underlying architecture. But I must say that programming .NET has been nothing but a pleasure so far, despite the cons of .NET programming, of which there’s also no shortage.

I was actually pretty surprised that the Express editions of all .NET languages (VB, C++, C#, and J#) are freely downloadable and, for all intents and purposes, fully functional.

My first stab at programming VB.NET is a simple Mandelbrot Set viewer:

Mandelbrot Set

The total time to get this program written was about 25 minutes, which says a lot about the possibilities for tremendous productivity using .NET, although this application hardly scratches the surface of .NET functionality…

The Moon Rulz

Ignignokt
It’s pretty hilarious watching the nation’s reaction to the bomb scare in Boston. Supposedly city officials are prepared to charge Turner Broadcasting $500,000 to pay for the police and bomb squad response.

I hope this doesn’t affect the release schedule of Aqua Teen Hunger Force, Colon, Movie Film For Theaters. Hopefully, if anything, ticket sales resulting from this ingenious advertising campaign will make up for it!

It looks like, in our “post-9/11 world,” there’s no end to the irrationality and paranoia that people will succumb to, just because they can’t find anyone else to blame.

Hyperbolic Tessellations

A tessellation refers to a uniform tiling of a plane with polygons, such that an equal number of identical polygons meet at each vertex. For example, the tiles in a bathroom, the squares of linoleum on an office floor, or the honeycomb pattern in a bees’ nest are all tessellations of the Euclidean plane.

Hyperbolic TessellationHowever, tessellations are also possible on non-Euclidean spaces, such as the elliptic plane (like the stitching pattern on a soccer ball), and the hyperbolic plane (like… nothing you’d find around the house). In fact, the Euclidean plane has only three regular tessellations (with squares, hexagons, and triangles), while the hyperbolic plane can be tessellated in infinitely many ways.

Since we do not exist in hyperbolic space, we cannot truly “see” hyperbolic tessellations. We can only “represent” them in Euclidean form. A common way of doing this is on the Poincaré disk, which is a finite circle that represents the boundary of the (infinite) hyperbolic plane that is contained inside. The image on the right is a hyperbolic tessellation drawn on the Poincaré disk.

Since tessellations of the hyperbolic plane are especially interesting and mesmerizing to look at, I wrote a small program that generates them, with a great deal of configurable options.

Tessellation Application

Using the Program

The program allows you to create an unlimited number of tessellations by selecting “File -> New” from the menu.

When viewing a tessellation, click-and-drag inside of it to shift its position within hyperbolic space. You can also click-and drag with the right mouse button to manipulate the truncation of the tessellation.

Tessellation ControlsThe “Tessellation Controls” window allows you to change the settings for the tessellation that is currently active.

  • p and q — The numbers specified by p and q refer to the Schläfli symbol {p,q} of the tessellation. The Schläfli symbol is a simple way of classifying tessellations where p is the number of sides in each polygon, and q is the number of polygons that meet at each vertex.
  • Max. Vertices — This specifies the number of vertices that will be drawn (how far the tessellation will extend towards the disk boundary). More vertices will take exponentially longer to draw. Also, with more vertices, clicking-and-dragging the tessellation will become slower. With a good screen resolution, 10000 vertices fills up the Poincaré disk almost completely.
  • Model — Select “Poincaré” to draw the tessellation on a Poincaré-style disk, and “Klein” to draw on a Klein-style disk. The Klein disk is similar to the Poincaré disk, except the Klein disk transforms hyperbolic space so that a line between two points appears as a straight line, instead of a circle arc, which is what the Poincaré disk gives.
  • Quality — Select “Low” to display simple straight lines between vertices (and let the tessellation be drawn much faster). Select “High” to draw actual curved lines between vertices. This will slow down drawing considerably.
  • Truncation — This is a list of predefined levels of truncation for the tessellation. Select from this list to apply a certain truncation. You can also do free-form truncation by clicking-and-dragging on the tessellation with the right mouse button.
  • Colors — This allows you to select different colors for each of the components of the tessellation, and to enable or disable drawing of each component.
  • Driver — This selects what functions the program will use to draw the tessellation. Select “OpenGL” to use OpenGL technology, or “Windows GDI” to use plain Windows functions. In most cases, selecting OpenGL will enable the images to be drawn considerably faster, especially with Antialiasing enabled. However, OpenGL is not supported on some (very) old graphics cards. Also, if you create multiple tessellations, only one can be drawn with OpenGL at any given time.
  • Antialias lines — Check this box to draw “smooth” lines.
  • Line Thickness — This specifies the thickness (in pixels) of the lines that make up the tessellation.
  • Advanced — These options are mostly experimental and will not be discussed here.

Gallery

Here’s a brief collection of images created using this program. Click on an image to view a larger version.

{7,3} tessellations, with various truncation:
none, (0,1,0), (0,.5,.5), runcinated, omnitruncated, and snub.

No Truncation(0,1,0) Truncation(0,.5,.5) Truncationruncinatedomnitruncatedsnub

Links

  • This program borrows a substantial amount of code from Don Hatch‘s page, which has an exhaustive gallery of {p,q} permutations and truncations, as well as a tessellation Java applet.
  • David E. Joyce’s tessellation page at Clark University.

Ulam’s Prime Number Spiral

There is an infinite number of prime numbers, and yet the prime numbers themselves do not display any apparent pattern, nor does any formula exist that generates prime numbers. In fact, Legendre proved that there cannot be an algebraic function which always gives primes.

Prime SpiralHowever, prime numbers do exhibit a curious phenomenon when arranged in a spiral along with other consecutive integers, as in the figure to the right (in the figure, prime numbers are highlighted in white, twin primes are green, and Mersenne primes are red).

The Phenomenon

It was first noticed by the physicist Stanisław Ulam in 1963, when he got bored in a meeting and started doodling spirals of numbers. He noticed that, if he makes a spiral of consecutive integers, and circles only the prime numbers, strange diagonal “lines” of prime numbers emerge.

This is quite surprising, since we would intuitively expect a random distribution of prime numbers. However, these diagonal segments occur on an impressively large scale, and arbitrarily far from the center of the spiral. The following image is a spiral containing about 4000 primes, and next to it is the same image with some of the diagonal paths highlighted.
Prime Spiral

Application

To explore this phenomenon on a large scale, I wrote a small program that generates arbitrarily large spirals, with configurable coloring and other options.

Download the program! (Or browse the source code on GitHub)

Prime Spiral Application
The program generates a spiral based on the total number of integers that you specify. It also allows you to specify the colors to use for the background, prime numbers, twin primes, and Mersenne primes.

In addition, the program allows you to use a custom polynomial (up to degree-2) for generating the spiral. By default, the polynomial is set to
f(n) = n
so the spiral will have the normal sequence 0, 1, 2, 3, etc. However, as an example, suppose you want the spiral to consist only of odd integers (1, 3, 5, 7, etc). You can simply set the polynomial to be
f(n) = 2n + 1
Odd Prime Spiral
by writing “2” in the text box next to “n“, and “1” in the last of the three text boxes. The image to the right shows a spiral constructed from odd integers only. Notice the prominent “patterns,” this time extending vertically and horizontally.

Conclusions

Ultimately, all that these patterns show is that certain polynomials are more “likely” to generate prime numbers than others. In fact, we can speculate that these kinds of patterns would emerge if we arrange the integers in any ordered design, not just a spiral. Even if we arrange the integers in a simple table, we would still see occasional “streaks” of prime numbers similar to the ones seen in the spiral.

The existence of “prime-generating” polynomials was known since the time of Euler, who discovered a polynomial that gives 40 consecutive prime numbers, namely
$$f(n) = n^2 – n + 41$$
The reason why some polynomials generate more primes than others is still not known.

Extreme Spirals

Using my program, you can generate extremely large spirals, limited only by the amount of memory on your computer. Here are some fairly large ones that I generated:

On the Existence of George Washington

In yet another friendly religious debate, I was given the argument that goes something like, “How do you know that _____ _____ existed?” The blanks can obviously be replaced with any prominent historical figure who is no longer living. On this occasion it was George Washington. This argument is quite weak in itself, since it is not even an argument for or against the existence of God (or Jesus); instead, it argues only that human knowledge is fallible, therefore no fact can be absolutely certain, indirectly leaving a little room for the possibility of a god.

The response to this kind of argument is three-fold. First, we have thousands of instances of indirect evidence that supports the existence of George Washington in the form of biographies, paintings, and letters, as well as documents and letters written by the man himself. It’s highly unlikely and unnecessary for all of these sources to have conspired to invent a non-existent first president of the United States.

The second part of the response is perhaps the most important: George Washington never claimed to be able to break the laws of physics! There are no claims of Washington parting seas, curing the blind, or turning water into wine. If such a claim had been made, we would undoubtedly need some truly convincing evidence, like confirmations of the observed phenomena by the greatest scientists of the time (emphasizing their inability to explain the phenomena), as well as experimental data on repeatability and consistency of Washington’s powers.

The third part of the response is a bit more subtle, but also very important. Believing in the existence of George Washington is not integral to the understanding of reality. History is reevaluated all the time. One day, historians might even discover that Washington was a hoax, and never existed as a real person. However, this kind of finding would have no effect on the foundations of physics, cosmology, or biology. The existence of Jesus, however (especially the god-man Jesus of the Bible) would have profound consequences in many scientific disciplines. The fact that the Bible is the only (second-hand) source that attributes supernatural powers to Jesus makes for particularly weak evidence for his divinity. If there was a single manuscript claiming that George Washington had magical powers, I would undoubtedly want evidence that is as credible as the claim is outlandish. Wouldn’t you?