Skip to main content Accessibility help
×
Hostname: page-component-848d4c4894-wzw2p Total loading time: 0 Render date: 2024-06-05T12:16:20.536Z Has data issue: false hasContentIssue false

7 - Recursion

Published online by Cambridge University Press:  05 February 2013

Get access

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 - 250
Publisher: Cambridge University Press
Print publication year: 2013

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Recursion
  • Paul Wellin
  • Book: Programming with <I>Mathematica</I>®
  • Online publication: 05 February 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9780511972942.008
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Recursion
  • Paul Wellin
  • Book: Programming with <I>Mathematica</I>®
  • Online publication: 05 February 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9780511972942.008
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Recursion
  • Paul Wellin
  • Book: Programming with <I>Mathematica</I>®
  • Online publication: 05 February 2013
  • Chapter DOI: https://doi.org/10.1017/CBO9780511972942.008
Available formats
×