More ‘Spirograph (®) plots using ‘matplotlib’

‘Spirograph’ includes toothed rings which can be used with small disks to draw Spirograph patterns inside the ring. The small toothed rolls around the inside of the fixed ring, producing the typical Spirograph spirals.

The diagram above shows how this works. The small circle rolls around inside the larger circle (which represents the inside of the ring). If there is no slippage, the small circle rotates in the opposite direction to its movement around the larger circle.

I modified my Python program to simulate this situation. As before, the rate of rotation of the smaller circle can be controlled by varying the ‘mult2’ variable in the program. To start with I used a small value for the variable as shown below.

The diagram has five ‘lobes’ and an empty patch in the middle. The curve can never go through the centre. If the ratio of the sizes of the circles is less than one half, then smaller circle is not big enough to reach the centre of the larger circle. If the ratio of the sizes of the circles is greater than one half, then the point on the circumference of the smaller circle that is drawing the curve (point D on the diagram above) never falls on the centre of the larger circle. If the ratio of sizes is exactly one half, all the loops will pass through the centre of the larger circle.

As the multiplier ‘mult2’ is increased, the curve comes to resemble the circular shape of a typical Spirograph. I think that it looks a bit like a torus or a donut.

I’m not going to try to emulate the behaviour of the non-circular Spirograph components. In fact, I have only emulated the circular ones, but not completely. I’ve only plotted the curves that would result if the point P (the pen) corresponded to the point D (on the smaller circle) in the diagram above.

Here’s one final plot, where the ratio of the smaller circle to the larger circle is exactly one half. The program draws a pleasant chrysanthemum or dahlia shape.

Finally, here’s the Python program that I used to draw these diagrams. To get the different figures, I’ve changed the multipliers, mainly ‘mult2’. I’ve also changed the sizes of the circles (variables ‘large’ and ‘small’) to get some of them.


import numpy as np
import matplotlib.pyplot as plt

# Dimensions of two circles
r1 = 100
r2 = 50
# c0 = [0,0]
# c1 = [1,0]

# Multipliers
mult = 10   # Used to generate the number of points plotted.
mult2 = 25  # Controls speed of rotation of the smaller circle, relative to the first.

ax = plt.subplot()
ax.set_aspect( 1 )

# Parametric array for the larger circle
t1 = np.linspace(-2 * np.pi, 2 * np.pi, mult * 360)
# Parametric array for the smaller circle
t2 = t1 * mult2

# Calculation of X/y cordinates using the parametric arrays.
# x0 and y0 are the coordinates of the tangential point, B.
x0 = r1 * np.cos(t1)
y0 = r1 * np.sin(t1)
# plt.plot(x0, y0, label=("Large circle"), color = 'r', linewidth = 2, linestyle = '--')
# x1 and y1 are the cordinates of the centre of the small circle, C.
x1 = (r1 - r2) * np.cos(t1)
y1 = (r1 - r2) * np.sin(t1)
# x1a and y1a are the coordinates of D relative to C.
x1a = r2 * np.cos(t2)
y1a = r2 * np.sin(t2)
# plt.plot(x1a, y1a, label=("Small circle"), c = 'r', linewidth = 2, linestyle = '--')
# x2 and y2 are the coordinates of the desired point on the curve, D.
plt.plot(x0[0],y0[0], color='r')
# The small circle rolls in the opposite direction if it is inside
x2 = r2 * np.cos(-t2)
y2 = r2 * np.sin(-t2)

# Plot the Curve
# plt.plot(x1 - 1.5 * x2, y1 - 1.5 * y2)
plt.plot(x1 + x2, y1 + y2, label=("'Spirograph' curve"), c = 'b', linewidth = 1)

plt.title("Inside, mult = {}, mult2 = {} ".format(mult, mult2))
plt.legend(loc="upper right")
plt.show()

Drawing ‘Spirograph'(®)-like Curves with matplotlib

‘Spirograph’® is a set of devices which can be used to draw some interesting looping curves. It consists of various toothed wheels and other toothed shapes with small holes them. A wheel or other shape is chosen, and fixed to the drawing surface. A second wheel is placed so that its teeth interlock with the teeth on the second wheel and a pen is inserted into a hole in the second wheel. The pen is moved to keep the two gear wheels enmeshed at all times. As a result the pen traces out a curve.

This can, of course, be plotted mathematically, using a tool like ‘matplotlib’. The above diagram shows how the Spirograph system works. The circle representing the first wheel is centred on point A and is fixed. The other circle is centred on point C, rolls around the first circle, and is always in contact with the first circle at point B. The point P is a point inside the smaller circle, and the line CD is the radius which passes through point B.

It is easy to see that the centre of the smaller circle (C) travels in a larger circle around the static circle. This larger circle (not drawn) has a radius is equal to the sum of the radii of the two circles. This radius corresponds to the line AC. As C travels around the circle, the smaller circle, CD, rotates. Meanwhile, the point P on CD traces out the curve we are interested in.

In the ‘Spirograph’ case, the two circles are linked by the teeth on the gears wheels. This connection ensures that the smaller circle rotates at a fixed speed. The Wikipedia page on the ‘Spirograph’ system mentions that the teeth prevent any slipping.

