×

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 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 Grid Computing

Grid computing is the group of connected computers that work together to perform large tasks or compute bigger and more complex problems. These computers are configured to act as a...

4 minutes read.

What is Application Software?

There are two types of software system software and application software. Application software is, also known as end-user software or productivity software, is designed to perform specific tasks controlled by...

5 minutes read.

What is Amazon Cognito

Amazon Cognito is a simple user identification and data synchronization solution that allows you to securely manage and synchronize app data across many devices for your users. You can keep...

6 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 WPS

WPS stands for Wi-Fi Protected Setup, created by the Wi-Fi Alliance and introduced in 2006. The network security standard helps create a secure and easy home wireless network by pressing...

3 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 CBI

CBI is the acronym for Central Bureau of Investigation. CBI is considered as India's top investigative organisation. The Ministry of Personnel, Public Grievances, and Pensions has control over the organisation...

9 minutes read.

What is BTS - Bangtan Sonyeondan

Introduction Bangtan Sonyeondan, popularly known as BTS, is a music band with members from South Korea. The band BTS was formed in 2010, and their first music album was released in...

6 minutes read.

What is MBBS, Curriculum of MBBS?

We all know MBBS refers to the doctor, but only a few of us know the full form of MBBS. The full form of the abbreviation MBBS is ‘Bachelor of...

6 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 Anxiety Disorders

Anxiety disorders refer to situations in which anxiety is permanent and doesn't go away over time. It's your brain's way of reacting to different emotions. Types of Anxiety Disorders Following are the...

4 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 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 Database?

A database is an organized collection of data that can be stored and accessed electronically. It is actually a set up for easy access, manage and update the data. Before...

9 minutes read.

What is IPS

An IPS is a type of network security tool that attempts to detect and prevent threat assaults. Intrusion prevention is designed to take a proactive approach to network security, allowing...

9 minutes read.

What is Mobile Computing

Mobile Computing is the technology that allows users to share data such as documents, audio, video, message, etc., without connecting with the central network or server or through any physical...

10 minutes read.

What is Exploit?

Define Exploit The exploit can be defined as a command’s sequence, data’s chunk, or software part that grabs benefits of vulnerability or bug in a system or application. It can result...

3 minutes read.

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...

3 minutes read.

What is Distributed Computing

The field of computer science that includes the study of distributed systems is known as distributed computing. And its main goal is to create a network of distributed computers and...

5 minutes read.