Algorithms and Data Structures

187 downloads 926211 Views 8MB Size Report
Dec 22, 2013 - One example application of recursion is in parsers for programming ...... is given a choice to use it to free her father as well as the builder of.
Algorithms and Data Structures Part 6: Recursion (Wikipedia Book 2014)

By Wikipedians

Editors: Reiner Creutzburg, Jenny Knackmuß

PDF generated using the open source mwlib toolkit. See http://code.pediapress.com/ for more information. PDF generated at: Sun, 22 Dec 2013 18:33:46 UTC

Contents Articles Recursion

1

Recursion

1

Fibonacci number

7

Fibonacci numbers in popular culture

22

Golden ratio

26

Tower of Hanoi

47

Backtracking

60

Collatz conjecture

65

Primitive recursive function

78

Μ-recursive function

84

Ackermann function

88

Recursion (computer science)

95

Computability theory

114

References Article Sources and Contributors

124

Image Sources, Licenses and Contributors

127

Article Licenses License

129

1

Recursion Recursion Recursion is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The term has a variety of meanings specific to a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics and computer science, in which it refers to a method of defining functions in which the function being defined is applied within its own definition. Specifically this defines an infinite number of instances (function values), using a finite expression that for some instances may refer to other instances, but in such a way that no loop or infinite chain of references can occur. The term is also used more generally to describe a process of repeating objects in a self-similar way.

A visual form of recursion known as the Droste effect. The woman in this image holds an object that contains a smaller image of her holding an identical object, which in turn contains a smaller image of herself holding an identical object, and so forth.

Formal definitions of recursion In mathematics and computer science, a class of objects or methods exhibit recursive behavior when they can be defined by two properties: 1. A simple base case (or cases) 2. A set of rules that reduce all other cases toward the base case For example, the following is a recursive definition of a person's ancestors: • One's parents are one's ancestors (base case). • The ancestors of one's ancestors are also one's ancestors (recursion step). The Fibonacci sequence is a classic example of recursion:

Recursion in a screen recording program, where the smaller window contains a snapshot of the entire screen.

Recursion

Many mathematical axioms are based upon recursive rules. For example, the formal definition of the natural numbers by the Peano axioms can be described as: 0 is a natural number, and each natural number has a successor, which is also a natural number. By this base case and recursive rule, one can generate the set of all natural numbers. Recursively defined mathematical objects include functions, sets, and especially fractals. There are various more tongue-in-cheek "definitions" of recursion; see recursive humor.

Informal definition Recursion is the process a procedure goes through when one of the steps of the procedure involves invoking the procedure itself. A procedure that goes through recursion is said to be 'recursive'. To understand recursion, one must recognize the distinction between a procedure and the running of a procedure. A procedure is a set of steps based on a set of rules. The running of a procedure involves actually following the rules and performing the steps. An analogy: a procedure is like a written recipe; running a procedure is like actually preparing the meal. Recursion is related to, but not the same as, a reference within the specification of a procedure to the execution of some other procedure. For instance, a recipe might refer to cooking vegetables, which is another procedure that in turn requires heating water, and so forth. However, a recursive procedure is where (at least) one of its steps calls for a new instance of the very same procedure, like a sourdough recipe calling for some dough left over from the last time the same recipe was made. This of course immediately creates the possibility of an endless loop; recursion can only be properly used in a definition if the step in question is skipped in certain cases so that the procedure can complete, like a sourdough recipe that also tells you how to get some starter dough in case you've never made it before. Even if properly defined, a recursive procedure is not easy for humans to perform, as it requires distinguishing the new from the old (partially executed) invocation of the procedure; this requires some administration of how far various simultaneous instances of the procedures have progressed. For this reason recursive definitions are very rare in everyday situations. An example could be the following procedure to find a way through a maze. Proceed forward until reaching either an exit or a branching point (a dead end is considered a branching point with 0 branches). If the point reached is an exit, terminate. Otherwise try each branch in turn, using the procedure recursively; if every trial fails by reaching only dead ends, return on the path that led to this branching point and report failure. Whether this actually defines a terminating procedure depends on the nature of the maze: it must not allow loops. In any case, executing the procedure requires carefully recording all currently explored branching points, and which of their branches have already been exhaustively tried.

Recursion in language Linguist Noam Chomsky theorizes that unlimited extension of any natural language is possible using the recursive device of embedding clauses within sentences (Aspects of the Theory of Syntax. 1965). For example, two simple sentences—"Dorothy met the Wicked Witch of the West in Munchkin Land" and "The Wicked Witch's sister was killed in Munchkin Land"—can be embedded in a third sentence, "Dorothy liquidated the Wicked Witch with a pail of water," to obtain a recursive sentence: "Dorothy, who met the Wicked Witch of the West in Munchkin Land where her sister was killed, liquidated her with a pail of water." The idea that recursion is an essential property of human language (as Chomsky suggests) is challenged by linguist Daniel Everett in his work Cultural Constraints on Grammar and Cognition in Pirahã: Another Look at the Design Features of Human Language, in which he hypothesizes that cultural factors made recursion unnecessary in the development of the Pirahã language. This concept, which challenges Chomsky's idea that recursion is the only trait that differentiates human and animal communication, is currently under debate. Andrew Nevins, David Pesetsky and Cilene Rodrigues provide a debate against this proposal. Everett, however, does not minimize the importance of

2

Recursion

3

recursion in thought or information processing, but rather tries to flip Chomsky's argument around, contending that recursion can selectively go from thought to languages, rather than language to thought. He states that recursive structures are fundamental to information processing (quoting Herbert Simon), and then says: "If you go back to the Piraha language, and you look at the stories they tell, you do find recursion. You find that ideas are built inside of other ideas..." (2013, Thinking, John Brockman ed., p. 273). This quote is after the Nevins, Pesetsky, Rodrigues responses. In other words, recursion is acknowledged by all parties in the debate as central to thought, information processing, perhaps consciousness itself (in robotics recursion is a proxy for self-awareness in many designs), and either as cause or effect in many grammars, whether genetic or not. Recursion in linguistics enables 'discrete infinity' by embedding phrases within phrases of the same type in a hierarchical structure. Without recursion, language does not have 'discrete infinity' and cannot embed sentences into infinity (with a 'Russian nesting doll' effect). Everett contests that language must have discrete infinity, and asserts that the Pirahã language—which he claims lacks recursion—is in fact finite. He likens it to the finite game of chess, which has a finite number of moves but is nevertheless very productive, with novel moves being discovered throughout history.

Recursive humor Recursion is sometimes used humorously in computer science, programming, philosophy, or mathematics textbooks, generally by giving a circular definition or self-reference, in which the putative recursive step does not get closer to a base case, but instead leads to an infinite regress. It is not unusual for such books to include a joke entry in their glossary along the lines of: Recursion, see Recursion. A variation is found on page 269 in the index of some editions of Kernighan and Ritchie's book The C Programming Language; the index entry recursively references itself ("recursion 86, 139, 141, 182, 202, 269"). The earliest version of this joke was in "Software Tools" by Kernighan and Plauger, and also appears in "The UNIX Programming Environment" by Kernighan and Pike. It did not appear in the first edition of The C Programming Language. Another joke is that "To understand recursion, you must understand recursion." In the English-language version of the Google web search engine, when a search for "recursion" is made, the site suggests "Did you mean: recursion." An alternative form is the following, from Andrew Plotkin: "If you already know what recursion is, just remember the answer. Otherwise, find someone who is standing closer to Douglas Hofstadter than you are; then ask him or her what recursion is." Recursive acronyms can also be examples of recursive humor. PHP, for example, stands for "PHP Hypertext Preprocessor", WINE stands for "Wine Is Not an Emulator." and GNU stands for "GNU's not Unix".

Recursion

4

Recursion in mathematics Recursively defined sets Example: the natural numbers The canonical example of a recursively defined set is given by the natural numbers: 0 is in if n is in

, then n + 1 is in

The set of natural numbers is the smallest set satisfying the previous two properties. Example: The set of true reachable propositions Another interesting example is the set of all "true reachable" propositions in an axiomatic system.

A Sierpinski triangle—a confined recursion of triangles to form a geometric lattice

• if a proposition is an axiom, it is a true reachable proposition. • if a proposition can be obtained from true reachable propositions by means of inference rules, it is a true reachable proposition. • The set of true reachable propositions is the smallest set of propositions satisfying these conditions. This set is called 'true reachable propositions' because in non-constructive approaches to the foundations of mathematics, the set of true propositions may be larger than the set recursively constructed from the axioms and rules of inference. See also Gödel's incompleteness theorems.