In the program generated case, smaller wheel can be programmed to rotate at any rate that is desired, with ‘slippage’. It can, for example, be programmed to move around the large circle without rotating at all. The next image shows what happens then. [Note: For simplicity, the point P is assumed to be located on the circumference of the small circle.]

The plot shows large fixed circle drawn with a dashed line. The small circle is not visible because it is actually a single point. The ‘Spirograph’ curve is just a larger circle offset from the centre of the large circle.

If the small circle rolls around the larger circle without slipping, then the ratio of small circle to the large should be exactly in the ratio of the radius of the small circle to the radius of the large circle. So in this next image, the size of the small circle is 75, and the size of the large circle is 100. The smaller circle rotates 100/75 (4/3) times every time it goes around the large circle.

I’m going to finish up with a couple more images that look more like a standard ‘Spirograph’. The point P is still on the circumference of the smaller circle, but this makes little difference to the plots.

This show a typical curve that a ‘Spirograph’ would plot. The ‘mult2’ parameter controls how many lobes the figure has. In this case, with a value of 25, there should be 24 lobes.

Finally, this image, with a mult2 value of 67 will have 66 lobes. When a Spirograph Wheel rotates around a fixed wheel, the pattern typically shows a rosette of loops, with a hole in the middle where the fixed wheel is located. I’m going to experiment with a moving wheel inside and if it is interesting I might do another post on the topic of ‘Spirographs’.

?Below I have pasted the program that I used to draw these images. Feel free to take it and alter it as much as you like.

import numpy as np
import matplotlib.pyplot as plt

# Dimensions of two circles
r1 = 100
r2 = 75
# c0 = [0,0]
# c1 = [1,0]

# Multipliers
mult = 10
mult2 = 67  # was 11

ax = plt.subplot()
ax.set_aspect( 1 )

# Parametric array for the larger circle
t1 = np.linspace(-2 * np.pi, 2 * np.pi, mult * 360)
# Parametric array for the smaller circle
t2 = t1 * mult2

# Calculation of X/y coordinates using the parametric arrays.
# x0 and y0 are the coordinates of the tangential point, B.
x0 = r1 * np.cos(t1)
y0 = r1 * np.sin(t1)
# plt.plot(x0, y0, label=("Large circle"), color = 'g', linewidth = 1, linestyle = '--')
# x1 and y1 are the cordinates of the centre of the small circle, C.
x1 = (r1 + r2) * np.cos(t1)
y1 = (r1 + r2) * np.sin(t1)
# x1a and y1a are the coordinates of D relative to C.
x1a = r2 * np.cos(t2)
y1a = r2 * np.sin(t2)
# plt.plot(x1a, y1a, label=("Small circle"), c = 'r', linewidth = 3, linestyle = '--')
# x2 and y2 are the coordinates of the desired point on the curve, D.

x2 = r2 * np.cos(t2)
y2 = r2 * np.sin(t2)

# Plot the Curve
# plt.plot(x1 - 1.5 * x2, y1 - 1.5 * y2)
plt.plot(x1 + x2, y1 + y2, label=("'Spirograph' curve"), c = 'b', linewidth = 1)

plt.title("mult = {}, mult2 = {} ".format(mult, mult2))
plt.legend(loc="upper right")
plt.show()

Plotting with ‘matplotlib’

What is ‘matplotlib’? It’s a Python package which can be used to plot everything from a simple parabola or sine wave right up to complex statistical data. Of course, I use it just to print interesting curves, like the one above. I’ll discuss the program I wrote below.

Since it is a Python package it helps if you know how to write Python programs, but I don’t dive too deep into Python. Anyway, the above curves were printed by a program that is only eleven lines long!

At the top of the Python code, we need to tell it to use ‘matplotlib’ and I’ve included a line to tell the code that we need to use the ‘numpy’ maths package. Here’s the first bit of the program:

import matplotlib.pyplot as plt  # This is the plotting library
import numpy as np               # A common Python package

Plotting something involves matching one set of data against another. Commonly these sets of data are named ‘x’ and ‘y’, but they can have any names that the plotter desires. The relevant code in this program is as follows:

max_range = 1000
x = np.linspace(-2*np.pi, 2*np.pi, max_range)
y = np.sin(x)

The line that starts ‘x =’ uses the numpy ‘linspace’ routine to generate a numpy array of one thousand (max_range) elements evenly spaced between -2 time pi and 2 times pi. The line that starts ‘y =’ then creates another numpy array, taking the individual elements of the array x, applying the numpy sine function and appending the result to the end of the array y.

In the earliest version of this program, I created the two numpy arrays by means of a loop, but by creating numpy arrays using this method, I can do it in two lines. Like all good ideas I got it from someone else’s program on the Internet. There is only one program, the old joke goes, and that is the “Hello World!” program, and all other programs are descendants of that single archetype.

OK, so, I created two more arrays using the same technique, and here are the two lines of code:

z = np.sin(2*x)
zz = np.sin(4*x)

So, I could have drawn three plots, one for each array, but that wouldn’t have been that interesting, so I decide to plot the sum of all three arrays (against the x array), and also the product of all three arrays (again, against the x array). Numpy arrays make this easy.

