Even a very simple post about mathematics, for example, takes a very long time to write. Time that I haven’t had available in a while.

But I do have time to help make the internet a safer, more secure place.

So I have set up a secure domain (rather painlessly thanks to my hosting company) and https://aelservices.ca is now a thing.

Certificate is from Let’s Encrypt!

So, I guess the take away is use a good hosting company (I like mine) and no excuse not to offer encryption, so, get on it.

]]>I grieve with Paris, and stand strong against those who would use a totalitarian, vile ideology to enslave or murder any human.

I haven’t posted in a very long time as my life has been very busy. So busy in fact that I did not even become aware of the news of the attacks until late yesterday afternoon.

I was able to quickly track down a very important friend, knowing he lived near the epicentre of the vile acts that took place. He let me know he was fine, and even though his home was close to were the first cold blooded murders of civilians took place, he was not caught up in it. A friend of his was in attendance at the concert that was targeted but survived by convincingly playing dead since he was already drenched in some other innocent civilians blood. Think about that if there is the smallest part of you that thinks any single one of those people deserved to be attacked or if you have any sympathy for the murderers or the ideology they cower behind and bully the world with. My only hope is you see how deep and uncaring your error in thought is. Nothing can justify this attack. Literally nothing. Not revenge, since if the original act revenge is being sought upon was on civilians, then it had no justification and therefore a like act also has none. Not offence at others not obeying your beliefs, because offence (unlike incitement, where the words are not offensive to you because you disagree and are too childish to accept criticism, but when the words are indeed meant to incite violence against you) harms no one, not even the one offended. Not your beliefs, because anyone who does not voluntarily follow and repeatedly gives continuing consent to follow a set of beliefs is simply not subject to your beliefs. They are yours, and you cannot impose them on anyone else ethically, no matter what any book or other authority claims.

And I cannot state this clearly enough, never ever can the intentional targeting of civilians BECAUSE they are civilians ever be justified, nor forgiven. Any group that does so in an attempt to control a population is a danger to all human life, and they will never get our compliance, nor our surrender.

We who love life and freedom are united by this. We are all Parisians.

]]>It’s a good project as the actual mathematics are simple, despite the fact that calculations are on the complex plane. Even if you’re not confident on basic algebra and geometry with complex numbers pretty well every programming language has libraries that will do all the real work for you anyway. Arguably, even if you don’t have an interest in the math involved itself, it’s still a good first project.

So, besides the actual calculation parts (I can say out of all the functions in my application, the actual calculation and value testing functions are the simplest by far) one has to work out how a user sets values they wish to change, how to write output to the screen and to files, including making and saving image files. It is a nice first complete application project.

It’s a project that covers the entire workflow, user input, data manipulation, output to user. Further, there are always improvements to try as you learn more. Most optimizing in one sense isn’t worth it (“Premature optimization is the root of all evil” – Donald Knuth. Take this advise to heart, you don’t know what needs optimizing until you have stable, working code to profile in the first place). However, a project like this isn’t for a client, so, feel free to break your code and resurrect it over and over. There are HUGE time savings to be found in there, and website after website discussing all sorts of tricks and tips. No reason for me to repeat what many have said far better than I could.

What I want to mention is data presentation. The Mandelbrot set image is actually communicating very little. If a pixel is black, the point it is representing is almost definitely in the set. If it is not black, the point it is representing is very likely not in the set. The only time membership is really in question is for points close to the boundary. How close do they have to be to the boundary to be questionable? Well, the more iterations you allow the program to try, the closer to the boundary you can go and consider the determination trustworthy. Even so, your computer is almost definitely using decimal approximations of the point in question (I guess if you had (eg) Maple do the symbolic manipulations the only time you touch an approximation is when you draw a pixel, but that is beyond the scope of this discussion), so there may be rounding errors leading your computer to present the wrong conclusion. Finally your pixel is a square region, but the point calculated is a singular location, so the farther from the centre of the pixel you go, the less reliable the colour of that pixel is. Clear as mud, I know.

So, hand-waving all that aside, you do have an image that is approximately correct. Since a pixel is just a number mapped to a colour, the colour mapped to is basically arbitrary.

Take RGB colour space for example. A colour is defined by three components, how much red, how much green and how much blue light to emit, each one taking a value from 0 to 255. You end up with a cube with area:

Since we can only have discrete values this give us our entire 24 bit colour space of 16,777,216 colours.

