Turtles and More

Kina
Turtle graphics. This to me resembles a Kina or Sea Urchin

My wife recently became interested in the Spirograph (™) system. Since her birthday was coming up, so did I, for obvious reasons. If you have never come across Spirograph (™) I can highly recommend it, as it enables the production of glorious swirls and spirals, using a system of toothed wheels and other shapes. When you use multicoloured pen, the results can be amazing.

Of course, I had to translate this interest into the computer sphere, and I immediately recalled “Turtle Graphics” which I have used before. It is possible to create graphics very similar to the Spirograph (™) designs very simply with Turtle Graphics.

Trefoil
This resembles the sort of things generated by Spirograph (TM)

Turtle Graphics have a long history, stretching back at least to the educational programming language Logo. Although variations of the original Logo language exist, they are fairly rare, but the concept of Turtle Graphics, where a cursor (sometimes shown as the image of a cartoon turtle) draws a line on a page, still exists. The turtle can be directed to move in a particular way, based on instructions by the programmer.

For instance the turtle can be instructed to move forward a certain distance, turn right through 90°, and repeat this process three times. The result is a small square. Or the turtle could be instructed to move forward and turn only 60°, repeating this 5 times to draw a hexagon. Using simple instructions like this allow the drawing of practically anything.

Square and Hexagonal spirals
Square and hexagonal spirals drawn by Turtle Graphics

I use an implementation of Turtle Graphics in the turtle module of the Python programming language but it is probably available for other programming languages. Python is probably an easy language to learn from scratch than Logo, and in addition Python can be used for many other things than Turtle Graphics. Python is available for Windows, OS/X, and Linux/Unix, and for several other older or less well known platforms.

Where things become interesting is when the looping abilities of Python are used to enhance a program. If the programmer gets the turtle to draw a square, then makes the turtle turn a little and repeats the process, the result is a circular pattern. Starting with a more interesting shape can produce some interesting patterns.

Rotated Square - Turtle graphics
Rotated Square – Turtle graphics

After a while, though, the patterns begin to seem very similar to one another. One way to add a bit of variation is to use the ability to make the turtle move to a specific position, drawing a line on the way. As an example, consider a stick hinged to another stick, much like a nunchaku. If one stick rotates as a constant speed and the second stick rotates at some multiple of that, then the end of the second stick traces out a complex curve.

Flower shape
Flower shape – turtle graphics

In Python this can be expressed like this:

x = int(a * math.sin(math.radians(c * i)) + b * math.sin(math.radians(d * i)))
y = int(a * math.cos(math.radians(c * i)) + b * math.cos(math.radians(d * i)))

where c and d are the rates of rotation of the two sticks and and b are the lengths of the stick. i is a counter that causes the two sticks to rotate. If the turtle is moved to the position x, y, a line is drawn from the previous position, and a curve is drawn.

The fun part is varying the various parameters, a, b, c, d, to see what effect that has. The type of curve that is created here is an epicycloid. For larger values of c and d the curves resemble the familiar shapes generated by Spirograph (™).

Epitrochoids
Epitrochoids

The equations above use the same constants in each equation. If the constant are different, some very interesting shapes appear, but I’m not going to go into that here. Suffice it to say, I got distracted from writing this post by playing around with those constants!

The above equations do tend to produce curves with radial symmetry, but there is another method that can be used to produce other curves, this time with rotational symmetry. For instance, a curve can be generated by moving to new point depending on the latest move. This process is then iterative.

Gravity Wave - turtle graphics
Gravity Wave turtle graphics

For instance, the next position could be determined by turning through an angle and move forward a little more than the last time. Something like this snippet of code would do that:

for i in range(1, 200):
t.forward(a)
t.pendown()

t.left(c)
a = a + 1
c = c + 10

This brings up a point of interest. If you run code like this, ensure that you don’t stop it too soon. This code causes the turtle to spin and draw in a small area for a while, and then fly off. However it quickly starts to spin again in a relatively small area before once more shooting off again. Evidently it repeats this process as it continues to move off in a particular direction.