# y = np.sin(x) * np.sin(2*x) * np.sin(4*x)
plt.plot(x, y * z * zz, label='product')
# y = np.sin(x) + np.sin(2*x) + np.sin(4*x)
plt.plot(x, y + z + zz, label='sum')

The ‘plot’ statements each draw a line in the final figure, and generate a label for the line. The comments describe the curve in an x/y format, in a simple mathematical style .

The final couple of lines (see below) are needed to show the labels and the complete figure. Below is the whole Python program, comments and all.

import matplotlib.pyplot as plt
import numpy as np

# Basic Figures
# sine wave
max_range = 1000
x = np.linspace(-2*np.pi, 2*np.pi, max_range)
y = np.sin(x)

# sine wave, freq * 2
# x = np.linspace(-2*np.pi, 2*np.pi, max_range)
z = np.sin(2*x)
zz = np.sin(4*x)

# y = np.sin(x) * np.sin(2*x) * np.sin(4*x)
plt.plot(x, y * z * zz, label='product')
# y = np.sin(x) + np.sin(2*x) + np.sin(4*x)
plt.plot(x, y + z + zz, label='sum')

plt.legend()
plt.show()

To close the post, I’m going present a more complex example. This one combines the plots described above, with a separate subplot of the three waves that were used to create the first subplot. At the very end is the source code.

import matplotlib.pyplot as plt
import numpy as np

# Basic Figures
# sine wave
max_range = 1000

fig, (ax1, ax2) = plt.subplots(2, 1)

# The x array runs from -2*pi to +2*pi
x = np.linspace(-2*np.pi, 2*np.pi, max_range)

# One component of the final plot
y = np.sin(x)

# sine wave, freq * 2
z = np.sin(2*x)
# Freq * 4
zz = np.sin(4*x)import matplotlib.pyplot as plt
import numpy as np

# Basic Figures
# sine wave
max_range = 1000

fig, (ax1, ax2) = plt.subplots(2, 1)

# The x array runs from -2*pi to +2*pi
x = np.linspace(-2*np.pi, 2*np.pi, max_range)

# One component of the final plot
y = np.sin(x)

# sine wave, freq * 2
z = np.sin(2*x)
# Freq * 4
zz = np.sin(4*x)
ax1.plot(x, y, label='sin(x)')
ax1.plot(x, z, label='sin(2*x)')
ax1.plot(x, zz, label='sin(4*x)')

legend1 = ax1.legend()

# y = sin(x) * sin(2x) * sin(4x)
ax2.plot(x, y * z * zz, label='product')
# y = sin(x) + sin(2x) + sin(4x)
ax2.plot(x, y + z + zz, label='sum')

legend2 = ax2.legend()

plt.show()
ax1.plot(x, y, label='sin(x)')
ax1.plot(x, z, label='sin(2*x)')
ax1.plot(x, zz, label='sin(4*x)')

legend1 = ax1.legend()

# y = sin(x) * sin(2x) * sin(4x)
ax2.plot(x, y * z * zz, label='product')
# y = sin(x) + sin(2x) + sin(4x)
ax2.plot(x, y + z + zz, label='sum')

legend2 = ax2.legend()

plt.show()

A Simple KmPlot Example

A simple sine wave is not that interesting. However adding sine waves together can produce something more aesthetically satisfying. I could, for example, add another sine wave with a higher frequency to the above simple sine wave, as shown below.

The above diagram shows the result of adding a sine wave of three times the original frequency to the first wave. Below I show the result of adding a third sine wave of five times the original fequency to the first.

A pattern is beginning to emerge from this process. I’ll add a few more terms to the summation.

This shows the sum of the terms up to the the term for the sine wave which is 13 times the original frequency. Those who have done some maths probably recognise that this is tending towards a square wave. Here’s a link to a MatLab version of what I’ve done here.

Here’s a depiction of all the individual waves that have been added together, plus the final result.

Here’s an image of just a few of the waves. It’s probably more aesthetic than the full set!

A couple of times when I was creating the above series of plots, I made mistakes, and ended up with some more interesting graphs, but I discarded those ‘mistakes’ and stuck closely to my original idea, which was to show how simply adding a few sine waves together could result in an approximate square wave.

In fact the Fourier series for a square wave can be expressed as an infinite sum of sine waves, as shown here. A fairly complex mathematical fact can be approximated by a few simple plots.

Now I’m going to go back to the ‘mistakes’ that I made and rejected earlier when developing and writing this post.

Plotting using KmPlot

I created the above image using a program called ‘KmPlot’. It is a program for the KDE desktop for plotting mathematical functions. The function that I used for the above is something like the following:-

2∙cos(y) + 1.5∙sin(3y) = cos(5x)  −0.5∙sin(9x)

I don’t plot these curves for scientific or mathematical reasons, and that is why I can’t be 100% sure of which function(s) I actually used. I plot these curves simply to create shapes and designs which I find attractive.

I continually tweak the equations that I use until I find something that I like. There is an endless array of possibilities, even with very similar equations and for example the following image:-

The equation in this case is:-

k(x) = tan(tan(x))

