Topic 13 - Turtle Numbers

You can use MAKE to set the value of a variable, for example:

MAKE "A 2
MAKE "B 2
PRINT :A + :B
MAKE "C :A * :B
PRINT :C

And in a loop:

MAKE "A 2
REPEAT 12 [GRAPHICSWRITE :A * 7 MAKE "A :A + 1]

And again:

MAKE "B 1
REPEAT 100 [PRINT 1 / :B MAKE "B :B + 1]

The Fibonacci squence is very famous in Mathematics. Starting with 0 and 1 the next number in the sequence is found by adding the previous two: 0, 1, 1, 2, 3, 5, 8, and so on. In Logo:

MAKE "A 0
MAKE "B 1
REPEAT 12 [MAKE "C :A + :B PRINT :C MAKE "A :B MAKE "B :C]

Fibonacci was an Italian mathematician who, in the early 13th century, introduced the Hindu-Arabic numeral system to Europe with its 10 digits and rich mathematical culture. Prior to that Europe had been dependent on the Roman number system, which was too cumbersome for serious mathematics (this was probably a major reason for the lack of eminent mathematicians in Roman and European culture after the Greeks).

Now we can define a Fibonacci function:

TO FIB :A :B
REPEAT 12 [MAKE "C :A + :B PRINT :C MAKE "A :B MAKE "B :C]
END

Or we can use a recursive definition:

TO FIB :A :B
IF :A > 2000 [STOP]
MAKE "C :A + :B
PRINT :C
FIB :B :C
END

Notice how the recursive version removes the need for the two MAKE statements to transfer the values of B to A and C to B - we simply call the function again passing B and C which become A and B the next time the function runs.

We can amend either of these functions to draw the Fibonacci sequence:

TO FIB :A :B
IF :A > 2000 [STOP]
MAKE "C :A + :B
FD :B LT 90 FD :C LT 90
FIB :B :C
END

Run this by entering FIB 2 3.

The spiral here resembles the shape of a Nautilus and in fact the cells of this creature increase in size at a rate very close to the ratio between successive Fibonacci numbers.

 

 

 

 

 

 

 

We can also calculate the ratio between the current pair of Fibonacci values :

TO FIB :A :B
IF :A > 2000 [STOP]
MAKE "C :A + :B
PRINT :C
MAKE "D :B / :A
PRINT :D
MAKE "E :A / :B
PRINT :E
FIB :B :C
END

The ratio of B:A moves from 1:1 to 2:1 to 3:2 to 5:3, and so on. The value settles around 1.618, though it never reaches a single stable value as the Fibonacci numbers keep growing. The ratio of A:B stabilises around 0.618.

The numbers 0.618 and 1.618 are known as the 'golden ratio'.

Scientists have observed this ratio in many parts of the natural world (such as the Nautilus) and for this reason the ratio has been considered to be a part of divine creation. The Greeks discovered the ratio (but not from the Fibonacci sequence) and used them in their architecture to create what they considered perfect proportions. On some Greek temples the pillars at each successive level are scaled by the golden ratio - see Disney's 'Donald in Mathmagic Land' for an excellent animated guide to this.

You can find a lot of material on Fibonacci at this web site: http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fib.html.

The golden ratio reappears in the Renaissance where it is used for the layout and design of some of the world's most famous paintings. In classical and neo-classical paintings and architecture the focus of a subject is often placed at around 6/10 of the horizontal or vertical axis. Each of the two segments thus created are themselves divided by the same rule, creating an underlying sense of proportion and harmony.

Here is another version of the function which draws rectangles with sides equal to Fibonacci numbers:

TO FIB :X :A :B
IF :A > 2000 [STOP]
MAKE "C :A + :B
IF REMAINDER :X 2 = 0 [REPEAT 2 [FD :A LT 90 FD :B LT 90]]
[REPEAT 2[FD :B LT 90 FD :A LT 90]]
FIB :X+1 :B :C
END

 

 

 

 

 

 

A new primitive is introduced here, REMAINDER :A :B, which finds the remainder when B is divided by A. For example, REMAINDER 5 2 gives 1, while REMAINDER 6 2 gives 0. In the new function an extra value, X, has been added which is first set to 0 and then increased by 1 each time the function is called (remember it is recursive). As X is divided by 2 the remainder alternates between 1 and 0 as X is alternately odd and even. Depending on the value of the remainder a choice is made in the IF statement between drawing a rectangle with sides A and B or a rectangle with sides B and A. Assuming initial Fibonacci values of 1 and 2 the sequence of sides of rectangles drawn is as follows:

1, 2, 1, 2 (X=0, so shortest side first)
3, 2, 3, 2 (X=1, so longest side first)
3, 5, 3, 5 (X=0, etc.)
8, 5, 8, 5
8, 13, 8, 13
21, 13, 21, 13, and so on.

This code and the sequence of numbers ensures that the rectangles are drawn with their long and short axes in alternating positions.

Here are two images taken from the pages of R Knott, Surrey University, which extend this line of thought:

Here is a picture of a nautilus shell, which embeds the figure for the golden ratio in the dimensions of its spirals (for details see the reference above).

The Greeks, like some other groups of people both ancient and modern, were fascinated by numbers and there were cults such as the Pythagoreans whose members believed in the mystical power of numbers - they also believed that it was sinful to eat beans!. The 'science' of numbers is called 'numerology' and its adherents are called 'numerologists'. Even today people think 3 is 'lucky' and 13 'unlucky' and many players of lotteries and other forms of gambling believe the numbers they use have special qualities - even though the opposite is proved to be the case time after after time. There are religious groups whose members believe that God has planted numbers in the scriptures from which can be calculated events such as the end of the world.

 

 

 

 

 

 

 

 

Return to Logo Home Page