Turtle graphics - a complex curve from a simple equation
Turtle graphics – a complex curve from a simple equation

Another use of turtle graphics is to draw graphs of functions, much like we learnt to do in school with pencil and squared paper. One such function is the cycloid function:

x = r(t – sine(t))

y = r(1 – cosine))

This function describes the motion of a wheel rolling along a level surface and can easily be translated into Python. More generally it is the equation of a radius of a circle rolling along a straight line. If a different point is picked, such a point on a radius inside the circle or a point outside the circle on the radius extended, a family of curves can be generated.

Cycloid curve - turtle graphics
Cycloid curve – turtle graphics

Finally, a really technical example. An equation like the following is called a dynamic equation. Each new ‘x’ is generated from the equation using the previous ‘x’. If this process is repeated many times, then depending on the value of ‘r’, the new value of ‘x’ may become ever closer to the previous value of ‘x’.

x(n+1) = rx(n)(1 – x(n))

If the value of ‘r’ is bigger than a certain value and less than another value, then ‘x’ flip-flops between two values. If the value of ‘r’ is bigger than the other value, and smaller than yet another value then ‘x’ rotates between 4 values. This doubling happens again and again in a “period doubling cascade“.

Turtle graphics - electron orbitals
Turtle graphics – electron orbitals

I’ve written a turtle program to demonstrate this. First a value for ‘r’ is chosen, then the equation is repeated applied 1,000 times, and the next 100 results are plotted, x against r. In the end result, the period doubling can easily be seen, although after a few doubling, the results become messy (which may be related to the accuracy and validity of my equations, and the various conversion between float and integer types).

Period doubling
The “fig tree” curve calculated in Python and plotted by Turtle Graphics.

Upgrading

English: Upgrading Menu
English: Upgrading Menu (Photo credit: Wikipedia)

I’m a little late with this post because of an issue with my computer. An upgrade resulted in me not being able to send and receive emails. While this is partially fixed I still have work to do.

I’ve been in the business for decades so I’m acutely aware of how things can go wrong in an upgrade. Sensible systems administrators take backups, plan out the upgrade in as much detail as they can and probably spend more time getting ready than in actually performing the upgrade.


Embed from Getty Images

This pays huge dividends, but still, not infrequently, things can go wrong. The wrongness can be major, with a totally destroyed system, or minor, as in niggling irritations like something behaving slightly differently after the upgrade.

Computer firms and software suppliers often make huge efforts to make an upgrade work easily and cleanly, and many have put in place systems to make it easier to upgrade their software or back it out if something goes awry.

Microsoft Windows wordmark
Microsoft Windows wordmark (Photo credit: Wikipedia)

There are various levels of upgrade – a small part of a program may need to be upgraded, or the whole program may need to be upgraded, or indeed the whole operating system, Windows or what have you, may need to be upgraded.

In the early days of computer systems upgrading would mean downloading some source code or source code changes called “patches”, making changes to the existing source code, compiling it and then installing it into a particular location on the computer.

English: C++ source code for an (unfinished) p...
English: C++ source code for an (unfinished) program, shown in the geany editor, screen shot Svenska: Källkod (c++) för ett ofärdigt program visad i geany (textredigerare), skärmbild (Photo credit: Wikipedia)

The technical terms don’t matter too much. I just want to convey how complex and manual the process was. That is fertile ground for errors to creep in. You download a bunch of code, trusting that it will work and fix some problems, some of which you may not even be aware of, and then transfer them to the existing source code.

You may mistype something, or mistakenly overwrite something in the existing source, feed the new code into the compiler, and out pops a new program, which you then transfer into the correct location and cross your fingers and test.

English: Works Records System - schematic
English: Works Records System – schematic (Photo credit: Wikipedia)

Incidentally a compiler is also a program and as such it has bugs which need to be fixed. What if you update or patch the compiler and it breaks? You can’t remove patch and re-compile as you just broke the compiler!

The solution is to reinstall the original compiler that came from the supplier, and potentially patch that to the point before you broke it. Or, if you a sensible system administrator, you restore the original compiler from the backup that you took before the upgrade. Either solution is tedious and frustrating.