The two plots above use trigonometric functions, exponential function can produce some interesting images, too, like this one:-

The equation of this curve is simply:-

s(x) = 1/x−1/x^3+1/x^5−1/x^7+1/^9

I just fiddle with these equations to produce new images. For instance, the above equation has alternating terms. What would happen if I changed all the negative terms to positive ones. This is the answer to that question:-

It is similar but different. The equation is as follows:-

s(x) = 1/x+1/x^3+1/x^5+1/x^7+1/^9

Just adding sine and cosine terms together sometimes produces interesting results. Here’s one:-

In the case of these curves, the main function is made up of multiple smaller functions, so I can’t post the formula, unfortunately. A few simple curves plotted on the same plot can produce interesting images. Below is a plot of four curves of the hyperbolic trig functions, sinh and cosh. It demonstrates how an interesting image can be built up from several curves:-

At the time I created that I was trying to recreate the following image. I have the image, but I don’t have the source! It is long gone:-

Just by fiddling with the functions and adding and multiplying them together can serendipitously result in interesting images. Here’s one. I don’t recall how I created it:-

My penultimate image is the result of trying to re-create the above image. It resembles a drawing of a flying creature, and results from lucky mistakes in copying the equations:-

That’s it for now. KmPlot allows you to create simple or complex shapes using only a little bit of elementary maths. Just by fiddling with the equations you can create weird and interesting images and I for one can’t predict what I am going to create!

Here’s one last image. This one is different from most of the others, but it has a pleasing stretched and compressed feel to it:-

What’s the answer?

The Maths is out There

Last year I posted an article which discussed some simple arithmetic and algebraic expressionss that people are posting on the Internet. I mentioned in that post that the questions are not posted to be answered. They are posted to incite discussion. Since then, there has been an upsurge of such postings, and I am going to address this topic further and expand on it.

Most people have left school with the impression that there is only one way to solve an arithmetic or algebraic question, and there is only ever one correct answer.

This is true, in a way. The rules of maths are rigid. However, when we write a problem down on paper, we write down a representation of the maths, in symbols. In the simplest case, we write down the symbol for a number, eg the symbol ‘7’. However in Ancient Rome, a mathematician would have written the symbols ‘VII’ to represent the same number. Even when we say the word ‘seven’, the word is only a name for the number.

Of course, our minds cut out all these distractions, and we, inaccurately, conflate the number and the symbol or name for the number. “This is the number seven,” we say, pointing to the symbol, but it isn’t.

When we add mathematical operations into the mix, things get more complicated of course. We write “7 + 3”, and think “Seven plus three”, mentally come up with the sum, the number 10, and think everything is fine.

But what if we were from a culture that reads and writes from right to left? We might possibly think “Three plus seven”, and would come up with the sum, the number 10.

However the language that we would use is unlikely to be the same as the one that I am using here, and the symbols would be different. Nevertheless, in some eldritch way, the maths is identical.

In this rather long preamble I have suggested that mathematics, specifically arithmetic and algebra, is independent of the symbols on the paper, and, probably, independent of the way our brains think of maths.

The Need for an ‘Order of Operations’

From now on I’m going to assume that that we are not from a culture that reads and writes from right to left, but the following reasoning can be expressed in a similar way for those who do write that manner.

Now, if I multiply two numbers I get a third number. I’m not too concerned about what multiplication actually is, but essentially I am taking two (or more) number, doing something with them and ending up with a single, different number. I can communicate this idea to someone else by writing down the two numbers with a multiplication symbol between them. I might then write a ‘=’ symbol next, and then the result.

5 x 4 = 20

A string of multiplications is easy:

5 x 4 x 2 = 40

Similarly with addition:

5 + 4 + 2 = 11

So far so good. Note that it makes no difference which order we perform the multiplications or additions. If we decide to start with the ‘2’, rather than the ‘5’, we get the same answer at the end. ‘5 x 4′ gives us ’20’ and so does ‘4 x 5’.

Problems arise when we introduce division and subtraction into the mix. Firstly, you can’t reverse the order in which you perform a subtraction or division:

5 - 4 = 1, but 4 - 5 = -1
Worse, 5 - 4 - 2 = 1 - 2 = -1, but 5 - 4 - 2 = 5 - 2 = 3

Even worse things happen when you mix addition and subtraction with multiplication and division. It’s important to note that the order that we should perform operations on numbers is not an essential part of arithmetic and algebra, but is related to the way we portray numbers and operations on paper.

So, mathematicians introduced the concept of the order of operations. This simply means that there are conventions for writing down arithmetical and other mathematical processes, in a way that someone else can take the expression, evaluate it and reach the same result as the originator of the expression.

There are ways of writing mathematical expressions which do not need an order of operations (or brackets, see later), indicating that the issues are not something within mathematics itself, but I’ll leave that for another time.

There are two ways of of writing an arithmetic or algebraic expressions in a way that can be communicated to someone else. Firstly, an order of operations rule can be applied to writing such expressions. Then expressions such as

1 - 21 / 7 + 4 * 2 =  6

can be written and understood unequivocally. The order of operation rules that are most often used are usually referred by the mnemonic PEMDAS or BODMAS.

