The Most Difficult Program to Compute? - Computerphile

Computerphile · 1.4M views · 2014 · 14:55

Open on YouTube

Computability & complexity theoryAlgorithms & data structuresUniversity lectures & coursesexplainer

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about recursion versus loops, to show that the Ackermann function is recursive but not primitive recursive, and when people try to reproduce it and hit stack overflows.

Recommended by 3 people across 3 different months, 2014 to 2020.

What it is

Computerphile video in which Professor Brailsford explains Ackermann's function as a continuation of the series on recursion. It shows how a tiny recursive definition can demand enormous amounts of computation, with a program run live as a demonstration.

What people said

Strong rec dan4thewin · 2016-01 · Stack Overflow · on “Recursion vs. Stack”

There are so-called primitive recursive functions which can be rewritten with a loop. Then there is a class of functions called recursive, which must be defined recursively. A final class is the recursively enumerable functions. The famous Ackermann function is recursive but not primitive recursive. There's an excellent video on the subject on the Computerphile youtube channel: The Most Difficult Program to Compute? [this video] Recursion can certainly be efficient. Consider that the glibc implementation of merge sort ( msort.c [LINK] ) is recursive. Note that there is a common compiler optimization for tail recursion which compiles the recursive function into a loop.

Recommends Michael Albers · 2016-11 · Stack Overflow · on “Creating a Recursive Function for Number Sequence”

Recursive functions have two "parts", the base case and the recursion. The base case is when your function stops recursing (and starts unwinding the call stack). Without the base the function just keeps calling itself until the stack overflow happens and the program is terminated by the OS. The recursive part takes the initial problem (in your case finding the ith number in a sequence) and shrinks it. This happens until the base case is hit. So for finding the ith number in a sequence, let's say the 4th, you start looking for the 4th number, but that depends on the 3rd, which depends on the 2nd which depends on the first. The initial recursion shrinks the problem from the 4th number to the 3

Recommends Christian Schnorr · 2017-02 · Stack Overflow · on “Is there a way to declare an inline function in Swift?”

@user965972 Recursive functions, for example. Note that some recursive functions can derecursed into a loop, but some functions are inherently recursive, see this great video [this video] .

Cites user1938344 · 2014-07 · Stack Overflow · on “What is the logical difference between loops and recursive functions?”

I came across this [this video] video which is discussing how most recursive functions can be written with for loops but when I thought about it, I couldn't see the logical difference between the two. I found this [LINK] topic here but it only focuses on the practical difference as do many other similar topics on the web so what is the logical difference in the way a loop and a recursion are handled?

Cites Morgan Gethin Barrett · 2015-01 · Stack Overflow · on “Who to talk to about non recursive Ackermann function?”

That was the point in the question, I was led to believe that the Ackermann function was a problem which couldn't have a iterative solution. I first heard of the Ackermann function from this video link [this video] where he clearly states that it could only be defined recursively.

Cites Matthew Franglen · 2015-02 · Stack Overflow · on “Change a Recursive function that has a for loop in it into an iterative function?”

You have a recursive function that can be summarised as this: recursive(i, j): if stopping condition: return value loop: if test current value involving recursive call passes: set value based on recursive call return value # this appears to be missing from your example (I am going to be pretty loose with the pseudo code here, to emphasize the structure of the code rather than the specific implementation) And you want to flatten it to a purely iterative approach. First it would be good to describe exactly what this involves in the general case, as you seem to be interested in that. Then we can move on to flattening the pseudo code above. Now flattening a primitive recursive function is quite

Cites Chris Huang-Leaver · 2016-02 · Stack Overflow · on “Which recursive functions cannot be rewritten using loops?”

Is *mostly* true. In other words it is not true. There are problems which cannot be done in loops, they have to be recursive. Rare, but they do exist [this video]

Cites MrVimes · 2017-09 · Stack Overflow · on “I wrote the "Ackerman" function in Visual Studio. Stack Overflow occured very quickly”

I was watching this video - [this video] on youtube, and decided it would be fun to copy that function in C# Well I ran it, and it stopped after 21 calls and around one second. The guy's program on the video has apparently been running for about 4 weeks and is still running. static int ack(int m, int n) { int answer; if (m == 0) answer = n + 1; else if (n == 0) answer = ack(m - 1, 1); else answer = ack(m - 1, ack(m, n - 1)); return answer; } static void Main(string[] args) { for (int i = 0; i < 6; i++) for (int j = 0; j < 6; j++) Console.WriteLine($"ackerman ({i},{j}) is:{ack(i, j)}"); Console.ReadLine(); } Is there something I can do to make mine run for longer? Edit: I changed from 'Debug' to '

Cites chharvey · 2019-03 · Stack Overflow · on “Simple loop Ackermann function”

Apparently, the Ackermann function is not **primitively recursive** — it’s impossible to refactor it into a loop. [this video]

Cites Ju Ko · 2019-04 · Stack Overflow · on “Avoiding Stack overflow with Ackermann function in R”

I recently saw an interesting Computerphile Video [this video] about the Ackermann function and tried to recreate it in R, here's what I came up with: Ackermann <- function(m,n){ if (m == 0){ return(n+1) } else if (m > 0 & n == 0){ return(Ackermann(m-1,1)) } else if (m > 0 & n > 0){ return(Ackermann(m-1,Ackermann(m,n-1))) } } in the video, they implemented their own version of the code (in C, I think) and explained that it takes a massive amount of recursive computation for specific value pairs such as 4,1 and it took them 3 minutes to compute that value. If I try to recreate this in R with my algorithm I get a stack overflow: Error: C stack usage 7971652 is too close to the limit Is there a way