Administrator interface in WordPress blog system
Administrator interface in WordPress blog system (Photo credit: Wikipedia)

Operating systems are the biggest upgrades that can be done. They are also the most dangerous because they are big and complex, which multiplies the chances of hitting problems or ending up with a system that doesn’t work.

Operating systems upgrades used to come as a magnetic tape or two, and a small book or manual of instructions. IBM for instance used to supply several books of instructions, hints, cross references, dependency lists and so on for each major upgrade. The necessary books for looking after IBM mainframes amounted to a library and that was what it was called.

Reel of 1/2" tape showing beginning-of-ta...
Reel of 1/2″ tape showing beginning-of-tape reflective marker. (Photo credit: Wikipedia)

IBM and others quickly realised that something needed to be done to help the system administrators to install, maintain and operate their big computer systems. Otherwise people would end up with unusable systems, and IBM would have to spend time and money helping them fix them up.

So the concept of a package was conceived and from very early in computing history, everything was supplied to the customer as a package from the actual operating system down to the programs that ran the printers.

English: The Siemens SIMATIC S7 SATEP 7 V5.4 S...
English: The Siemens SIMATIC S7 SATEP 7 V5.4 Software Package. Deutsch: Das Siemens SIMATIC S7 SATEP 7 V5.4 Software Paket. (Photo credit: Wikipedia)

A package was a cluster of programs that provided some feature or facility on the computer. Packages requisites and dependencies on other program – it would be no use installing a package that needs stuff printed, like an accounting package, if there was no printing package already installed.

Computer manufacturers also moved away from providing source code to customers. They supplied, for example, a printer driver or a compiler in binary, ready to run, form, so that the program binary could be simply dropped in place and it would run right away.


Embed from Getty Images

I’m simplifying a little, as there were other program chunks that, while they weren’t compilable source code, could not be run as supplied and which had to be intimately connected to other program chunks to produce a runnable program.

Nowadays the average user, professional or home, of the Windows operating system has never seen source code. All updates through Windows Update, and programs like browsers, games, utilities and other programs, are binary distributions, binary packages that the operating system installs for you. The Windows operating system doesn’t even provide a compiler.

A Nuon DVD player with a video game controller
A Nuon DVD player with a video game controller (Photo credit: Wikipedia)

This whole distribution system for programs and updates requires very rigid interfaces between the bits of the operating system itself and other programs which are not part of the operating system, and this is, when you know what is going on in the background, truly amazing.

Indeed, a Brazilian Windows systems operator can confidently install a program on his computer, which communicates with him in Portuguese, and so can a Windows systems operator in Finland or even Japan. All can expect that the program will work almost perfectly on all these diverse systems.

中文:
中文: (Photo credit: Wikipedia)

It’s slightly more blurry in the Unix/Linux world. There the operator or maintainer is given an option – use packages similar to those used with Windows or use source code. Many Unix/Linux users these days will never have knowingly compiled source code packages, though sometimes the package maintenance system may compile code for them. However this is rare.

Some Unix/Linux users however like to compile some things for themselves, so that they can get the very latest versions of things, and some even compile their whole systems from the ground up though this is rare.

Diagram of Monolithic kernels
Diagram of Monolithic kernels (Photo credit: Wikipedia)

So when you complain about your Windows system installing updates when you shut it down, reflect that things could be worse – you could have needed to compile them yourself.


Embed from Getty Images

It’s History

The Sunken Road at Waterloo, painting by Stanl...
The Sunken Road at Waterloo, painting by Stanley Berkley, from A History of the Nineteenth Century, Year by Year, Edwin Emerson, Jr., 1902. (Photo credit: Wikipedia)

I was never any good at history. That’s probably because I couldn’t get straight in my mind who was battling who and for what reason and for how long and so on. Later I came across the concept that history is written by the victors. This makes sense to me in some ways but the losers will still have their point of view and will likely instruct their children according to that point of view.

So while one side may say that a battle was a heroic victory over huge odds, the other party may describe the heroic resistance against huge odds. One side might add that an ally came to the rescue at the last minute while the other side might mention a traitorous change of allegiance of a former ally.

