

Our treatise of recursion leads us now to another interesting case of recursion. It's as easy and elegant as the mathematical definition. Now we come to implement the factorial in Python. In other words, recursion in computer science is a method where the solution to a problem is based on solving smaller instances of the same problem. Replacing the calculated values gives us the following expression A recursion can end up in an infinite loop, if the base case is not met in the calls. A base case is a case, where the problem can be solved without further recursion. A recursive function terminates, if with every recursive call the solution of the problem is downsized and moves towards a base case. Termination condition: A recursive function has to fulfil an important condition to be used in a program: it has to terminate. If a function definition satisfies the condition of recursion, we call this function a recursive function. Usually, it is returning the return value of this function call. Recursion is a method of programming or coding a problem, in which a function calls itself one or more times in its body.

It's used so often as an example for recursion because of its simplicity and clarity.Įnjoying this page? We offer live Python training courses covering the content of this site. Most people who have done some mathematics, computer science or read a book about programming will have encountered the factorial, which is defined in mathematical terms as And this is what a recursive definition or a recursive function does: It is "running back" or returning to itself. The adjective "recursive" originates from the Latin verb "recurrere", which means "to run back". We have to stop our short excursion to the use of recursion in natural language to come back to recursion in computer science and programs and finally to recursion in the programming language Python. And if the number of sentences is infinite, the number of possible thoughts and intentions is infinite too, because virtually every sentence expresses a different thought or intention."1 Indeed, the repertoire of sentences is theoretically infinite, because the rules of language use a trick called recursion.Ī recursive rule allows a phrase to contain an example of itself, as in She thinks that he thinks that they think that he knows and so on, ad infinitum. The possible combinations quickly multiply out to unimaginably large numbers. The cognitive scientist and linguist Stephen Pinker phrases it like this: "With a few thousand nouns that can fill the subject slot and a few thousand verbs that can fill the predicate slot, one already has several million ways to open a sentence. Even with a very simple grammar rule, like "An English sentence contains a subject and a predicate, and a predicate contains a verb, an object and a complement", we can demonstrate the infinite possibilities of the natural language.

Our way of thinking is based on a recursive thinking processes. Recursion is not only a fundamental feature of natural language, but of the human cognitive capacity. We think that, you think, we convinced you now that, we can go on forever with this example of a recursion from natural language. He is sure I think I know recursion has something to do with infinity. I think I know recursion has something to do with infinity. I know recursion has something to do with infinity. Recursion has something to do with infinity.