Secondly, brackets can be used to specify the order that operations should be performed. The previous example could have been written as

(1 - (21/7)) + (4 * 2) = 6

You can always add brackets to an expression, even if they are not essential, as above.

So, if we agree to use PEMDAS, we can pass equations to and fro with a good chance of agreeing on the results, but there are some edge cases.

Is PEMDAS enough?

Some people write things like

2 / 3(5 -2)

I think that this is badly formed, and one should not write ‘…3(5…’, but people do it all the time. That said, there is an implied multiplication symbol between the ‘3’ and ‘(‘, so the same thing, with the implicit multiplication made explicit is

2 / 3 * (5 - 2)

Now there are two schools of thought on how this expression should be processed. The first group say that there is nothing special about the multiplication sign and the rules should be applied as usual. That is, from left to right as each symbol is reached.

2 /  3 * (5 - 2) = 2 / 3 * 3 = 2

The other group say that because the multiplication sign is implicit, the multiplication between the ‘3’ and the bracketed item should be processed as soon as the bracket is evaluated, before the usual left to right processing. In other words

2 / 3 * (5 - 2) = 2 / 3 * 3 = 2 / 9 = 2/9

The two schools of thought result in different answers, so which is correct? The answer is either or both. It depends on what the writer intended, and he/she could have used a set of brackets and made certain that the idea was communicated properly.

Why is it such a big thing on the Internet?

People like to cause arguments! So they post ‘quizzes’ on the Internet which are ambiguous, and then sit back and watch the fireworks. Other people read the posts and provide answers which are informed or not informed as the case may be.

Then those who think that they know, mock those who they think are wrong. Neither side acknowledge the fact that it is a communications problem. There are those who try to point this out, but they are often ignored.

Those who know of BODMAS/PEMDAS are usually adamant that they are right because it’s maths and they were taught it, right? Those who don’t are ridiculed. The BODMAS/PEMDAS believers are certain that they are correct because, it’s maths, isn’t it, and maths is never wrong. They lose track of the fact that PEMDAS/BODMAS is just a convention , and other conventions, such ‘strict left to right’ or SADMEP/SAMDOB (the reverse of BODMAS/PEMDAS) could be used. Providing both parties agree on a convention, they can communicate mathematical (well, arithmetical or algebraic) ideas successfully to each other.

Those who have been taught about implied multiplication by juxtaposition dispute the answer with those who haven’t heard of it, but really, the answer to the poser is irrelevant. The reason for that people post these dubious and intriguing equations is not to seek a value for equation. It’s not to find ‘the answer’. It’s usually to stir discussion, and the rowdier the discussion is, the better from the poster’s point of view.

2 + 4 x 3 = ?

There are innumerable Facebook posts posing the above question (or similar). It usually results in more or less acrimonious discussions. There are two main camps: those who believe that the answer is fourteen (14), and those who believe that the answer is eighteen (16).

So, which camp is correct? Well, the answer is that the question is not complete. It doesn’t specify the way that the answer should be evaluated. If you do it one way, you get one answer, and if you do it another way, you get a different answer.

How can this be? The answer lies in how we break down the question in order to evaluate it. A mathematician or a computer programmer would perhaps ask how we intend to ‘parse’ the question.

When we learn arithmetic, we learn how to add and subtract, and how multiply and divide. For instance, we learn that:

7 + 6 = 13
4 x 8 = 32

Simple! A crucial point here is that it doesn’t appear to matter which way round the numbers appear.

6 + 7 = 13
4 x 8 = 32

If we want to add three numbers together or multiple three numbers, it doesn’t matter what order we perform the operation:

6 + 7 + 12 = 12 + 6 + 7 = 25
4 x 8 x 3 = 3 x 8 x 4 = 96

It also doesn’t matter if we work from left to right, or from right to left. If we start from the right we have the number 12, we add the number 7, giving the number 19, then finally we add the number 6, giving the final result. So far, so simple.

But if we had an arithmetic problem which involves subtraction or division, then things start to become complex. The order of symbols used and the direction in which the problem is processed does matter.

8 - 3 = 5          (Left to right)
8 - 3 = -5         (Right to left)
2 / 4 = 0.5        (Left to right)
2 / 4 = 2          (Right to left)

OK, a convention is called for. If I pose you an arithmetic question, I don’t want to have to tell you how I want it to be processed. So the convention, at least in languages which are written from left to right, is that arithmetic problems are also processed in the direction that the language is written. So from now on, I will assume that any arithmetic problem is processed from left to right.

I’d like to add that, though I’ve chosen the convention that the expression is processed from left to right, the issue can be resolved in other ways. For instance, I could suggest a convention that a bare number is always associated with the operator that precedes it. In other words:

8 - 3 = 8 + (-3) = 5 (LTR or RTL)

But this could cause other issues for more complex expressions.

If we mix addition and subtraction with multiplication and division, we get something like our original problem:

2 + 4 x 3 = ?

We can, some people may be surprised to learn, get more than one answer to this problem, depending on how we process the expression.

2 + 4 x 3 = 6 x 3 = 18 (proceeding strictly from left to right)
2 + 4 x 3 = 2 + 12 = 14 (using the BODMAS convention, see below)

Many people would argue that the first answer is correct. Why jump to the multiplication first in the second example? The answer is that it is simply a convention among mathematicians and computer scientists and programmers use. It’s the answer that you would get if you put those numbers and symbols into most calculators.

Some calculators (eg Microsoft’s Windows Calculator) can give either answer depending on what mode the calculator is set up to use. There’s a simple explanation in the linked article on why that is. Maybe too simple.

The convention that mathematicians and computer scientists use is not a law of arithmetic or mathematics, as some people believe. So, why is a convention necessary? The real answer is so that you can pass a random piece of mathematics to someone else and they will understand how to process it unambiguously, if there is a commonly used convention for processing such expressions.

In particular, in algebra and computer science, using the common BODMAS conventions actually reduces the complexity of the strings of symbols necessary to express a mathematical idea. Einstein’s famous equation would be more complex without the convention – there would need to be a multiplication symbol between the ‘m’ and the ‘c’, if the equation was to be understood strictly left to right.

E = mc2 is more explicitly E = m*(c2)

The convention that I’m using here is that if two non-operator symbols are adjacent to one another, there is an implied multiplication operator between them. e.g.

2ab is equivalent to 2 x a x b
2a + b is equivalent to 2 x a + b

This convention is, strictly speaking, not part of BODMAS.

Notice the brackets around the exponentiation. Brackets are the ‘B’ of BODMAS, and are always evaluated first. The ‘O’ stands for ‘orders’ or powers, so an expression with multiplication and powers is interpreted as follows:

3 * 24 = 3 * 16 = 48

It is not interpreted as follows:

3 * 24 = 64 = 1,296 (Wrong!)

The D and M of BODMAS stand for division and multiplication. If there are both multiplications and divisions in an expression, division is not always done first. The multiplications and divisions are processed, by convention, from left to right, and the same holds for addition and subtraction, but multiplications/divisions are done before additions/subtractions. I’ve seen explanations of BODMAS that say that divisions should precede multiplications and subtractions should be carried out before additions, but this is not so, and gives wrong answers. Or rather answers that don’t really comply with the BODMAS convention, as understood by most people.

Fine, that’s all sorted. Except that it isn’t. There are cases where the simple BODMAS, left to right, convention is insufficient. One such case is the case of exponentiation on exponentiation:

2 ^ 3 ^ 4 interpreted as 2 ^ (3 ^ 4) = 2 ^ 81 = 2.417x10^24
2 ^ 3 ^ 4 interpreted as (2 ^ 3) ^ 4 = 8 ^ 4 = 4096
Note: The '^' is used here for the exponentiation process, because it is difficult to apply superscripting twice. It also makes things a little clearer.

This case is usually interpreted by the first method, above. Such cases aside, the BODMAS convention clearly describes how to evaluate any arithmetic or mathematical expression. If you are not sure of the correct methods to use to create a complex expression, you should use brackets to clarify matters, whichever convention is used. If you are trying to evaluate a dubious one, you are out of luck, unless you can contact the author of the expression!

So, given that mathematicians and computer scientists (and many others) use the BODMAS conventions, what does that say about the expression ‘2 + 3 x 4’? Is the correct answer fourteen (14)?

The problem is posed ambiguously on purpose. The original setter was not really requesting an answer. He/she was inciting debate. Therefore the ‘solution’ doesn’t really matter. For what it is worth, I understand and use BODMAS, so I favour the answer of 14, but if the poser of the conundrum really wanted a unique answer, then they would have included brackets. Either:

2 + (4 x 3) = 14 or (2 + 4) x 3 = 18

Unfortunately the debate often quickly becomes acrimonious, with one side or the other hurling insults. But that’s the Internet for you.

What Happens When Your Body Encounters a Virus?

Image by Zeathiel. Downloaded from Freeimages

When your body encounters a virus, any virus, the virus enters your body and starts to multiply. It multiplies fast. It does this by taking over the genetic systems of the cells, and so the cells can’t maintain themselves and die. When this happens the cells burst open and release many copies of the virus from each cell into your body. Each copy of the virus finds another cell to invade. This applies to all viral infections, not just Covid-19.

Let’s say that each cell releases 100 copies of the virus, a number which is far smaller than the real number. The real number is much higher. So in the first step one virus becomes 100 viruses. Each copy infects another cell, and each produces 100 viruses. So, at the second step, 10,000 virus copies are released. At the third step, 1,000,000 copies are released. At the fourth step, 100,000,000 copies of the virus are released. By the time that the replication has gone through 10 steps, an astronomical number of copies of the virus are floating around your system. After 20 steps… Remember that replication factor is enormously more than 100, too. This is termed exponential growth.

Of course, the virus doesn’t have things all its own way. Your body has an immune system. It detects the virus and starts to fight it. If the virus has not yet managed to reduce your lungs to a bag of slime, or dismantled your nervous system, or whatever, your immune system starts to fight the virus. It starts killing infected cells thus preventing them from creating copies of the virus.

It recognises infected cells by proteins on the surface of the cell. These proteins are different for different viruses, and the immune system ‘remembers’ the signature of an infected cell, and eventually, if you are lucky, the immune system succeeds in killing off all virus infected cells and the infection is over.

(Please note that specialists in this field would probably find the above hysterically funny, but I don’t think that it is too far off the mark.)

So that’s what happens when a person encounters a virus for the first time. The outwards signs of the battle between the virus and the immune system are what we consider to be the disease. That is, raised temperature, headache, spots, cough, sneezing, and so on. Maybe more life-threatening symptoms. The virus does not directly cause any symptoms itself.

When a person who has already encountered the virus encounters it again, the immune system already knows about the virus and kicks in immediately. It doesn’t have to work out, firstly, that there is a virus and secondly, how to fight it. Your temperature might peak and you might have a headache, but any symptoms will likely be much reduced this time around, and virus will be killed off much faster.

But while your body is fighting the virus, there is a short time interval when the virus is in your body and you may be mildly infectious. Since your body is already fighting the infection, the infectious period will be short, and you won’t be ‘shedding’ as much virus to infect others.

The vaccine, any vaccine, is designed to fool the immune system and provide it with the necessary information to fight the virus without actually inflicting the virus on the body. It does this either by supplying the body with the dead virus or with a very much weakened virus, or with the information necessary to detect virus infected cells.

To do this, it needs to trigger some parts of the immune system into action, but doesn’t need to do more than that, so any side effects will be minor. A sore arm, for example.

A side effect indicates that your body is configuring your immune system to handle the virus. If you had previously encountered the virus in the wild, you would, at that time, possibly have had a severe infection. Side effects of the vaccines are rare, but if there is one, it signifies that your body is doing its job, and preparing a defence against the virus.

Of course, it is theoretically possible that you might have a reaction to some component of the vaccine. It’s theoretically possible that you will be killed by a piece of falling space junk such as a falling space toilet, of course. Or you could win the lotto. All these things would be of the same order of possibility. They are theoretically possible but very unlikely.

Worrying about the contents of the vaccine seems to be silly. If you end up in hospital after an accident, or you are hospitalised for something like pneumonia, or something worse, you would be pumped full of all sorts of things. Full blood. Blood plasma. Antibiotics. Many other things that the doctors and nurses would put into your body to save your life. They might even shoot X-rays through you, or irradiate you to kill cancer cells. It is ludicrous to worry about the contents of a simple vaccine, most ingredients of which are present only in microscopic amounts.

If you tell people that there is the possibility of a side effect on taking a medicine, then a number of people will experience that side effect, even when they are not given the medicine, but are instead given a placebo. A chalk pill or an injection of plain saline. If they are worried or concerned, the likelihood of the side effect will be higher. This is called the nocebo affect, and been blamed for up to two thirds of the ‘adverse reactions’ to the Covid-19 vaccine.

When someone who hasn’t been in contact with virus catches it, it takes a relatively long time for the body to learn how to fight the virus, which means that the body is shedding virus during the period that the body is learning how to fight the virus, and while the body is destroying the virus.

On the other hand, if the person has already had the virus or has been vaccinated against it, the body doesn’t have to learn how to fight the virus. That means that the shedding period is much shorter and the level of the virus in the body is lower, so that the total amount of virus that is shed is very much lower.

In summary, a vaccinated person sheds less of the virus for a shorter period and doesn’t usually get sick. There is less chance, therefore that they will infect someone else.

People often ask if you can catch the Covid-19 virus twice. Of course you can. The protection that the vaccine gives you wanes over time, which is why we need booster shots. This is also true for other viruses, like the flu virus. If you have had the flu, then you are protected for a while by your immune system, but the immunity fades over time. That, and variants of the virus, are why we have to have a flu booster shot every year.

If you don’t come in contact with the virus, then vaccination has no effect. If you do encounter it, it doesn’t stop the virus from entering your body. No vaccine does. It just allows your body to deal with the virus quickly and efficiently. Sometimes, in spite of you catching the virus before or being vaccinated, your body doesn’t properly remember that you have had it or been vaccinated, because the protection has waned.

In which case you will get the infection again, but it is likely that your body will at least partially remember the previous infection, so if you catch the virus twice the second time will likely be less severe.

Can you infect others if you are vaccinated? Yes, you can, if your body is fighting off the infection at the time, but the chances of you doing so are very much reduced. The virus will be in your body for only a short period, and you will not have time to shed much of the virus in that time.

I have tried to explain what happens when you are infected by a virus, such as Covid-19. It is always a good idea to be vaccinated. If you decide not to get vaccinated because of the very small chance of having a usually mild side effect, that is like being in a crashing plane and refusing a parachute because ‘you know, those parachute things have been known to get tangled and people have been killed by tangled parachutes’.

Asking for Donations

Photo by Niels Timmer from FreeImages

I’m useless at self-promotion, so up until now, I’ve avoided asking for donations for my work. It’s partly because of the ‘imposter syndrome’, and it’s partly because the tools that were available were once difficult to use or expensive.

It’s the ‘imposter syndrome’ which really cripples me and causes me to hesitate to ask for money. Questions arise like ‘Am I being cheeky, asking for donations?’ or ‘Is my writing good enough to be asking for donations?’ or ‘Can I really call myself an author?’.

I’m less worried by the technical complexities that go with asking for donations. Technical stuff has been my whole life, and I don’t usually have problems with that sort of thing, but sometimes a prerequisite of the technical stuff is a paid subscription to something, and that is a problem for me.

There also has to be a driver. Why do I want to ask people for money? The reason is that I want my writing to improve. I want it to be worth reading, and that involves asking people for advice. People, friends and relations could be asked to help, I suppose, but to really get the lowdown on my writing I would need to employ a professional editor.

So that is why I am asking for donations. If I can get enough, I can ask someone to look over my work, and give their professional opinion. I should be able to improve my writing, both by editing my past work, and by taking account of the editorial comments when writing new stuff.

Please consider donating via Paypal (you don’t have to have Paypal to do it), so that I can improve my past and future writing. Thank you.

Help me improve my stories!

A Self-Limiting Problem

Photo by eddmun from FreeImages

Some wag, way back when dinosaurs ruled the earth, once commented that homosexuality is a self-limiting problem. I assume that he (or for that matter, maybe, she) meant that homosexuals don’t breed, so they can’t produce more little homosexuals. Of course there’s many things wrong with this comment, not the least of which is that homosexuality is somehow a ‘problem’.

The writer of the comment assumes that homosexuality has a genetic component. That is, homosexuals are born not made, which is almost certainly true. But the writer was totally wrong when he/she suggested that homosexuals do not breed. They can, they do, and they have always done so, by one means or another.

I don’t know whether the babies of homosexuals are more likely be homosexual or not, but if I were to hazard a guess, I’d say that the kids of homosexuals would be slightly more likely to be homosexual than the kids of heterosexuals. This would be because the kids of homosexuals would be less likely to suppress any homosexual tendencies in themselves than the kids of heterosexuals. Just a guess.

The mothers of homosexuals are mainly heterosexual women, so homosexuals are not going to die out unless the human race changes and homosexuals are not born. This is good, because they are often colourful and interesting characters. I know that’s a stereotype, but it’s not far off the mark.

Photo by quil from FreeImages

The thoughts above came to me when I was thinking about something completely different. Anti-vaxxers. They are far from my favourite people. They are the aggressive fundamentalists of this era, the sort that get up in your face and cover you in spittle as they shout their arguments at you from very short range. That’s also a stereotype, and it is also not far off the mark.

When we get vaccinated, we protect ourselves and others from diseases like Covid-19. We all wear masks because that probably reduces transmission of the disease. The vaccines will protect us and will reduce the effects of the virus if we come in contact with it, but they are not perfect. A few people will get the virus even though they have been vaccinated, but only a small number out of an already small number will need hospitalisation. Very few will die.

But those who have not been vaccinated will, if infected, probably need medical help. Many of them will end up in hospital. Some will die.

So, will anti-vaxxers die out? Will they die or recant before they can have children? That seems unlikely, as many of them already have children and scream “You’re not putting that junk into my child’s arm!”

Also, being an anti-vaxxer is probably not hereditary. Of course, their children will be indoctrinated by their parents with their parents’ anti-vaxxer views, and in that way the parents’ views would be ‘inherited’ by the children. Later the children could encounter a disease that kills them because they are not protected against it. They would not pass along the anti-vaxxer mind set to their potential children and the anti-vaxxer mind set would die out, but only in that family.

Unfortunately, the anti-vaxxer mind set can spread sideways much faster than it can die out. An anti-vaxxer can ‘infect’ many others with their mind set in a very short time.

Since it looks like anti-vaxxers are not a self-limiting problem, we will have to live with them. We’ll need to get vaccinated, and we will need to pay our taxes to provide the medical services that they and their kids will likely need. It’s the price we pay for living in a free society. It would be a lot easier if we could compel them to get vaccinated, but that is not something that anyone in their right mind would want to do.

Photo by Andrzej Pobiedziński from FreeImages

With any luck the rise and fall of the anti-vaxxers will parallel the rise and fall of smoking. At first no one smoked. Then everyone did. It became apparent that people were dying as a result, and while the smokers and the tobacco industry pushed back, the numbers slowly started to fall though it will be a long time until smoking tobacco all but disappears.

Probably the most effective measure that was taken to reduce the number of smokers was the banning of smoking in public places, like pubs and restaurants. It used to be automatic to light up after sitting down. When you had to go outside to light up, it became a chore and this make it easier to give up.

I think that one way to reduce the number of anti-vaxxers would be to ban unvaccinated people from public places, like cinemas and clubs, but that is hard. If everyone carried an inoculation ‘passport’, it might work. Almost everyone carries a driver license, and that works, but there are valid reasons to be wary of requiring everyone to carry an inoculation passport.

Maybe the anti-vaxxers will come to their senses eventually, when they see their unvaccinated family members dying off. Maybe. But by then they will have passed the virus on to others. Innocent people who would get the vaccination if they could, but can’t for some medical reason.

Every unvaccinated person is a Typhoid Mary. It is worth reading that Wikipedia article to get an idea of the mayhem that an uncooperative unvaccinated person can cause. If you are not vaccinated, and you infect someone and they die, then it would make sense that you could be charged with manslaughter. The problem would be proof.

Photo by Marcus Österberg from FreeImages