English: US and Iraqi Army Soldiers guard bord...
English: US and Iraqi Army Soldiers guard borders in Iraq (Photo credit: Wikipedia)

In wars before the twentieth century it might be that the average person would be unlikely to see any military action or even be directly affected by a war or battle. Of course, the authorities might increase taxes and conscript young men, but most people would not have seen any fighting.

Communication about the battles and the progress of the war would have been hit and miss. An injured person on their way home after fighting would no doubt have little idea of what was actually happening either on the small scale of the actual battle or on the wider canvas of the whole campaign.

English: trench listening to a handmade crysta...
English: trench listening to a handmade crystal radio during the First World War 1914-1918 . Français : poste à crystal utilisé durant la première guerre mondiale 1914-1918 (Photo credit: Wikipedia)

Anyone who has taken part in any sort of war games, such as paint-ball or capture the flags type games, will know that an awful lot of running through undergrowth and an awful lot of lying in wait is involved, and an awful lot of not knowing what is happening. In older times, it could be that what is going on 100 metres away would not be known.

A lot of ancient warfare was waged based on intelligence brought in by scouts and observers. That’s why armies always try to take higher ground, as it gives you a better view of the field of battle and it also can be defended by fewer people. The disadvantage of course is that a patch of higher ground can be surrounded and isolated.

English: View across Gordano Valley View acros...
English: View across Gordano Valley View across Gordano Valley from Tickenham near Cadbury Camp. The south Wales coast can be seen on the horizon. (Photo credit: Wikipedia)

Scouts and observers can of course be mistaken. That “100 or so” men that were spotted may actually be many more, or it may even be a contingent of one’s own troops or allies which are out of position. A scout also risks his life by approaching as close to the enemy as he can.

Such intelligence as filters back to the commanders is obviously flawed and incomplete. They probably don’t know too much about the country that they are invading, whereas the locals may possibly have a better idea of the lay of the land. Maps may be incomplete or inaccurate, and may even have been built up directly from the intelligence.

The Map Room in the Churchill Museum and Cabin...
The Map Room in the Churchill Museum and Cabinet War Rooms (Photo credit: Wikipedia)

The commanders then need to deploy their troops according to their best knowledge and the intelligence. As a result they may send off troops to places where they may be easily overwhelmed or may be ineffective.

The commanders will instruct their platoon commanders on the objectives for their troops but once the platoon commanders reach their positions they are pretty much on their own. Chaos inevitably ensues, in spite of any attempts to keep order.


Embed from Getty Images

Signals are used for communication, bugle calls, semaphores, runners and other methods are used to try to give the overall commanders an idea of what is happening at the front lines. Inevitably messages will go astray and orders will be misunderstood and this may well turn the tide of battle.

Perhaps this is why I was no good at history. When one is taught about the battle of Waterloo for example, one learns that Wellington deployed his troops here and here and that Napoleon attacked here and here and the Prussian army attacked here and here. While these statements may cover the actual flow of the battle, much of this will have been rationalised after the event.

Am Morgen nach der Schlacht von Waterloo Detai...
Am Morgen nach der Schlacht von Waterloo Detail John Heaviside Clarke (1771 – 1863) England, um 1816 Öl auf Leinwand aus der ständigen Sammlung des Deutschen Historischen Museum, Berlin (Photo credit: Wikipedia)

On a wider scale, take Napoleon for example. He is described in Wikipedia as “one of the most celebrated and controversial political figures in Western history”. From the English point of view he is the villain of the piece but I suspect that to many on his side he was a hero. There is no doubt that he was respected even by his enemies as a brilliant politician and military leader.

On the principal of “history is written by the victors” mentioned above, if Napoleon had won, and should France have held sway over England, then no doubt he would have been painted either as a benevolent leader or as a heavy-handed dictator, depending on his acceptance or rejection by England. By “England” I mean the politicians and powerful in the country. The “man in the field” probably wouldn’t care too much, unless it affected him in some way.