It would almost feel like you now have the only tool you need to do any colour manipulations you want. The space is well defined and closed under addition modulo 256 allowing cyclic behaviour. In fact one can further just choose a point within the space, use it to define one corner of a cube within the space centred around the colour space’s midpoint and you have all reflections and at least a few rotations available (or just allow reduction modulo 256 so any rotation that puts the point outside the colour space maps it back in. We have no need of a one to one mapping after all. The possibilities are endless (for finite values of endless) really). However, just ask an engineer about RGB space and they will tell you how happy they are that no display is actually built on that model. In the end, there is no natural way to navigate the space that is aesthetically pleasing, or even sensible.

Instead, and this is only one of several other colour spaces, let’s try a cylindrical coordinate system. A cylinder is made by taking a circular disk and drawing it through space perpendicular to its face. Let the hues all be represented as being at a given angle on the disk’s edge, so as you go around the curved surface you cycle through all available hues [Fun fact, you can do this since we perceive a colour we call magenta which does not actually exist as a discrete wavelength of light. The EM spectrum goes from red to violet, but if you present the human eye with a mix of red and voilet light we perceive magenta as if it were a distinct colour and further as one that fills the role of looping the colours around for us. Your brain is constantly lying to you and this fictional colour is one of my favourite examples]. Go up the cylinder, let it be as if you were turing up a light and the colours get lighter and eventualy wash out. Go down the cube, turn the light down until no illumination at the bottom and we have black. The the disk in the middle of the cylinder is optimum lighting. Finally, highest saturation is at the outside edge of the cylinder and saturation goes down as you approach the centre of the disk at the height you are at on the cylinder. So, all points in this space are defined by an angle (around the disk), a distance from the centre of the disk towards the edge, and a distance from the base to the desired height. This is a cartoon version of the HSL colour space (and I do mean cartoon since what I’m describing there is actually wrong since HSL is better understood as two cones rather than one cylinder, the wikipedia article is actually amazing and if you have the time and care, read through it).

Ok, now, we compare two images from the Mandelbrot set, both exact same region, same maximum iterations, same subsampling, same everything as I did one right after the other and all I did was change with colouring algorithms I used. The upper image is an RGB space colouring system that is sometimes ok, but, here really just does not give anything nice, and the bottom one is an HSL algorithm I wrote that ties magnitude to trigonometric functions with results that I think look neat.

Simple RGB cube, linear walk through space systematically. | |

HSL Mapping of colour space. Sinusoidal movement through space. Click on image for full size. |

We have the exact same data, and the functions I built have the capacity to never cycle (as in if you want to make sure you don’t have a collision of two values to one colour, that is a setting I included) at which point the colours themselves do indeed have a one to one mapping for the data at the point in the centre of the pixel as my program calculated it. That is to say, both images are as information perfect as you can hope for here, it’s just one is far more compelling to the average viewer. Information preservation is just not enough to engage and inform.

]]>The original intent was to have the output be the final animated gif file, but I never finished that aspect and just used GIMP to compile the stills.

The idea was just to have sine waves that emanated from given points and be able to accurately display the waves and in the case of multiple origins, the interference patterns.

Just think of them as being seen from above, white being crests and black being troughs. Now, this was around the same time as the Voronoi images so no surprise that different metrics where on my mind. I did the normal Euclidean distance but also threw in my favourite alternate metric, Manhattan distance.

So, some typical examples follow. These are the same sine waves, same amplitude, frequency and velocity, just different metrics.

So, there are nine rectangles in that last image. Look at the centre one and compare it to the same region on the Euclidean distance version just above it. The upper right and lower left corners of that middle rectangle are the origin points of our waves.

So, consider the upper right corner of that centre rectangle. A horizontal line through that point right across the image and also a vertical line through that point divide the image into locale regions of behaviour.

We have the grey, never too dark never too light diagonal line group extending off to the upper right. Also a checkerboard pattern of squares with fuzzy edges extending away to the lower right and upper left of that point. Finally, as far as that point is concerned, we see the rectangle with the two wave origin points describing two opposite corners has an interference pattern of diagonal lines between which are a set of linear standing waves.

There are also the upper left and lower right regions, which have no edges that touch a wave origin point. Neat features there to notice are how the dark bands and light bands match with the checkerboard regions. Thinking about the math here it’s not surprising. In fact none of the behaviour of this image is surprising after looking at it and thinking about it for a bit. In advance though, I had no idea what to expect.

I first produced still images, and found them intriguing enough to make a first animation. Looking at it at first I found it neat and strange. Thinking about it for a bit it started to make a lot of sense. I was able to notice all sorts of features, including many that I haven’t mentioned above at all. A simple change and suddenly I could look back at the standard circular interference patterns above and see those had corresponding regions, but they didn’t jump out visually like they do here. You can now look back at the circular versions above and notice that yes, there are sub-regions of behaviour that do map up, but they transition so slowly you probably missed them before.

