HomeSoftware DevelopmentKnuth's Up-Arrow Notation For Exponentiation

Knuth’s Up-Arrow Notation For Exponentiation


Enhance Article

Save Article

Like Article

Enhance Article

Save Article

Knuth’s up-arrow notation, also called Knuth’s arrow notation, is a mathematical notation for exponentiation that was launched by Donald Knuth in his e book “Concrete Arithmetic”. It makes use of a sequence of up-arrows () to characterize exponentiation with numerous bases and exponents.

Strategy: Exponentiation is dependent upon the variety of arrows used within the notation. Here’s a common method for every sort of exponentiation represented by the up-arrow notation.

  • One Arrow (a↑b): For any such exponentiation, the method is to multiply the bottom a by itself b occasions. That is equal to a * a * a * … * a the place there are b a‘s. .000000000000000000000000000For Instance, 5↑4 is represented as 5↑4 = 5^4 = 625
  • Two Arrows (a↑↑b): For any such exponentiation, the method is to boost the bottom a to the ability of a b occasions. That is equal to a^(a^(a^(…))) the place there are b a‘s contained in the parentheses. For Instance, 3↑↑4 is represented as 3↑↑3 = 3^(3^3) = 3^27 = 7625597484987.
  • Three or Extra Arrows: For any such exponentiation, the method is to carry out the exponentiation operation b occasions, with every exponentiation operation taking the earlier consequence as its base. The primary exponentiation is carried out utilizing the bottom a. For Instance, 2↑↑↑3 is represented as 2↑↑↑3 = 2↑↑(2↑↑2) = 2↑↑(2^2) = 2↑↑4 = (2^(2^(2^2))) = 2^16 = 65536

Beneath is the implementation of Knuth’s up-arrow notation:

C++

#embody <bits/stdc++.h>

utilizing namespace std;

typedef lengthy lengthy int lli;

  

lli knuth_arrow(int a, int ok, int b)

{

  

    

    if (b == 0)

        return 1;

    if (ok == 1)

        return pow(a, b);

  

    return knuth_arrow(a, ok - 1, knuth_arrow(a, ok, b - 1));

}

  

int foremost()

{

  

    

    cout << knuth_arrow(5, 1, 4) << endl;

  

    

    cout << knuth_arrow(3, 2, 3) << endl;

  

    

    

    cout << knuth_arrow(2, 3, 3) << endl;

    return 0;

}

Java

public class GFG {

    public static lengthy knuth_arrow(int a, int ok, lengthy b)

    {

        

        if (b == 0)

            return 1;

        if (ok == 1)

            return (lengthy)Math.pow(a, b);

        return knuth_arrow(a, ok - 1,

                           knuth_arrow(a, ok, b - 1));

    }

  

    

    public static void foremost(String[] args)

    {

        

        System.out.println(knuth_arrow(5, 1, 4));

  

        

        System.out.println(knuth_arrow(3, 2, 3));

  

        

        

        System.out.println(knuth_arrow(2, 3, 3));

    }

}

Python3

  

  

def knuth_arrow(a, ok, b):

        

    if b == 0:

        return 1

    if ok == 1:

        return a**b

    return knuth_arrow(a, ok-1, knuth_arrow(a, ok, b-1))

  

  

print(knuth_arrow(5, 1, 4))

  

print(knuth_arrow(3, 2, 3))

  

print(knuth_arrow(2, 3, 3))

Output

625
7625597484987
65536

Time Complexity: O(Okay)
Auxiliary Area: O(Okay)

RELATED ARTICLES

Most Popular

Recent Comments