×

What is Ackermann Function?

The Wilhelm Ackermann-inspired Ackermann function is one of the simplest and earliest examples of a complete computable function that is not basic recursive in computability theory. Although the Ackermann function demonstrates that not all total computable functions are primitive recursive, all primitive recursive functions are total and computable. The "Ackermann function" today refers to any of the many variations of the original function that were created after Ackermann published his function (which had three nonnegative integer arguments). Carry on reading to understand more about this.

Definition of Ackerman Function

As a result of several authors modifying Ackermann's function, which had three nonnegative integer arguments when it was first published, "the Ackermann function" nowadays might refer to any of the many different iterations of the original function. The two-argument Ackermann-Péter function, one popular variant, is defined as follows for nonnegative integers m and n:

A ( 0 , n ) = n + 1
A(m+1,0)=A(m,1)
A(m+1,n+1)=A(m,A(m+1,n))

Let's use a problem to clarify the definition.

 Ackermanfun(1, 2)

Solution:

  1. The given issue is ACKERMANFUN (1, 2)
  2. In this case, m = 1 and n = 2, hence m > 0 and n > 0
  3. Applying the Ackermann function's third condition, ACKERMANFUN(1, 2) = ACKERMANFUN(0, ACKERMANFUN(1, 1)), results. ———- (1)
  4. Now let's use the third condition of the Ackermann function, ACKERMANFUN(1, 1) = ACKERMANFUN(0, ACKERMANFUN(1, 0))———- (2)
  5. Applying the second criterion of the Ackermann function, ACKERMANFUN(1, 0) = ACKERMANFUN (0, 1) ———- (3)
  6. Applying the first condition of the Ackermann function, ACKERMANFUN(0, 1) = 1 + 1 = 2
  7. Add this value to equation 3 now.
  8. Hence ACKERMANFUN(1, 0) = 2
  9. After that, enter this value into equation 2: ACKERMANFUN(1, 1) = ACKERMANFUN(0, 2) ———- (4)
  10.  Let's now use the first condition of the Ackermann function, which is ACKERMANFUN(0, 2) = 2 + 1 = 3
  11.  Add this value to equation 4 now, ACKERMANFUN(1,1)=3
  12.  After that, enter this value into equation 1: ACKERMANFUN(1, 2) = ACKERMANFUN(0, 3) ———- (5)
  13.  Applying the first condition of the Ackermann function, ACKERMANFUN(0, 3) = 3 + 1 = 4
  14.  Add this value to equation 5 now.
  15.  So, ACKERMANFUN(1, 2) = 4.

Let’s understand the above idea with implementation of codes.

Example 1:

// C++ program to illustrate Ackermann function
#include <iostream>
using namespace std;


int ackermanfun(int m, int n)
{
	if (m == 0){
		return n + 1;
	}
	else if((m > 0) && (n == 0)){
		return ackermanfun(m - 1, 1);
	}
	else if((m > 0) && (n > 0)){
		return ackermanfun(m - 1, ackermanfun(m, n - 1));
	}
}


// Driver code
int main()
{
	int VALUE;
	VALUE = ackermanfun(1, 2);
	cout << VALUE << endl;
	return 0;
}

Output:

What is Ackerman Function

Example 2:

// C program to illustrate Ackermann function
#include <stdio.h>
int ackermanfun(int m, int n)
{
	if (m == 0){
		return n+1;
	}
	else if((m > 0) && (n == 0)){
		return ackermanfun(m-1, 1);
	}
	else if((m > 0) && (n > 0)){
		return ackermanfun(m-1, ackermanfun(m, n-1));
	}
}


int main(){
	int VALUE;
	VALUE = ackermanfun(1, 2);
	printf("%d", VALUE);
	return 0;
}

Output:

What is Ackerman Function

Example 3:

// Java program to illustrate Ackermann function
class bn
{
	static int ackermanfun(int m, int n)
	{
		if (m == 0)
		{
			return n + 1;
		}
		else if((m > 0) && (n == 0))
		{
			return ackermanfun(m - 1, 1);
		}
		else if((m > 0) && (n > 0))
		{
			return ackermanfun(m - 1, ackermanfun(m, n - 1));
		}else
		return n + 1;
	}
	public static void main(String args[])
	{
		System.out.println(ackermanfun(1, 2));
	}
}

Output:

What is Ackerman Function

Example 4:

// C# program to illustrate Ackermann function
using System;
class bn
{
	static int ackermanfun(int m, int n)
	{
		if (m == 0)
		{
			return n + 1;
		}
		else if((m > 0) && (n == 0))
		{
			return ackermanfun(m - 1, 1);
		}
		else if((m > 0) && (n > 0))
		{
			return ackermanfun(m - 1, ackermanfun(m, n - 1));
		}else
		return n + 1;
	}
	public static void Main()
	{
		
		Console.WriteLine(ackermanfun(1, 2));
	}
}