English: One of the signatures of Napoleon Bon...
English: One of the signatures of Napoleon Bonaparte (1804), made with Inkscape by David Torres Costales (Photo credit: Wikipedia)

History, to my mind, attributes intent much more than is justified, which renders it debatable at the least. We read that Country A pushed into a region in order to cut off Country B from some resource or other. More likely Country A had the opportunity and the resources to be able to expand into the region while Country B failed to do so because of lack of foresight, opportunity or resources.

So the expansion of Country A would have more to do with young men seeing the opportunities and travelling to the colonies to make their fortunes than any real plans by the government of Country A.

Canadian CF-18 Hornets participated in combat ...
Canadian CF-18 Hornets participated in combat during the Gulf War. (Photo credit: Wikipedia)

Baudrillard published some articles on the Gulf War, the last of which is entitled “The Gulf War Did Not Take Place“. He disputed the history of the events in the Gulf as presented.

Firstly he argued that, because of the superior air power of the Americans, they did not actually come into actually engage in conflict with the Iraqi army, and therefore the events could not be really considered to be a war.

Ex-Iraqi BMP-1 IFV captured by the US forces i...
Ex-Iraqi BMP-1 IFV captured by the US forces in Iraq during the First Persian Gulf War. (Photo credit: Wikipedia)

Secondly he argued that the view of the war as presented by the media which was fed, not from actual events but mainly from the propaganda machine of the American military and as such it presented only one point of view, that of the Americans.

History will present the Gulf War and the American handling of it in overwhelmingly positive light. History has been written by the Americans for better or worse, as the victors in this event. I’m not arguing that history is wrong. Just that it presents a picture and that picture may ignore many important aspects of an event and we should be wary of official histories.

Braine-l'Alleud Belgium, Lions' Hillock. - Com...
Braine-l’Alleud Belgium, Lions’ Hillock. – Commemorative monument of the Battle of Waterloo standing on the spot where the Prince of Orange was wounded during the fight. (Photo credit: Wikipedia)

 

 

Philosophy and Science


Embed from Getty Images

Philosophy can be described, not altogether accurately, as the things that science can’t address. With the modern urge to compartmentalise things, we designate some problems as philosophy and science, and conveniently ignore the fuzzy boundary between the two disciplines.

The ancient Greek philosophers didn’t appear to distinguish much between philosophy and science as such, and the term “Natural Philosophy” described the whole field before the advent of science. The Scientific Revolution of Newton, Leibniz and the rest had the effect of splitting natural philosophy into science and philosophy.

Statue of Isaac Newton at the Oxford Universit...
Statue of Isaac Newton at the Oxford University Museum of Natural History. Note apple. (Photo credit: Wikipedia)

Science is (theoretically at least) build on observations. You can’t seriously believe a theory that contradicts the facts, although there is a get-out clause. You can believe such a theory if you have an explanation as to why it doesn’t fit the facts, which amounts to having an extended theory that includes a bit that contains the explanation for the discrepancy.

Philosophy however, is intended to go beyond the facts. Way beyond the facts. Philosophy asks question for example about the scientific method and why it works, and why it works so well. It asks why things are the way they are and other so called “deep” questions.


Embed from Getty Images

One of the questions that Greek philosopher/scientists considered was what everything is made of. Some of them thought that it was made up four elements and some people still do. Democritus had a theory that everything was made up of small indivisible particles, and this atomic theory is a very good explanation of the way things work at a chemical level.

Democritus and his fellow philosopher/scientists had, it is true, some evidence to go and to be fair so did those who preferred the four elements theory, but the idea was more philosophical in nature rather than scientific, I feel. While it was evident that while many substances could be broken down into their components by chemical method, some could not.

Antoine Lavoisier developed the theory of comb...
Antoine Lavoisier developed the theory of combustion as a chemical reaction with oxygen (Photo credit: Wikipedia)

So Democritus would have looked at a lump of sulphur, for example, and considered it to be made up of many atoms of sulphur. The competing theory of the four elements however can’t easily explain the irreducible nature of sulphur.

