Book contents
- Frontmatter
- Contents
- Preface
- 1 An introduction to Mathematica
- 2 The Mathematica language
- 3 Lists
- 4 Patterns and rules
- 5 Functional programming
- 6 Procedural programming
- 7 Recursion
- 8 Numerics
- 9 Strings
- 10 Graphics and visualization
- 11 Dynamic expressions
- 12 Optimizing Mathematica programs
- 13 Applications and packages
- Solutions to exercises
- Bibliography
- Index
- Frontmatter
- Contents
- Preface
- 1 An introduction to Mathematica
- 2 The Mathematica language
- 3 Lists
- 4 Patterns and rules
- 5 Functional programming
- 6 Procedural programming
- 7 Recursion
- 8 Numerics
- 9 Strings
- 10 Graphics and visualization
- 11 Dynamic expressions
- 12 Optimizing Mathematica programs
- 13 Applications and packages
- Solutions to exercises
- Bibliography
- Index
Summary
Many important and classical problems in mathematics and computer science are defined, or have solutions in terms of recursive definitions: the factorial function, the natural numbers, many divide-and-conquer algorithms, and parsers for programming languages all use recursion in fundamental ways. A function is defined using recursion if in its definition, it makes calls to itself. The great advantage of recursive definitions is their simplicity and directness. Their one major drawback however, is how quickly the depth and complexity can increase to the point of making your computations intractable.
This programming paradigm is easily implemented in Mathematica in a manner that is both natural and quite efficient. In fact, many of the built-in operations of Mathematica could be written in Mathematica itself using recursion. In this chapter, we will present several examples of recursion and explain how recursive functions are written and what you can do to work around some of their potential inefficiencies.
Fibonacci numbers
Recursive definitions of mathematical quantities were used by mathematicians for centuries before computers even existed. One famous example is the definition of a special sequence of numbers first studied in the Middle Ages by the Italian mathematician Leonardo Fibonacci (ca. 1170 – ca. 1250). The Fibonacci numbers have since been studied extensively, finding application in such diverse areas as random number generation, compression algorithms, musical tunings, phyllotaxy in plants, population generation, and much more. See Knuth (1997) for a detailed discussion.
- Type
- Chapter
- Information
- Programming with Mathematica®An Introduction, pp. 231 - 250Publisher: Cambridge University PressPrint publication year: 2013