I was just playing around when I made these, but I ended up learning a bit more about waves as a result. It shows how math is like drawing or painting. Sometimes when you draw or paint you should rotate your canvas 90 degrees then look at it. Little mistakes or areas that need attention suddenly jump out from this changed perspective. You end up with a far better final work for having taken just those few minutes to change your perspective. It’s true in art, in math, and just in life in general.

There, you even got a greeting card sentiment at the end.

]]>So, one can think of the solid colour areas as the area of influence of the point that colour was assigned to that is somewhere within that solid region. That is one way to think about it, see the wikipedia entry linked above for a far better explaination that I have supplied, along with a partial list of applications of these diagrams.

A while ago a friend of mine was talking about ways to tessellate 2 dimensional images for a certain effect he wanted. He was talking to me about this and mentioned he thought interpolating a given image as a Voronoi diagram could give him the effect he wanted if consistent reference points and colour mappings were possible. I wasn’t at the time familiar with these diagrams and read up on them. The first question was if an original image could be discerned from such a diagram, and I offered to throw together a quick proof of concept program (the friend in question is far and away a better programmer than I am, but I have been doing computer imagery for a long time and I also have a formal mathematics education whereas he does not. I still am deeply in his debt for his help in many of my projects).

Here is an example of what the first images we produced looked like. |

However, and I do not at all claim originality in this, I wondered how the same image might look in a different metric. I had only skimmed the first few paragraphs of the wikipedia article I linked above and did not know that an example in Manhattan distance was included when I first produced the initial code. Using different metrics to reexamine the same data in different ways was already a well worn analytic tool for me, so included the ability to output the same points but with different metrics, Manhattan distance in particular, was included matter of fact. |

If you skipped the wikipedia entry, Euclidean distance is a measure between to points using the shortest line possible. Manhattan distance is the distance between to points where movement is only possible parallel to one axis but also only perpendicular to all other axes. To get to a point not colinear in the way described from the initial point being tested, one has to make right angle turns. So, it’s like taking a cab in Manhattan. The City is pretty well a grid, so a cab has to make a few right angle turns to get where you want to go. As you can see, the maps are similar, but they are not the same. We test all the same points but a given non-key point can be considered closer to a different point depending on how we measure distance. Further, the boundaries of a key points influence are markedly different in their behaviour between these two metrics.

It’s fair to say that although the images do look neat, it’s hard to say that the aesthetic effect we were after is possible. For interest’s sake the source images are below:

In other words, it’s time for Numberwang!

(Clip from That Mitchell & Webb Look. I did not post the linked clip, so if anyone involved with the show wants the clip removed please contact Youtube directly. Also, one of the greatest comedy sketch shows ever made, so check it out if you get the chance.)

]]>Well, that is at least the cartoon version, as we say.

So, on to that neat result. Let’s say that on the real plane you pick 3 distinct points. Here we will pick them such that they mark the corners of an equilateral triangle, but this is not necessary. Now, place a point at any finite value at all on the real plane. It doesn’t matter where, inside the three points, outside the three points, directly between two points, it doesn’t matter. Now, choose any one of those three points at random (we will call those special points corners). Draw a new point one half of the distance between that first random point and the chosen corner. Now, pick a corner at random, draw a new point half way between that last point and the new chosen corner. Repeat this as many times as you please. We are picking corners at random but a very regular shape starts to emerge.

The shape is this function’s strange attractor, which just happens to be Sierpinski’s Triangle. Sierpinski’s Triangle is classically made by taking an equilateral triangle, finding the midpoint of each side and removing the triangle described from those points from the triangle’s centre. Then do the same with all three new triangles you have. Then with all nine new triangles etc, an infinite number of times. Yet we can approach that same strictly defined shape using a process that is in fact dependent on randomness.

Below are two images of this from some software I whipped up (still in progress as it’s a bit clunky). The larger of the two is what this process looks like after 40,000 iterations (sort of, I’m rounding off to the nearest pixel right now with it). The smaller one is a blow up of one region of the image.

You can see the initial point which was clearly outside the attractor altogether. It starts nearish one of the corners, and it seems the same corner was picked a few times in a row so there is another point halfway between it and the same corner, and another point halfway between that one and the same corner again. A different corner was chosen after that and the points start to be drawn exclusively inside the outer boundaries of the triangle, and once in, it never escapes again. The new points just wanders around inside drawing out this fractal.

If you pick four corners in a square and preform similar transforms you can get a different fractal, in this case a 2 dimensional version of the Cantor Set. I hesitate to call the result Cantor Dust or Sierpinski’s Carpet as the method to produce these points is so different, but like the above, either do describe the shape of the strange attractor.

]]>

]]>