Output:

What is Ackerman Function

Example 5:

# Python program to illustrate Ackermann function
def A(m, n, s ="% s"):
	print(s % ("A(% d, % d)" % (m, n)))
	if m == 0:
		return n + 1
	if n == 0:
		return A(m - 1, 1, s)
	n2 = A(m, n - 1, s % ("A(% d, %% s)" % (m - 1)))
	return A(m - 1, n2, s)


print(A(1, 2))

Output:

What is Ackerman Function

Related Topics

What is Emotion?

Emotion is a strong feeling aroused in human beings for somebody or something. Basically, it is a psychological phenomenon that influences our thought and behaviour. There are different theories regarding...

4 minutes read.

What is GDP

What is GDP GDP stands for Gross Domestic Product. It refers to the market value of final goods and services that are produced within the domestic territory of a country during...

7 minutes read.

What is NASA

Introduction National Aeronautics and Space Administration, commonly known as NASA, is an independent agency working in Space Exploration and developing advanced technologies for the aviation industry. Ever since it was established,...

8 minutes read.

What is Computer Engineering?

Computer Engineering Topics Covered What is computer Engineering?What does computer engineers do?Application of Computer EngineeringHow to become computer Engineer What is Computer Engineering? Computers and humans are connected in such a way that today...

7 minutes read.

What is the Difference between Sensors and Actuators?

In an embedded system, the sensor and actuator collaborate and depend on one another. They are employed to automate processes and make a system more reliable. The main difference between...

5 minutes read.

What is BBA, Full Form, Courses, Subjects, Colleges, Fee 2024

BBA (Bachelor of Business Administration) We'll provide in-depth details of the B.B.A. course in this report. It is a basic education program in the business. This technical course is valid for...

6 minutes read.

What is Interpreted Language?

As we all use a language to communicate with each other. But a machine does not understand the language we speak. Instead, it understands the only binary language. So, we...

3 minutes read.

What is FSSAI?

The Food Safety and Standards Authority of India (FSSAI) is a legal agency formed by the Government of India's Ministry of Health and Family Welfare. The Food Safety and Standards...

5 minutes read.

What is Scanner?

A scanner is a hardware input gadget that peripherally renders or reads a given image and transforms it into a digital format, one which is accessible by computer. It was first...

4 minutes read.

What is Graphics?

Graphics can be described as sketches, drawings, or pictorial representations of some pitchy or significant data. They are used when specific images or pictures are needed to be exploited. It...

4 minutes read.

What is PCS?

This tutorial will briefly learn about the various full forms of PCS including their definition, history, functions, overviews, vision and other detailed information. (i) PCS: Provincial Civil Service The full form of...

3 minutes read.

What is IAS: Roles and Responsibilities

What is IAS? IAS stands for Indian Administrative Service. During colonial rule, IAS was known as the Imperial Civil Service (ICS). From the three arms of All India Services, the IAS...

6 minutes read.

What is Wi-Fi?

We all come across the term Wi-Fi in our daily lives, mobiles, laptops, and everywhere Wi-Fi is supported. It is a piece of wireless networking equipment through which we can...

4 minutes read.

What is DDoS Attack?

Distributed Denial of Service (DDoS) attack is an advanced version of a DoS attack and one of the most dangerous cyber threats. Here distributed tells that the attack sources are...

19 minutes read.

What is system software?

System software is a computer program that provides an interface between the application software and the computer hardware. This software is designed to control the computer itself and is built...

5 minutes read.

What is AGP (Accelerated Graphics Port)

AGP stands for “Accelerated Graphics Port”. It is a point to point channel that can provide high-speed visual output. This is used to connect graphic cards to a computer's motherboard....

3 minutes read.

What is TRP

TRP is better known as Television Rating Point or Target Rating Point. A target rating point (TRP) is a marketing and advertising measurement. Comparing impressions of a campaign or advertisement on...

8 minutes read.

What is BC?

Arithmetic operations are the simplest operation that we can perform in a programming language. When we start learning a certain language, we clear our basics through these operations only, and...

4 minutes read.

What is Direct Selling

As the name suggests, direct selling is the new business model that is free from the middlemen or intermediaries like distributor, the wholesaler, and the fixed retail stores who are...

6 minutes read.

What is USB

Definition USB stands for universal serial bus, and it is a technology that allows computers to communicate with other devices. The USB standard was created by many American corporations, including IBM,...

7 minutes read.