My point here is that while these theories explained some of the properties of matter, the early philosopher/scientists were not too interested in experimentation, so these theories remained philosophical theories. It was not until the Scientific Revolution arrived that these theories were actually tested, albeit indirectly and the science of chemistry took off.

Model for the Three Superior Planets and Venus...
Model for the Three Superior Planets and Venus from Georg von Peuerbach, Theoricae novae planetarum. Image enhanced for legibility. The abbreviations in the center of the diagram read: C[entrum] æquantis (Center of the equant) C[entrum] deferentis (Center of the deferent) C[entrum] mundi (Center of the world) (Photo credit: Wikipedia)
Before that, chemical knowledge was very run by recipes and instructions. Once scientists realised the implications of atomic theory, they could predict chemical reactions and even weigh atoms, or at least assign masses to atoms, and atomic theory moved from philosophy to science.

That’s not such a big change as you might think. Philosophy says “I’ve got some vague ideas about atoms”. Science says “Based on observations, your theory seems good and I can express your vague ideas more concretely in these equations. Things behave as if real atoms exist and that they behave that way”. Science cannot say that things really are that way, or that atoms really exist as such.

English: Adenine_chemical_structure + atoms nu...
English: Adenine_chemical_structure + atoms numbers (Photo credit: Wikipedia)

Indeed, when scientists took a closer look at these atom things they found some issues. For instance the (relative) masses of the atoms are mostly pretty close to integers. Hydrogen’s mass is about 1, Helium’s is about 4, and Lithium’s is about 7. So far so tidy. But Chlorine’s mass is measured as not being far from 35.5.

This can be resolved if atoms contain constituent particles which cannot be added or removed by chemical reactions. A Chlorine atom behaves as if it were made up of 17 positive particles and 18 or 19 uncharged particles of more or less the same mass. If you measure the average mass of a bunch of Chlorine atoms, it will come out at 35.5 (ish). Problem solved.

English: Chlorine gas
English: Chlorine gas (Photo credit: Wikipedia)

Except that it has not been solved. Democritus’s atoms (it means “indivisibles”) are made up of something else. The philosophical problem is still there. If atoms are not indivisible, what are their component particles made of? The current answer seems to be that they are made of little twists of energy and probability. I wouldn’t put money on that being the absolute last word on it though. Some people think that they are made up of vibrating strings.

All through history philosophy has been raising issues without any regard for whether or not the issues can be solved, or even put to the test. Science has been taking issues at the edges of philosophy and bringing some light to them. Philosophy has been taking issues at the edge of science and conjecturing on them. Often such conjectures are taken back by science and moulded into theory again. Very often the philosophers who conjecture are the scientists who theorise, as in famous scientists like Einstein, Schroedinger and Hawking.

:The Black Hole, Los Alamos
:The Black Hole, Los Alamos (Photo credit: Wikipedia)

The end result is that the realm of philosophy is reduced somewhat in some places and the realm of science is expanded to cover those areas. But the expansion of science suggests new areas for philosophy. To explain some of the features of quantum mechanics some people suggest that there are many “worlds” or universes rather than just the one familiar to us.

This is really in the realm of philosophy as it is, as yet, unsupported by any evidence (that I know of, anyway). There are philosophers/scientists on both sides of the argument so the issue is nowhere near settled and the “many worlds interpretation” of quantum mechanics is only one of many interpretations. The problem is that quantum mechanics is not intuitively understandable.

Diagram of one interpretation of the Nine Worl...
Diagram of one interpretation of the Nine Worlds of Norse Mythology. (Photo credit: Wikipedia)

The “many worlds interpretation” at least so far the Wikipedia article goes, views reality as a many branched tree. This seems unlikely as probabilities are rarely as binary as a branched tree. Probability is a continuum, like space or time, and it is likely that any event is represented on a dimension of space, time, and probability.

I don’t know if such a possibility makes sense in terms of the equations, so that means that I am practising philosophy and not science! Nevertheless, I like the idea.

Displacement of a continuum body, from a refer...
Displacement of a continuum body, from a reference configuration to the current configuration. Continuum mechanics. (Photo credit: Wikipedia)