Finite subdivision rules Finite subdivision rules are a geometric form of recursion, which can be used to create fractal-like images. A subdivision rule starts with a collection of polygons labelled by finitely many labels, and then each polygon is subdivided into smaller labelled polygons in a way that depends only on the labels of the original polygon. This process can be iterated. The standard `middle thirds' technique for creating the Cantor set is a subdivision rule, as is barycentric subdivision.

Functional recursion A function may be partly defined in terms of itself. A familiar example is the Fibonacci number sequence: F(n) = F(n − 1) + F(n − 2). For such a definition to be useful, it must lead to non-recursively defined values, in this case F(0) = 0 and F(1) = 1. A famous recursive function is the Ackermann function, which—unlike the Fibonacci sequence—cannot easily be expressed without recursion.

Recursion

Proofs involving recursive definitions Applying the standard technique of proof by cases to recursively defined sets or functions, as in the preceding sections, yields structural induction, a powerful generalization of mathematical induction widely used to derive proofs in mathematical logic and computer science.

Recursive optimization Dynamic programming is an approach to optimization that restates a multiperiod or multistep optimization problem in recursive form. The key result in dynamic programming is the Bellman equation, which writes the value of the optimization problem at an earlier time (or earlier step) in terms of its value at a later time (or later step).

Recursion in computer science A common method of simplification is to divide a problem into subproblems of the same type. As a computer programming technique, this is called divide and conquer and is key to the design of many important algorithms. Divide and conquer serves as a top-down approach to problem solving, where problems are solved by solving smaller and smaller instances. A contrary approach is dynamic programming. This approach serves as a bottom-up approach, where problems are solved by solving larger and larger instances, until the desired size is reached. A classic example of recursion is the definition of the factorial function, given here in C code: unsigned int factorial(unsigned int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); } } The function calls itself recursively on a smaller version of the input (n - 1) and multiplies the result of the recursive call by n, until reaching the base case, analogously to the mathematical definition of factorial. Recursion in computer programming is exemplified when a function is defined in terms of simpler, often smaller versions of itself. The solution to the problem is then devised by combining the solutions obtained from the simpler versions of the problem. One example application of recursion is in parsers for programming languages. The great advantage of recursion is that an infinite set of possible sentences, designs or other data can be defined, parsed or produced by a finite computer program. Recurrence relations are equations to define one or more sequences recursively. Some specific kinds of recurrence relation can be "solved" to obtain a non-recursive definition. Use of recursion in an algorithm has both advantages and disadvantages. The main advantage is usually simplicity. The main disadvantage is often that the algorithm may require large amounts of memory if the depth of the recursion is very large.

5

Recursion

6

The recursion theorem In set theory, this is a theorem guaranteeing that recursively defined functions exist. Given a set X, an element a of X and a function , the theorem states that there is a unique function (where denotes the set of natural numbers including zero) such that

for any natural number n.

Proof of uniqueness Take two functions

and

such that:

where a is an element of X. It can be proved by mathematical induction that Base Case: Inductive

for all natural numbers n:

so the equality holds for Step:

Suppose

. for

some

.

Then

Hence F(k) = G(k) implies F(k+1) = G(k+1). By Induction,

for all

.

Examples Some common recurrence relations are: •

Golden Ratio:



Factorial:



Fibonacci numbers:



Catalan numbers:



Computing compound interest



The Tower of Hanoi



Ackermann function

,

Bibliography • Dijkstra, Edsger W. (1960). "Recursive Programming". Numerische Mathematik 2 (1): 312–318. doi:10.1007/BF01386232 [1]. • Johnsonbaugh, Richard (2004). Discrete Mathematics. Prentice Hall. ISBN 0-13-117686-2. • Hofstadter, Douglas (1999). Gödel, Escher, Bach: an Eternal Golden Braid. Basic Books. ISBN 0-465-02656-7. • Shoenfield, Joseph R. (2000). Recursion Theory. A K Peters Ltd. ISBN 1-56881-149-7. • Causey, Robert L. (2001). Logic, Sets, and Recursion. Jones & Bartlett. ISBN 0-7637-1695-2. • Cori, Rene; Lascar, Daniel; Pelletier, Donald H. (2001). Recursion Theory, Gödel's Theorems, Set Theory, Model Theory. Oxford University Press. ISBN 0-19-850050-5. • Barwise, Jon; Moss, Lawrence S. (1996). Vicious Circles. Stanford Univ Center for the Study of Language and Information. ISBN 0-19-850050-5. - offers a treatment of corecursion.

Recursion

7

• Rosen, Kenneth H. (2002). Discrete Mathematics and Its Applications. McGraw-Hill College. ISBN 0-07-293033-0. • Cormen, Thomas H., Charles E. Leiserson, Ronald L. Rivest, Clifford Stein (2001). Introduction to Algorithms. Mit Pr. ISBN 0-262-03293-7. • Kernighan, B.; Ritchie, D. (1988). The C programming Language. Prentice Hall. ISBN 0-13-110362-8. • Stokey, Nancy,; Robert Lucas; Edward Prescott (1989). Recursive Methods in Economic Dynamics. Harvard University Press. ISBN 0-674-75096-9. • Hungerford (1980). Algebra. Springer. ISBN 978-0-387-90518-1., first chapter on set theory.

References [1] http:/ / dx. doi. org/ 10. 1007%2FBF01386232

External links • Recursion (http://www.freenetpages.co.uk/hp/alan.gauld/tutrecur.htm) - tutorial by Alan Gauld • A Primer on Recursion (http://amitksaha.files.wordpress.com/2009/05/recursion-primer.pdf)- contains pointers to recursion in Formal Languages, Linguistics, Math and Computer Science • Zip Files All The Way Down (http://research.swtch.com/2010/03/zip-files-all-way-down.html) • Nevins, Andrew and David Pesetsky and Cilene Rodrigues. Evidence and Argumentation: A Reply to Everett (2009). Language 85.3: 671--681 (2009) (http://www.ucl.ac.uk/psychlangsci/staff/linguistics-staff/ nevins-publications/npr09b)

Fibonacci number In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence:[1][2]

or (often, in modern usage): (sequence A000045 in OEIS) By definition, the first two numbers in the Fibonacci sequence are 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.

A tiling with squares whose side lengths are successive Fibonacci numbers

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation with seed values[1][2] or[3]

Fibonacci number

8

The Fibonacci sequence is named after Leonardo Fibonacci. His 1202 book Liber Abaci introduced the sequence to Western European mathematics,[4] although the sequence had been described earlier in Indian mathematics. By modern convention, the sequence begins either with F0 = 0 or with F1 = 1. The Liber Abaci began the sequence with F1 = 1, without an initial 0. An approximation of the golden spiral created by drawing circular arcs connecting the opposite corners of squares in the Fibonacci tiling; this one uses squares of sizes 1, 1, 2, 3, 5, 8, 13, 21, and 34.

Fibonacci numbers are closely related to Lucas numbers in that they are a complementary pair of Lucas sequences. They are intimately connected with the golden ratio; for example, the closest rational approximations to the ratio are 2/1, 3/2, 5/3, 8/5, ... . Applications include computer algorithms such as the Fibonacci search technique and the Fibonacci heap data structure, and graphs called Fibonacci cubes used for interconnecting parallel and distributed systems. They also appear in biological settings, such as branching in trees, phyllotaxis (the arrangement of leaves on a stem), the fruit sprouts of a pineapple, the flowering of artichoke, an uncurling fern and the arrangement of a pine cone.

Origins The Fibonacci sequence appears in Indian mathematics, in connection with Sanskrit prosody. In the Sanskrit oral tradition, there was much emphasis on how long (L) syllables mix with the short (S), and counting the different patterns of L and S within a given fixed length results in the Fibonacci numbers; the number of patterns that are m short syllables long is the Fibonacci number Fm + 1. Susantha Goonatilake writes that the development of the Fibonacci sequence "is attributed in part to Pingala (200 BC), later being associated with Virahanka (c. 700 AD), Gopāla (c. 1135), and Hemachandra (c. 1150)". Parmanand Singh cites Pingala's cryptic formula misrau cha ("the two are mixed") and cites scholars who interpret it in context as saying that the cases for m beats (Fm+1) is obtained by adding a [S] to Fm cases and [L] to the Fm−1 cases. He dates Pingala before 450 BC. However, the clearest exposition of the series arises in the work of Virahanka (c. 700 AD), whose own work is lost, but is available in a quotation by Gopala (c. 1135): Variations of two earlier meters [is the variation]... For example, for [a meter of length] four, variations of meters of two [and] three being mixed, five happens. [works out examples 8, 13, 21]... In this way, the process should be followed in all mātrā-vṛttas [prosodic combinations].

A page of Fibonacci's Liber Abaci from the Biblioteca Nazionale di Firenze showing (in box on right) the Fibonacci sequence with the position in the sequence labeled in Latin and Roman numerals and the value in Hindu-Arabic numerals.

The series is also discussed by Gopala (before 1135 AD) and by the Jain scholar Hemachandra (c. 1150).

Fibonacci number

9

In the West, the Fibonacci sequence first appears in the book Liber Abaci (1202) by Leonardo of Pisa, known as Fibonacci.[4] Fibonacci considers the growth of an idealized (biologically unrealistic) rabbit population, assuming that: a newly born pair of rabbits, one male, one female, are put in a field; rabbits are able to mate at the age of one month so that at the end of its second month a female can produce another pair of rabbits; rabbits never die and a mating pair always produces one new pair (one male, one female) every month from the second month on. The puzzle that Fibonacci posed was: how many pairs will there be in one year? • • • •

At the end of the first month, they mate, but there is still only 1 pair. At the end of the second month the female produces a new pair, so now there are 2 pairs of rabbits in the field. At the end of the third month, the original female produces a second pair, making 3 pairs in all in the field. At the end of the fourth month, the original female has produced yet another new pair, the female born two months ago produces her first pair also, making 5 pairs.

At the end of the nth month, the number of pairs of rabbits is equal to the number of new pairs (which is the number of pairs in month n − 2) plus the number of pairs alive last month (n − 1). This is the nth Fibonacci number. The name "Fibonacci sequence" was first used by the 19th-century number theorist Édouard Lucas.

List of Fibonacci numbers The first 21 Fibonacci numbers Fn for n = 0, 1, 2, ..., 20 are:[5] F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 0

1

1

2

3

5

8 13 21 34

55

F17

F18

F19

F20

89 144 233 377 610 987 1597 2584 4181 6765

The sequence can also be extended to negative index n using the re-arranged recurrence relation

which yields the sequence of "negafibonacci" numbers satisfying

Thus the bidirectional sequence is F−8 F−7 F−6 F−5 F−4 F−3 F−2 F−1 F0 F1 F2 F3 F4 F5 F6 F7 F8 −21

13

−8

5

−3

2

−1

1

0

1

1

2

3

5

8 13 21

Use in mathematics The Fibonacci numbers occur in the sums of "shallow" diagonals in Pascal's triangle (see Binomial coefficient).[6]

The Fibonacci numbers can be found in different ways in the sequence of binary strings. • The number of binary strings of length n without consecutive 1s is

The Fibonacci numbers are the sums of the "shallow" diagonals (shown in red) of Pascal's triangle.

Fibonacci number

10

the Fibonacci number Fn+2. For example, out of the 16 binary strings of length 4, there are F6 = 8 without consecutive 1s – they are 0000, 0001, 0010, 0100, 0101, 1000, 1001 and 1010. (The strings with consecutive 1s are: 0011, 0110, 0111, 1011, 1100, 1101, 1110 and 1111.) By symmetry, the number of strings of length n without consecutive 0s is also Fn+2. • The number of binary strings of length n without an odd number of consecutive 1s is the Fibonacci number Fn+1. For example, out of the 16 binary strings of length 4, there are F5 = 5 without an odd number of consecutive 1s – they are 0000, 0011, 0110, 1100, 1111. • The number of binary strings of length n without an even number of consecutive 0s or 1s is 2Fn. For example, out of the 16 binary strings of length 4, there are 2F4 = 6 without an even number of consecutive 0s or 1s – they are 0001, 0111, 0101, 1000, 1010, 1110.

Relation to the golden ratio Closed-form expression Like every sequence defined by a linear recurrence with constant coefficients, the Fibonacci numbers have a closed-form solution. It has become known as Binet's formula, even though it was already known by Abraham de Moivre:

where

is the golden ratio (sequence A001622 in OEIS), and [7]

Since

, this formula can also be written as

To see this,[8] note that φ and ψ are both solutions of the equations

so the powers of φ and ψ satisfy the Fibonacci recursion. In other words

and

It follows that for any values a and b, the sequence defined by

satisfies the same recurrence

If a and b are chosen so that U0 = 0 and U1 = 1 then the resulting sequence Un must be the Fibonacci sequence. This is the same as requiring a and b satisfy the system of equations:

Fibonacci number which has solution

producing the required formula.

Computation by rounding Since

for all n ≥ 0, the number Fn is the closest integer to

Therefore it can be found by rounding, or in terms of the floor function:

Or the nearest integer function:

Similarly, if we already know that the number F > 1 is a Fibonacci number, we can determine its index within the sequence by

Limit of consecutive quotients Johannes Kepler observed that the ratio of consecutive Fibonacci numbers converges. He wrote that "as 5 is to 8 so is 8 to 13, practically, and as 8 is to 13, so is 13 to 21 almost", and concluded that the limit approaches the golden ratio .

This convergence does not depend on the starting values chosen, excluding 0, 0. For example, the initial values 19 and 31 generate the sequence 19, 31, 50, 81, 131, 212, 343, 555 ... etc. The ratio of consecutive terms in this sequence shows the same convergence towards the golden ratio. In fact this holds for any sequence that satisfies the Fibonacci recurrence other than a sequence of 0s. This can be derived from Binet's formula. Another consequence is that the limit of the ratio of two Fibonacci numbers offset by a particular finite deviation in index corresponds to the golden ratio raised by that deviation. Or, in other words:

11

Fibonacci number

12

Decomposition of powers of the golden ratio Since the golden ratio satisfies the equation

this expression can be used to decompose higher powers

as a linear function of lower powers, which in turn can

be decomposed all the way down to a linear combination of

and 1. The resulting recurrence relationships yield

Fibonacci numbers as the linear coefficients: This equation can be proved by induction on n. This expression is also true for n < 1 if the Fibonacci sequence Fn is extended to negative integers using the Fibonacci rule

Matrix form A 2-dimensional system of linear difference equations that describes the Fibonacci sequence is

The eigenvalues of the matrix A are

and

, for the respective eigenvectors

and

. Since

, and

the above closed-form expression for the nth element in the

Fibonacci series as an analytic function of n is now read off directly,

The matrix has a determinant of −1, and thus it is a 2×2 unimodular matrix. This property can be understood in terms of the continued fraction representation for the golden ratio:

The Fibonacci numbers occur as the ratio of successive convergents of the continued fraction for φ, and the matrix formed from successive convergents of any continued fraction has a determinant of +1 or −1. The matrix representation gives the following closed expression for the Fibonacci numbers:

Taking the determinant of both sides of this equation yields Cassini's identity, Moreover, since An Am = An+m for any square matrix A, the following identities can be derived,

In particular, with m = n,

Fibonacci number

13

These last two identities provide a way to compute Fibonacci numbers recursively in O(log(n)) arithmetic operations and in time O(M(n) log(n)), where M(n) is the time for the multplication of two numbers of n digits. This matches the time for computing the nth Fibonacci number from the closed-form matrix formula, but with fewer redundant steps if one avoids to recompute an already computed Fibonacci number (recursion with memoization).

Recognizing Fibonacci numbers The question may arise whether a positive integer x is a Fibonacci number. This is true if and only if one or both of or is a perfect square. This is because Binet's formula above can be rearranged to give (allowing one to find the position in the sequence of a given Fibonacci number) This formula must return an integer for all n, so the expression under the radical must be an integer (otherwise the logarithm does not even return a rational number).

Combinatorial Identities Most identities involving Fibonacci numbers can be proven using combinatorial arguments using the fact that Fn can be interpreted as the number of sequences of 1s and 2s that sum to n − 1. This can be taken as the definition of Fn, with the convention that F0 = 0, meaning no sum adds up to −1, and that F1 = 1, meaning the empty sum "adds up" to 0. Here, the order of the summand matters. For example, 1 + 2 and 2 + 1 are considered two different sums. For example, the recurrence relation

or in words, the nth Fibonacci number is the sum of the previous two Fibonacci numbers, may be shown by dividing the Fn sums of 1s and 2s that add to n−1 into two non-overlapping groups. One group contains those sums whose first term is 1 and the other those sums whose first term is 2. In the first group the remaining terms add to n − 2, so it has F(n−1) sums, and in the second group the remaining terms add to n−3, so there are Fn−2 sums. So there are a total of Fn−1 + Fn−2 sums altogether, showing this is equal to Fn. Similarly, it may be shown that the sum of the first Fibonacci numbers up to the nth is equal to the (n + 2)-nd Fibonacci number minus 1.[9] In symbols:

This is done by dividing the sums adding to n+1 in a different way, this time by the location of the first 2. Specifically, the first group consists of those sums that start with 2, the second group those that start 1+2, the third 1+1+2, and so on, until the last group, which consists of the single sum where only 1's are used. The number of sums in the first group is F(n), F(n − 1) in the second group, and so on, with 1 sum in the last group. So the total number of sums is F(n) + F(n−1) + ... + F(1)+1 and therefore this quantity is equal to F(n+2) A similar argument, grouping the sums by the position of the first 1 rather than the first 2, gives two more identities:

and

Fibonacci number

14

In words, the sum of the first Fibonacci numbers with odd index up to F2n−1 is the (2n)th Fibonacci number, and the sum of the first Fibonacci numbers with even index up to F2n is the (2n+1)-st Fibonacci number minus 1. A different trick may be used to prove

or in words, the sum of the squares of the first Fibonacci numbers up to Fn is the product of the nth and (n+1)-st Fibonacci numbers. In this case note that Fibonacci rectangle of size Fn by F (n+1) can be decomposed into squares of size Fn, Fn−1, and so on to F1 = 1, from which the identity follows by comparing areas.

Other identities Numerous other identities can be derived using various methods. Some of the most noteworthy are: Catalan's Identity:

Cassini's Identity:

d'Ocagne's identity:

where Ln is the n'th Lucas number. The last is an identity for doubling n; other identities of this type are by Cassini's identity.

These can be found experimentally using lattice reduction, and are useful in setting up the special number field sieve to factorize a Fibonacci number.[citation needed] More generally,

Putting k = 2 in this formula, one gets again the formulas of the end of above section Matrix form.

Power series The generating function of the Fibonacci sequence is the power series

This series is convergent for

and its sum has a simple closed-form:

Fibonacci number

15

This can be proven by using the Fibonacci recurrence to expand each coefficient in the infinite sum:

Solving the equation

for s(x) results in the above closed form. If x is the inverse of an integer, the closed form of the series becomes

In particular,

for all non-negative integers k. Some math puzzle-books present as curious the particular value

.

Reciprocal sums Infinite sums over reciprocal Fibonacci numbers can sometimes be evaluated in terms of theta functions. For example, we can write the sum of every odd-indexed reciprocal Fibonacci number as

and the sum of squared reciprocal Fibonacci numbers as

If we add 1 to each Fibonacci number in the first sum, there is also the closed form

and there is a nice nested sum of squared Fibonacci numbers giving the reciprocal of the golden ratio,

Results such as these make it plausible that a closed formula for the plain sum of reciprocal Fibonacci numbers could be found, but none is yet known. Despite that, the reciprocal Fibonacci constant

Fibonacci number

16

has been proved irrational by Richard André-Jeannin. Millin series gives a remarkable identity:

which follows from the closed form for its partial sums as N tends to infinity:

Primes and divisibility Divisibility properties Every 3rd number of the sequence is even and more generally, every kth number of the sequence is a multiple of Fk. Thus the Fibonacci sequence is an example of a divisibility sequence. In fact, the Fibonacci sequence satisfies the stronger divisibility property

Any three consecutive Fibonacci numbers are pairwise coprime, which means that, for every n, gcd(Fn, Fn+1) = gcd(Fn, Fn+2) = gcd(Fn+1, Fn+2) = 1.

Fibonacci primes A Fibonacci prime is a Fibonacci number that is prime. The first few are: 2, 3, 5, 13, 89, 233, 1597, 28657, 514229, … (sequence A005478 in OEIS). Fibonacci primes with thousands of digits have been found, but it is not known whether there are infinitely many. Fkn is divisible by Fn, so, apart from F4 = 3, any Fibonacci prime must have a prime index. As there are arbitrarily long runs of composite numbers, there are therefore also arbitrarily long runs of composite Fibonacci numbers. No Fibonacci number greater than F6 = 8 is one greater or one less than a prime number. The only nontrivial square Fibonacci number is 144. Attila Pethő proved in 2001 that there is only a finite number of perfect power Fibonacci numbers. In 2006, Y. Bugeaud, M. Mignotte, and S. Siksek proved that 8 and 144 are the only such non-trivial perfect powers.

Prime divisors of Fibonacci numbers With the exceptions of 1, 8 and 144 (F1 = F2, F6 and F12) every Fibonacci number has a prime factor that is not a factor of any smaller Fibonacci number (Carmichael's theorem). The divisibility of Fibonacci numbers by a prime p is related to the Legendre symbol follows:

If p is a prime number then [10]

which is evaluated as

Fibonacci number For example,

It is not known whether there exists a prime p such that

Such primes (if there are any) would be called Wall–Sun–Sun primes. Also, if p ≠ 5 is an odd prime number then:[10]

Example 1. p = 7, in this case p ≡ 3 (mod 4) and we have:

Example 2. p = 11, in this case p ≡ 3 (mod 4) and we have:

Example 3. p = 13, in this case p ≡ 1 (mod 4) and we have:

Example 4. p = 29, in this case p ≡ 1 (mod 4) and we have:

For odd n, all odd prime divisors of Fn are congruent to 1 modulo 4, implying that all odd divisors of Fn (as the products of odd prime divisors) are congruent to 1 modulo 4.[11] For example, All known factors of Fibonacci numbers F(i) for all i < 50000 are collected at the relevant repositories.[12][13]

17

Fibonacci number

18

Periodicity modulo n It may be seen that if the members of the Fibonacci sequence are taken mod n, the resulting sequence must be periodic with period at most n2−1. The lengths of the periods for various n form the so-called Pisano periods (sequence A001175 in OEIS). Determining the Pisano periods in general is an open problem,[citation needed] although for any particular n it can be solved as an instance of cycle detection.

Right triangles Starting with 5, every second Fibonacci number is the length of the hypotenuse of a right triangle with integer sides, or in other words, the largest number in a Pythagorean triple. The length of the longer leg of this triangle is equal to the sum of the three sides of the preceding triangle in this series of triangles, and the shorter leg is equal to the difference between the preceding bypassed Fibonacci number and the shorter leg of the preceding triangle. The first triangle in this series has sides of length 5, 4, and 3. Skipping 8, the next triangle has sides of length 13, 12 (5 + 4 + 3), and 5 (8 − 3). Skipping 21, the next triangle has sides of length 34, 30 (13 + 12 + 5), and 16 (21 − 5). This series continues indefinitely. The triangle sides a, b, c can be calculated directly:

These formulas satisfy

for all n, but they only represent triangle sides when n > 2.

Any four consecutive Fibonacci numbers Fn, Fn+1, Fn+2 and Fn+3 can also be used to generate a Pythagorean triple in a different way:

Example 1: let the Fibonacci numbers be 1, 2, 3 and 5. Then:

Magnitude Since Fn is asymptotic to

, the number of digits in Fn is asymptotic to

. As a

consequence, for every integer d > 1 there are either 4 or 5 Fibonacci numbers with d decimal digits. More generally, in the base b representation, the number of digits in Fn is asymptotic to .

Applications The Fibonacci numbers are important in the computational run-time analysis of Euclid's algorithm to determine the greatest common divisor of two integers: the worst case input for this algorithm is a pair of consecutive Fibonacci numbers. Yuri Matiyasevich was able to show that the Fibonacci numbers can be defined by a Diophantine equation, which led to his original solution of Hilbert's tenth problem. The Fibonacci numbers are also an example of a complete sequence. This means that every positive integer can be written as a sum of Fibonacci numbers, where any one number is used once at most. Moreover, every positive integer can be written in a unique way as the sum of one or more distinct Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers. This is known as

Fibonacci number

19

Zeckendorf's theorem, and a sum of Fibonacci numbers that satisfies these conditions is called a Zeckendorf representation. The Zeckendorf representation of a number can be used to derive its Fibonacci coding. Fibonacci numbers are used by some pseudorandom number generators. Fibonacci numbers are used in a polyphase version of the merge sort algorithm in which an unsorted list is divided into two lists whose lengths correspond to sequential Fibonacci numbers – by dividing the list so that the two parts have lengths in the approximate proportion φ. A tape-drive implementation of the polyphase merge sort was described in The Art of Computer Programming. Fibonacci numbers arise in the analysis of the Fibonacci heap data structure. The Fibonacci cube is an undirected graph with a Fibonacci number of nodes that has been proposed as a network topology for parallel computing. A one-dimensional optimization method, called the Fibonacci search technique, uses Fibonacci numbers. The Fibonacci number series is used for optional lossy compression in the IFF 8SVX audio file format used on Amiga computers. The number series compands the original audio wave similar to logarithmic methods such as µ-law. Since the conversion factor 1.609344 for miles to kilometers is close to the golden ratio (denoted φ), the decomposition of distance in miles into a sum of Fibonacci numbers becomes nearly the kilometer sum when the Fibonacci numbers are replaced by their successors. This method amounts to a radix 2 number register in golden ratio base φ being shifted. To convert from kilometers to miles, shift the register down the Fibonacci sequence instead.

In nature Fibonacci sequences appear in biological settings, in two consecutive Fibonacci numbers, such as branching in trees, arrangement of leaves on a stem, the fruitlets of a pineapple, the flowering of artichoke, an uncurling fern and the arrangement of a pine cone, and the family tree of honeybees. However, numerous poorly substantiated claims of Fibonacci numbers or golden sections in nature are found in popular sources, e.g., relating to the breeding of rabbits in Fibonacci's own unrealistic example, the seeds on a sunflower, the spirals of shells, and the curve of waves. Przemysław Prusinkiewicz advanced the idea that real instances can in part be understood as the expression of certain algebraic constraints on free groups, specifically as certain Lindenmayer grammars.

Yellow Chamomile head showing the arrangement in 21 (blue) and 13 (aqua) spirals. Such arrangements involving consecutive Fibonacci numbers appear in a wide variety of plants.

Fibonacci number

20 A model for the pattern of florets in the head of a sunflower was proposed by H. Vogel in 1979. This has the form

where n is the index number of the floret and c is a constant scaling factor; the florets thus lie on Fermat's spiral. The divergence angle, approximately 137.51°, is the golden angle, dividing the circle in the golden ratio. Because this ratio is irrational, no floret has a neighbor at exactly the same angle from the center, so the florets pack efficiently. Because the rational approximations to the golden ratio are of the form F(j):F(j + 1), the nearest neighbors of floret number n are those at Illustration of Vogel's model for n=1 ... 500 n ± F(j) for some index j, which depends on r, the distance from the center. It is often said that sunflowers and similar arrangements have 55 spirals in one direction and 89 in the other (or some other pair of adjacent Fibonacci numbers), but this is true only of one range of radii, typically the outermost and thus most conspicuous.

The bee ancestry code Fibonacci numbers also appear in the description of the reproduction of a population of idealized honeybees, according to the following rules: • If an egg is laid by an unmated female, it hatches a male or drone bee. • If, however, an egg was fertilized by a male, it hatches a female. Thus, a male bee always has one parent, and a female bee has two. If one traces the ancestry of any male bee (1 bee), he has 1 parent (1 bee), 2 grandparents, 3 great-grandparents, 5 great-great-grandparents, and so on. This sequence of numbers of parents is the Fibonacci sequence. The number of ancestors at each level, Fn, is the number of female ancestors, which is Fn−1, plus the number of male ancestors, which is Fn−2. This is under the unrealistic assumption that the ancestors at each level are otherwise unrelated.

Generalizations The Fibonacci sequence has been generalized in many ways. These include: • Generalizing the index to negative integers to produce the negafibonacci numbers. • Generalizing the index to real numbers using a modification of Binet's formula. • Starting with other integers. Lucas numbers have L1 = 1, L2 = 3, and Ln = Ln−1 + Ln−2. Primefree sequences use the Fibonacci recursion with other starting points to generate sequences in which all numbers are composite. • Letting a number be a linear function (other than the sum) of the 2 preceding numbers. The Pell numbers have Pn = 2Pn − 1 + Pn − 2. • Not adding the immediately preceding numbers. The Padovan sequence and Perrin numbers have P(n) = P(n − 2) + P(n − 3). • Generating the next number by adding 3 numbers (tribonacci numbers), 4 numbers (tetranacci numbers), or more. The resulting sequences are known as n-Step Fibonacci numbers. • Adding other objects than integers, for example functions or strings – one essential example is Fibonacci polynomials.

Fibonacci number

Notes [1] Beck & Geoghegan 2010. [2] Bona 2011, p. 180. [3] Lucas 1891, p. 3. [4] Pisano 2002, pp. 404–5. [5] has the first 300 Fn factored into primes and links to more extensive tables. [6] Lucas 1891, p. 7. [7] Ball 2003, p. 156. [8] Ball 2003, pp. 155–6. [9] Lucas 1891, p. 4. [10] Lemmermeyer 2000, pp. 73–4. [11] Lemmermeyer 2000, p. 73. [12] collects all known factors of F(i) with i < 10000. [13] collects all known factors of F(i) with 10000 < i < 50000.

References • Ball, Keith M (2003), "8: Fibonacci's Rabbits Revisited", Strange Curves, Counting Rabbits, and Other Mathematical Explorations, Princeton, NJ: Princeton University Press, ISBN 0-691-11321-1. • Beck, Matthias; Geoghegan, Ross (2010), The Art of Proof: Basic Training for Deeper Mathematics, New York: Springer. • Bóna, Miklós (2011), A Walk Through Combinatorics (3rd ed.), New Jersey: World Scientific. • Lemmermeyer, Franz (2000), Reciprocity Laws, New York: Springer, ISBN 3-540-66957-4. • Lucas, Édouard (1891), Théorie des nombres (in French) 1, Gauthier-Villars. • Pisano, Leonardo (2002), Fibonacci's Liber Abaci: A Translation into Modern English of the Book of Calculation (hardback), Sources and Studies in the History of Mathematics and Physical Sciences, Sigler, Laurence E, trans, Springer, ISBN 0-387-95419-8, 978-0-387-40737-1 (paperback).

External links • Hazewinkel, Michiel, ed. (2001), "Fibonacci numbers" (http://www.encyclopediaofmath.org/index. php?title=p/f040020), Encyclopedia of Mathematics, Springer, ISBN 978-1-55608-010-4 • Fibonacci Sequence (http://www.bbc.co.uk/programmes/b008ct2j) on In Our Time at the BBC. ( listen now (http://www.bbc.co.uk/iplayer/console/b008ct2j/In_Our_Time_Fibonacci_Sequence)) • " Sloane's A000045 : Fibonacci Numbers (http://oeis.org/A000045)", The On-Line Encyclopedia of Integer Sequences. OEIS Foundation. • Periods of Fibonacci Sequences Mod m (http://www.mathpages.com/home/kmath078/kmath078.htm) at MathPages • Scientists find clues to the formation of Fibonacci spirals in nature (http://www.physorg.com/news97227410. html)

21

Fibonacci numbers in popular culture

22

Fibonacci numbers in popular culture The Fibonacci numbers are a sequence of integers, starting with 0, 1 and continuing 1, 2, 3, 5, 8, 13, ..., each new number being the sum of the previous two. The Fibonacci numbers, and in conjunction the golden ratio, are a popular theme in culture. They have been mentioned in novels, films, television shows, and songs. The numbers have also been used in the creation of music, visual art, and architecture.

Finance • Stock traders frequently look to the "Fibonacci retracement" when predicting future share prices.

Architecture • The sequence has been used in the design of a building, the Core, at the Eden Project, near St Austell, Cornwall, England.[1]

Cinema • Along with the golden rectangle and golden spiral, the Fibonacci sequence is mentioned in Darren Aronofsky's independent film Pi (1998). They are used to find the name of God. • In The Da Vinci Code, the numbers are used to unlock a safe. They are also placed out of order in a message to indicate that the message is also out of order (anagram). • In Mr. Magorium's Wonder Emporium (2007), Magorium hires accountant Henry Weston (Jason Bateman) after an interview in which he demonstrates knowledge of Fibonacci numbers. • In "Death Note: L, Change the World" (2008), genius boy Near is seen arranging sugar cubes in a Fibonacci sequence.

Comic strips

Chimney of Turku Energia, Turku, Finland featuring Fibonacci sequence in 2m high neon lights. By Italian artist Mario Merz for an environmental art project (1994)

• In the February 8, 2009 edition of FoxTrot by Bill Amend, characters Jason and Marcus take one nacho from a bowl, one more nacho, then two nachos, three nachos, five nachos, eight nachos, etc., calling it 'Fibonacho.' • In the strip "Alone [2]" of the online comic xkcd by Randall Munroe, a male and female stick figure are seen together in an intimate situation. The male voices over, explaining his obsessive tendency to count numbers and find patterns. When he realizes that she is touching him in a pattern corresponding to the Fibonacci Sequence, his appreciation for her increases tremendously. • In a strip of Frazz by Jef Mallett, Frazz and a student are discussing her knitted hat. The student says, "Mom sewed one sparkly here and here. Two sparklies here. Three sparklies. Five sparklies. Eight sparklies. Thirteen..." To which Frazz replies, "Fibonacci sequins, of course."

Fibonacci numbers in popular culture

Human development John Waskom postulated that stages of human development followed the Fibonacci sequence, and that the unfolding psychology of human life would ideally be a "living proof" of the Golden Mean. This theory was originally developed and published by Norman Rose in two articles. The first article, which laid out the general theory, was entitled "Design and Development of Wholeness: Waskom's Paradigm."[3] The second article laid out the applications and implications of the theory to the topic of moral development, and was entitled "Moral Development: The Experiential Perspective."[4]

Literature • The Fibonacci sequence plays a small part in the bestselling novel and film The Da Vinci Code. • In Philip K. Dick's novel VALIS, the Fibonacci sequence (as well as the Fibonacci constant) are used as identification signs by an organization called the "Friends of God". • In the collection of poetry alfabet by the Danish poet Inger Christensen, the Fibonacci sequence is used to define the number of lines in each poem. • It was briefly included (and recognized by Charles Wallace Murry) in the television film adaptation of A Wrinkle in Time. • The Fibonacci sequence is frequently referenced in the 2001 book The Perfect Spiral by Jason S. Hornsby. • A youthful Fibonacci is one of the main characters in the novel Crusade in Jeans (1973). He was left out of the 2006 movie version, however. • The Fibonacci sequence and golden ratio are briefly described in John Fowles's 1985 novel A Maggot • The Fibonacci sequence is explored in Emily Gravett's 2009 book The Rabbit Problem • "Ice Station" a novel by Australian writer Matthew Reilly involves a partially completed access code, the remaining numbers of which can only be found by extrapolating a Fibonacci pattern. • The Fibonacci sequence is used by a serial killer to attract the protagonist Special Agent Pendergast in the Preston/Childs novel "Two Graves" (2012).

Music • hip hop duo Black Star's song "Astronomy (8th Light)" from the 1998 album Mos Def & Talib Kweli are Black Star, features the Fibonacci sequence in the chorus: Now everybody hop on the one, the sounds of the two It's the third eye vision, five side dimension The 8th Light, is gonna shine bright tonight • Tool's song "Lateralus" from the album of the same name features the Fibonacci sequence symbolically in the verses of the song. The syllables in the first verse count 1, 1, 2, 3, 5, 8, 5, 3, 13, 8, 5, 3. The missing section (2, 1, 1, 2, 3, 5, 8) is later filled in during the second verse.[5] The time signatures of the chorus change from 9/8 to 8/8 to 7/8; as drummer Danny Carey says, "It was originally titled 9-8-7. For the time signatures. Then it turned out that 987 was the 16th number of the Fibonacci sequence. So that was cool." • Ernő Lendvaï analyzes Béla Bartók's works as being based on two opposing systems, that of the golden ratio and the acoustic scale. In the third movement of Bartok's Music for Strings, Percussion and Celesta, the opening xylophone passage uses Fibonacci rhythm as such: 1:1:2:3:5:8:5:3:2:1:1.[6] • The Fibonacci numbers are also apparent in the organisation of the sections in the music of Debussy's Image, Reflections in Water, in which the sequence of keys is marked out by the intervals 34, 21, 13 and 8. • Polish composer Krzysztof Meyer structured the values in his Trio for clarinet, cello and piano according to the Fibonacci sequence.[7]

23

Fibonacci numbers in popular culture

24

• Fibonacci's name was adopted by a Los Angeles-based art rock group The Fibonaccis, that recorded from 1981 to 1987. • American musician BT also recorded a song titled "Fibonacci Sequence". The narrator in the song goes through all the numbers of the sequence from 1 to 21 (0 is not mentioned). The track appeared on a limited edition version of his 1999 album Movement in Still Life, and is also featured on the second disc of the Global Underground 013: Ibiza compilation mixed by Sasha. • Voiceover and recording artist Ken Nordine described Fibonacci numbers in a word jazz piece called "Fibonacci Numbers" on his album A Transparent Mask.[8] • American musician Doctor Steel has a song titled "Fibonacci Sequence" on his album People of Earth.[9] • Australian electronic group Angelspit uses the Fibonnaci in the song "Vermin." The lyrics start with, "1, 2 3 5 8, Who do we decapitate?" and continues through a few more iterations of the sequence.

Visual arts • Artist Mario Merz made the Fibonacci sequence a recurring theme in his work. Examples are the Chimney of Turku Energia, in Turku, Finland, featuring the start of the Fibonacci sequence in 2m high neon lights, and the representation of the first Fibonacci numbers with red neon lights on one of the four-faced dome of the Mole Antonelliana in Turin, Italy, part of the artistic work Il volo dei Numeri ("Flight of the numbers"). • Fibonacci numbers have also been used in knitting to create aesthetically appealing patterns. • The artist Martina Schettina uses Fibonacci numbers in her paintings.[10][11] Her "Mathemagic paintings" were shown at the Museumsquartier Vienna in 2010.[12]

Martina Schettina: Fibonaccis Dream, 2008, 40 x 40 cm

Television • The scientist character Walter Bishop in the television show Fringe recites the Fibonacci sequence to fall asleep. It is later revealed to be the key sequence identifying a series of safe deposit boxes he had maintained. • Square One Television's Mathnet series had a storyline that featured a parrot belonging to a deceased individual who was fascinated by the Fibonacci numbers. When "1, 1, 2, 3" is said in the parrot's presence, it responds "5, eureka!" This proves to be the key to case; tiles in a garden wall are found to follow the Fibonacci sequence, with a secret compartment hidden behind the lone misplaced tile. • The Criminal Minds episode "Masterpiece" in season 4 features a serial killer who uses Fibonacci sequences to choose both the number of victims he kills at a given time, as well as the location of their hometowns. • Aliens use Fibonacci's sequence in the Taken episode "God's Equation". • In the Disney Channel TV show So Weird, the Fibonacci sequence is used to build a house. The house becomes a nexus for lost spirits. One character, Fiona, is given a choice to use it to free her father as well as the builder of the house, but ultimately chooses to free the spirits, and destroys the nexus. • The Fibonacci sequence is a main plot theme in the 2012 television show Touch, produced by Fox Network and starring Kiefer Sutherland It revolves around a number sequence (318 5296 3287 9.5 22 975 6 1188 1604 55124... and on. These numbers are calculated from using the Fibonacci sequence in some way to reveal patterns in both natural and artificial systems, essentially allowing the characters to predict the future.

Fibonacci numbers in popular culture • In the CBS show Numb3rs episode "Thirteen", a Fibonacci sequence is embedded in a numeric code left behind by a serial killer. • On the TV show, Adventure Time, the sequence of 8, 13, 21, is shown on the back of the Enchiridion in certain episodes.

References [1] The Engineer, "Eden Project gets into flower power" (http:/ / www. theengineer. co. uk/ Articles/ 293054/ Eden+ Project+ gets+ into+ flower+ power. htm). [2] https:/ / xkcd. com/ 289/ [3] The Educational Forum, 55, 3 (Spring 1991), 243-259 http:/ / whizkidz. org/ design/ DevelopmentDesign. pdf) [4] Journal of Moral Education, 21, 1 (Winter, 1992), 29-40 http:/ / whizkidz. org/ design/ MoralDevelopment. pdf [5] . An exposition of how the fibonacci sequence appears in Lateralus set to pictures from the Hubble telescope: http:/ / youtube. com/ watch?v=wS7CZIJVxFY [6] Smith, Peter F. The Dynamics of Delight: Architecture and Aesthetics (New York: Routledge, 2003) p. 83, ISBN 0-415-30010-X [7] Weselmann, Thomas (2003) Musica incrostata. Poznan [8] Fibonacci Numbers: Ken Nordine (http:/ / www. amazon. com/ gp/ product/ B000URZG2U/ ref=dm_mu_dp_trk16) at Amazon.com. [9] People of Earth track list (http:/ / worlddominationtoys. com/ music_cds_peopleofearth. html) [10] Ingmar Lehman: „Fibonacci-numbers in visual arts and literature" (http:/ / www. mathematik. uni-dortmund. de/ ieem/ BzMU/ BzMU2009/ Beitraege/ LEHMANN_Ingmar_2009_Fibonacci. pdf) (German)(last called on November 7, 2009) [11] 2009: Martina Schettina:Mathemagische Bilder - Bilder und Texte. Vernissage Verlag Brod Media, Wien 2009, ISBN 978-3-200-01743-6 (German) [12] About the exhibition, interview on Radio [[Ö1 (http:/ / oe1. orf. at/ programm/ 20100222801. html)]](recalled at February 28, 2010)

External links • Subhash Kak, The Golden Mean and the Physics of Aesthetics (http://uk.arxiv.org/abs/physics/0411195), Archive of Physics, (2004). • Math for Poets and Drummers (http://www.sju.edu/~rhall/Rhythms/Poets/arcadia.pdf) – Rachael Hall surveys rhythm and Fibonacci numbers and also the Hemachandra connection. Saint Joseph's University, 2005. • Rachel Hall, Hemachandra's application to Sanskrit poetry (http://www.sju.edu/~rhall/Multi/rhythm2.pdf), (undated; 2005 or earlier). • Fibonacci Numbers and The Golden Section in Art, Architecture and Music (http://www.mcs.surrey.ac.uk/ Personal/R.Knott/Fibonacci/fibInArt.html), which lists a number of academic sources.

25

Golden ratio

26

Golden ratio In mathematics, two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities, i.e. their maximum. The figure on the right illustrates the geometric relationship. Expressed algebraically, for quantities a and b with a > b,

where the Greek letter phi (

) represents the golden ratio. Its value

Line segments in the golden ratio

is: [1]

The golden ratio is also called the golden section (Latin: sectio aurea) or golden mean.[2][3] Other names include extreme and mean ratio,[4] medial section, divine proportion, divine section (Latin: sectio divina), golden proportion, golden cut,[5] and golden number.[6][7][8] Many artists and architects have proportioned their works to approximate the golden ratio—especially in the form of the golden rectangle, in which the ratio of the longer side to the shorter is the golden ratio—believing this proportion to be aesthetically pleasing (see Applications and observations below). Mathematicians since Euclid have studied the properties of the golden ratio, including its appearance in the dimensions of a regular pentagon and in a golden rectangle, which can be cut into a square and a smaller rectangle with the same aspect ratio. The golden ratio has also been used to analyze the proportions of natural objects as well as man-made systems such as financial markets, in some cases based on dubious fits to data.

A golden rectangle with longer side a and shorter side b, when placed adjacent to a square with sides of length a, will produce a similar golden rectangle with longer side a + b and shorter side a. This illustrates the relationship

Calculation • •

List of numbers Irrational and suspected irrational numbers

• • • • • • • • • • •

γ ζ(3) √2 √3 √5 φ ρ δS e π δ

Binary

1.1001111000110111011...

Decimal

1.6180339887498948482...

Hexadecimal

1.9E3779B97F4A7C15F39...

.

Golden ratio

27 Continued fraction

Algebraic form

Infinite series

Two quantities a and b are said to be in the golden ratio φ if:

One method for finding the value of φ is to start with the left fraction. Through simplifying the fraction and substituting in b/a = 1/φ,

By definition, it is shown that

Multiplying by φ gives

which can be rearranged to

Using the quadratic formula, two solutions are obtained:

and

Because φ is the ratio between positive quantities φ is necessarily positive: .

Golden ratio

28

History The golden ratio has fascinated Western intellectuals of diverse interests for at least 2,400 years. According to Mario Livio: Some of the greatest mathematical minds of all ages, from Pythagoras and Euclid in ancient Greece, through the medieval Italian mathematician Leonardo of Pisa and the Renaissance astronomer Johannes Kepler, to present-day scientific figures such as Oxford physicist Roger Penrose, have spent endless hours over this simple ratio and its properties. But the fascination with the Golden Ratio is not confined just to mathematicians. Biologists, artists, musicians, historians, architects, psychologists, and even mystics have pondered and debated the basis of its ubiquity and appeal. In fact, it is probably fair to say that the Golden Ratio has inspired thinkers of all disciplines like no other number in the history of mathematics.[9]

Mathematician Mark Barr proposed using the first letter in the name of Greek sculptor Phidias, phi, to symbolize the golden ratio. Usually, the lowercase form (φ) is used. Sometimes, the uppercase form (Φ) is used for the reciprocal of the golden ratio, 1/φ.

Ancient Greek mathematicians first studied what we now call the golden ratio because of its frequent appearance in geometry. The division of a line into "extreme and mean ratio" (the golden section) is important in the geometry of regular pentagrams and pentagons. Euclid's Elements (Greek: Στοιχεῖα) provides the first known written definition of what is now called the golden ratio: "A straight line is said to have been cut in extreme and mean ratio when, as the whole line is to the greater segment, so is the greater to the lesser." Euclid explains a construction for cutting (sectioning) a line "in extreme and mean ratio", i.e., the golden ratio.[10] Throughout the Elements, several propositions (theorems in modern terminology) and their proofs employ the golden ratio.[11] The golden ratio is explored in Luca Pacioli's book De divina proportione of 1509. The first known approximation of the (inverse) golden ratio by a decimal fraction, stated as "about 0.6180340", was written in 1597 by Michael Maestlin of the University of Tübingen in a letter to his former student Johannes Kepler.

Michael Maestlin, first to publish a decimal approximation of the golden ratio, in 1597.

Since the 20th century, the golden ratio has been represented by the Greek letter Φ or φ (phi, after Phidias, a sculptor who is said to have employed it) or less commonly by τ (tau, the first letter of the ancient Greek root τομή—meaning cut).

Timeline Timeline according to Priya Hemenway: • Phidias (490–430 BC) made the Parthenon statues that seem to embody the golden ratio.

Golden ratio • Plato (427–347 BC), in his Timaeus, describes five possible regular solids (the Platonic solids: the tetrahedron, cube, octahedron, dodecahedron, and icosahedron), some of which are related to the golden ratio. • Euclid (c. 325–c. 265 BC), in his Elements, gave the first recorded definition of the golden ratio, which he called, as translated into English, "extreme and mean ratio" (Greek: ἄκρος καὶ μέσος λόγος). • Fibonacci (1170–1250) mentioned the numerical series now named after him in his Liber Abaci; the ratio of sequential elements of the Fibonacci sequence approaches the golden ratio asymptotically. • Luca Pacioli (1445–1517) defines the golden ratio as the "divine proportion" in his Divina Proportione. • Michael Maestlin (1550–1631) publishes the first known approximation of the (inverse) golden ratio as a decimal fraction. • Johannes Kepler (1571–1630) proves that the golden ratio is the limit of the ratio of consecutive Fibonacci numbers, and describes the golden ratio as a "precious jewel": "Geometry has two great treasures: one is the Theorem of Pythagoras, and the other the division of a line into extreme and mean ratio; the first we may compare to a measure of gold, the second we may name a precious jewel." These two treasures are combined in the Kepler triangle. • Charles Bonnet (1720–1793) points out that in the spiral phyllotaxis of plants going clockwise and counter-clockwise were frequently two successive Fibonacci series. • Martin Ohm (1792–1872) is believed to be the first to use the term goldener Schnitt (golden section) to describe this ratio, in 1835. • Édouard Lucas (1842–1891) gives the numerical sequence now known as the Fibonacci sequence its present name. • Mark Barr (20th century) suggests the Greek letter phi (φ), the initial letter of Greek sculptor Phidias's name, as a symbol for the golden ratio. • Roger Penrose (b. 1931) discovered a symmetrical pattern that uses the golden ratio in the field of aperiodic tilings, which led to new discoveries about quasicrystals.[citation needed]

Applications and observations Aesthetics De Divina Proportione, a three-volume work by Luca Pacioli, was published in 1509. Pacioli, a Franciscan friar, was known mostly as a mathematician, but he was also trained and keenly interested in art. De Divina Proportione explored the mathematics of the golden ratio. Though it is often said that Pacioli advocated the golden ratio's application to yield pleasing, harmonious proportions, Livio points out that the interpretation has been traced to an error in 1799, and that Pacioli actually advocated the Vitruvian system of rational proportions. Pacioli also saw Catholic religious significance in the ratio, which led to his work's title. De Divina Proportione contains illustrations of regular solids by Leonardo da Vinci, Pacioli's longtime friend and collaborator.

29

Golden ratio

Architecture The Parthenon's façade as well as elements of its façade and elsewhere are said by some to be circumscribed by golden rectangles.[12] Other scholars deny that the Greeks had any aesthetic association with golden ratio. For example, Midhat J. Gazalé says, "It was not until Euclid, however, that the golden ratio's mathematical properties were studied. In the Elements (308 BC) the Greek mathematician merely regarded that number as an interesting irrational number, in connection with the middle and extreme ratios. Its occurrence in regular Many of the proportions of the Parthenon are alleged to exhibit the pentagons and decagons was duly observed, as well as golden ratio. in the dodecahedron (a regular polyhedron whose twelve faces are regular pentagons). It is indeed exemplary that the great Euclid, contrary to generations of mystics who followed, would soberly treat that number for what it is, without attaching to it other than its factual properties."[13] And Keith Devlin says, "Certainly, the oft repeated assertion that the Parthenon in Athens is based on the golden ratio is not supported by actual measurements. In fact, the entire story about the Greeks and golden ratio seems to be without foundation. The one thing we know for sure is that Euclid, in his famous textbook Elements, written around 300 BC, showed how to calculate its value."[14] Near-contemporary sources like Vitruvius exclusively discuss proportions that can be expressed in whole numbers, i.e. commensurate as opposed to irrational proportions. A 2004 geometrical analysis of earlier research into the Great Mosque of Kairouan reveals a consistent application of the golden ratio throughout the design, according to Boussora and Mazouz.[15] They found ratios close to the golden ratio in the overall proportion of the plan and in the dimensioning of the prayer space, the court, and the minaret. The authors note, however, that the areas where ratios close to the golden ratio were found are not part of the original construction, and theorize that these elements were added in a reconstruction. The Swiss architect Le Corbusier, famous for his contributions to the modern international style, centered his design philosophy on systems of harmony and proportion. Le Corbusier's faith in the mathematical order of the universe was closely bound to the golden ratio and the Fibonacci series, which he described as "rhythms apparent to the eye and clear in their relations with one another. And these rhythms are at the very root of human activities. They resound in man by an organic inevitability, the same fine inevitability which causes the tracing out of the Golden Section by children, old men, savages and the learned."[16] Le Corbusier explicitly used the golden ratio in his Modulor system for the scale of architectural proportion. He saw this system as a continuation of the long tradition of Vitruvius, Leonardo da Vinci's "Vitruvian Man", the work of Leon Battista Alberti, and others who used the proportions of the human body to improve the appearance and function of architecture. In addition to the golden ratio, Le Corbusier based the system on human measurements, Fibonacci numbers, and the double unit. He took suggestion of the golden ratio in human proportions to an extreme: he sectioned his model human body's height at the navel with the two sections in golden ratio, then subdivided those sections in golden ratio at the knees and throat; he used these golden ratio proportions in the Modulor system. Le Corbusier's 1927 Villa Stein in Garches exemplified the Modulor system's application. The villa's rectangular ground plan, elevation, and inner structure closely approximate golden rectangles.[17] Another Swiss architect, Mario Botta, bases many of his designs on geometric figures. Several private houses he designed in Switzerland are composed of squares and circles, cubes and cylinders. In a house he designed in Origlio, the golden ratio is the proportion between the central section and the side sections of the house.[18]

30

Golden ratio

31

In a recent book, author Jason Elliot speculated that the golden ratio was used by the designers of the Naqsh-e Jahan Square and the adjacent Lotfollah mosque.

Painting The 16th-century philosopher Heinrich Agrippa drew a man over a pentagram inside a circle, implying a relationship to the golden ratio. Leonardo da Vinci's illustrations of polyhedra in De divina proportione (On the Divine Proportion) and his views that some bodily proportions exhibit the golden ratio have led some scholars to speculate that he incorporated the golden ratio in his paintings.[19] But the suggestion that his Mona Lisa, for example, employs golden ratio proportions, is not supported by anything in Leonardo's own writings. Similarly, although the Vitruvian Man is often[20] shown in connection with the golden ratio, the proportions of the figure do not actually match it, and the text only mentions whole number ratios. The drawing of a man's body in a pentagram suggests relationships to the golden ratio. Salvador Dalí, influenced by the works of Matila Ghyka, explicitly used the golden ratio in his masterpiece, The Sacrament of the Last Supper. The dimensions of the canvas are a golden rectangle. A huge dodecahedron, in perspective so that edges appear in golden ratio to one another, is suspended above and behind Jesus and dominates the composition.[21]

Mondrian has been said to have used the golden section extensively in his geometrical paintings,[22] though other experts (including critic Yve-Alain Bois) have disputed this claim. A statistical study on 565 works of art of different great painters, performed in 1999, found that these artists had not used the golden ratio in the size of their canvases. The study concluded that the average ratio of the two sides of the paintings studied is 1.34, with averages for individual artists ranging from 1.04 (Goya) to 1.46 (Bellini).[23] On the other hand, Pablo Tosto listed over 350 works by well-known artists, including more than 100 which have canvasses with golden rectangle and root-5 proportions, and others with proportions like root-2, 3, 4, and 6.[24]

Book design According to Jan Tschichold,[26] There was a time when deviations from the truly beautiful page proportions 2:3, 1:√3, and the Golden Section were rare. Many books produced between 1550 and 1770 show these proportions exactly, to within half a millimeter.

Design Some sources claim that the golden ratio is commonly used in everyday design, for example in the shapes of postcards, playing cards, posters, wide-screen televisions, photographs, light switch plates and cars.

Music

Depiction of the proportions in a medieval manuscript. According to Jan Tschichold: "Page proportion 2:3. Margin proportions 1:1½:2:3. Text area proportioned in the Golden [25] Section."

Golden ratio

32

Ernő Lendvaï analyzes Béla Bartók's works as being based on two opposing systems, that of the golden ratio and the acoustic scale,[27] though other music scholars reject that analysis. French composer Erik Satie used the golden ratio in several of his pieces, including Sonneries de la Rose+Croix. The golden ratio is also apparent in the organization of the sections in the music of Debussy's Reflets dans l'eau (Reflections in Water), from Images (1st series, 1905), in which "the sequence of keys is marked out by the intervals 34, 21, 13 and 8, and the main climax sits at the phi position."[28] The musicologist Roy Howat has observed that the formal boundaries of La Mer correspond exactly to the golden section. Trezise finds the intrinsic evidence "remarkable," but cautions that no written or reported evidence suggests that Debussy consciously sought such proportions. Pearl Drums positions the air vents on its Masters Premium models based on the golden ratio. The company claims that this arrangement improves bass response and has applied for a patent on this innovation. Though Heinz Bohlen proposed the non-octave-repeating 833 cents scale based on combination tones, the tuning features relations based on the golden ratio. As a musical interval the ratio 1.618... is 833.090... cents (  Play Wikipedia:Media helpFile:Golden ratio on C.mid).[29]

Nature Adolf Zeising, whose main interests were mathematics and philosophy, found the golden ratio expressed in the arrangement of branches along the stems of plants and of veins in leaves. He extended his research to the skeletons of animals and the branchings of their veins and nerves, to the proportions of chemical compounds and the geometry of crystals, even to the use of proportion in artistic endeavors. In these phenomena he saw the golden ratio operating as a universal law. In connection with his scheme for golden-ratio-based human body proportions, Zeising wrote in 1854 of a universal law "in which is contained the ground-principle of all formative striving for beauty and completeness in the realms of both nature and art, and which permeates, as a paramount spiritual ideal, all structures, forms and proportions, whether cosmic or individual, organic or inorganic, acoustic or optical; which finds its fullest realization, however, in the human form." In 2010, the journal Science reported that the golden ratio is present at the atomic scale in the magnetic resonance of spins in cobalt niobate crystals.

A detail of an Aeonium tabuliforme in Trädgårdsföreningen, Göteborg

Since 1991, several researchers have proposed connections between the golden ratio and human genome DNA.[30][31][32][33] However, some have argued that many of the apparent manifestations of the golden ratio in nature, especially in regard to animal dimensions, are in fact fictitious.[34]

Golden ratio

Optimization The golden ratio is key to the golden section search.

Perceptual studies Studies by psychologists, starting with Fechner, have been devised to test the idea that the golden ratio plays a role in human perception of beauty. While Fechner found a preference for rectangle ratios centered on the golden ratio, later attempts to carefully test such a hypothesis have been, at best, inconclusive.[35]

Mathematics Golden ratio conjugate The negative root of the quadratic equation for φ (the "conjugate root") is

The absolute value of this quantity (≈ 0.618) corresponds to the length ratio taken in reverse order (shorter segment length over longer segment length, b/a), and is sometimes referred to as the golden ratio conjugate. It is denoted here by the capital Phi (Φ):

Alternatively, Φ can be expressed as

This illustrates the unique property of the golden ratio among positive numbers, that

or its inverse:

This means 0.61803...:1 = 1:1.61803....

33

Golden ratio

34

Short proofs of irrationality Contradiction from an expression in lowest terms Recall that: the whole is the longer part plus the shorter part; the whole is to the longer part as the longer part is to the shorter part. If we call the whole n and the longer part m, then the second statement above becomes n is to m as m is to n − m, or, algebraically

If φ were rational, then it would be the ratio of sides of a rectangle with integer sides. But it is also a ratio of sides, which are also integers, of the smaller rectangle obtained by deleting a square. The sequence of decreasing integer side lengths formed by deleting squares cannot be continued indefinitely, so φ cannot be rational.

To say that φ is rational means that φ is a fraction n/m where n and m are integers. We may take n/m to be in lowest terms and n and m to be positive. But if n/m is in lowest terms, then the identity labeled (*) above says m/(n − m) is in still lower terms. That is a contradiction that follows from the assumption that φ is rational. Derivation from irrationality of √5 Another short proof—perhaps more commonly known—of the irrationality of the golden ratio makes use of the closure of rational numbers under addition and multiplication. If is rational, then is also rational, which is a contradiction if it is already known that the square root of a non-square natural number is irrational.

Alternative forms The formula φ = 1 + 1/φ can be expanded recursively to obtain a continued fraction for the golden ratio:

and its reciprocal:

The convergents of these continued fractions (1/1, 2/1, 3/2, 5/3, 8/5, 13/8, ..., or 1/1, 1/2, 2/3, 3/5, 5/8, 8/13, ...) are ratios of successive Fibonacci numbers.

Approximations to the reciprocal golden ratio by finite continued fractions, or ratios of Fibonacci numbers

The equation φ2 = 1 + φ likewise produces the continued square root, or infinite surd, form:

Golden ratio

An infinite series can be derived to express phi:[36]

Also:

These correspond to the fact that the length of the diagonal of a regular pentagon is φ times the length of its side, and similar relations in a pentagram.

Geometry The number φ turns up frequently in geometry, particularly in figures with pentagonal symmetry. The length of a regular pentagon's diagonal is φ times its side. The vertices of a regular icosahedron are those of three mutually orthogonal golden rectangles. There is no known general algorithm to arrange a given number of nodes evenly on a sphere, for any of several definitions of even distribution (see, for example, Thomson problem). However, a useful approximation results from dividing the sphere into Approximate and true golden spirals. The green spiral is made from quarter-circles parallel bands of equal surface area tangent to the interior of each square, while the red spiral is a Golden Spiral, a special type of logarithmic spiral. Overlapping portions appear yellow. The length of the side of and placing one node in each band at one square divided by that of the next smaller square is the golden ratio. longitudes spaced by a golden section of the circle, i.e. 360°/φ ≅ 222.5°. This method was used to arrange the 1500 mirrors of the student-participatory satellite Starshine-3.

35

Golden ratio

36

Dividing a line segment The following algorithm produces a geometric construction that divides a line segment into two line segments where the ratio of the longer to the shorter line segment is the golden ratio: 1. Having a line segment AB, construct a perpendicular BC at point B, with BC half the length of AB. Draw the hypotenuse AC. 2. Draw an arc with center C and radius BC. This arc intersects the hypotenuse AC at point D. 3. Draw an arc with center A and radius AD. This arc intersects the original line segment AB at point S. Point S divides the original segment AB into line segments AS and SB with lengths in the golden ratio.

Dividing a line segment according to the golden ratio

Golden triangle, pentagon and pentagram Golden triangle The golden triangle can be characterized as an isosceles triangle ABC with the property that bisecting the angle C produces a new triangle CXB which is a similar triangle to the original. If angle BCX = α, then XCA = α because of the bisection, and CAB = α because of the similar triangles; ABC = 2α from the original isosceles symmetry, and BXC = 2α by similarity. The angles in a triangle add up to 180°, so 5α = 180, giving α = 36°. So the angles of the golden triangle are thus 36°-72°-72°. The angles of the remaining obtuse isosceles triangle AXC (sometimes called the golden gnomon) are 36°-36°-108°.

Golden triangle

Suppose XB has length 1, and we call BC length φ. Because of the isosceles triangles XC=XA and BC=XC, so these are also length φ. Length AC = AB, therefore equals φ + 1. But triangle ABC is similar to triangle CXB, so AC/BC = BC/BX, and so AC also equals φ2. Thus φ2 = φ + 1, confirming that φ is indeed the golden ratio. Similarly, the ratio of the area of the larger triangle AXC to the smaller CXB is equal to φ, while the inverse ratio is φ − 1.

Golden ratio

37

Pentagon In a regular pentagon the ratio between a side and a diagonal is

(i.e. 1/φ), while intersecting diagonals section

each other in the golden ratio. Odom's construction George Odom has given a remarkably simple construction for φ involving an equilateral triangle: if an equilateral triangle is inscribed in a circle and the line segment joining the midpoints of two sides is produced to intersect the circle in either of two points, then these three points are in golden proportion. This result is a straightforward consequence of the intersecting chords theorem and can be used to construct a regular pentagon, a construction that attracted the attention of the noted Canadian geometer H. S. M. Coxeter who published it in Odom's name as a diagram in the American Mathematical Monthly accompanied by the single word "Behold!"

Let A and B be midpoints of the sides EF and ED of an equilateral triangle DEF. Extend AB to meet the circumcircle of DEF at C.\tfrac{|AB|}{|BC|}=\tfrac{|AC|}{|AB|}=\phi

Pentagram The golden ratio plays an important role in the geometry of pentagrams. Each intersection of edges sections other edges in the golden ratio. Also, the ratio of the length of the shorter segment to the segment bounded by the two intersecting edges (a side of the pentagon in the pentagram's center) is φ, as the four-color illustration shows. The pentagram includes ten isosceles triangles: five acute and five obtuse isosceles triangles. In all of them, the ratio of the longer side to the shorter side is φ. The acute triangles are golden triangles. The obtuse isosceles triangles are golden gnomons.

A pentagram colored to distinguish its line segments of different lengths. The four lengths are in golden ratio to one another.

Golden ratio

38

Ptolemy's theorem The golden ratio properties of a regular pentagon can be confirmed by applying Ptolemy's theorem to the quadrilateral formed by removing one of its vertices. If the quadrilateral's long edge and diagonals are b, and short edges are a, then Ptolemy's theorem gives b2 = a2 + ab which yields

Scalenity of triangles Consider a triangle with sides of lengths a, b, and c in decreasing order. Define the "scalenity" of the triangle to be the smaller of the two ratios a/b and b/c. The scalenity is always less than φ and can be made as close as desired to φ.[37]

The golden ratio in a regular pentagon can be computed using Ptolemy's theorem.

Triangle whose sides form a geometric progression If the side lengths of a triangle form a geometric progression and are in the ratio 1 : r : r2, where r is the common ratio, then r must lie in the range φ−1 < r < φ, which is a consequence of the triangle inequality (the sum of any two sides of a triangle must be strictly bigger than the length of the third side). If r = φ then the shorter two sides are 1 and φ but their sum is φ2, thus r < φ. A similar calculation shows that r > φ−1. A triangle whose sides are in the ratio 1 : √φ : φ is a right triangle (because 1 + φ = φ2) known as a Kepler triangle. Golden triangle, rhombus, and rhombic triacontahedron A golden rhombus is a rhombus whose diagonals are in the golden ratio.[citation needed] The rhombic triacontahedron is a convex polytope that has a very special property: all of its faces are golden rhombi. In the rhombic triacontahedron the dihedral angle between any two adjacent rhombi is 144°, which is twice the isosceles angle of a golden triangle and four times its most acute angle.[citation needed]

Relationship to Fibonacci sequence The mathematics of the golden ratio and of the Fibonacci sequence are intimately interconnected. The Fibonacci sequence is:

One of the rhombic triacontahedron's rhombi

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, .... The closed-form expression (known as Binet's formula, even though it was already known by Abraham de Moivre) for the Fibonacci sequence involves the golden ratio:

Golden ratio

39

All of the faces of the rhombic triacontahedron are golden rhombi

The golden ratio is the limit of the ratios of successive terms of the Fibonacci sequence (or any Fibonacci-like sequence), as originally shown by Kepler:

Therefore, if a Fibonacci number is divided by its immediate predecessor in the sequence, the quotient approximates φ; e.g., 987/610 ≈ 1.6180327868852. These approximations are alternately lower and higher than φ, and converge on φ as the Fibonacci numbers increase, and:

A Fibonacci spiral which approximates the golden spiral, using Fibonacci sequence square sizes up to 34.

More generally:

where above, the ratios of consecutive terms of the Fibonacci sequence, is a case when

.

Furthermore, the successive powers of φ obey the Fibonacci recurrence:

This identity allows any polynomial in φ to be reduced to a linear expression. For example:

However, this is no special property of φ, because polynomials in any solution x to a quadratic equation can be reduced in an analogous manner, by applying:

for given coefficients a, b such that x satisfies the equation. Even more generally, any rational function (with rational coefficients) of the root of an irreducible nth-degree polynomial over the rationals can be reduced to a polynomial of

Golden ratio

40

degree n ‒ 1. Phrased in terms of field theory, if α is a root of an irreducible nth-degree polynomial, then n over

, with basis

has degree

.

Symmetries The golden ratio and inverse golden ratio

have a set of symmetries that preserve and

interrelate them. They are both preserved by the fractional linear transformations



this fact corresponds to the identity and the definition quadratic equation. Further, they are interchanged by the three maps – they are reciprocals, symmetric about , and (projectively) symmetric about 2. More deeply, these maps form a subgroup of the modular group 3 letters,

corresponding to the stabilizer of the set

the symmetries correspond to the quotient map the identity

isomorphic to the symmetric group on of 3 standard points on the projective line, and

– the subgroup

consisting of the 3-cycles and

fixes the two numbers, while the 2-cycles interchange these, thus realizing the map.

Other properties The golden ratio has the simplest expression (and slowest convergence) as a continued fraction expansion of any irrational number (see Alternate forms above). It is, for that reason, one of the worst cases of Lagrange's approximation theorem and it is an extremal case of the Hurwitz inequality for Diophantine approximations. This may be why angles close to the golden ratio often show up in phyllotaxis (the growth of plants).[38] The defining quadratic polynomial and the conjugate relationship lead to decimal values that have their fractional part in common with φ:

The sequence of powers of φ contains these values 0.618..., 1.0, 1.618..., 2.618...; more generally, any power of φ is equal to the sum of the two immediately preceding powers:

As a result, one can easily decompose any power of φ into a multiple of φ and a constant. The multiple and the constant are always adjacent Fibonacci numbers. This leads to another property of the positive powers of φ: If

, then:

When the golden ratio is used as the base of a numeral system (see Golden ratio base, sometimes dubbed phinary or φ-nary), every integer has a terminating representation, despite φ being irrational, but every fraction has a non-terminating representation. The golden ratio is a fundamental unit of the algebraic number field In the field

we have

, where

is the

and is a Pisot–Vijayaraghavan number. -th Lucas number.

The golden ratio also appears in hyperbolic geometry, as the maximum distance from a point on one side of an ideal triangle to the closer of the other two sides: this distance, the side length of the equilateral triangle formed by the points of tangency of a circle inscribed within the ideal triangle, is 4 ln φ.[39]

Golden ratio

Decimal expansion The golden ratio's decimal expansion can be calculated directly from the expression

with √5 ≈ 2.2360679774997896964. The square root of 5 can be calculated with the Babylonian method, starting with an initial estimate such as xφ = 2 and iterating

for n = 1, 2, 3, ..., until the difference between xn and xn−1 becomes zero, to the desired number of digits. The Babylonian algorithm for √5 is equivalent to Newton's method for solving the equation x2 − 5 = 0. In its more general form, Newton's method can be applied directly to any algebraic equation, including the equation x2 − x − 1 = 0 that defines the golden ratio. This gives an iteration that converges to the golden ratio itself,

for an appropriate initial estimate xφ such as xφ = 1. A slightly faster method is to rewrite the equation as x − 1 − 1/x = 0, in which case the Newton iteration becomes

These iterations all converge quadratically; that is, each step roughly doubles the number of correct digits. The golden ratio is therefore relatively easy to compute with arbitrary precision. The time needed to compute n digits of the golden ratio is proportional to the time needed to divide two n-digit numbers. This is considerably faster than known algorithms for the transcendental numbers π and e. An easily programmed alternative using only integer arithmetic is to calculate two large consecutive Fibonacci numbers and divide them. The ratio of Fibonacci numbers F 25001 and F 25000, each over 5000 digits, yields over 10,000 significant digits of the golden ratio. The golden ratio φ has been calculated to an accuracy of several millions of decimal digits (sequence A001622 in OEIS). Alexis Irlande performed computations and verification of the first 17,000,000,000 digits.

41

Golden ratio

42

Pyramids Both Egyptian pyramids and those mathematical regular square pyramids that resemble them can be analyzed with respect to the golden ratio and other ratios.

Mathematical pyramids and triangles A pyramid in which the apothem (slant height along the bisector of a face) is equal to φ times the semi-base (half the base width) is sometimes called a golden pyramid. The isosceles triangle that is the face of such a pyramid can be constructed from the two halves of a diagonally split golden rectangle (of size semi-base by apothem), joining the medium-length edges to make the apothem. The height of this pyramid is times the semi-base (that is, the slope of the face is

A regular square pyramid is determined by its medial right triangle, whose edges are the pyramid's apothem (a), semi-base (b), and height (h); the face inclination angle is also marked. Mathematical proportions b:h:a of and and

); the

are of particular interest in relation to Egyptian pyramids.

square of the height is equal to the area of a face, φ times the square of the semi-base. The medial right triangle of this "golden" pyramid (see diagram), with sides right, demonstrating via the Pythagorean theorem the relationship

is interesting in its own or

. This

"Kepler triangle" is the only right triangle proportion with edge lengths in geometric progression, just as the 3–4–5 triangle is the only right triangle proportion with edge lengths in arithmetic progression. The angle with tangent corresponds to the angle that the side of the pyramid makes with respect to the ground, 51.827... degrees (51° 49' 38").[40] A nearly similar pyramid shape, but with rational proportions, is described in the Rhind Mathematical Papyrus (the source of a large part of modern knowledge of ancient Egyptian mathematics), based on the 3:4:5 triangle; the face slope corresponding to the angle with tangent 4/3 is 53.13 degrees (53 degrees and 8 minutes). The slant height or apothem is 5/3 or 1.666... times the semi-base. The Rhind papyrus has another pyramid problem as well, again with rational slope (expressed as run over rise). Egyptian mathematics did not include the notion of irrational numbers,[41] and the rational inverse slope (run/rise, multiplied by a factor of 7 to convert to their conventional units of palms per cubit) was used in the building of pyramids. Another mathematical pyramid with proportions almost identical to the "golden" one is the one with perimeter equal to 2π times the height, or h:b = 4:π. This triangle has a face angle of 51.854° (51°51'), very close to the 51.827° of the Kepler triangle. This pyramid relationship corresponds to the coincidental relationship . Egyptian pyramids very close in proportion to these mathematical pyramids are known.

Golden ratio

Egyptian pyramids In the mid-nineteenth century, Röber studied various Egyptian pyramids including Khafre, Menkaure and some of the Giza, Sakkara, and Abusir groups, and was interpreted as saying that half the base of the side of the pyramid is the middle mean of the side, forming what other authors identified as the Kepler triangle; many other mathematical theories of the shape of the pyramids have also been explored. One Egyptian pyramid is remarkably close to a "golden pyramid"—the Great Pyramid of Giza (also known as the Pyramid of Cheops or Khufu). Its slope of 51° 52' is extremely close to the "golden" pyramid inclination of 51° 50' and the π-based pyramid inclination of 51° 51'; other pyramids at Giza (Chephren, 52° 20', and Mycerinus, 50° 47')[] are also quite close. Whether the relationship to the golden ratio in these pyramids is by design or by accident remains open to speculation. Several other Egyptian pyramids are very close to the rational 3:4:5 shape. Adding fuel to controversy over the architectural authorship of the Great Pyramid, Eric Temple Bell, mathematician and historian, claimed in 1950 that Egyptian mathematics would not have supported the ability to calculate the slant height of the pyramids, or the ratio to the height, except in the case of the 3:4:5 pyramid, since the 3:4:5 triangle was the only right triangle known to the Egyptians and they did not know the Pythagorean theorem, nor any way to reason about irrationals such as π or φ.Wikipedia:Disputed statement Michael Rice[42] asserts that principal authorities on the history of Egyptian architecture have argued that the Egyptians were well acquainted with the golden ratio and that it is part of mathematics of the Pyramids, citing Giedon (1957).[43] Historians of science have always debated whether the Egyptians had any such knowledge or not, contending rather that its appearance in an Egyptian building is the result of chance. In 1859, the pyramidologist John Taylor claimed that, in the Great Pyramid of Giza, the golden ratio is represented by the ratio of the length of the face (the slope height), inclined at an angle θ to the ground, to half the length of the side of the square base, equivalent to the secant of the angle θ.[44] The above two lengths were about 186.4 and 115.2 meters respectively. The ratio of these lengths is the golden ratio, accurate to more digits than either of the original measurements. Similarly, Howard Vyse, according to Matila Ghyka,[45] reported the great pyramid height 148.2 m, and half-base 116.4 m, yielding 1.6189 for the ratio of slant height to half-base, again more accurate than the data variability.

Disputed observations Examples of disputed observations of the golden ratio include the following: • Historian John Man states that the pages of the Gutenberg Bible were "based on the golden section shape". However, according to Man's own measurements, the ratio of height to width was 1.45.[46] • Some specific proportions in the bodies of many animals (including humans) and parts of the shells of mollusks are often claimed to be in the golden ratio. There is a large variation in the real measures of these elements in specific individuals, however, and the proportion in question is often significantly different from the golden ratio. The ratio of successive phalangeal bones of the digits and the metacarpal bone has been said to approximate the golden ratio. The nautilus shell, the construction of which proceeds in a logarithmic spiral, is often cited, usually with the idea that any logarithmic spiral is related to the golden ratio, but sometimes with the claim that each new chamber is proportioned by the golden ratio relative to the previous one;[47] however, measurements of nautilus shells do not support this claim. • The proportions of different plant components (numbers of leaves to branches, diameters of geometrical figures inside flowers) are often claimed to show the golden ratio proportion in several species.[48] In practice, there are significant variations between individuals, seasonal variations, and age variations in these species. While the golden ratio may be found in some proportions in some individuals at particular times in their life cycles, there is no consistent ratio in their proportions.[citation needed]

43

Golden ratio • In investing, some practitioners of technical analysis use the golden ratio to indicate support of a price level, or resistance to price increases, of a stock or commodity; after significant price changes up or down, new support and resistance levels are supposedly found at or near prices related to the starting price via the golden ratio.[49] The use of the golden ratio in investing is also related to more complicated patterns described by Fibonacci numbers (e.g. Elliott wave principle and Fibonacci retracement). However, other market analysts have published analyses suggesting that these percentages and patterns are not supported by the data.[50]

References and footnotes [1] The golden ratio can be derived by the quadratic formula, by starting with the first number as 1, then solving for 2nd number x, where the ratios (x + 1)/x = x/1 or (multiplying by x) yields: x + 1 = x2, or thus a quadratic equation: x2 − x − 1 = 0. Then, by the quadratic formula, for positive x = (−b + √(b2 − 4ac))/(2a) with a = 1, b = −1, c = −1, the solution for x is: (−(−1) + √((−1)2 − 4·1·(−1)))/(2·1) or (1 + √(5))/2. [2] Piotr Sadowski, The Knight on His Quest: Symbolic Patterns of Transition in Sir Gawain and the Green Knight, Cranbury NJ: Associated University Presses, 1996 [3] Richard A Dunlap, The Golden Ratio and Fibonacci Numbers, World Scientific Publishing, 1997 [4] Euclid, Elements (http:/ / aleph0. clarku. edu/ ~djoyce/ java/ elements/ toc. html), Book 6, Definition 3. [5] Summerson John, Heavenly Mansions: And Other Essays on Architecture (New York: W.W. Norton, 1963) p. 37. "And the same applies in architecture, to the rectangles representing these and other ratios (e.g. the 'golden cut'). The sole value of these ratios is that they are intellectually fruitful and suggest the rhythms of modular design." [6] Jay Hambidge, Dynamic Symmetry: The Greek Vase, New Haven CT: Yale University Press, 1920 [7] William Lidwell, Kritina Holden, Jill Butler, Universal Principles of Design: A Cross-Disciplinary Reference, Gloucester MA: Rockport Publishers, 2003 [8] Pacioli, Luca. De divina proportione, Luca Paganinem de Paganinus de Brescia (Antonio Capella) 1509, Venice. [9] Mario Livio,The Golden Ratio: The Story of Phi, The World's Most Astonishing Number, p.6 [10] Euclid, Elements (http:/ / aleph0. clarku. edu/ ~djoyce/ java/ elements/ toc. html), Book 6, Proposition 30. [11] Euclid, Elements (http:/ / aleph0. clarku. edu/ ~djoyce/ java/ elements/ toc. html), Book 2, Proposition 11; Book 4, Propositions 10–11; Book 13, Propositions 1–6, 8–11, 16–18. [12] Van Mersbergen, Audrey M., "Rhetorical Prototypes in Architecture: Measuring the Acropolis with a Philosophical Polemic", Communication Quarterly, Vol. 46 No. 2, 1998, pp 194-213. [13] Midhat J. Gazalé , Gnomon, Princeton University Press, 1999. ISBN 0-691-00514-1 [14] Keith J. Devlin The Math Instinct: Why You're A Mathematical Genius (Along With Lobsters, Birds, Cats, And Dogs), p. 108 (http:/ / books. google. com/ books?id=eRD9gYk2r6oC& pg=PA108). New York: Thunder's Mouth Press, 2005, ISBN 1-56025-672-9 [15] Boussora, Kenza and Mazouz, Said, The Use of the Golden Section in the Great Mosque of Kairouan, Nexus Network Journal, vol. 6 no. 1 (Spring 2004), (http:/ / www. emis. de/ journals/ NNJ/ BouMaz. html) [16] Le Corbusier, The Modulor p. 25, as cited in Padovan, Richard, Proportion: Science, Philosophy, Architecture (1999), p. 316, Taylor and Francis, ISBN 0-419-22780-6 [17] Le Corbusier, The Modulor, p. 35, as cited in Padovan, Richard, Proportion: Science, Philosophy, Architecture (1999), p. 320. Taylor & Francis. ISBN 0-419-22780-6: "Both the paintings and the architectural designs make use of the golden section". [18] Urwin, Simon. Analysing Architecture (2003) pp. 154-5, ISBN 0-415-30685-X [19] Leonardo da Vinci's Polyhedra, by George W. Hart (http:/ / www. georgehart. com/ virtual-polyhedra/ leonardo. html) [20] "Part of the process of becoming a mathematics writer is, it appears, learning that you cannot refer to the golden ratio without following the first mention by a phrase that goes something like 'which the ancient Greeks and others believed to have divine and mystical properties.' Almost as compulsive is the urge to add a second factoid along the lines of 'Leonardo Da Vinci believed that the human form displays the golden ratio.' There is not a shred of evidence to back up either claim, and every reason to assume they are both false. Yet both claims, along with various others in a similar vein, live on." [21] Hunt, Carla Herndon and Gilkey, Susan Nicodemus. Teaching Mathematics in the Block pp. 44, 47, ISBN 1-883001-51-X [22] Bouleau, Charles, The Painter's Secret Geometry: A Study of Composition in Art (1963) pp.247-8, Harcourt, Brace & World, ISBN 0-87817-259-9 [23] Olariu, Agata, Golden Section and the Art of Painting Available online (http:/ / arxiv. org/ abs/ physics/ 9908036/ ) [24] Tosto, Pablo, La composición áurea en las artes plásticas – El número de oro, Librería Hachette, 1969, p. 134–144 [25] Jan Tschichold. The Form of the Book, pp.43 Fig 4. "Framework of ideal proportions in a medieval manuscript without multiple columns. Determined by Jan Tschichold 1953. Page proportion 2:3. margin proportions 1:1:2:3, Text area proportioned in the Golden Section. The lower outer corner of the text area is fixed by a diagonal as well." [26] Jan Tschichold, The Form of the Book, Hartley & Marks (1991), ISBN 0-88179-116-4. [27] Lendvai, Ernő (1971). Béla Bartók: An Analysis of His Music. London: Kahn and Averill. [28] Smith, Peter F. The Dynamics of Delight: Architecture and Aesthetics (http:/ / books. google. com/ books?id=ZgftUKoMnpkC& pg=PA83& dq=bartok+ intitle:The+ intitle:Dynamics+ intitle:of+ intitle:Delight+ intitle:Architecture+ intitle:and+ intitle:Aesthetics& as_brr=0& ei=WkkSR5L6OI--ogLpmoyzBg& sig=Ijw4YifrLhkcdQSMVAjSL5g4zVk) (New York: Routledge, 2003) pp 83, ISBN 0-415-30010-X

44

Golden ratio [29] " An 833 Cents Scale: An experiment on harmony (http:/ / www. huygens-fokker. org/ bpsite/ 833cent. html)", Huygens-Fokker.org. Accessed December 1, 2012. [30] J.C. Perez (1991), "Chaos DNA and Neuro-computers: A Golden Link" (http:/ / golden-ratio-in-dna. blogspot. com/ 2008/ 01/ 1991-first-publication-related-to. html), in Speculations in Science and Technology vol. 14 no. 4, . [31] Yamagishi, Michel E.B., and Shimabukuro, Alex I. (2007), "Nucleotide Frequencies in Human Genome and Fibonacci Numbers" (http:/ / www. springerlink. com/ content/ p140352473151957/ ?p=d5b18a2dfee949858e2062449e9ccfad& pi=0), in Bulletin of Mathematical Biology, (print), (online). PDF full text (http:/ / www. springerlink. com/ content/ p140352473151957/ fulltext. pdf) [32] PDF full text (http:/ / fr. scribd. com/ doc/ 95641538/ Codon-Populations-in-Single-stranded-Whole-Human-Genome-DNA-Are-Fractal-and-Fine-tuned-by-the-Golden-Ratio-1-618) [33] J.C. Perez, The “3 Genomic Numbers” Discovery: How Our Genome Single-Stranded DNA Sequence Is “Self-Designed” as a Numerical Whole, Applied Mathematics (Biomathematics issue October 2013) (http:/ / file. scirp. org/ Html/ 4-7401586_37457. htm) [34] Pommersheim, James E., Tim K. Marks, and Erica L. Flapan, eds. 2010. Number Theory: A Lively Introduction with Proofs, Applications, and Stories. John Wiley and Sons: 82. [35] The golden ratio and aesthetics (http:/ / plus. maths. org/ issue22/ features/ golden/ ), by Mario Livio. [36] Brian Roselle, "Golden Mean Series" (http:/ / sites. google. com/ site/ goldenmeanseries/ ) [37] American Mathematical Monthly, pp. 49-50, 1954. [38] Fibonacci Numbers and Nature - Part 2 : Why is the Golden section the "best" arrangement? (http:/ / www. maths. surrey. ac. uk/ hosted-sites/ R. Knott/ Fibonacci/ fibnat2. html), from Dr. Ron Knott's (http:/ / www. maths. surrey. ac. uk/ hosted-sites/ R. Knott/ ) Fibonacci Numbers and the Golden Section (http:/ / www. maths. surrey. ac. uk/ hosted-sites/ R. Knott/ Fibonacci/ ), retrieved 2012-11-29. [39] Horocycles exinscrits : une propriété hyperbolique remarquable (http:/ / www. cabri. net/ abracadabri/ GeoNonE/ GeoHyper/ KBModele/ Biss3KB. html), cabri.net, retrieved 2009-07-21. [40] Midhat Gazale, Gnomon: From Pharaohs to Fractals, Princeton Univ. Press, 1999 [41] Lancelot Hogben, Mathematics for the Million, London: Allen & Unwin, 1942, p. 63., as cited by Dick Teresi, Lost Discoveries: The Ancient Roots of Modern Science—from the Babylonians to the Maya, New York: Simon & Schuster, 2003, p.56 [42] Rice, Michael, Egypt's Legacy: The Archetypes of Western Civilisation, 3000 to 30 B.C pp. 24 Routledge, 2003, ISBN 0-415-26876-1 [43] S. Giedon, 1957, The Beginnings of Architecture, The A.W. Mellon Lectures in the Fine Arts, 457, as cited in Rice, Michael, Egypt's Legacy: The Archetypes of Western Civilisation, 3000 to 30 B.C pp.24 Routledge, 2003 [44] Taylor, The Great Pyramid: Why Was It Built and Who Built It?, 1859 [45] Matila Ghyka The Geometry of Art and Life, New York: Dover, 1977 [46] Man, John, Gutenberg: How One Man Remade the World with Word (2002) pp. 166–167, Wiley, ISBN 0-471-21823-5. "The half-folio page (30.7 × 44.5 cm) was made up of two rectangles—the whole page and its text area—based on the so called 'golden section', which specifies a crucial relationship between short and long sides, and produces an irrational number, as pi is, but is a ratio of about 5:8." [47] Ivan Moscovich, Ivan Moscovich Mastermind Collection: The Hinged Square & Other Puzzles, New York: Sterling, 2004 [48] Derek Thomas, Architecture and the Urban Environment: A Vision for the New Age, Oxford: Elsevier, 2002 [49] For instance, Osler writes that "38.2 percent and 61.8 percent retracements of recent rises or declines are common," in [50] Roy Batchelor and Richard Ramyar, " Magic numbers in the Dow (http:/ / www. webcitation. org/ 5reh6NujR)," 25th International Symposium on Forecasting, 2005, p. 13, 31. " Not since the 'big is beautiful' days have giants looked better (http:/ / www. telegraph. co. uk/ finance/ 2947908/ Not-since-the-big-is-beautiful-days-have-giants-looked-better. html)", Tom Stevenson, The Daily Telegraph, Apr. 10, 2006, and "Technical failure", The Economist, Sep. 23, 2006, are both popular-press accounts of Batchelor and Ramyar's research.

Further reading • Doczi, György (2005) [1981]. The Power of Limits: Proportional Harmonies in Nature, Art, and Architecture. Boston: Shambhala Publications. ISBN 1-59030-259-1. • Huntley, H. E. (1970). The Divine Proportion: A Study in Mathematical Beauty. New York: Dover Publications. ISBN 0-486-22254-3. • Livio, Mario (2002) [2002]. The Golden Ratio: The Story of PHI, the World's Most Astonishing Number (Hardback ed.). NYC: Broadway (Random House). ISBN 0-7679-0815-5. • Joseph, George G. (2000) [1991]. The Crest of the Peacock: The Non-European Roots of Mathematics (New ed.). Princeton, NJ: Princeton University Press. ISBN 0-691-00659-8. • Sahlqvist, Leif (2008). Cardinal Alignments and the Golden Section: Principles of Ancient Cosmography and Design (3rd Rev. ed.). Charleston, SC: BookSurge. ISBN 1-4196-2157-2. • Schneider, Michael S. (1994). A Beginner's Guide to Constructing the Universe: The Mathematical Archetypes of Nature, Art, and Science. New York: HarperCollins. ISBN 0-06-016939-7. • Stakhov, A. P. (2009). The Mathematics of Harmony: From Euclid to Contemporary Mathematics and Computer Science. Singapore: World Scientific Publishing. ISBN 978-981-277-582-5.

45

Golden ratio • Walser, Hans (2001) [Der Goldene Schnitt 1993]. The Golden Section. Peter Hilton trans. Washington, DC: The Mathematical Association of America. ISBN 0-88385-534-8. • Scimone, Aldo (1997). La Sezione Aurea. Storia culturale di un leitmotiv della Matematica. Palermo: Sigma Edizioni. ISBN 978-88-7231-025-0.

External links • Hazewinkel, Michiel, ed. (2001), "Golden ratio" (http://www.encyclopediaofmath.org/index.php?title=p/ g044570), Encyclopedia of Mathematics, Springer, ISBN 978-1-55608-010-4 • "Golden Section" (http://demonstrations.wolfram.com/GoldenSection/) by Michael Schreiber, Wolfram Demonstrations Project, 2007. • Golden Section in Photography: Golden Ratio, Golden Triangles, Golden Spiral (http://photoinf.com/ Golden_Mean/Eugene_Ilchenko/GoldenSection.html) • Weisstein, Eric W., " Golden Ratio (http://mathworld.wolfram.com/GoldenRatio.html)", MathWorld. • "Researcher explains mystery of golden ratio" (http://www.physorg.com/news180531747.html). PhysOrg. December 21, 2009. • Knott, Ron. "The Golden section ratio: Phi" (http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/ Fibonacci/phi.html). Information and activities by a mathematics professor. • The Pentagram & The Golden Ratio (http://web.archive.org/web/20071105084747/http://www.contracosta. cc.ca.us/math/pentagrm.htm). Green, Thomas M. Updated June 2005. Archived November 2007. Geometry instruction with problems to solve. • Schneider, Robert P. (2011). "A Golden Pair of Identities in the Theory of Numbers". arXiv: 1109.3216 (http:// arxiv.org/abs/1109.3216) [ math.HO (http://arxiv.org/archive/math.HO)]. Proves formulas that involve the golden mean and the Euler totient and Möbius functions.

46

Tower of Hanoi

47

Tower of Hanoi The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower, and sometimes pluralised) is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape.

A model set of the Towers of Hanoi (with 8 disks)

The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1. Only one disk may be moved at a time. 2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack. 3. No disk may be placed on top of a smaller disk. With three disks, the puzzle can be solved in seven moves. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2n - 1, where n is the number of disks.

An animated solution of the Tower of Hanoi puzzle for T(4,3).

Origins The puzzle was first publicized in the West by the French mathematician Édouard Lucas in 1883. There is a story about an Indian temple in Kashi Vishwanath which contains a large room with three time-worn posts in it surrounded by 64 golden disks. Brahmin priests, acting out the command of an Tower of Hanoi interactive display at the Universum museum in Mexico City ancient prophecy, have been moving these disks, in accordance with the immutable rules of the Brahma, since that time. The puzzle is therefore also known as the Tower of Brahma puzzle. According to the legend, when the last move of the puzzle will be completed, the world will end. It is not clear whether Lucas invented this legend or was inspired by it. If the legend were true, and if the priests were able to move disks at a rate of one per second, using the smallest number of moves, it would take them 264−1 seconds or roughly 585 billion years or 18,446,744,073,709,551,615 turns to finish, or about 127 times the current age of the sun. There are many variations on this legend. For instance, in some tellings, the temple is a monastery and the priests are monks. The temple or monastery may be said to be in different parts of the world — including Hanoi, Vietnam, and

Tower of Hanoi may be associated with any religion. In some versions, other elements are introduced, such as the fact that the tower was created at the beginning of the world, or that the priests or monks may make only one move per day.

Solution The puzzle can be played with any number of disks, although many toy versions have around seven to nine of them. The minimum number of moves required to solve a Tower of Hanoi puzzle is 2n - 1, where n is the number of disks.

Iterative solution A simple solution for the toy puzzle: Alternate moves between the smallest piece and a non-smallest piece. When moving the smallest piece, always move it to the next position in the same direction (to the right if the starting number of pieces is even, to the left if the starting number of pieces is odd). If there is no tower position in the chosen direction, move the piece to the opposite end, but then continue to move in the correct direction. For example, if you started with three pieces, you would move the smallest piece to the opposite end, then continue in the left direction after that. When the turn is to move the non-smallest piece, there is only one legal move. Doing this will complete the puzzle using the fewest number of moves to do so. Simpler statement of iterative solution Alternating between the smallest and the next-smallest disks, follow the steps for the appropriate case: For an even number of disks: • make the legal move between pegs A and B • make the legal move between pegs A and C • make the legal move between pegs B and C • repeat until complete For an odd number of disks: • • • •

make the legal move between pegs A and C make the legal move between pegs A and B make the legal move between pegs C and B repeat until complete

In each case, a total of 2ⁿ-1 moves are made. Equivalent iterative solution Another way to generate the unique optimal iterative solution: Number the disks 1 through n (largest to smallest). • If n is odd, the first move is from the Start to the Finish peg. • If n is even the first move is from the Start to the Using peg. Now, add these constraints: • No odd disk may be placed directly on an odd disk. • No even disk may be placed directly on an even disk. • Never undo your previous move (that is, do not move a disk back to its immediate last peg). Considering those constraints after the first move, there is only one legal move at every subsequent turn. The sequence of these unique moves is an optimal solution to the problem equivalent to the iterative solution described above.

48

Tower of Hanoi

49

Recursive solution A key to solving this puzzle is to recognize that it can be solved by breaking the problem down into a collection of smaller problems and further breaking those problems down into even smaller problems until a solution is reached. For example: • label the pegs A, B, C — these labels may move at different steps • let n be the total number of discs • number the discs from 1 (smallest, topmost) to n (largest, bottommost) To move n discs from peg A to peg C: 1. move n−1 discs from A to B. This leaves disc n alone on peg A 2. move disc n from A to C 3. move n−1 discs from B to C so they sit on disc n The above is a recursive algorithm, to carry out steps 1 and 3, apply the same algorithm again for n−1. The entire procedure is a finite number of steps, since at some point the algorithm will be required for n = 1. This step, moving a single disc from peg A to peg B, is trivial. This approach can be given a rigorous mathematical formalism with the theory of dynamic programming, and is often used as an example of recursion when teaching programming. Logical analysis of the recursive solution As in many mathematical puzzles, finding a solution is made easier by solving a slightly more general problem: how to move a tower of h (h=height) disks from a starting peg A (f=from) onto a destination peg C (t=to), B being the remaining third peg and assuming t≠f. First, observe that the problem is symmetric for permutations of the names of the pegs (symmetric group S3). If a solution is known moving from peg A to peg C, then, by renaming the pegs, the same solution can be used for every other choice of starting and destination peg. If there is only one disk (or even none at all), the problem is trivial. If h=1, then simply move the disk from peg A to peg C. If h>1, then somewhere along the sequence of moves, the largest disk must be moved from peg A to another peg, preferably to peg C. The only situation that allows this move is when all smaller h-1 disks are on peg B. Hence, first all h-1 smaller disks must go from A to B. Subsequently move the largest disk and finally move the h-1 smaller disks from peg B to peg C. The presence of the largest disk does not impede any move of the h-1 smaller disks and can temporarily be ignored. Now the problem is reduced to moving h-1 disks from one peg to another one, first from A to B and subsequently from B to C, but the same method can be used both times by renaming the pegs. The same strategy can be used to reduce the h-1 problem to h-2, h-3, and so on until only one disk is left. This is called recursion. This algorithm can be schematized as follows. Identify the disks in order of increasing size by the natural numbers from 0 up to but not including h. Hence disk 0 is the smallest one and disk h-1 the largest one. The following is a procedure for moving a tower of h disks from a peg A onto a peg C, with B being the remaining third peg: • Step 1: If h>1 then first use this procedure to move the h-1 smaller disks from peg A to peg B. • Step 2: Now the largest disk, i.e. disk h can be moved from peg A to peg C. • Step 3: If h>1 then again use this procedure to move the h-1 smaller disks from peg B to peg C. By means of mathematical induction, it is easily proven that the above procedure requires the minimal number of moves possible, and that the produced solution is the only one with this minimal number of moves. Using recurrence relations, the exact number of moves that this solution requires can be calculated by: . This result is obtained by noting that steps 1 and 3 take

moves, and step 2 takes one move, giving

.

Tower of Hanoi

Non-recursive solution The list of moves for a tower being carried from one peg onto another one, as produced by the recursive algorithm has many regularities. When counting the moves starting from 1, the ordinal of the disk to be moved during move m is the number of times m can be divided by 2. Hence every odd move involves the smallest disk. It can also be observed that the smallest disk traverses the pegs f, t, r, f, t, r, etc. for odd height of the tower and traverses the pegs f, r, t, f, r, t, etc. for even height of the tower. This provides the following algorithm, which is easier, carried out by hand, than the recursive algorithm. In alternate moves: • move the smallest disk to the peg it has not recently come from. • move another disk legally (there will be one possibility only) For the very first move, the smallest disk goes to peg t if h is odd and to peg r if h is even. Also observe that: • • • •

Disks whose ordinals have even parity move in the same sense as the smallest disk. Disks whose ordinals have odd parity move in opposite sense. If h is even, the remaining third peg during successive moves is t, r, f, t, r, f, etc. If h is odd, the remaining third peg during successive moves is r, t, f, r, t, f, etc.

With this knowledge, a set of disks in the middle of an optimal solution can be recovered with no more state information than the positions of each disk: • Call the moves detailed above a disk's 'natural' move. • Examine the smallest top disk that is not disk 0, and note what its only (legal) move would be: (if there is no such disc, then we are either at the first or last move). • If that move is the disk's 'natural' move, then the disc has not been moved since the last disc 0 move, and that move should be taken. • If that move is not the disk's 'natural' move, then move disk 0.

Binary solution Disk positions may be determined more directly from the binary (base 2) representation of the move number (the initial state being move #0, with all digits 0, and the final state being #2n−1, with all digits 1), using the following rules: • There is one binary digit (bit) for each disk • The most significant (leftmost) bit represents the largest disk. A value of 0 indicates that the largest disk is on the initial peg, while a 1 indicates that it's on the final peg. • The bitstring is read from left to right, and each bit can be used to determine the location of the corresponding disk. • A bit with the same value as the previous one means that the corresponding disk is stacked on top the previous disk on the same peg. • (That is to say: a straight sequence of 1's or 0's means that the corresponding disks are all on the same peg). • A bit with a different value to the previous one means that the corresponding disk is one position to the left or right of the previous one. Whether it is left or right is determined by this rule: • Assume that the initial peg is on the left and the final peg is on the right. • Also assume "wrapping" - so the right peg counts as one peg "left" of the left peg, and vice versa. • Let n be the number of greater disks that are located on the same peg as their first greater disk and add 1 if the largest disk is on the left peg. If n is even, the disk is located one peg to the left, if n is odd, the disk located one peg to the right.

50

Tower of Hanoi For example, in an 8-disk Hanoi: • Move 0 = 00000000 • The largest disk is 0, so it is on the left (initial) peg. • All other disks are 0 as well, so they are stacked on top of it. Hence all disks are on the initial peg. • Move 28-1 = 11111111 • The largest disk is 1, so it is on the right (final) peg. • All other disks are 1 as well, so they are stacked on top of it. Hence all disks are on the final peg and the puzzle is complete. • Move 21610 = 11011000 • • • • • • •

The largest disk is 1, so it is on the right (final) peg. Disk two is also 1, so it is stacked on top of it, on the right peg. Disk three is 0, so it is on another peg. Since n is odd(n=3), it is one peg to the right, i.e. on the left peg. Disk four is 1, so it is on another peg. Since n is even(n=2), it is one peg to the left, i.e. on the right peg. Disk five is also 1, so it is stacked on top of it, on the right peg. Disk six is 0, so it is on another peg. Since n is odd(n=5), the disk is one peg to the right, i.e. on the left peg. Disks seven and eight are also 0, so they are stacked on top of it, on the left peg.

The source and destination pegs for the mth move can also be found elegantly from the binary representation of m using bitwise operations. To use the syntax of the C programming language, move m is from peg (m&m-1)%3 to peg ((m|m-1)+1)%3, where the disks begin on peg 0 and finish on peg 1 or 2 according as whether the number of disks is even or odd. Another formulation is from peg (m-(m&-m))%3 to peg (m+(m&-m))%3. Furthermore the disk to be moved is determined by the number of times the move count (m) can be divided by 2 (i.e. the number of zero bits at the right), counting the first move as 1 and identifying the disks by the numbers 0, 1, 2 etc. in order of increasing size. This permits a very fast non-recursive computer implementation to find the positions of the disks after m moves without reference to any previous move or distribution of disks. The count trailing zeros (ctz) operation, which counts the number of consecutive zeros at the end of a binary number, gives a simple solution to the problem: the disks are numbered from zero, and at move m, disk number ctz(m) is moved the minimum possible distance to the right (circling back around to the left as needed).

Gray code solution The binary numeral system of Gray codes gives an alternative way of solving the puzzle. In the Gray system, numbers are expressed in a binary combination of 0s and 1s, but rather than being a standard positional numeral system, Gray code operates on the premise that each value differs from its predecessor by only one (and exactly one) bit changed. The number of bits present in Gray code is important, and leading zeros are not optional, unlike in positional systems. If one counts in Gray code of a bit size equal to the number of disks in a particular Tower of Hanoi, begins at zero, and counts up, then the bit changed each move corresponds to the disk to move, where the least-significant-bit is the smallest disk and the most-significant-bit is the largest. Counting moves from 1 and identifying the disks by numbers starting from 0 in order of increasing size, the ordinal of the disk to be moved during move m is the number of times m can be divided by 2. This technique identifies which disk to move, but not where to move it to. For the smallest disk there are always two possibilities. For the other disks there is always one possibility, except when all disks are on the same peg, but in that case either it is the smallest disk that must be moved or the objective has already been achieved. Luckily, there is a rule which does say where to move the smallest disk to. Let f be the starting peg, t the destination peg and r the remaining third peg. If the number of disks is odd, the smallest disk cycles along the pegs in the order f→t→r→f→t→r, etc. If the number of disks is even, this must be reversed: f→r→t→f→r→t etc.

51

Tower of Hanoi

Graphical representation The game can be represented by an undirected graph, the nodes representing distributions of disks and the edges representing moves. For one disk, the graph is a triangle:

The graph for two disks is three triangles arranged in a larger triangle:

52

Tower of Hanoi

The nodes at the vertices of the outermost triangle represent distributions with all disks on the same peg. For h+1 disks, take the graph of h disks and replace each small triangle with the graph for two disks. For three disks the graph is:

53

Tower of Hanoi

54

• call the pegs a, b and c • list disk positions from left to right in order of increasing size The sides of the outermost triangle represent the shortest ways of moving a tower from one peg to another one. The edge in the middle of the sides of the largest triangle represents a move of the largest disk. The edge in the middle of the sides of each next smaller triangle represents a move of each next smaller disk. The sides of the smallest triangles represent moves of the smallest disk. In general, for a puzzle with n disks, there are 3n nodes in the graph; every node has three edges to other nodes, except the three corner nodes, which have two: it is always possible to move the smallest disk to one of the two other pegs; and it is possible to move one disk between those two pegs except in the situation where all disks are stacked on one peg. The corner nodes represent the three cases where all the disks are stacked on one peg. The diagram for n + 1 disks is obtained by taking three copies of the n-disk diagram—each one representing all the states and moves of the smaller disks for one particular position of the new largest disk—and joining them at the corners with three new edges, representing the only three opportunities to move the largest disk. The resulting figure thus has 3n+1 nodes and still has three corners remaining with only two edges.

The game graph of level 7 shows the relatedness to the Sierpiński triangle.

As more disks are added, the graph representation of the game will resemble a fractal figure, the Sierpiński triangle. It is clear that the great majority of positions in the puzzle will never be reached when using the shortest possible

Tower of Hanoi solution; indeed, if the priests of the legend are using the longest possible solution (without re-visiting any position), it will take them 364 − 1 moves, or more than 1023 years. The longest non-repetitive way for three disks can be visualized by erasing the unused edges:

Incidentally, this longest non-repetitive path can be obtained by forbidding all moves from a to b. The circular Hamiltonian path for three disks is:

55

Tower of Hanoi

The graphs clearly show that: • From every arbitrary distribution of disks, there is exactly one shortest way to move all disks onto one of the three pegs. • Between every pair of arbitrary distributions of disks there are one or two different shortest paths. • From every arbitrary distribution of disks, there are one or two different longest non selfcrossing paths to move all disks to one of the three pegs. • Between every pair of arbitrary distributions of disks there are one or two different longest non self-crossing paths. • Let Nh be the number of non selfcrossing paths for moving a tower of h disks from one peg to another one. Then: • N1 = 2 • Nh+1 = (Nh)2 + (Nh)3. • For example: N8 ≈ 1.5456×10795

56

Tower of Hanoi

57

Applications The Tower of Hanoi is frequently used in psychological research on problem solving. There also exists a variant of this task called Tower of London for neuropsychological diagnosis and treatment of executive functions. The Tower of Hanoi is also used as a Backup rotation scheme when performing computer data Backups where multiple tapes/media are involved. As mentioned above, the Tower of Hanoi is popular for teaching recursive algorithms to beginning programming students. A pictorial version of this puzzle is programmed into the emacs editor, accessed by typing M-x hanoi. There is also a sample algorithm written in Prolog. The Tower of Hanoi is also used as a test by neuropsychologists trying to evaluate frontal lobe deficits. In 2010, researchers published the results of an experiment that found that the ant species linepithema humile were successfully able to solve the Tower of Hanoi problem through non-linear dynamics and pheromone signals.

General shortest paths and the number 466/885 A curious generalization of the original goal of the puzzle is to start from a given configuration of the disks where all disks are not necessarily on the same peg, and to arrive in a minimal number of moves at another given configuration. In general it can be quite difficult to compute a shortest sequence of moves to solve this problem. A solution was proposed by Andreas Hinz, and is based on the observation that in a shortest sequence of moves, the largest disk that needs to be moved (obviously one may ignore all of the largest disks that will occupy the same peg in both the initial and final configurations) will move either exactly once or exactly twice. The mathematics related to this generalized problem becomes even more interesting when one considers the average number of moves in a shortest sequence of moves between two initial and final disk configurations that are chosen at random. Hinz and Chan Hat-Tung independently discovered (see also, Chapter 1, p. 14) that the average number of moves in an n-disk Tower is given by the following exact formula:

Note that for large enough n, only the first and second terms do not converge to zero, so we get an asymptotic expression: , as . Thus intuitively, we could interpret the fraction of as representing the ratio of the labor one has to perform when going from a randomly chosen configuration to another randomly chosen configuration, relative to the difficulty of having to cross the "most difficult" path of length

which involves moving all the disks from one peg to another. An alternative

explanation for the appearance of the constant 466/885, as well as a new and somewhat improved algorithm for computing the shortest path, was given by Romik.

Variations Cyclic Hanoi Cyclic Hanoi is a variation of the Hanoi in which each disk must be moved in the same cyclic direction, in most cases, clockwise. For example, given a standard three peg set-up, a given disk can be moved from peg A to peg B, then from B to C, C to A, etc. This can be solved using two mutually recursive procedures: To move n discs clockwise from peg A to peg C: 1. move n − 1 discs clockwise from A to C 2. move disc #n from A to B 3. move n − 1 discs counterclockwise from C to A 4. move disc #n from B to C

Tower of Hanoi

58

5. move n − 1 discs clockwise from A to C To move n discs counterclockwise from peg A to peg C: 1. move n − 1 discs clockwise from A to B 2. move disc #n from A to C 3. move n − 1 discs clockwise from B to C

With four pegs and beyond Although the three-peg version has a simple recursive solution as outlined above, the optimal solution for the Tower of Hanoi problem with four pegs (called Reve's puzzle), let alone more pegs, is still an open problem. This is a good example of how a simple, solvable problem can be made dramatically more difficult by slightly loosening one of the problem constraints. The fact that the problem with four or more pegs is an open problem does not imply that no algorithm exists for finding (all of) the optimal solutions. Simply represent the game by an undirected graph, the nodes being distributions of disks and the edges being moves and use breadth first search to find one (or all) shortest path(s) moving a tower from one peg onto another one. However, even smartly implemented on the fastest computer now available, this algorithm provides no way of effectively computing solutions for large numbers of disks; the program would require more time and memory than available. Hence, even having an algorithm, it remains unknown how many moves an optimal solution requires and how many optimal solutions exist for 1000 disks and 10 pegs. Though it is not known exactly how many moves must be made, there are some asymptotic results. There is also a "presumed-optimal solution" given by the Frame-Stewart algorithm, discovered independently by Frame and Stewart in 1941. The related open Frame-Stewart conjecture claims that the Frame-Stewart algorithm always gives an optimal solution. The optimality of the Frame-Stewart algorithm has been computationally verified for 4 pegs with up to 30 disks. For other variants of the four-peg Tower of Hanoi problem, see Paul Stockmeyer's survey paper. Frame–Stewart algorithm The Frame–Stewart algorithm, giving a presumably optimal solution for four (or even more) pegs, is described below: • Let • Let

be the number of disks. be the number of pegs.

• Define

to be the minimum number of moves required to transfer n disks using r pegs

The algorithm can be described recursively: 1. For some

,

, transfer the top

disks to a single peg other than the start or destination pegs,

taking moves. 2. Without disturbing the peg that now contains the top destination peg, using only the remaining 3. Finally, transfer the top

disks, transfer the remaining

pegs, taking

disks to the destination peg, taking

The entire process takes which this quantity is minimum. This algorithm (with the above choice for

disks to the

moves. moves.

moves. Therefore, the count

should be picked for

) is presumed to be optimal, and no counterexamples are known.

Tower of Hanoi

Multistack Tower of Hanoi U.S. patent number 7,566,057 issued to Victor Mascolo discloses multistack Tower of Hanoi puzzles with two or more stacks and twice as many pegs as stacks. After beginning on a particular peg, each stack displaces and is displaced by a different colored stack on another peg when the puzzle is solved. Disks of one color also have another peg that excludes all other colors, so that there are three pegs available for each color disk, two that are shared with other colors, and one that is not shared. On the shared pegs, a disk may not be placed on a different colored disk of the same size, a possibility that does not arise in the standard puzzle. The simplest multistack game, Tower of Hanoi (2 × 4), has two stacks and four pegs, and it requires 3[T(n)] moves to solve where T(n) is the number of moves needed to solve a single stack classic of n disks. The game proceeds in seesaw fashion with longer and longer series of moves that alternate between colors. It concludes in reverse seesaw fashion with shorter and shorter such series of moves. Starting with the second series of three moves, these alternate series of moves double in length for the first half of the game, and the lengths are halved as the game concludes. The solution involves nesting an algorithm suitable for Tower of Hanoi into an algorithm that indicates when to switch between colors. When there are k stacks of n disks apiece in a game, and k > 2, it requires k[T(n)] + T(n − 1) + 1 moves to relocate them. The addition of a centrally located universal peg open to disks from all stacks converts these multistack Tower of Hanoi puzzles to multistack Reve's puzzles as described in the preceding section. In these games each stack may move among four pegs, the same combination of three in the 2 × 4 game plus the central universal peg. The simplest game of this kind (2 × 5) has two stacks and five pegs. A solution conjectured to be optimal interlocks the optimal solution of the 2 × 4 puzzle with the presumed optimal solution to Reve's puzzle. It takes R(n) + 2R(n − 1) + 2 moves, where R(n) is the number of moves in the presumed optimal Reve's solution for a stack of n disks.

In popular culture In the science fiction story "Now Inhale", by Eric Frank Russell, the human is a prisoner on a planet where the local custom is to make the prisoner play a game until it is won or lost, and then his execution will be immediate. The protagonist knows that a rescue ship might take a year or more to arrive, so he chooses to play Towers of Hanoi with 64 disks. (This story makes reference to the legend about the Buddhist monks playing the game until the end of the world.) In the 1966 Doctor Who story The Celestial Toymaker, the eponymous villain forces the Doctor to play a ten-piece 1,023-move Tower of Hanoi game entitled The Trilogic Game with the pieces forming a pyramid shape when stacked. In 2007, the concept of the Towers Of Hanoi problem was used in Professor Layton and the Diabolical Box in puzzles 6, 83, and 84, but the discs had been changed to pancakes. The puzzle was based around a dilemma where the chef of a restaurant had to move a pile of pancakes from one plate to the other with the basic principles of the original puzzle (i.e. three plates that the pancakes could be moved onto, not being able to put a larger pancake onto a smaller one, etc.) In the film Rise of the Planet of the Apes (2011), this puzzle, called in the film the "Lucas Tower", is used as a test to study the intelligence of apes. The puzzle is featured regularly in adventure and puzzle games. Since it is easy to implement, and easily recognised, it is well-suited to use as a puzzle in a larger graphical game (e.g. Star Wars: Knights of the Old Republic and Mass Effect). Some implementations use straight disks, but others disguise the puzzle in some other form. There is an arcade version by Sega/Andamiro.[1] The problem is featured as part of a reward challenge in a 2011 episode of the American version of the Survivor TV series. Both players (Ozzy Lusth and Benjamin "Coach" Wade) struggle to understand how to solve the puzzle and are aided by their fellow tribe members.

59

Tower of Hanoi

60

Notes [1] http:/ / www. segaarcade. com/ towerofhanoi

External links • Weisstein, Eric W., " Tower of Hanoi (http://mathworld.wolfram.com/TowerofHanoi.html)", MathWorld. • Tower of Hanoi (http://www.dmoz.org/Science/Math/Recreations/Famous_Problems/Tower_of_Hanoi/) on the Open Directory Project • Tower of Hanoi: Code in Lisp (http://www.codeminima.com/Lisp:_Tower_of_Hanoi) • Tower of Hanoi Variant Game: Pyramid Mover (https://play.google.com/store/apps/details?id=com.ADP. pyramidmovers)

Backtracking Graph and tree search algorithms •

α–β



A*



B*



Backtracking



Beam



Bellman–Ford



Best-first



Bidirectional



Borůvka



Branch & bound



BFS



British Museum



D*



DFS



Depth-limited



Dijkstra



Edmonds



Floyd–Warshall



Fringe search



Hill climbing



IDA*



Iterative deepening



Kruskal



Johnson



Lexicographic BFS



Prim



SMA*



Uniform-cost Listings

Backtracking

61 • • •

Graph algorithms Search algorithms List of graph algorithms Related topics

• • • •

Dynamic programming Graph traversal Tree traversal Search games

• • •

v t

e [1]

Backtracking is a general algorithm for finding all (or some) solutions to some computational problem, that incrementally builds candidates to the solutions, and abandons each partial candidate c ("backtracks") as soon as it determines that c cannot possibly be completed to a valid solution. The classic textbook example of the use of backtracking is the eight queens puzzle, that asks for all arrangements of eight chess queens on a standard chessboard so that no queen attacks any other. In the common backtracking approach, the partial candidates are arrangements of k queens in the first k rows of the board, all in different rows and columns. Any partial solution that contains two mutually attacking queens can be abandoned, since it cannot possibly be completed to a valid solution. Backtracking can be applied only for problems which admit the concept of a "partial candidate solution" and a relatively quick test of whether it can possibly be completed to a valid solution. It is useless, for example, for locating a given value in an unordered table. When it is applicable, however, backtracking is often much faster than brute force enumeration of all complete candidates, since it can eliminate a large number of candidates with a single test. Backtracking is an important tool for solving constraint satisfaction problems, such as crosswords, verbal arithmetic, Sudoku, and many other puzzles. It is often the most convenient (if not the most efficient[citation needed]) technique for parsing, for the knapsack problem and other combinatorial optimization problems. It is also the basis of the so-called logic programming languages such as Icon, Planner and Prolog. Backtracking is also utilized in the (diff) difference engine for the MediaWiki software[citation needed]. Backtracking depends on user-given "black box procedures" that define the problem to be solved, the nature of the partial candidates, and how they are extended into complete candidates. It is therefore a metaheuristic rather than a specific algorithm – although, unlike many other meta-heuristics, it is guaranteed to find all solutions to a finite problem in a bounded amount of time. The term "backtrack" was coined by American mathematician D. H. Lehmer in the 1950s. The pioneer string-processing language SNOBOL (1962) may have been the first to provide a built-in general backtracking facility.

Backtracking

Description of the method The backtracking algorithm enumerates a set of partial candidates that, in principle, could be completed in various ways to give all the possible solutions to the given problem. The completion is done incrementally, by a sequence of candidate extension steps. Conceptually, the partial candidates are the nodes of a tree structure, the potential search tree. Each partial candidate is the parent of the candidates that differ from it by a single extension step; the leaves of the tree are the partial candidates that cannot be extended any further. The backtracking algorithm traverses this search tree recursively, from the root down, in depth-first order. At each node c, the algorithm checks whether c can be completed to a valid solution. If it cannot, the whole sub-tree rooted at c is skipped (pruned). Otherwise, the algorithm (1) checks whether c itself is a valid solution, and if so reports it to the user; and (2) recursively enumerates all sub-trees of c. The two tests and the children of each node are defined by user-given procedures. Therefore, the actual search tree that is traversed by the algorithm is only a part of the potential tree. The total cost of the algorithm is the number of nodes of the actual tree times the cost of obtaining and processing each node. This fact should be considered when choosing the potential search tree and implementing the pruning test.

Pseudocode In order to apply backtracking to a specific class of problems, one must provide the data P for the particular instance of the problem that is to be solved, and six procedural parameters, root, reject, accept, first, next, and output. These procedures should take the instance data P as a parameter and should do the following: 1. 2. 3. 4. 5. 6.

'root(P): return the partial candidate at the root of the search tree. reject(P,c): return true only if the partial candidate c is not worth completing. accept(P,c): return true if c is a solution of P, and false otherwise. first(P,c): generate the first extension of candidate c. next(P,s): generate the next alternative extension of a candidate, after the extension s. output(P,c): use the solution c of P, as appropriate to the application.

The backtracking algorithm reduces then to the call bt(root(P)), where bt is the following recursive procedure: procedure bt(c) if reject(P,c) then return if accept(P,c) then output(P,c) s ← first(P,c) while s ≠ Λ do bt(s) s ← next(P,s)

Usage considerations The reject procedure should be a boolean-valued function that returns true only if it is certain that no possible extension of c is a valid solution for P. If the procedure cannot reach a definite conclusion, it should return false. An incorrect true result may cause the bt procedure to miss some valid solutions. The procedure may assume that reject(P,t) returned false for every ancestor t of c in the search tree. On the other hand, the efficiency of the backtracking algorithm depends on reject returning true for candidates that are as close to the root as possible. If reject always returns false, the algorithm will still find all solutions, but it will be equivalent to a brute-force search.

62

Backtracking

63

The accept procedure should return true if c is a complete and valid solution for the problem instance P, and false otherwise. It may assume that the partial candidate c and all its ancestors in the tree have passed the reject test. Note that the general pseudo-code above does not assume that the valid solutions are always leaves of the potential search tree. In other words, it admits the possibility that a valid solution for P can be further extended to yield other valid solutions. The first and next procedures are used by the backtracking algorithm to enumerate the children of a node c of the tree, that is, the candidates that differ from c by a single extension step. The call first(P,c) should yield the first child of c, in some order; and the call next(P,s) should return the next sibling of node s, in that order. Both functions should return a distinctive "null" candidate, denoted here by 'Λ', if the requested child does not exist. Together, the root, first, and next functions define the set of partial candidates and the potential search tree. They should be chosen so that every solution of P occurs somewhere in the tree, and no partial candidate occurs more than once. Moreover, they should admit an efficient and effective reject predicate.

Early stopping variants The pseudo-code above will call output for all candidates that are a solution to the given instance P. The algorithm is easily modified to stop after finding the first solution, or a specified number of solutions; or after testing a specified number of partial candidates, or after spending a given amount of CPU time.

Examples Typical examples are • Puzzles such as eight queens puzzle, crosswords, verbal arithmetic, Sudoku, Peg Solitaire. • Combinatorial optimization problems such as parsing and the knapsack problem. • Logic programming languages such as Icon, Planner and Prolog, which use backtracking internally to generate answers. • Backtracking is also utilized in the "diff" (version comparing) engine for the MediaWiki software. • Parsing • Knapsack problem Below is an example for the constraint satisfaction problem:

Sudoku puzzle solved by backtracking.

Constraint satisfaction The general constraint satisfaction problem consists in finding a list of integers x = (x[1],x[2], ..., x[n]), each in some range {1, 2, ..., m}, that satisfies some arbitrary constraint (boolean function) F. For this class of problems, the instance data P would be the integers m and n, and the predicate F. In a typical backtracking solution to this problem, one could define a partial candidate as a list of integers c = (c[1],c[2], ... c[k]), for any k between 0 and n, that are to be assigned to the first k variables x[1],x[2], ..., x[k]). The root candidate would then be the empty list (). The first and next procedures would then be function first(P,c) k ← length(c) if k = n then return Λ

Backtracking else return (c[1], c[2], ..., c[k], 1) function next(P,s) k ← length(s) if s[k] = m then return Λ else return (s[1], s[2], ..., s[k-1], 1 + s[k]) Here "length(c)" is the number of elements in the list c. The call reject(P,c) should return true if the constraint F cannot be satisfied by any list of n integers that begins with the k elements of c. For backtracking to be effective, there must be a way to detect this situation, at least for some candidates c, without enumerating all those mn-k n-tuples. For example, if F is the conjunction of several boolean predicates, F = F[1] F[2] F[p], and each F[i] depends only on a small subset of the variables x[1], ..., x[n], then the reject procedure could simply check the terms F[i] that depend only on variables x[1], ..., x[k], and return true if any of those terms returns false. In fact, reject needs only check those terms that do depend on x[k], since the terms that depend only on x[1], ..., x[k-1] will have been tested further up in the search tree. Assuming that reject is implemented as above, then accept(P,c) needs only check whether c is complete, that is, whether it has n elements. It is generally better to order the list of variables so that it begins with the most critical ones (i.e. the ones with fewest value options, or which have a greater impact on subsequent choices). One could also allow the next function to choose which variable should be assigned when extending a partial candidate, based on the values of the variables already assigned by it. Further improvements can be obtained by the technique of constraint propagation. In addition to retaining minimal recovery values used in backing up, backtracking implementations commonly keep a variable trail, to record value change history. An efficient implementation will avoid creating a variable trail entry between two successive changes when there is no choice point, as the backtracking will erase all of the changes as a single operation. An alternative to the variable trail is to keep a timestamp of when the last change was made to the variable. The timestamp is compared to the timestamp of a choice point. If the choice point has an associated time later than that of the variable, it is unnecessary to revert the variable when the choice point is backtracked, as it was changed before the choice point occurred.

Notes [1] http:/ / en. wikipedia. org/ w/ index. php?title=Template:Graph_search_algorithm& action=edit

References • Gilles Brassard, Paul Bratley (1995). Fundamentals of Algorithmics. Prentice-Hall.

External links • HBmeyer.de (http://www.hbmeyer.de/backtrack/backtren.htm), Interactive animation of a backtracking algorithm • Solving Combinatorial Problems with STL and Backtracking (http://www.drdobbs.com/cpp/ solving-combinatorial-problems-with-stl/184401194), Article and C++ source code for a generic implementation of backtracking

64

Backtracking

65

• Sample Java Code (http://github.com/kapild/Permutations), Sample code for backtracking of 8 Queens problem.

Collatz conjecture List of unsolved problems in mathematics Does the Collatz sequence from initial value n eventually reach 1, for all n > 0?

The Collatz conjecture is a conjecture in mathematics named after Lothar Collatz, who first proposed it in 1937. The conjecture is also known as the 3n + 1 conjecture, the Ulam conjecture (after Stanislaw Ulam), Kakutani's problem (after Shizuo Kakutani), the Thwaites conjecture (after Sir Bryan Thwaites), Hasse's algorithm (after Helmut Hasse), or the Syracuse problem;[1] the sequence of numbers involved is referred to as the hailstone sequence or hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud), or as wondrous numbers. Take any natural number n. If n is even, divide it by 2 to get n / 2. If n is odd, multiply it by 3 and add 1 to obtain 3n + 1. Repeat the process (which has been called "Half Or Triple Plus One", or HOTPO) indefinitely. The conjecture is that no matter what number you start with, you shall always eventually reach 1. The property has also been called oneness. Paul Erdős said, allegedly, about the Collatz conjecture: "Mathematics is not yet ripe for such problems." He also offered $500 for its solution.[2] In 1972, J.H. Conway proved that a natural generalization of the Collatz problem is algorithmically undecidable.[3]

Statement of the problem Consider the following operation on an arbitrary positive integer: • If the number is even, divide it by two. • If the number is odd, triple it and add one. In modular arithmetic notation, define the function f as follows:

Now, form a sequence by performing this operation repeatedly, beginning with any positive integer, and taking the result at each step as the input at the next.

Statistic for the numbers 1 to 100 million, showing the total stopping time on the x-axis against the number of occurrences on the y-axis.

In notation:

(that is:

is the value of

applied to

recursively

times;

).

Collatz conjecture

66

The Collatz conjecture is: This process will eventually reach the number 1, regardless of which positive integer is chosen initially. That smallest i such that ai = 1 is called the total stopping time of n. The conjecture asserts that every n has a well-defined total stopping time. If, for some n, such an i doesn't exist, we say that n has infinite total stopping time and the conjecture is false. If the conjecture is false, it can only be because there is some starting number which gives rise to a sequence which does not contain 1. Such a sequence might enter a repeating cycle that excludes 1, or increase without bound. No such sequence has been found.

Numbers from 1 to 9999 and their corresponding total stopping time.

Examples For instance, starting with n = 6, one gets the sequence 6, 3, 10, 5, 16, 8, 4, 2, 1. n = 11, for example, takes longer to reach 1: 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1. The sequence for n = 27, listed and graphed below, takes 111 steps, climbing to 9232 before descending to 1. { 27, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079, 3238, 1619, 4858, 2429, 7288, 3644, 1822, 911, 2734, 1367, 4102, 2051, 6154, 3077, 9232, 4616, 2308, 1154, 577, 1732, 866, 433, 1300, 650, 325, 976, 488, 244, 122, 61, 184, 92, 46, 23, 70, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1 }

Collatz conjecture

67

Numbers with a total stopping time longer than any smaller starting value form a sequence beginning with: 1, 2, 3, 6, 7, 9, 18, 25, 27, 54, 73, 97, … (sequence A006877 in OEIS). The longest progression for any initial starting number less than 100 million is 63,728,127, which has 949 steps. For starting numbers less than 1 billion it is 670,617,279, with 986 steps, and for numbers less than 10 billion it is 9,780,657,630, with 1132 steps.[4] The powers of two converge to one quickly because

is halved

times to reach one, and is never increased.

Program to calculate Hailstone sequences A specific Hailstone sequence can be easily computed, as is shown by this pseudocode example: function hailstone(n) while n > 1 show n if n is odd then set n = 3n + 1 else set n = n / 2 endif endwhile show n This program halts when the sequence reaches 1, in order to avoid printing an endless cycle of 4, 2, 1. If the Collatz conjecture is true, the program will always halt (stop) no matter what positive starting integer is given to it.

Collatz conjecture

68

Cycles The conjecture could be proven, indirectly, as a consequence of the following: • no infinite divergent trajectory occurs • no cycle occurs (apart from the trivial (1,2) cycle for the "shortcut" definition of the Collatz map) These being true, all natural numbers would have a trajectory down to one. In 1977, R. Steiner, and in 2000 and 2002, J. Simons and B. de Weger (based on Steiner's work), proved the nonexistence of certain types of cycles.

Notation To explain this we refer to the "shortcut" definition of the Collatz map,

for odd n and

for even n. A cycle is a sequence

where

,

, and so on, up to

in a

closed loop. The only known cycle is (1,2). If the cycle consists of an increasing sequence of odd numbers followed by a decreasing sequence of even numbers, it is called a 1-cycle. If it consists of an increasing sequence of odd numbers, then a decreasing sequence of even numbers, then another increasing sequence of odd numbers, then another decreasing sequence of even numbers, it is called a 2-cycle. In general, an m-cycle has m subsequences of one or more odd numbers, interlaced with m subsequences of one or more even numbers.[5]

Theorems • Steiner proved in 1977 that there is no 1-cycle other than the trivial (1,2). • Simons proved in 2000 (based on Steiner's method) that there is no 2-cycle. • Simons/deWeger in 2003 extended their own proof up to 68-cycles: there is no m-cycle up to m = 68. (Steiner claimed in a usenet discussion he could extend this up to m = 71.[6]) Beyond 68, this method gives upper bounds for the elements in such a cycle: for example, if there is a 75-cycle, then at least one element of the cycle is less than 2385×250. Therefore as exhaustive computer searches continue, slightly larger cycles may be ruled out.

Supporting arguments Although the conjecture has not been proven, most mathematicians who have looked into the problem think the conjecture is true because experimental evidence and heuristic arguments support it.

Experimental evidence The conjecture has been checked by computer for all starting values up to 5 × 260 ≈ 5.764×1018. All initial values tested so far eventually end in the repeating cycle {4,2,1}, which has only three terms. From this lower bound on the starting value, a lower bound can also be obtained for the number of terms a repeating cycle other than {4,2,1} must have. When this relationship was established in 1981, the formula gave a lower bound of 35,400 terms. Such computer evidence is not a proof that the conjecture is true. As shown in the cases of the Pólya conjecture, the Mertens conjecture and the Skewes' number, sometimes a conjecture's only counterexamples are found when using very large numbers. Since sequentially examining all natural numbers is a process which can never be completed, such an approach can never demonstrate that the conjecture is true, merely that no counterexamples have yet been discovered.

Collatz conjecture

69

A probabilistic heuristic If one considers only the odd numbers in the sequence generated by the Collatz process, then each odd number is on average 3/4 of the previous one.[7] (More precisely, the geometric mean of the ratios of outcomes is 3/4.) This yields a heuristic argument that every Hailstone sequence should decrease in the long run, although this is not evidence against other cycles, only against divergence. The argument is not a proof because it assumes that Hailstone sequences are assembled from uncorrelated probabilistic events. (It does rigorously establish that the 2-adic extension of the Collatz process has two division steps for every multiplication step for almost all 2-adic starting values.)

Rigorous bounds Although it is not known rigorously whether all positive numbers eventually reach one according to the Collatz iteration, it is known that many numbers do so. In particular, Krasikov and Lagarias showed that the number of integers in the interval [1,x] that eventually reach one is at least proportional to x0.84.

Other formulations of the conjecture In reverse There is another approach to prove the conjecture, which considers the bottom-up method of growing the so-called Collatz graph. The Collatz graph is a graph defined by the inverse relation

The first 21 levels of the Collatz graph generated in bottom-up fashion. The graph includes all numbers with an orbit length of 21 or less.

So, instead of proving that all natural numbers eventually lead to 1, we can prove that 1 leads to all natural numbers. For any integer n, n ≡ 1 (mod 2) iff 3n + 1 ≡ 4 (mod 6). Equivalently, (n − 1)/3 ≡ 1 (mod 2) iff n ≡ 4 (mod 6). Conjecturally, this inverse relation forms a tree except for the 1–2–4 loop (the inverse of the 1–4–2 loop of the unaltered function f defined in the statement of the problem above). When the relation 3n + 1 of the function f is replaced by the common substitute "shortcut" relation (3n + 1)/2, the Collatz graph is defined by the inverse relation,

Conjecturally, this inverse relation forms a tree except for a 1–2 loop (the inverse of the 1–2 loop of the function f(n) revised as indicated above).

Collatz conjecture

As an abstract machine that computes in base two Repeated applications of the Collatz function can be represented as an abstract machine that handles strings of bits. The machine will perform the following three steps on any odd number until only one "1" remains: 1. Append 1 to the (right) end of the number in binary (giving 2n + 1); 2. Add this to the original number by binary addition (giving 2n + 1 + n = 3n + 1); 3. Remove all trailing "0"s (i.e. repeatedly divide by two until the result is odd). This prescription is plainly equivalent to computing a Hailstone sequence in base two. Example The starting number 7 is written in base two as 111. The resulting Hailstone sequence is: 111 1111 10110 10111 100010 100011 110100 11011 101000 1011 10000

As a parity sequence For this section, consider the Collatz function in the slightly modified form

This can be done because when n is odd, 3n + 1 is always even. If P(…) is the parity of a number, that is P(2n) = 0 and P(2n + 1) = 1, then we can define the Hailstone parity sequence for a number n as pi = P(ai), where a0 = n, and ai+1 = f(ai). Using this form for f(n), it can be shown that the parity sequences for two numbers m and n will agree in the first k terms if and only if m and n are equivalent modulo 2k. This implies that every number is uniquely identified by its parity sequence, and moreover that if there are multiple Hailstone cycles, then their corresponding parity cycles must be different. The proof is simple: it is easy to verify by hand that applying the f function k times to the number a·2k + b will give the result a·3c + d, where d is the result of applying the f function k times to b, and c is how many odd numbers were encountered during that sequence. So the parity of the first k numbers is determined purely by b, and the parity of the (k + 1)th number will change if the least significant bit of a is changed. The Collatz Conjecture can be rephrased as stating that the Hailstone parity sequence for every number eventually enters the cycle 0 → 1 → 0.

70

Collatz conjecture

71

As a tag system For the Collatz function in the form

Hailstone sequences can be computed by the extremely simple 2-tag system with production rules a → bc, b → a, c → aaa. In this system, the positive integer n is represented by a string of n a's, and iteration of the tag operation halts on any word of length less than 2. (Adapted from De Mol.) The Collatz conjecture equivalently states that this tag system, with an arbitrary finite string of a's as the initial word, eventually halts (see Example: Computation of Collatz sequences for a worked example).

Extensions to larger domains Iterating on all integers An obvious extension is to include all integers, not just positive integers. In this case there are a total of 5 known cycles, which all integers seem to eventually fall into under iteration of f. These cycles are listed here, starting with the well-known cycle for positive n. Odd values are listed in bold. Each cycle is listed with its member of least absolute value (which is always odd or zero) first. Cycle

Odd-value cycle length

Full cycle length

1→4→2→1…

1

3

0→0…

0

1

−1 → −2 → −1 …

1

2

−5 → −14 → −7 → −20 → −10 → −5 …

2

5

−17 → −50 → −25 → −74 → −37 → −110 → −55 → −164 → −82 → −41 → −122 → −61 → −182 → −91 → −272 → −136 → −68 → −34 → −17 …

7

18

The Generalized Collatz Conjecture is the assertion that every integer, under iteration by f, eventually falls into one of these five cycles.

Iterating with odd denominators or 2-adic integers The standard Collatz map can be extended to (positive or negative) rational numbers which have odd denominators when written in lowest terms. The number is taken to be odd or even according to whether its numerator is odd or even. A closely related fact is that the Collatz map extends to the ring of 2-adic integers, which contains the ring of rationals with odd denominators as a subring. The parity sequences as defined above are no longer unique for fractions. However, it can be shown that any possible parity cycle is the parity sequence for exactly one fraction: if a cycle has length n and includes odd numbers exactly m times at indices k0, …, km−1, then the unique fraction which generates that parity cycle is

For example, the parity cycle (1 0 1 1 0 0 1) has length 7 and has 4 odd numbers at indices 0, 2, 3, and 6. The unique fraction which generates that parity cycle is

Collatz conjecture

the complete cycle being: 151/47 → 250/47 → 125/47 → 211/47 → 340/47 → 170/47 → 85/47 → 151/47 Although the cyclic permutations of the original parity sequence are unique fractions, the cycle is not unique, each permutation's fraction being the next number in the loop cycle: (0 1 1 0 0 1 1) → (1 1 0 0 1 1 0) → (1 0 0 1 1 0 1) → (0 0 1 1 0 1 1) → (0 1 1 0 1 1 0) → (1 1 0 1 1 0 0) → Also, for uniqueness, the parity sequence should be "prime", i.e., not partitionable into identical sub-sequences. For example, parity sequence (1 1 0 0 1 1 0 0) can be partitioned into two identical sub-sequences (1 1 0 0)(1 1 0 0). Calculating the 8-element sequence fraction gives (1 1 0 0 1 1 0 0) → But when reduced to lowest terms {5/7}, it is the same as that of the 4-element sub-sequence (1 1 0 0) → And this is because the 8-element parity sequence actually represents two circuits of the loop cycle defined by the 4-element parity sequence. In this context, the Collatz conjecture is equivalent to saying that (0 1) is the only cycle which is generated by positive whole numbers (i.e. 1 and 2).

72

Collatz conjecture

73

Iterating on real or complex numbers The Collatz map can be viewed as the restriction to the integers of the smooth real and complex map

which

simplifies

to

If the standard Collatz map defined above is optimized by replacing the relation 3n + 1 with the common substitute "shortcut" relation (3n + 1)/2, it can be viewed as the restriction to the integers of the smooth real and complex map

which

simplifies

to .

Cobweb plot of the orbit 10-5-8-4-2-1-2-1-2-1-etc. in the real extension of the Collatz map (optimized by replacing "3n + 1" with "(3n + 1)/2" )

Collatz fractal Iterating the above optimized map in the complex plane produces the Collatz fractal. The point of view of iteration on the real line was investigated by Chamberland (1996), and on the complex plane by Letherman, Schleicher, and Wood (1999).

Collatz map fractal in a neighbourhood of the real line

Collatz conjecture

74

Optimizations The As a parity sequence section above gives a way to speed up simulation of the sequence. To jump ahead k steps on each iteration (using the f function from that section), break up the current number into two parts, b (the k least significant bits, interpreted as an integer), and a (the rest of the bits as an integer). The result of jumping ahead k steps can be found as: f k(a 2k + b) = a 3c(b) + d(b). The c and d arrays are precalculated for all possible k-bit numbers b, where d(b) is the result of applying the f function k times to b, and c(b) is the number of odd numbers encountered on the way. For example, if k=5, you can jump ahead 5 steps on each iteration by separating out the 5 least significant bits of a number and using: c(0..31) = {0,3,2,2,2,2,2,4,1,4,1,3,2,2,3,4,1,2,3,3,1,1,3,3,2,3,2,4,3,3,4,5} d(0..31) = {0,2,1,1,2,2,2,20,1,26,1,10,4,4,13,40,2,5,17,17,2,2,20,20,8,22,8,71,26,26,80,242}. This requires 2k precomputation and storage to speed up the resulting calculation by a factor of k, a space-time tradeoff. For the special purpose of searching for a counterexample to the Collatz conjecture, this precomputation leads to an even more important acceleration due to Tomás Oliveira e Silva and is used in the record confirmation of the Collatz conjecture. If, for some given b and k, the inequality f k(a 2k + b) = a 3c(b) + d(b) < a 2k + b holds for all a, then the first counterexample, if it exists, cannot be b modulo 2k. For instance, the first counterexample must be odd because f(2n) = n; and it must be 3 mod 4 because f2(4n + 1) = 3n + 1. For each starting value a which is not a counterexample to the Collatz conjecture, there is a k for which such an inequality holds, so checking the Collatz conjecture for one starting value is as good as checking an entire congruence class. As k increases, the search only needs to check those residues b that are not eliminated by lower values of k. On the order of 3k/2 residues survive.[citation needed] For example, the only surviving residues mod 32 are 7, 15, 27, and 31; only 573,162 residues survive mod 225 = 33,554,432.

Syracuse function If k is an odd integer, then 3k + 1 is even, so we can write 3k + 1 = 2ak′, with k' odd and a ≥ 1. We define a function f from the set of odd integers into itself, called the Syracuse function, by taking f (k) = k′ (sequence A075677 in OEIS). Some properties of the Syracuse function are: • f (4k + 1) = f (k) for all k in . • For all p ≥ 2 and h odd, f p−1(2p h − 1) = 2·3p − 1h − 1 (here, f p−1 is function iteration notation). • For all odd h, f(2h − 1) ≤ (3h − 1)/2 The Syracuse conjecture is that for all k in

, there exists an integer n ≥ 1 such that fn(k) = 1. Equivalently, let E be

the set of odd integers k for which there exists an integer n ≥ 1 such that fn(k) = 1. The problem is to show that E =  . The following is the beginning of an attempt at a proof by induction: 1, 3, 5, 7, and 9 are known to be elements of E. Let k be an odd integer greater than 9. Suppose that the odd numbers up to and including k − 2 are in E and let us try to prove that k is in E. As k is odd, k + 1 is even, so we can write k + 1 = 2ph for p ≥ 1, h odd, and k = 2ph − 1. Now we have: • If p = 1, then k = 2h − 1. It is easy to check that f (k) < k , so f (k) ∈ E; hence k ∈ E. • If p ≥ 2 and h is a multiple of 3, we can write h = 3h′. Let k′ = 2p + 1h′ − 1; then f (k′) = k , and as k′ < k , k′ is in E; therefore k = f (k′) ∈ E. • If p ≥ 2 and h is not a multiple of 3 but h ≡ (−1)p mod 4, we can still show that k ∈ E.

Collatz conjecture The problematic case is that where p ≥ 2 , h not multiple of 3 and h ≡ (−1)p + 1 mod 4. Here, if we manage to show that for every odd integer k′, 1 ≤ k′ ≤ k − 2 ; 3k′ ∈ E we are done.

Notes [1] According to Lagarias (1985, p.4), the name "Syracuse problem" was proposed by Hasse in the 1950s, during a visit to Syracuse University. [2] R. K. Guy: Don't try to solve these problems, Amer. Math. Monthly, 90(1983), 35–41. By this Erdos means that there aren't powerful tools for manipulating such objects. [3] "J. H. Conway proved the remarkable result that a simple generalization of the problem is algorithmically undecidable." Quoting Lagarias 1985: [4] (Note: "Delay records" are total stopping time records.) [5] Simons,J.;de Weger, B.; "Theoretical and computational bounds for m-cycles of the 3n + 1 problem" (http:/ / deweger. xs4all. nl/ papers/ [35]SidW-3n+ 1-ActaArith[2005]. pdf), Acta Arithmetica, (online version 1.0, November 18, 2003), 2005. [6] http:/ / groups. google. com/ group/ sci. math/ msg/ 1ed7cd277079efdd [7] http:/ / www. cecm. sfu. ca/ organics/ papers/ lagarias/ paper/ html/ node3. html

References and external links Papers • Jeffrey C. Lagarias. (1985). The 3x + 1 problem and its generalizations. The American Mathematical Monthly 92(1):3-23. • Jeffrey C. Lagarias (2001), "Syracuse problem" (http://www.encyclopediaofmath.org/index.php?title=S/ s110330), in Hazewinkel, Michiel, Encyclopedia of Mathematics, Springer, ISBN 978-1-55608-010-4 • Jeffrey C. Lagarias (2006). "The 3x + 1 problem: An annotated bibliography, II (2000–)". arXiv: math.NT/0608208 (http://arxiv.org/abs/math.NT/0608208) [ math.NT (http://arxiv.org/archive/math. NT)]. • Günther J. Wirsching. The Dynamical System Generated by the Function. Number 1681 in Lecture Notes in Mathematics. Springer-Verlag, 1998. • Keith Matthews' 3x + 1 page: Review of progress, plus various programs (http://www.numbertheory.org/3x+ 1/) • Marc Chamberland. A continuous extension of the 3x + 1 problem to the real line. Dynam. Contin. Discrete Impuls Systems 2:4 (1996), 495–509. • Simon Letherman, Dierk Schleicher, and Reg Wood: The (3n + 1)-Problem and Holomorphic Dynamics. Experimental Mathematics 8:3 (1999), 241–252. • Ohira, Reiko & Yamashita, Michinori A generalization of the Collatz problem (http://risweb2.ris.ac.jp/faculty/ earth_env/yamasita/open/p-col.pdf) (Japanese) • Urata, Toshio Some Holomorphic Functions connected with the Collatz Problem (http://web.archive.org/web/ 20080406061036/http://auemath.aichi-edu.ac.jp/~turata/Fall.files/CTZVI.pdf) • Eliahou, Shalom, The 3x+1 problem: new lower bounds on nontrivial cycle lengths, Discrete Mathematics 118 (1993) p. 45-56; Le problème 3n+1 : y a-t-il des cycles non triviaux ? (http://images.math.cnrs.fr/ Le-probleme-3n-1-y-a-t-il-des.html), Images des mathématiques (2011) (French) • Matti K. Sinisalo: On the minimal cycle lengths of the Collatz sequences (http://web.archive.org/web/ 20091024183537/http://geocities.com/mattiksinisalo/collatz.doc), Preprint, June 2003, University of Oulu • Paul Stadfeld: Blueprint for Failure: How to Construct a Counterexample to the Collatz Conjecture (http://home. versatel.nl/galien8/blueprint/blueprint.html) • De Mol, Liesbeth, "Tag systems and Collatz-like functions", Theoretical Computer Science, 390:1, 92–101, January 2008 ( Preprint Nr. 314 (http://logica.ugent.be/liesbeth/TagColOK.pdf)). • Bruschi, Mario (2008). "A generalization of the Collatz problem and conjecture". arXiv: 0810.5169 (http://arxiv. org/abs/0810.5169) [ math.NT (http://arxiv.org/archive/math.NT)].

75

Collatz conjecture • Andrei, Stefan; Masalagiu, Cristian (1998). "About the Collatz conjecture". Acta Informatica 35 (2): 167. doi: 10.1007/s002360050117 (http://dx.doi.org/10.1007/s002360050117). • Van Bendegem, Jean Paul, "The Collatz Conjecture: A Case Study in Mathematical Problem Solving" (http:// compmath.files.wordpress.com/2008/08/jpvb_collatz.pdf), Logic and Logical Philosophy, Volume 14 (2005), 7–23 • Belaga, Edward G., "Reflecting on the 3x+1 Mystery" (http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10. 1.1.54.483), University of Strasbourg preprint, 1998. • Belaga, Edward G.; Mignotte, Maurice, "Walking Cautiously into the Collatz Wilderness: Algorithmically, Number Theoretically, Randomly" (http://www-irma.u-strasbg.fr/~belaga/ a8*BelagaMathInfo06Presentation060920.ppt), Fourth Colloquium on Mathematics and Computer Science : Algorithms, Trees, Combinatorics and Probabilities, September 18–22, 2006, Institut Élie Cartan, Nancy, France • Belaga, Edward G.; Mignotte, Maurice, "Embedding the 3x+1 Conjecture in a 3x+d Context" (http://www.emis. de/journals/EM/expmath/volumes/7/7.html), Experimental Mathematics, Volume 7, issue 2, 1998. • Steiner, R.P.; "A theorem on the syracuse problem", Proceedings of the 7th Manitoba Conference on Numerical Mathematics,pages 553–559, 1977. • Simons,J.;de Weger, B.; "Theoretical and computational bounds for m-cycles of the 3n + 1 problem" (http:// deweger.xs4all.nl/papers/[35]SidW-3n+1-ActaArith[2005].pdf), Acta Arithmetica, (online version 1.0, November 18, 2003), 2005. • Sinyor, J.; "The 3x+1 Problem as a String Rewriting System" (http://downloads.hindawi.com/journals/ijmms/ 2010/458563.pdf), International Journal of Mathematics and Mathematical Sciences, Volume 2010 (2010), Article ID 458563, 6 pages.

Books • Everest, Graham; van der Poorten, Alf; Shparlinski, Igor; Ward, Thomas (2003). Recurrence sequences. Mathematical Surveys and Monographs 104. Providence, RI: American Mathematical Society. Chapter 3.4. ISBN 0-8218-3387-1. Zbl  1033.11006 (http://www.zentralblatt-math.org/zmath/en/search/ ?format=complete&q=an:1033.11006). • Guy, Richard K. (2004). Unsolved problems in number theory (3rd ed.). Springer-Verlag. "E17: Permutation Sequences". ISBN 0-387-20860-7. Zbl  1058.11001 (http://www.zentralblatt-math.org/zmath/en/search/ ?format=complete&q=an:1058.11001). Cf. pp.336–337 (http://books.google.com/ books?id=1AP2CEGxTkgC&pg=PA337&lpg=PA337&dq="Unpredictable+Iterations"+conway&source=bl& ots=Tilvg0yIqF&sig=5Nz7invP8gpLKpkgd0Q7aX2njUU&hl=en&ei=WVITSp-fHdmLtgfJmKCTBA&sa=X& oi=book_result&ct=result&resnum=9#PPA336,M1) • Lagarias, Jeffrey C., ed. (2010). The Ultimate Challenge: the 3x+1 problem. American Mathematical Society. ISBN 978-0-8218-4940-8. Zbl  1253.11003 (http://www.zentralblatt-math.org/zmath/en/search/ ?format=complete&q=an:1253.11003).

76

Collatz conjecture

External links • Distributed Computing project (http://boinc.thesonntags.com/collatz/) that verifies the Collatz conjecture for larger values. • An ongoing distributed computing project (http://www.ericr.nl/wondrous/index.html) by Eric Roosendaal verifies the Collatz conjecture for larger and larger values. • Another ongoing distributed computing project (http://www.ieeta.pt/~tos/3x+1.html) by Tomás Oliveira e Silva continues to verify the Collatz conjecture (with fewer statistics than Eric Roosendaal's page but with further progress made). • An animated implementation (http://gfredericks.com/sandbox/arith/collatz) that uses arbitrary-precision arithmetic. • Weisstein, Eric W., " Collatz Problem (http://mathworld.wolfram.com/CollatzProblem.html)", MathWorld. • Collatz Sequence (http://codeabbey.com/index/task_view/collatz-sequence) explanation and exercise • Collatz Problem (http://planetmath.org/encyclopedia/CollatzProblem.html) at PlanetMath • Hailstone Patterns (http://Mensanator.com/mensanator666/collatz/hailstone.htm) discusses different resonators along with using important numbers in the problem (like 6 and 3^5) to discover patterns. • Collatz Iterations on the Ulam Spiral grid (https://www.youtube.com/watch?v=BhR-iIjhTNM) on YouTube • Collatz Paths (http://demonstrations.wolfram.com/CollatzPaths/) by Jesse Nochella, Wolfram Demonstrations Project. • Page allowing to study and to show the guess for a given number (http://syracuse.elaunira.com) • Collatz cycles? (http://go.helms-net.de/math/collatz/aboutloop/collloopintro_main.htm) about cycles, very basic, contains also some unusual graphs(html) • Collatz cycles? (pdf) (http://go.helms-net.de/math/collatz/Collatz061102.pdf) about loops, compacted text, rather basic (pdf) • Collatz sequence (http://www.nitrxgen.net/collatz.php) for any number up to 500 digits in length.

77

Primitive recursive function

78

Primitive recursive function In computability theory, primitive recursive functions are a class of functions that are defined using primitive recursion and composition as central operations and are a strict subset of the total µ-recursive functions (µ-recursive functions are also called partial recursive). Primitive recursive functions form an important building block on the way to a full formalization of computability. These functions are also important in proof theory. The term was coined by Rózsa Péter. Most of the functions normally studied in number theory are primitive recursive. For example: addition, division, factorial, exponential and the nth prime are all primitive recursive. So are many approximations to real-valued functions.[1] In fact, it is difficult to devise a computable function that is not primitive recursive, although some are known (see the section on Limitations below). The set of primitive recursive functions is known as PR in complexity theory. Every primitive recursive function is a general recursive function.

Definition The primitive recursive functions are among the number-theoretic functions, which are functions from the natural numbers (nonnegative integers) {0, 1, 2, ...} to the natural numbers. These functions take n arguments for some natural number n and are called n-ary. The basic primitive recursive functions are given by these axioms: 1. Constant function: The 0-ary constant function 0 is primitive recursive. 2. Successor function: The 1-ary successor function S, which returns the successor of its argument (see Peano postulates), is primitive recursive. That is, S(k) = k + 1. 3. Projection function: For every n≥1 and each i with 1≤i≤n, the n-ary projection function Pin, which returns its i-th argument, is primitive recursive. More complex primitive recursive functions can be obtained by applying the operations given by these axioms: 1. Composition: Given f, a k-ary primitive recursive function, and k m-ary primitive recursive functions g1,...,gk, the composition of f with g1,...,gk, i.e. the m-ary function is primitive recursive. 2. Primitive recursion: Given f, a k-ary primitive recursive function, and g, a (k+2)-ary primitive recursive function, the (k+1)-ary function h is defined as the primitive recursion of f and g, i.e. the function h is primitive recursive when and The primitive recursive functions are the basic functions and those obtained from the basic functions by applying these operations a finite number of times.

Primitive recursive function

Role of the projection functions The projection functions can be used to avoid the apparent rigidity in terms of the arity of the functions above; by using compositions with various projection functions, it is possible to pass a subset of the arguments of one function to another function. For example, if g and h are 2-ary primitive recursive functions then

is also primitive recursive. One formal definition using projection functions is

Converting predicates to numeric functions In some settings it is natural to consider primitive recursive functions that take as inputs tuples that mix numbers with truth values { t= true, f=false }, or that produce truth values as outputs (see Kleene [1952 pp. 226–227]). This can be accomplished by identifying the truth values with numbers in any fixed manner. For example, it is common to identify the truth value t with the number 1 and the truth value f with the number 0. Once this identification has been made, the characteristic function of a set A, which literally returns 1 or 0, can be viewed as a predicate that tells whether a number is in the set A. Such an identification of predicates with numeric functions will be assumed for the remainder of this article.

Computer language definition An example of a primitive recursive programming language is one that contains basic arithmetic operators (e.g. + and -, or ADD and SUBTRACT), conditionals and comparison (IF-THEN, EQUALS, LESS-THAN), and bounded loops, such as the basic for loop, where there is a known or calculable upper bound to all loops (FOR i FROM 1 to n). No control structures of greater generality, such as while loops or IF-THEN plus GOTO, are admitted in a primitive recursive language. Douglas Hofstadter's Bloop in Gödel, Escher, Bach is one such. Adding unbounded loops (WHILE, GOTO) makes the language partially recursive, or Turing-complete; Floop is such, as are almost all real-world computer languages. Arbitrary computer programs, or Turing machines, cannot in general be analyzed to see if they halt or not (the halting problem). However, all primitive recursive functions halt. This is not a contradiction; primitive recursive programs are a non-arbitrary subset of all possible programs, constructed specifically to be analyzable.

Examples Most number-theoretic functions definable using recursion on a single variable are primitive recursive. Basic examples include the addition and "limited subtraction" functions.

Addition Intuitively, addition can be recursively defined with the rules: add(0,x)=x, add(n+1,x)=add(n,x)+1. To fit this into a strict primitive recursive definition, define: add(0,x)=P11(x) , add(S(n),x)=S(P23(n,add(n,x),x)). Here P23 is the projection function that takes 3 arguments and returns the second one. P11 is simply the identity function; its inclusion is required by the definition of the primitive recursion operator above; it plays the role of f. The composition of S and P23, which is primitive recursive, plays the role of g. The term

79

Primitive recursive function S(n) refers to "the successor of n".

Subtraction Because primitive recursive functions use natural numbers rather than integers, and the natural numbers are not closed under subtraction, a limited subtraction function (also called "proper subtraction") is studied in this context. This limited subtraction function sub(a,b) [or b ∸ a] returns b - a if this is nonnegative and returns 0 otherwise. The predecessor function acts as the opposite of the successor function and is recursively defined by the rules: pred(0)=0, pred(n+1)=n. These rules can be converted into a more formal definition by primitive recursion: pred(0)=0, pred(S(n))=P12(n, pred(n)). The limited subtraction function is definable from the predecessor function in a manner analogous to the way addition is defined from successor: sub(0,x)=P11(x), sub(S(n),x)=pred(P23(n,sub(n,x),x)). Here sub(a,b) corresponds to b∸a; for the sake of simplicity, the order of the arguments has been switched from the "standard" definition to fit the requirements of primitive recursion. This could easily be rectified using composition with suitable projections. Other primitive recursive functions include exponentiation and primality testing. Given primitive recursive functions e, f, g, and h, a function that returns the value of g when e≤f and the value of h otherwise is primitive recursive.

Operations on integers and rational numbers By using Gödel numberings, the primitive recursive functions can be extended to operate on other objects such as integers and rational numbers. If integers are encoded by Gödel numbers in a standard way, the arithmetic operations including addition, subtraction, and multiplication are all primitive recursive. Similarly, if the rationals are represented by Gödel numbers then the field operations are all primitive recursive.

Relationship to recursive functions The broader class of partial recursive functions is defined by introducing an unbounded search operator. The use of this operator may result in a partial function, that is, a relation with at most one value for each argument, but does not necessarily have any value for any argument (see domain). An equivalent definition states that a partial recursive function is one that can be computed by a Turing machine. A total recursive function is a partial recursive function that is defined for every input. Every primitive recursive function is total recursive, but not all total recursive functions are primitive recursive. The Ackermann function A(m,n) is a well-known example of a total recursive function that is not primitive recursive. There is a characterization of the primitive recursive functions as a subset of the total recursive functions using the Ackermann function. This characterization states that a function is primitive recursive if and only if there is a natural number m such that the function can be computed by a Turing machine that always halts within A(m,n) or fewer steps, where n is the sum of the arguments of the primitive recursive function.[citation needed] An important property of the primitive recursive functions is that they are a recursively enumerable subset of the set of all total recursive functions (which is not itself recursively enumerable). This means that there is a single computable function f(e,n) such that:

80

Primitive recursive function • For every primitive recursive function g, there is an e such that g(n) = f(e,n) for all n, and • For every e, the function h(n) = f(e,n) is primitive recursive. However, the primitive recursive functions are not the largest recursively enumerable set of total computable functions.

Limitations Primitive recursive functions tend to correspond very closely with our intuition of what a computable function must be. Certainly the initial functions are intuitively computable (in their very simplicity), and the two operations by which one can create new primitive recursive functions are also very straightforward. However the set of primitive recursive functions does not include every possible total computable function — this can be seen with a variant of Cantor's diagonal argument. This argument provides a total computable function that is not primitive recursive. A sketch of the proof is as follows: The primitive recursive functions of one argument (i.e., unary functions) can be computably enumerated. This enumeration uses the definitions of the primitive recursive functions (which are essentially just expressions with the composition and primitive recursion operations as operators and the basic primitive recursive functions as atoms), and can be assumed to contain every definition once, even though a same function will occur many times on the list (since many definitions define the same function; indeed simply composing by the identity function generates infinitely many definitions of any one primitive recursive function). This means that the n-th definition of a primitive recursive function in this enumeration can be effectively determined from n. Indeed if one uses some Gödel numbering to encode definitions as numbers, then this n-th definition in the list is computed by a primitive recursive function of n. Let fn denote the unary primitive recursive function given by this definition. Now define the "evaluator function" ev with two arguments, by ev(i,j) = fi(j). Clearly ev is total and computable, since one can effectively determine the definition of fi, and being a primitive recursive function fi is itself total and computable, so fi(j) is always defined and effectively computable. However a diagonal argument will show that the function ev of two arguments is not primitive recursive. Suppose ev were primitive recursive, then the unary function g defined by g(i) = S(ev(i,i)) would also be primitive recursive, as it is defined by composition from the successor function and ev. But then g occurs in the enumeration, so there is some number n such that g = fn. But now g(n) = S(ev(n,n)) = S(fn(n)) = S(g(n)) gives a contradiction. This argument can be applied to any class of computable (total) functions that can be enumerated in this way, as explained in the article Machines that always halt. Note however that the partial computable functions (those that need not be defined for all arguments) can be explicitly enumerated, for instance by enumerating Turing machine encodings. Other examples of total recursive but not primitive recursive functions are known: • The function that takes m to Ackermann(m,m) is a unary total recursive function that is not primitive recursive. • The Paris–Harrington theorem involves a total recursive function that is not primitive recursive. Because this function is motivated by Ramsey theory, it is sometimes considered more "natural" than the Ackermann function. • The Sudan function • The Goodstein function

81

Primitive recursive function

Some common primitive recursive functions The following examples and definitions are from Kleene (1952) pp. 223-231 — many appear with proofs. Most also appear with similar names, either as proofs or as examples, in Boolos-Burgess-Jeffrey 2002 pp. 63-70; they add #22 the logarithm lo(x, y) or lg(x, y) depending on the exact derivation. In the following we observe that primitive recursive functions can be of four types: 1. 2. 3. 4.

functions for short: "number-theoretic functions" from { 0, 1, 2, ...} to { 0, 1, 2, ...}, predicates: from { 0, 1, 2, ...} to truth values { t =true, f =false }, propositional connectives: from truth values { t, f } to truth values { t, f }, representing functions: from truth values { t, f } to { 0, 1, 2, ... }. Many times a predicate requires a representing function to convert the predicate's output { t, f } to { 0, 1 } (note the order "t" to "0" and "f" to "1" matches with ~(sig( )) defined below). By definition a function φ(x) is a "representing function" of the predicate P(x) if φ takes only values 0 and 1 and produces 0 when P is true".

In the following the mark " ' ", e.g. a', is the primitive mark meaning "the successor of", usually thought of as " +1", e.g. a +1 =def a'. The functions 16-21 and #G are of particular interest with respect to converting primitive recursive predicates to, and extracting them from, their "arithmetical" form expressed as Gödel numbers. 1. Addition: a+b 2. Multiplication: a×b 3. Exponentiation: ab, 4. Factorial a! : 0! = 1, a'! = a!×a' 5. pred(a): Decrement: "predecessor of a" defined as "If a> 0 then a-1 → anew else 0 → a." 6. Proper subtraction: a ∸ b defined as "If a ≥ b then a-b else 0." 7. Minimum (a1, ... an) 8. Maximum (a1, ... an) 9. Absolute value: | a-b | =defined (a ∸ b) + (b ∸ a) 10. ~sg(a): NOT[signum(a)]: If a=0 then sg(a)=1 else if a>0 then sg(a)=0 11. sg(a): signum(a): If a=0 then sg(a)=0 else if a>0 then sg(a)=1 12. "b divides a" [ a | b ]: If the remainder ( a, b )=0 then [ a | b ] else b does not divide a "evenly" 13. Remainder ( a, b ): the leftover if b does not divide a "evenly". Also called MOD(a, b) 14. a = b: sg | a - b | 15. a < b: sg( a' ∸ b ) 16. Pr(a): a is a prime number Pr(a) =def a>1 & NOT(Exists c)1 2 hence 2 → n → m = A(m+2,n-3) + 3 for n>2. (n=1 and n=2 would correspond with A(m,−2) = −1 and A(m,−1) = 1, which could logically be added.) For small values of m like 1, 2, or 3, the Ackermann function grows relatively slowly with respect to n (at most exponentially). For m ≥ 4, however, it grows much more quickly; even A(4, 2) is about 2×1019,728, and the decimal expansion of A(4, 3) is very large by any typical measure. Logician Harvey Friedman defines a version of the Ackermann function as follows: • For n = 0: A(m, n) = 1 • For m = 1: A(m, n) = 2n • Else: A(m, n) = A(m - 1, A(m, n - 1)) He also defines a single-argument version A(n) = A(n, n).[3] A single-argument version A(k) = A(k, k) that increases both m and n at the same time dwarfs every primitive recursive function, including very fast-growing functions such as the exponential function, the factorial function,

Ackermann function

90

multi- and superfactorial functions, and even functions defined using Knuth's up-arrow notation (except when the indexed up-arrow is used). It can be seen that A(n) is roughly comparable to fω(n) in the fast-growing hierarchy. This extreme growth can be exploited to show that f, which is obviously computable on a machine with infinite memory such as a Turing machine and so is a computable function, grows faster than any primitive recursive function and is therefore not primitive recursive. In a category with exponentials, using the isomorphism (in computer science, this is called currying), the Ackermann function may be defined via primitive recursion over higher-order functionals as follows:

where Succ is the usual successor function and Iter is defined by primitive recursion as well:

One interesting aspect of the Ackermann function is that the only arithmetic operations it ever uses are addition and subtraction of 1. Its properties come solely from the power of unlimited recursion. This also implies that its running time is at least proportional to its output, and so is also extremely huge. In actuality, for most cases the running time is far larger than the output; see below.

Table of values Computing the Ackermann function can be restated in terms of an infinite table. We place the natural numbers along the top row. To determine a number in the table, take the number immediately to the left, then look up the required number in the previous row, at the position given by the number just taken. If there is no number to its left, simply look at the column headed "1" in the previous row. Here is a small upper-left portion of the table:

Values of A(m, n) m\n

0

1

2

3

4

0

1

2

3

4

5

1

2

3

4

5

6

2

3

5

7

9

11

3

5

13

29

61

125

4

13 =

65533 =

265536 − 3 =

=

=

n

The numbers listed here in a recursive reference are very large and cannot be easily notated in some other form. Despite the large values occurring in this early section of the table, some even larger numbers have been defined, such as Graham's number, which cannot be written with any small number of Knuth arrows. This number is constructed with a technique similar to applying the Ackermann function to itself recursively. This is a repeat of the above table, but with the values replaced by the relevant expression from the function definition to show the pattern clearly:

Ackermann function

91

Values of A(m, n) m\n

0

1 1+1

2 2+1

3 3+1

4

n

0

0+1

4+1

1

A(0,1) A(0,A(1,0)) A(0,A(1,1)) A(0,A(1,2)) A(0,A(1,3))

2

A(1,1) A(1,A(2,0)) A(1,A(2,1)) A(1,A(2,2)) A(1,A(2,3))

3

A(2,1) A(2,A(3,0)) A(2,A(3,1)) A(2,A(3,2)) A(2,A(3,3))

4

A(3,1) A(3,A(4,0)) A(3,A(4,1)) A(3,A(4,2)) A(3,A(4,3))

5

A(4,1) A(4,A(5,0)) A(4,A(5,1)) A(4,A(5,2)) A(4,A(5,3)) A(4, A(5, n-1))

6

A(5,1) A(5,A(6,0)) A(5,A(6,1)) A(5,A(6,2)) A(5,A(6,3)) A(5, A(6, n-1))

Expansion To see how the Ackermann function grows so quickly, it helps to expand out some simple expressions using the rules in the original definition. For example, we can fully evaluate in the following way:

To demonstrate how

's computation results in many steps and in a large number:

Ackermann function

92

Written as a power of 10, this is roughly equivalent to 106.031×1019,727.

Inverse Since the function  f (n) = A(n, n) considered above grows very rapidly, its inverse function, f−1, grows very slowly. This inverse Ackermann function f−1 is usually denoted by α. In fact, α(n) is less than 5 for any practical input size n, since A(4, 4) is on the order of . This inverse appears in the time complexity of some algorithms, such as the disjoint-set data structure and Chazelle's algorithm for minimum spanning trees. Sometimes Ackermann's original function or other variations are used in these settings, but they all grow at similarly high rates. In particular, some modified functions simplify the expression by eliminating the −3 and similar terms. A two-parameter variation of the inverse Ackermann function can be defined as follows, where function:

is the floor

Ackermann function

93

This function arises in more precise analyses of the algorithms mentioned above, and gives a more refined time bound. In the disjoint-set data structure, m represents the number of operations while n represents the number of elements; in the minimum spanning tree algorithm, m represents the number of edges while n represents the number of vertices. Several slightly different definitions of α(m, n) exist; for example, log2 n is sometimes replaced by n, and the floor function is sometimes replaced by a ceiling. Other studies might define an inverse function of one where m is set to a constant, such that the inverse applies to a particular row.[4]

Use as benchmark The Ackermann function, due to its definition in terms of extremely deep recursion, can be used as a benchmark of a compiler's ability to optimize recursion. The first use of Ackermann's function in this way was by Yngve Sundblad, The Ackermann function. A Theoretical, computational and formula manipulative study. (BIT 11 (1971), 107119). This seminal paper was taken up by Brian Wichmann (co-author of the Whetstone benchmark) in a trilogy of papers written between 1975 and 1982.

Ackermann numbers In The Book of Numbers, John Horton Conway and Richard K. Guy define the sequence of Ackermann numbers to be 1↑1, 2↑↑2, 3↑↑↑3, etc.;[5] that is, the n-th Ackermann number is defined to be n↑nn (n = 1, 2, 3, ...), where m↑kn is Knuth's up-arrow version of the Ackermann function. The first few Ackermann numbers are: • 1↑1 = 11 = 1, • 2↑↑2 = 2↑2 = 22 = 4, • 3↑↑↑3 = 3↑↑3↑↑3 = 3↑↑(3↑3↑3) = The fourth Ackermann number, 4↑↑↑↑4, can be written in terms of tetration towers as follows: 4↑↑↑↑4 = 4↑↑↑4↑↑↑4↑↑↑4 = 4↑↑↑4↑↑↑(4↑↑4↑↑4↑↑4)

Explanation: in the middle layer, there is a tower of tetration whose full height is

and the final result is the top

layer of tetrated 4s whose full height equals the calculation of the middle layer. Note that by way of size comparison, the simple expression 44 already exceeds a googolplex, so the fourth Ackermann number is quite large. Alternatively, this can be written in terms of exponentiation towers as

where the number of towers on the previous line (including the rightmost "4") is

where the number of towers on the previous line (including the rightmost "4") is

Ackermann function

where the number of "4"s in each tower, on each of the lines above, is specified by the value of the next tower to its right (as indicated by a brace).

References [1] [2] [3] [4]

Decimal expansion of A(4,2) (http:/ / www. kosara. net/ thoughts/ ackermann42. html) von Heijenoort. From Frege To Gödel (http:/ / mathgate. info/ cebrown/ notes/ vonHeijenoort. php), 1967. http:/ / www. math. osu. edu/ ~friedman. 8/ pdf/ AckAlgGeom102100. pdf An inverse-Ackermann style lower bound for the online minimum spanning tree verification problem (http:/ / cat. inist. fr/ ?aModele=afficheN& cpsidt=15618233) November 2002 [5] John Horton Conway and Richard K. Guy. The Book of Numbers (http:/ / books. google. com/ books?id=0--3rcO7dMYC& lpg=PA60& dq="Ackermann number"& pg=PA60#v=onepage& q="Ackermann number"& f=false). New York: Springer-Verlag, pp. 60-61, 1996. ISBN 978-0-387-97993-9

External links • Hazewinkel, Michiel, ed. (2001), "Ackermann function" (http://www.encyclopediaofmath.org/index. php?title=p/a120110), Encyclopedia of Mathematics, Springer, ISBN 978-1-55608-010-4 • Weisstein, Eric W., " Ackermann function (http://mathworld.wolfram.com/AckermannFunction.html)", MathWorld. • Paul E. Black, Ackermann's function (http://www.nist.gov/dads/HTML/ackermann.html) at the NIST Dictionary of Algorithms and Data Structures. • An animated Ackermann function calculator (http://www.gfredericks.com/main/sandbox/arith/ackermann) • Scott Aaronson, Who can name the biggest number? (http://www.scottaaronson.com/writings/bignumbers. html) (1999) • Ackermann function's (http://www-users.cs.york.ac.uk/~susan/cyc/a/ackermnn.htm). Includes a table of some values. • Hyper-operations: Ackermann's Function and New Arithmetical Operation (http://forum.wolframscience.com/ showthread.php?s=&threadid=579) • Robert Munafo's Large Numbers (http://www.mrob.com/pub/math/largenum.html) describes several variations on the definition of A. • Gabriel Nivasch, Inverse Ackermann without pain (http://www.yucs.org/~gnivasch/alpha/index.html) on the inverse Ackermann function. • Raimund Seidel, Understanding the inverse Ackermann function (http://cgi.di.uoa.gr/~ewcg06/invited/ Seidel.pdf) (PDF presentation). • The Ackermann function written in different programming languages (http://rosettacode.org/wiki/ Ackermann_Function), (on Rosetta Code) • Ackermann's Function (http://www.geocities.com/hjsmithh/Ackerman/index.html) ( Archived (http://www. webcitation.org/5km8K6GSP) 2009-10-24) — Some study and programming by Harry J. Smith.

94

Recursion (computer science)

95

Recursion (computer science) Programming paradigms •

Action



Agent-oriented



Aspect-oriented



Automata-based



Concurrent computing •

Relativistic programming



Data-driven



Declarative (contrast: Imperative) • •

Constraint Dataflow Flow-based Cell-oriented (spreadsheets) Reactive Functional Logic • • •

• •

• • • • •

Abductive logic Answer set Constraint logic Functional logic Inductive logic



End-user programming



Event-driven • •

Service-oriented Time-driven



Expression-oriented



Feature-oriented



Function-level (contrast: Value-level)



Generic



Imperative (contrast: Declarative) •



Procedural

Language-oriented • • •

Discipline-specific Domain-specific Grammar-oriented Dialecting Intentional •

• •

Metaprogramming • •

Automatic Reflective Attribute-oriented Homoiconic Template •

• •

• •

Non-structured (contrast: Structured) •



Policy-based

Array

Nondeterministic

Recursion (computer science)

96 •

Parallel computing •



Process-oriented

Point-free style •

Concatenative



Programming in the large and small



Semantic



Structured (contrast: Non-structured) • • •

Block-structured Modular (contrast: Monolithic) Object-oriented (OOP) •

By separation of concerns:

Aspect-oriented Role-oriented Subject-oriented • Class-based • Prototype-based Recursive • • •

• •

Value-level (contrast: Function-level)



Probabilistic

• • •

v t

e [1]

Recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem (as opposed to iteration). The approach can be applied to many types of problems, and recursion is one of the central ideas of computer science. "The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions." Most computer programming languages support recursion by allowing a function to call itself within the program text. Some functional programming languages do not define any looping constructs but rely solely on recursion to repeatedly call code. Computability theory has provenWikipedia:Attribution needed that these recursive-only languages are Turing complete; they are as computationally powerful as Turing complete imperative languages, meaning they can solve the same kinds of problems as imperative languages even without iterative control structures such as “while” and “for”.

Recursion (computer science)

97

Recursive functions and algorithms A common computer programming tactic is to divide a problem into sub-problems of the same type as the original, solve those sub-problems, and combine the results. This is often referred to as the divide-and-conquer method; when combined with a lookup table that stores the results of solving sub-problems (to avoid solving them repeatedly and incurring extra computation time), it can be referred to as dynamic programming or memoization. A recursive function definition has one or more base cases, meaning input(s) for which the function produces a result trivially (without recurring), and one or more recursive cases, meaning input(s) for which the program recurs (calls itself). For example, the factorial function can be defined recursively by the equations 0! = 1 and, for all n > 0, n! = n(n − 1)!. Neither equation by itself constitutes a complete definition; the first is the base case, and the second is the recursive case. Because the base case breaks the chain of recursion, it is sometimes also called the "terminating case".

Tree created using the Logo programming language and relying heavily on recursion.

The job of the recursive cases can be seen as breaking down complex inputs into simpler ones. In a properly designed recursive function, with each recursive call, the input problem must be simplified in such a way that eventually the base case must be reached. (Functions that are not intended to terminate under normal circumstances—for example, some system and server processes—are an exception to this.) Neglecting to write a base case, or testing for it incorrectly, can cause an infinite loop. For some functions (such as one that computes the series for e = 1/0! + 1/1! + 1/2! + 1/3! + ...) there is not an obvious base case implied by the input data; for these one may add a parameter (such as the number of terms to be added, in our series example) to provide a 'stopping criterion' that establishes the base case. Such an example is more naturally treated by co-recursion, where successive terms in the output are the partial sums; this can be converted to a recursion by using the indexing parameter to say "compute the nth term (nth partial sum)".

Recursive data types Many computer programs must process or generate an arbitrarily large quantity of data. Recursion is one technique for representing data whose exact size the programmer does not know: the programmer can specify this data with a self-referential definition. There are two types of self-referential definitions: inductive and coinductive definitions.

Inductively defined data An inductively defined recursive data definition is one that specifies how to construct instances of the data. For example, linked lists can be defined inductively (here, using Haskell syntax): data ListOfStrings = EmptyList | Cons String ListOfStrings The code above specifies a list of strings to be either empty, or a structure that contains a string and a list of strings. The self-reference in the definition permits the construction of lists of any (finite) number of strings. Another example of inductive definition is the natural numbers (or positive integers): A natural number is either 1 or n+1, where n is a natural number. Similarly recursive definitions are often used to model the structure of expressions and statements in programming languages. Language designers often express grammars in a syntax such as Backus-Naur form; here is such a

Recursion (computer science) grammar, for a simple language of arithmetic expressions with multiplication and addition: ::= | ( * ) | ( + ) This says that an expression is either a number, a product of two expressions, or a sum of two expressions. By recursively referring to expressions in the second and third lines, the grammar permits arbitrarily complex arithmetic expressions such as (5 * ((3 * 6) + 8)), with more than one product or sum operation in a single expression.

Coinductively defined data and corecursion A coinductive data definition is one that specifies the operations that may be performed on a piece of data; typically, self-referential coinductive definitions are used for data structures of infinite size. A coinductive definition of infinite streams of strings, given informally, might look like this: A stream of strings is an object s such that head(s) is a string, and tail(s) is a stream of strings. This is very similar to an inductive definition of lists of strings; the difference is that this definition specifies how to access the contents of the data structure—namely, via the accessor functions head and tail—and what those contents may be, whereas the inductive definition specifies how to create the structure and what it may be created from. Corecursion is related to coinduction, and can be used to compute particular instances of (possibly) infinite objects. As a programming technique, it is used most often in the context of lazy programming languages, and can be preferable to recursion when the desired size or precision of a program's output is unknown. In such cases the program requires both a definition for an infinitely large (or infinitely precise) result, and a mechanism for taking a finite portion of that result. The problem of computing the first n prime numbers is one that can be solved with a corecursive program (e.g. here).

Types of recursion Single recursion and multiple recursion Recursion that only contains a single self-reference is known as single recursion, while recursion that contains multiple self-references is known as multiple recursion. Standard examples of single recursion include list traversal, such as in a linear search, or computing the factorial function, while standard examples of multiple recursion include tree traversal, such as in a depth-first search, or computing the Fibonacci sequence. Single recursion is often much more efficient than multiple recursion, and can generally be replaced by an iterative computation, running in linear time and requiring constant space. Multiple recursion, by contrast, may require exponential time and space, and is more fundamentally recursive, not being able to be replaced by iteration without an explicit stack. Multiple recursion can sometimes be converted to single recursion (and, if desired, thence to iteration). For example, while computing the Fibonacci sequence naively is multiple iteration, as each value requires two previous values, it can be computed by single recursion by passing two successive values as parameters. This is more naturally framed as corecursion, building up from the initial values, at each step track two successive values – see corecursion: examples. A more sophisticated example is using a threaded binary tree, which allows iterative tree traversal, rather than multiple recursion.

98

Recursion (computer science)

Indirect recursion Most basic examples of recursion, and most of the examples presented here, demonstrate direct recursion, in which a function calls itself. Indirect recursion occurs when a function is called not by itself but by another function that it called (either directly or indirectly). For example, if f calls f, that is direct recursion, but if f calls g which calls f, then that is indirect recursion of f. Chains of three or more functions are possible; for example, function 1 calls function 2, function 2 calls function 3, and function 3 calls function 1 again. Indirect recursion is also called mutual recursion, which is a more symmetric term, though this is simply a different of emphasis, not a different notion. That is, if f calls g and then g calls f, which in turn calls g again, from the point of view of f alone, f is indirectly recursing, while from the point of view of g alone, it is indirectly recursing, while from the point of view of both, f and g are mutually recursing on each other. Similarly a set of three or more functions that call each other can be called a set of mutually recursive functions.

Anonymous recursion Recursion is usually done by explicitly calling a function by name. However, recursion can also be done via implicitly calling a function based on the current context, which is particularly useful for anonymous functions, and is known as anonymous recursion.

Structural versus generative recursion Some authors classify recursion as either "structural" or "generative". The distinction is related to where a recursive procedure gets the data that it works on, and how it processes that data: [Functions that consume structured data] typically decompose their arguments into their immediate structural components and then process those components. If one of the immediate components belongs to the same class of data as the input, the function is recursive. For that reason, we refer to these functions as (STRUCTURALLY) RECURSIVE FUNCTIONS. Thus, the defining characteristic of a structurally recursive function is that the argument to each recursive call is the content of a field of the original input. Structural recursion includes nearly all tree traversals, including XML processing, binary tree creation and search, et cetera. By considering the algebraic structure of the natural numbers (that is, a natural number is either zero or the successor of a natural number), functions such as factorial may also be regarded as structural recursion. Generative recursion is the alternative: Many well-known recursive algorithms generate an entirely new piece of data from the given data and recur on it. HtDP (How To Design Programs) refers to this kind as generative recursion. Examples of generative recursion include: gcd, quicksort, binary search, mergesort, Newton's method, fractals, and adaptive integration. This distinction is important in proving termination of a function. All structurally recursive functions on finite (inductively defined) data structures can easily be shown to terminate, via structural induction: intuitively, each recursive call receives a smaller piece of input data, until a base case is reached. Generatively recursive functions, in contrast, do not necessarily feed smaller input to their recursive calls, so proof of their termination is not necessarily as simple, and avoiding infinite loops requires greater care. These generatively recursive functions can often be interpreted as corecursive functions – each step generates the new data, such as successive approximation in Newton's method – and terminating this corecursion requires that the data eventually satisfy some condition, which is not necessarily guaranteed. In terms of loop variants, structural recursion is when there is an obvious loop variant, namely size or complexity, which starts off finite and decreases at each recursive step. By contrast, generative recursion is when there is not such an obvious loop variant, and termination depends on a function, such as "error of approximation" that does not

99

Recursion (computer science)

100

necessarily decrease to zero, and thus termination is not guaranteed without further analysis.

Recursive programs Recursive procedures Factorial A classic example of a recursive procedure is the function used to calculate the factorial of a natural number:

Pseudocode (recursive): function factorial is: input: integer n such that n >= 0 output: [n × (n-1) × (n-2) × … × 1]

1. if n is 0, return 1 2. otherwise, return [ n × factorial(n-1) ]

end factorial

The function can also be written as a recurrence relation:

This evaluation of the recurrence relation demonstrates the computation that would be performed in evaluating the pseudocode above: Computing the recurrence relation for n = 4: b4

= 4 * b3 = = = = = = = =

4 * 4 * 4 * 4 * 4 * 4 * 4 * 24

(3 (3 (3 (3 (3 (3 6

* * * * * *

b2) (2 * (2 * (2 * (2 * 2)

b1)) (1 * b0))) (1 * 1))) 1))

This factorial function can also be described without using recursion by making use of the typical looping constructs found in imperative programming languages: Pseudocode (iterative):

Recursion (computer science)

101

function factorial is: input: integer n such that n >= 0 output: [n × (n-1) × (n-2) × … × 1]

1. create new variable called running_total with a value of 1

2. begin 1. 2. 3. 4.

loop if n is 0, exit loop set running_total to (running_total × n) decrement n repeat loop

3. return running_total

end factorial

The imperative code above is equivalent to this mathematical definition using an accumulator variable t:

The definition above translates straightforwardly to functional programming languages such as Scheme; this is an example of iteration implemented recursively. Greatest common divisor The Euclidean algorithm, which computes the greatest common divisor of two integers, can be written recursively. Function definition:

Pseudocode (recursive): function gcd is: input: integer x, integer y such that x >= y and y >= 0

1. if y is 0, return x 2. otherwise, return [ gcd( y, (remainder of x/y) ) ]

end gcd

Recurrence relation for greatest common divisor, where

expresses the remainder of

:

Recursion (computer science)

102

Computing the recurrence relation for x = 27 and y = 9: gcd(27, 9)

= gcd(9, 27% 9) = gcd(9, 0) = 9

Computing the recurrence relation for x = 259 and y = 111: gcd(259, 111)

= = = =

gcd(111, 259% 111) gcd(111, 37) gcd(37, 0) 37

The recursive program above is tail-recursive; it is equivalent to an iterative algorithm, and the computation shown above shows the steps of evaluation that would be performed by a language that eliminates tail calls. Below is a version of the same algorithm using explicit iteration, suitable for a language that does not eliminate tail calls. By maintaining its state entirely in the variables x and y and using a looping construct, the program avoids making recursive calls and growing the call stack. Pseudocode (iterative): function gcd is: input: integer x, integer y such that x >= y and y >= 0

1. create new variable called remainder

2. begin 1. 2. 3. 4. 5.

loop if y is zero, exit loop set remainder to the remainder of x/y set x to y set y to remainder repeat loop

3. return x

end gcd

The iterative algorithm requires a temporary variable, and even given knowledge of the Euclidean algorithm it is more difficult to understand the process by simple inspection, although the two algorithms are very similar in their steps.

Recursion (computer science)

103

Towers of Hanoi For a full discussion of this problem's description, history and solution see the main article or one of the many references. Simply put the problem is this: given three pegs, one with a set of N disks of increasing size, determine the minimum (optimal) number of steps it takes to move all the disks from their initial position to a single stack on another peg without placing a larger disk on top of a smaller one. Function definition:

Recurrence relation for hanoi:

Computing the recurrence relation for n = 4: hanoi(4)

= = = = = = =

2*hanoi(3) + 1 2*(2*hanoi(2) + 1) + 1 2*(2*(2*hanoi(1) + 1) + 1) + 1 2*(2*(2*1 + 1) + 1) + 1 2*(2*(3) + 1) + 1 2*(7) + 1 15

Example Implementations: Pseudocode (recursive): function hanoi is: input: integer n, such that n >= 1

1. if n is 1 then return 1

2. return [2 * [call hanoi(n-1)] + 1]

end hanoi

Although not all recursive functions have an explicit solution, the Tower of Hanoi sequence can be reduced to an explicit formula. An explicit formula for Towers of Hanoi: h1 h2 h3 h4 h5 h6 h7

= = = = = = =

1 3 7 15 31 63 127

= = = = = = =

21 22 23 24 25 26 27

-

1 1 1 1 1 1 1

In general: hn = 2n - 1, for all n >= 1

Recursion (computer science) Binary search The binary search algorithm is a method of searching a sorted array for a single element by cutting the array in half with each recursive pass. The trick is to pick a midpoint near the center of the array, compare the data at that point with the data being searched and then responding to one of three possible conditions: the data is found at the midpoint, the data at the midpoint is greater than the data being searched for, or the data at the midpoint is less than the data being searched for. Recursion is used in this algorithm because with each pass a new array is created by cutting the old one in half. The binary search procedure is then called recursively, this time on the new (and smaller) array. Typically the array's size is adjusted by manipulating a beginning and ending index. The algorithm exhibits a logarithmic order of growth because it essentially divides the problem domain in half with each pass. Example implementation of binary search in C: /* Call binary_search with proper initial conditions. INPUT: data is an array of integers SORTED in ASCENDING order, toFind is the integer to search for, count is the total number of elements in the array OUTPUT: result of binary_search */ int search(int *data, int toFind, int count) { // Start = 0 (beginning index) // End = count - 1 (top index) return binary_search(data, toFind, 0, count-1); } /* Binary Search Algorithm. INPUT: data is a array of integers SORTED in ASCENDING order, toFind is the integer to search for, start is the minimum array index, end is the maximum array index OUTPUT: position of the integer toFind within array data, -1 if not found */ int binary_search(int *data, int toFind, int start, int end) { //Get the midpoint. int mid = start + (end - start)/2; //Integer division

104

Recursion (computer science)

105

//Stop condition. if (start > end) return -1; else if (data[mid] == toFind) //Found? return mid; else if (data[mid] > toFind) //Data is greater than toFind, search lower half return binary_search(data, toFind, start, mid-1); else //Data is less than toFind, search upper half return binary_search(data, toFind, mid+1, end); }

Recursive data structures (structural recursion) An important application of recursion in computer science is in defining dynamic data structures such as lists and trees. Recursive data structures can dynamically grow to a theoretically infinite size in response to runtime requirements; in contrast, the size of a static array must be set at compile time. "Recursive algorithms are particularly appropriate when the underlying problem or the data to be treated are defined in recursive terms." The examples in this section illustrate what is known as "structural recursion". This term refers to the fact that the recursive procedures are acting on data that is defined recursively. As long as a programmer derives the template from a data definition, functions employ structural recursion. That is, the recursions in a function's body consume some immediate piece of a given compound value. Linked lists Below is a C definition of a linked list node structure. Notice especially how the node is defined in terms of itself. The "next" element of struct node is a pointer to another struct node, effectively creating a list type. struct node { int data; struct node *next; };

// some integer data // pointer to another struct node

Because the struct node data structure is defined recursively, procedures that operate on it can be implemented naturally as recursive procedures. The list_print procedure defined below walks down the list until the list is empty (i.e., the list pointer has a value of NULL). For each node it prints the data element (an integer). In the C implementation, the list remains unchanged by the list_print procedure. void list_print(struct node *list) { if (list != NULL) { printf ("%d ", list->data); space list_print (list->next);

// base case // print integer data followed by a // recursive call on the next node

Recursion (computer science)

106

} } Binary trees Below is a simple definition for a binary tree node. Like the node for linked lists, it is defined in terms of itself, recursively. There are two self-referential pointers: left (pointing to the left sub-tree) and right (pointing to the right sub-tree). struct node { int data; struct node *left; struct node *right; };

// some integer data // pointer to the left subtree // point to the right subtree

Operations on the tree can be implemented using recursion. Note that because there are two self-referencing pointers (left and right), tree operations may require two recursive calls: // Test if tree_node contains i; return 1 if so, 0 if not. int tree_contains(struct node *tree_node, int i) { if (tree_node == NULL) return 0; // base case else if (tree_node->data == i) return 1; else return tree_contains(tree_node->left, i) || tree_contains(tree_node->right, i); } At most two recursive calls will be made for any given call to tree_contains as defined above. // Inorder traversal: void tree_print(struct node *tree_node) { if (tree_node != NULL) { tree_print(tree_node->left); printf("%d ", tree_node->data); followed by a space tree_print(tree_node->right); } }

// base case // go left // print the integer // go right

The above example illustrates an in-order traversal of the binary tree. A Binary search tree is a special case of the binary tree where the data elements of each node are in order.

Recursion (computer science) Filesystem traversal Since the number of files in a filesystem may vary, recursion is the only practical way to traverse and thus enumerate its contents. Traversing a filesystem is very similar to that of tree traversal, therefore the concepts behind tree traversal are applicable to traversing a filesystem. More specifically, the code below would be an example of a preorder traversal of a filesystem. import java.io.*; public class FileSystem { public static void main (String [] args) { traverse (); } /** * Obtains the filesystem roots * Proceeds with the recurisve filesystem traversal */ private static void traverse () { File [] fs = File.listRoots (); for (int i = 0; i < fs.length; i++) { if (fs[i].isDirectory () && fs[i].canRead ()) { rtraverse (fs[i]); } } } /** * Recursively traverse a given directory * * @param fd indicates the starting point of traversal */ private static void rtraverse (File fd) { File [] fss = fd.listFiles (); for (int i = 0; i < fss.length; i++) { System.out.println (fss[i]); if (fss[i].isDirectory () && fss[i].canRead ()) { rtraverse (fss[i]); } } } } This code blends the lines, at least somewhat, between recursion and iteration. It is, essentially, a recursive implementation, which is the best way to traverse a filesystem. It is also an example of direct and indirect recursion. The method "rtraverse" is purely a direct example; the method "traverse" is the indirect, which calls "rtraverse." This

107

Recursion (computer science) example needs no "base case" scenario due to the fact that there will always be some fixed number of files and/or directories in a given filesystem.

Implementation issues In actual implementation, rather than a pure recursive function (single check for base case, otherwise recursive step), a number of modifications may be made, for purposes of clarity or efficiency. These include: • Wrapper function (at top) • Short-circuiting the base case, aka "Arm's-length recursion" (at bottom) • Hybrid algorithm (at bottom) – switching to a different algorithm once data is small enough On the basis of elegance, wrapper functions are generally approved, while short-circuiting the base case is frowned upon, particularly in academia. Hybrid algorithms are often used for efficiency, to reduce the overhead of recursion in small cases, and arm's-length recursion is a special case of this.

Wrapper function A wrapper function is a function that is directly called but does not recurse itself, instead calling a separate auxiliary function which actually does the recursion. Wrapper functions can be used to validate parameters (so the recursive function can skip these), perform initialization (allocate memory, initialize variables), particularly for auxiliary variables such as "level of recursion" or partial computations for memoization, and handle exceptions and errors. In languages that support nested functions, the auxiliary function can be nested inside the wrapper function and use a shared scope. In the absence of nested functions, auxiliary functions are instead a separate function, if possible private (as they are not called directly), and information is shared with the wrapper function by using pass-by-reference.

Short-circuiting the base case Short-circuiting the base case, also known as arm's-length recursion, consists of checking the base case before making a recursive call – i.e., checking if the next call will be the base case, instead of calling and then checking for the base case. Short-circuiting is particularly done for efficiency reasons, to avoid the overhead of a function call that immediately returns. Note that since the base case has already been checked for (immediately before the recursive step), it does not need to be checked for separately, but one does need to use a wrapper function for the case when the overall recursion starts with the base case itself. For example, in the factorial function, properly the base case is 0! = 1, while immediately returning 1 for 1! is a short-circuit, and may miss 0; this can be mitigated by a wrapper function. Short-circuiting is primarily a concern when many base cases are encountered, such as Null pointers in a tree, which can be linear in the number of function calls, hence significant savings for O(n) algorithms; this is illustrated below for a depth-first search. Short-circuiting on a tree corresponds to considering a leaf (non-empty node with no children) as the base case, rather than considering an empty node as the base case. If there is only a single base case, such as in computing the factorial, short-circuiting provides only O(1) savings. Conceptually, short-circuiting can be considered to either have the same base case and recursive step, only checking the base case before the recursion, or it can be considered to have a different base case (one step removed from standard base case) and a more complex recursive step, namely "check valid then recurse", as in considering leaf nodes rather than Null nodes as base cases in a tree. Because short-circuiting has a more complicated flow, compared with the clear separation of base case and recursive step in standard recursion, it is often considered poor style, particularly in academia.

108

Recursion (computer science) Depth-first search A basic example of short-circuiting is given in depth-first search (DFS) of a binary tree; see binary trees section for standard recursive discussion. The standard recursive algorithm for a DFS is: • base case: If current node is Null, return false • recursive step: otherwise, check value of current node, return true if match, otherwise recurse on children In short-circuiting, this is instead: • check value of current node, return true if match, • otherwise, on children, if not Null, then recurse. In terms of the standard steps, this moves the base case check before the recursive step. Alternatively, these can be considered a different form of base case and recursive step, respectively. Note that this requires a wrapper function to handle the case when the tree itself is empty (root node is Null). In the case of a perfect binary tree of height h, there are 2h+1−1 nodes and 2h+1 Null pointers as children (2 for each of the 2h leaves), so short-circuiting cuts the number of function calls in half in the worst case. In C, the standard recursive algorithm may be implemented as: bool tree_contains(struct node *tree_node, int i) { if (tree_node == NULL) return false; // base case else if (tree_node->data == i) return true; else return tree_contains(tree_node->left, i) || tree_contains(tree_node->right, i); } The short-circuited algorithm may be implemented as: // Wrapper function to handle empty tree bool tree_contains(struct node *tree_node, int i) { if (tree_node == NULL) return false; // empty tree else return tree_contains_do(tree_node, i); // call auxiliary function } // Assumes tree_node != NULL bool tree_contains_do(struct node *tree_node, int i) { if (tree_node->data == i) return true; // found else // recurse return (tree_node->left && tree_contains(tree_node->left, i)) || (tree_node->right && tree_contains(tree_node->right, i)); }

109

Recursion (computer science) Note the use of short-circuit evaluation of the Boolean && (AND) operators, so that the recursive call is only made if the node is valid (non-Null). Note that while the first term in the AND is a pointer to a node, the second term is a bool, so the overall expression evaluates to a bool. This is a common idiom in recursive short-circuiting. This is in addition to the short-circuit evaluation of the Boolean || (OR) operator, to only check the right child if the left child fails. In fact, the entire control flow of these functions can be replaced with a single Boolean expression in a return statement, but legibility suffers at no benefit to efficiency.

Hybrid algorithm Recursive algorithms are often inefficient for small data, due to the overhead of repeated function calls and returns. For this reason efficient implementations of recursive algorithms often start with the recursive algorithm, but then switch to a different algorithm when the input becomes small. An important example is merge sort, which is often implemented by switching to the non-recursive insertion sort when the data is sufficiently small, as in the tiled merge sort. Hybrid recursive algorithms can often be further refined, as in Timsort, derived from a hybrid merge sort/insertion sort.

Recursion versus iteration Recursion and iteration are equally expressive: recursion can be replaced by iteration with an explicit stack, while iteration can be replaced with tail recursion. Which approach is preferable depends on the problem under consideration and the language used. In imperative programming, iteration is preferred, particularly for simple recursion, as it avoids the overhead of function calls and call stack management, but recursion is generally used for multiple recursion. By contrast, in functional languages recursion is preferred, with tail recursion optimization leading to little overhead, and sometimes explicit iteration is not available. For example, the factorial function may be implemented iteratively in C by assigning to an loop index variable and accumulator variable, rather than passing arguments and returning values by recursion: unsigned int factorial(unsigned int n) { unsigned int product = 1; // empty product is 1 while (n) { product *= n; --n; } return product; }

Expressive power Most programming languages in use today allow the direct specification of recursive functions and procedures. When such a function is called, the program's runtime environment keeps track of the various instances of the function (often using a call stack, although other methods may be used). Every recursive function can be transformed into an iterative function by replacing recursive calls with iterative control constructs and simulating the call stack with a stack explicitly managed by the program. Conversely, all iterative functions and procedures that can be evaluated by a computer (see Turing completeness) can be expressed in terms of recursive functions; iterative control constructs such as while loops and do loops routinely are rewritten in recursive form in functional languages. However, in practice this rewriting depends on tail call elimination, which is not a feature of all languages. C, Java, and Python are notable mainstream languages in which all function calls, including tail calls, cause stack allocation that would not occur with the use of looping constructs; in these languages, a working iterative program rewritten in recursive form may overflow the call stack.

110

Recursion (computer science)

111

Performance issues In languages (such as C and Java) that favor iterative looping constructs, there is usually significant time and space cost associated with recursive programs, due to the overhead required to manage the stack and the relative slowness of function calls; in functional languages, a function call (particularly a tail call) is typically a very fast operation, and the difference is usually less noticeable. As a concrete example, the difference in performance between recursive and iterative implementations of the "factorial" example above depends highly on the language used. In languages where looping constructs are preferred, the iterative version may be as much as several orders of magnitude faster than the recursive one. In functional languages, the overall time difference of the two implementations may be negligible; in fact, the cost of multiplying the larger numbers first rather than the smaller numbers (which the iterative version given here happens to do) may overwhelm any time saved by choosing iteration.

Stack space In some programming languages, the stack space available to a thread is much less than the space available in the heap, and recursive algorithms tend to require more stack space than iterative algorithms. Consequently, these languages sometimes place a limit on the depth of recursion to avoid stack overflows; Python is one such language. Note the caveat below regarding the special case of tail recursion.

Multiply recursive problems Multiply recursive problems are inherently recursive, because of prior state they need to track. One example is tree traversal as in depth-first search; contrast with list traversal and linear search in a list, which is singly recursive and thus naturally iterative. Other examples include divide-and-conquer algorithms such as Quicksort, and functions such as the Ackermann function. All of these algorithms can be implemented iteratively with the help of an explicit stack, but the programmer effort involved in managing the stack, and the complexity of the resulting program, arguably outweigh any advantages of the iterative solution.

Tail-recursive functions Tail-recursive functions are functions in which all recursive calls are tail calls and hence do not build up any deferred operations. For example, the gcd function (shown again below) is tail-recursive. In contrast, the factorial function (also below) is not tail-recursive; because its recursive call is not in tail position, it builds up deferred multiplication operations that must be performed after the final recursive call completes. With a compiler or interpreter that treats tail-recursive calls as jumps rather than function calls, a tail-recursive function such as gcd will execute using constant space. Thus the program is essentially iterative, equivalent to using imperative language control structures like the "for" and "while" loops. Tail recursion:

Augmenting recursion:

//INPUT: Integers x, y such that x >= y and y > 0 //INPUT: n is an Integer such that n >= 0 int gcd(int x, int y) int fact(int n) { { if (y == 0) if (n == 0) return x; return 1; else else return gcd(y, x % y); return n * fact(n - 1); } } The significance of tail recursion is that when making a tail-recursive call (or any tail call), the caller's return position need not be saved on the call stack; when the recursive call returns, it will branch directly on the previously saved return position. Therefore, in languages that recognize this property of tail calls, tail recursion saves both space

Recursion (computer science) and time.

Order of execution In the simple case of a function calling itself only once, instructions placed before the recursive call are executed once per recursion before any of the instructions placed after the recursive call. The latter are executed repeatedly after the maximum recursion has been reached. Consider this example:

Function 1 void recursiveFunction(int num) { printf("%d\n", num); if (num < 4) recursiveFunction(num + 1); }

Function 2 with swapped lines void recursiveFunction(int num) { if (num < 4) recursiveFunction(num + 1); printf("%d\n", num); }

112

Recursion (computer science)

113

Time-efficiency of recursive algorithms The time efficiency of recursive algorithms can be expressed in a recurrence relation of Big O notation. They can (usually) then be simplified into a single Big-Oh term.

Shortcut rule If the time-complexity of the function is in the form

Then the Big-Oh of the time-complexity is thus: • If • If • If where

, then the time-complexity is , then the time-complexity is , then the time-complexity is represents the number of recursive calls at each level of recursion,

represents by what factor smaller the

input is for the next level of recursion (i.e. the number of pieces you divide the problem into), and

represents the

work the function does independent of any recursion (e.g. partitioning, recombining) at each level of recursion.

Notes and references [1] http:/ / en. wikipedia. org/ w/ index. php?title=Template:Programming_paradigms& action=edit

Further reading • Dijkstra, Edsger W. (1960). "Recursive Programming". Numerische Mathematik 2 (1): 312–318. doi: 10.1007/BF01386232 (http://dx.doi.org/10.1007/BF01386232).

External links • Harold Abelson and Gerald Sussman: "Structure and Interpretation Of Computer Programs" (http://mitpress. mit.edu/sicp/full-text/book/book.html) • IBM DeveloperWorks: "Mastering Recursive Programming" (http://www-128.ibm.com/developerworks/ linux/library/l-recurs.html) • David S. Touretzky: "Common Lisp: A Gentle Introduction to Symbolic Computation" (http://www.cs.cmu. edu/~dst/LispBook/) • Matthias Felleisen: "How To Design Programs: An Introduction to Computing and Programming" (http://www. htdp.org/2003-09-26/Book/) • Duke University: "Big-Oh for Recursive Functions: Recurrence Relations" (http://www.cs.duke.edu/~ola/ap/ recurrence.html)

Computability theory

Computability theory Computability theory, also called recursion theory, is a branch of mathematical logic, of computer science, and of the theory of computation that originated in the 1930s with the study of computable functions and Turing degrees. The basic questions addressed by recursion theory are "What does it mean for a function on the natural numbers to be computable?" and "How can noncomputable functions be classified into a hierarchy based on their level of noncomputability?". The answers to these questions have led to a rich theory that is still being actively researched. The field has since grown to include the study of generalized computability and definability. In these areas, recursion theory overlaps with proof theory and effective descriptive set theory. Arguably, a child of recursion theory is complexity theory that concentrates on the complexity of decidable problems rather than proves undecidable problems. Both theories share the same tool, namely a Turing machine. Remarkably, the invention of the central combinatorial object of recursion theory, namely the Universal Turing Machine, pre-dates and pre-determines the invention of modern computers. Another reason for the area being quite active these days is the celebrated Higman's embedding theorem that provides a link between recursion theory and group theory. Recursion theorists in mathematical logic often study the theory of relative computability, reducibility notions and degree structures described in this article. This contrasts with the theory of subrecursive hierarchies, formal methods and formal languages that is common in the study of computability theory in computer science. There is considerable overlap in knowledge and methods between these two research communities, however, and no firm line can be drawn between them.

Computable and uncomputable sets Recursion theory originated in the 1930s, with work of Kurt Gödel, Alonzo Church, Alan Turing, Stephen Kleene and Emil Post.[1] The fundamental results the researchers obtained established Turing computability as the correct formalization of the informal idea of effective calculation. These results led Stephen Kleene (1952) to coin the two names "Church's thesis" (Kleene 1952:300) and "Turing's Thesis" (Kleene 1952:376). Nowadays these are often considered as a single hypothesis, the Church–Turing thesis, which states that any function that is computable by an algorithm is a computable function. Although initially skeptical, by 1946 Gödel argued in favor of this thesis: "Tarski has stressed in his lecture (and I think justly) the great importance of the concept of general recursiveness (or Turing's computability). It seems to me that this importance is largely due to the fact that with this concept one has for the first time succeeded in giving an absolute notion to an interesting epistemological notion, i.e., one not depending on the formalism chosen.*"(Gödel 1946 in Davis 1965:84).[2] With a definition of effective calculation came the first proofs that there are problems in mathematics that cannot be effectively decided. Church (1936a, 1936b) and Turing (1936), inspired by techniques used by Gödel (1931) to prove his incompleteness theorems, independently demonstrated that the Entscheidungsproblem is not effectively decidable. This result showed that there is no algorithmic procedure that can correctly decide whether arbitrary mathematical propositions are true or false. Many problems of mathematics have been shown to be undecidable after these initial examples were established. In 1947, Markov and Post published independent papers showing that the word problem for semigroups cannot be effectively decided. Extending this result, Pyotr Novikov and William Boone showed independently in the 1950s that the word problem for groups is not effectively solvable: there is no effective procedure that, given a word in a finitely presented group, will decide whether the element represented by the word is the identity element of the group. In 1970, Yuri Matiyasevich proved (using results of Julia Robinson) Matiyasevich's theorem, which implies that Hilbert's tenth problem has no effective solution; this problem asked whether there is an effective procedure to

114

Computability theory decide whether a Diophantine equation over the integers has a solution in the integers. The list of undecidable problems gives additional examples of problems with no computable solution. The study of which mathematical constructions can be effectively performed is sometimes called recursive mathematics; the Handbook of Recursive Mathematics (Ershov et al. 1998) covers many of the known results in this field.

Turing computability The main form of computability studied in recursion theory was introduced by Turing (1936). A set of natural numbers is said to be a computable set (also called a decidable, recursive, or Turing computable set) if there is a Turing machine that, given a number n, halts with output 1 if n is in the set and halts with output 0 if n is not in the set. A function f from the natural numbers to themselves is a recursive or (Turing) computable function if there is a Turing machine that, on input n, halts and returns output f(n). The use of Turing machines here is not necessary; there are many other models of computation that have the same computing power as Turing machines; for example the μ-recursive functions obtained from primitive recursion and the μ operator. The terminology for recursive functions and sets is not completely standardized. The definition in terms of μ-recursive functions as well as a different definition of rekursiv functions by Gödel led to the traditional name recursive for sets and functions computable by a Turing machine. The word decidable stems from the German word Entscheidungsproblem which was used in the original papers of Turing and others. In contemporary use, the term "computable function" has various definitions: according to Cutland (1980), it is a partial recursive function (which can be undefined for some inputs), while according to Soare (1987) it is a total recursive (equivalently, general recursive) function. This article follows the second of these conventions. Soare (1996) gives additional comments about the terminology. Not every set of natural numbers is computable. The halting problem, which is the set of (descriptions of) Turing machines that halt on input 0, is a well-known example of a noncomputable set. The existence of many noncomputable sets follows from the facts that there are only countably many Turing machines, and thus only countably many computable sets, but there are uncountably many sets of natural numbers. Although the Halting problem is not computable, it is possible to simulate program execution and produce an infinite list of the programs that do halt. Thus the halting problem is an example of a recursively enumerable set, which is a set that can be enumerated by a Turing machine (other terms for recursively enumerable include computably enumerable and semidecidable). Equivalently, a set is recursively enumerable if and only if it is the range of some computable function. The recursively enumerable sets, although not decidable in general, have been studied in detail in recursion theory.

Areas of research Beginning with the theory of recursive sets and functions described above, the field of recursion theory has grown to include the study of many closely related topics. These are not independent areas of research: each of these areas draws ideas and results from the others, and most recursion theorists are familiar with the majority of them.

Relative computability and the Turing degrees Recursion theory in mathematical logic has traditionally focused on relative computability, a generalization of Turing computability defined using oracle Turing machines, introduced by Turing (1939). An oracle Turing machine is a hypothetical device which, in addition to performing the actions of a regular Turing machine, is able to ask questions of an oracle, which is a particular set of natural numbers. The oracle machine may only ask questions of the form "Is n in the oracle set?". Each question will be immediately answered correctly, even if the oracle set is not computable. Thus an oracle machine with a noncomputable oracle will be able to compute sets that are not

115

Computability theory computable without an oracle. Informally, a set of natural numbers A is Turing reducible to a set B if there is an oracle machine that correctly tells whether numbers are in A when run with B as the oracle set (in this case, the set A is also said to be (relatively) computable from B and recursive in B). If a set A is Turing reducible to a set B and B is Turing reducible to A then the sets are said to have the same Turing degree (also called degree of unsolvability). The Turing degree of a set gives a precise measure of how uncomputable the set is. The natural examples of sets that are not computable, including many different sets that encode variants of the halting problem, have two properties in common: 1. They are recursively enumerable, and 2. Each can be translated into any other via a many-one reduction. That is, given such sets A and B, there is a total computable function f such that A = {x : f(x) ∈ B}. These sets are said to be many-one equivalent (or m-equivalent). Many-one reductions are "stronger" than Turing reductions: if a set A is many-one reducible to a set B, then A is Turing reducible to B, but the converse does not always hold. Although the natural examples of noncomputable sets are all many-one equivalent, it is possible to construct recursively enumerable sets A and B such that A is Turing reducible to B but not many-one reducible to B. It can be shown that every recursively enumerable set is many-one reducible to the halting problem, and thus the halting problem is the most complicated recursively enumerable set with respect to many-one reducibility and with respect to Turing reducibility. Post (1944) asked whether every recursively enumerable set is either computable or Turing equivalent to the halting problem, that is, whether there is no recursively enumerable set with a Turing degree intermediate between those two. As intermediate results, Post defined natural types of recursively enumerable sets like the simple, hypersimple and hyperhypersimple sets. Post showed that these sets are strictly between the computable sets and the halting problem with respect to many-one reducibility. Post also showed that some of them are strictly intermediate under other reducibility notions stronger than Turing reducibility. But Post left open the main problem of the existence of recursively enumerable sets of intermediate Turing degree; this problem became known as Post's problem. After ten years, Kleene and Post showed in 1954 that there are intermediate Turing degrees between those of the computable sets and the halting problem, but they failed to show that any of these degrees contains a recursively enumerable set. Very soon after this, Friedberg and Muchnik independently solved Post's problem by establishing the existence of recursively enumerable sets of intermediate degree. This groundbreaking result opened a wide study of the Turing degrees of the recursively enumerable sets which turned out to possess a very complicated and non-trivial structure. There are uncountably many sets that are not recursively enumerable, and the investigation of the Turing degrees of all sets is as central in recursion theory as the investigation of the recursively enumerable Turing degrees. Many degrees with special properties were constructed: hyperimmune-free degrees where every function computable relative to that degree is majorized by a (unrelativized) computable function; high degrees relative to which one can compute a function f which dominates every computable function g in the sense that there is a constant c depending on g such that g(x) < f(x) for all x > c; random degrees containing algorithmically random sets; 1-generic degrees of 1-generic sets; and the degrees below the halting problem of limit-recursive sets. The study of arbitrary (not necessarily recursively enumerable) Turing degrees involves the study of the Turing jump. Given a set A, the Turing jump of A is a set of natural numbers encoding a solution to the halting problem for oracle Turing machines running with oracle A. The Turing jump of any set is always of higher Turing degree than the original set, and a theorem of Friedburg shows that any set that computes the Halting problem can be obtained as the Turing jump of another set. Post's theorem establishes a close relationship between the Turing jump operation and the arithmetical hierarchy, which is a classification of certain subsets of the natural numbers based on their definability in arithmetic. Much recent research on Turing degrees has focused on the overall structure of the set of Turing degrees and the set of Turing degrees containing recursively enumerable sets. A deep theorem of Shore and Slaman (1999) states that

116

Computability theory the function mapping a degree x to the degree of its Turing jump is definable in the partial order of the Turing degrees. A recent survey by Ambos-Spies and Fejer (2006) gives an overview of this research and its historical progression.

Other reducibilities An ongoing area of research in recursion theory studies reducibility relations other than Turing reducibility. Post (1944) introduced several strong reducibilities, so named because they imply truth-table reducibility. A Turing machine implementing a strong reducibility will compute a total function regardless of which oracle it is presented with. Weak reducibilities are those where a reduction process may not terminate for all oracles; Turing reducibility is one example. The strong reducibilities include: One-one reducibility A is one-one reducible (or 1-reducible) to B if there is a total computable injective function f such that each n is in A if and only if f(n) is in B. Many-one reducibility This is essentially one-one reducibility without the constraint that f be injective. A is many-one reducible (or m-reducible) to B if there is a total computable function f such that each n is in A if and only if f(n) is in B. Truth-table reducibility A is truth-table reducible to B if A is Turing reducible to B via an oracle Turing machine that computes a total function regardless of the oracle it is given. Because of compactness of Cantor space, this is equivalent to saying that the reduction presents a single list of questions (depending only on the input) to the oracle simultaneously, and then having seen their answers is able to produce an output without asking additional questions regardless of the oracle's answer to the initial queries. Many variants of truth-table reducibility have also been studied. Further reducibilities (positive, disjunctive, conjunctive, linear and their weak and bounded versions) are discussed in the article Reduction (recursion theory). The major research on strong reducibilities has been to compare their theories, both for the class of all recursively enumerable sets as well as for the class of all subsets of the natural numbers. Furthermore, the relations between the reducibilities has been studied. For example, it is known that every Turing degree is either a truth-table degree or is the union of infinitely many truth-table degrees. Reducibilities weaker than Turing reducibility (that is, reducibilities that are implied by Turing reducibility) have also been studied. The most well known are arithmetical reducibility and hyperarithmetical reducibility. These reducibilities are closely connected to definability over the standard model of arithmetic.

Rice's theorem and the arithmetical hierarchy Rice showed that for every nontrivial class C (which contains some but not all r.e. sets) the index set E = {e: the eth r.e. set We is in C} has the property that either the halting problem or its complement is many-one reducible to E, that is, can be mapped using a many-one reduction to E (see Rice's theorem for more detail). But, many of these index sets are even more complicated than the halting problem. These type of sets can be classified using the arithmetical hierarchy. For example, the index set FIN of class of all finite sets is on the level Σ2, the index set REC of the class of all recursive sets is on the level Σ3, the index set COFIN of all cofinite sets is also on the level Σ3 and the index set COMP of the class of all Turing-complete sets Σ4. These hierarchy levels are defined inductively, Σn+1 contains just all sets which are recursively enumerable relative to Σn; Σ1 contains the recursively enumerable sets. The index sets given here are even complete for their levels, that is, all the sets in these levels can be many-one reduced to the given index sets.

117

Computability theory

Reverse mathematics The program of reverse mathematics asks which set-existence axioms are necessary to prove particular theorems of mathematics in subsystems of second-order arithmetic. This study was initiated by Harvey Friedman and was studied in detail by Stephen Simpson and others; Simpson (1999) gives a detailed discussion of the program. The set-existence axioms in question correspond informally to axioms saying that the powerset of the natural numbers is closed under various reducibility notions. The weakest such axiom studied in reverse mathematics is recursive comprehension, which states that the powerset of the naturals is closed under Turing reducibility.

Numberings A numbering is an enumeration of functions; it has two parameters, e and x and outputs the value of the e-th function in the numbering on the input x. Numberings can be partial-recursive although some of its members are total recursive, that is, computable functions. Admissible numberings are those into which all others can be translated. A Friedberg numbering (named after its discoverer) is a one-one numbering of all partial-recursive functions; it is necessarily not an admissible numbering. Later research dealt also with numberings of other classes like classes of recursively enumerable sets. Goncharov discovered for example a class of recursively enumerable sets for which the numberings fall into exactly two classes with respect to recursive isomorphisms.

The priority method For further explanation, see the section Post's problem and the priority method in the article Turing degree. Post's problem was solved with a method called the priority method; a proof using this method is called a priority argument. This method is primarily used to construct recursively enumerable sets with particular properties. To use this method, the desired properties of the set to be constructed are broken up into an infinite list of goals, known as requirements, so that satisfying all the requirements will cause the set constructed to have the desired properties. Each requirement is assigned to a natural number representing the priority of the requirement; so 0 is assigned to the most important priority, 1 to the second most important, and so on. The set is then constructed in stages, each stage attempting to satisfy one of more of the requirements by either adding numbers to the set or banning numbers from the set so that the final set will satisfy the requirement. It may happen that satisfying one requirement will cause another to become unsatisfied; the priority order is used to decide what to do in such an event. Priority arguments have been employed to solve many problems in recursion theory, and have been classified into a hierarchy based on their complexity (Soare 1987). Because complex priority arguments can be technical and difficult to follow, it has traditionally been considered desirable to prove results without priority arguments, or to see if results proved with priority arguments can also be proved without them. For example, Kummer published a paper on a proof for the existence of Friedberg numberings without using the priority method.

The lattice of recursively enumerable sets When Post defined the notion of a simple set as an r.e. set with an infinite complement not containing any infinite r.e. set, he started to study the structure of the recursively enumerable sets under inclusion. This lattice became a well-studied structure. Recursive sets can be defined in this structure by the basic result that a set is recursive if and only if the set and its complement are both recursively enumerable. Infinite r.e. sets have always infinite recursive subsets; but on the other hand, simple sets exist but do not have a coinfinite recursive superset. Post (1944) introduced already hypersimple and hyperhypersimple sets; later maximal sets were constructed which are r.e. sets such that every r.e. superset is either a finite variant of the given maximal set or is co-finite. Post's original motivation in the study of this lattice was to find a structural notion such that every set which satisfies this property is neither in the Turing degree of the recursive sets nor in the Turing degree of the halting problem. Post did not find such a property and the solution to his problem applied priority methods instead; Harrington and Soare (1991) found eventually such a property.

118

Computability theory

Automorphism problems Another important question is the existence of automorphisms in recursion-theoretic structures. One of these structures is that one of recursively enumerable sets under inclusion modulo finite difference; in this structure, A is below B if and only if the set difference B − A is finite. Maximal sets (as defined in the previous paragraph) have the property that they cannot be automorphic to non-maximal sets, that is, if there is an automorphism of the recursive enumerable sets under the structure just mentioned, then every maximal set is mapped to another maximal set. Soare (1974) showed that also the converse holds, that is, every two maximal sets are automorphic. So the maximal sets form an orbit, that is, every automorphism preserves maximality and any two maximal sets are transformed into each other by some automorphism. Harrington gave a further example of an automorphic property: that of the creative sets, the sets which are many-one equivalent to the halting problem. Besides the lattice of recursively enumerable sets, automorphisms are also studied for the structure of the Turing degrees of all sets as well as for the structure of the Turing degrees of r.e. sets. In both cases, Cooper claims to have constructed nontrivial automorphisms which map some degrees to other degrees; this construction has, however, not been verified and some colleagues believe that the construction contains errors and that the question of whether there is a nontrivial automorphism of the Turing degrees is still one of the main unsolved questions in this area (Slaman and Woodin 1986, Ambos-Spies and Fejer 2006).

Kolmogorov complexity The field of Kolmogorov complexity and algorithmic randomness was developed during the 1960s and 1970s by Chaitin, Kolmogorov, Levin, Martin-Löf and Solomonoff (the names are given here in alphabetical order; much of the research was independent, and the unity of the concept of randomness was not understood at the time). The main idea is to consider a universal Turing machine U and to measure the complexity of a number (or string) x as the length of the shortest input p such that U(p) outputs x. This approach revolutionized earlier ways to determine when an infinite sequence (equivalently, characteristic function of a subset of the natural numbers) is random or not by invoking a notion of randomness for finite objects. Kolmogorov complexity became not only a subject of independent study but is also applied to other subjects as a tool for obtaining proofs. There are still many open problems in this area. For that reason, a recent research conference in this area was held in January 2007[3] and a list of open problems[4] is maintained by Joseph Miller and Andre Nies.

Frequency computation This branch of recursion theory analyzed the following question: For fixed m and n with 0