How to resolve the algorithm Sudan function step by step in the BQN programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sudan function step by step in the BQN programming language
Table of Contents
Problem Statement
The Sudan function is a classic example of a recursive function, notable especially because it is not a primitive recursive function. This is also true of the better-known Ackermann function. The Sudan function was the first function having this property to be published. The Sudan function is usually defined as follows (svg):
F
0
( x , y )
= x + y
F
n + 1
( x , 0 )
= x
if
n ≥ 0
F
n + 1
( x , y + 1 )
=
F
n
(
F
n + 1
( x , y ) ,
F
n + 1
( x , y ) + y + 1 )
if
n ≥ 0
{\displaystyle {\begin{array}{lll}F_{0}(x,y)&=x+y\F_{n+1}(x,0)&=x&{\text{if }}n\geq 0\F_{n+1}(x,y+1)&=F_{n}(F_{n+1}(x,y),F_{n+1}(x,y)+y+1)&{\text{if }}n\geq 0\\end{array}}}
Write a function which returns the value of F(x, y).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sudan function step by step in the BQN programming language
Source code in the bqn programming language
_sudan←{
x 0 _𝕣 y: x + y;
x n _𝕣 0: x;
x n _𝕣 y: k (n-1)_𝕣 y+k←x𝕊y-1
}
•Show "⍉(↕7) 0 _sudan⌜ ↕6:"
•Show ⍉(↕7) 0 _sudan⌜ ↕6
•Show "⍉(↕7) 1 _sudan⌜ ↕6:"
•Show ⍉(↕7) 1 _sudan⌜ ↕6
•Show "1 2 _sudan 1: "∾•Fmt 1 2 _sudan 1
•Show "2 2 _sudan 1: "∾•Fmt 2 2 _sudan 1
•Show "1 3 _sudan 1: "∾•Fmt 1 3 _sudan 1
You may also check:How to resolve the algorithm Exponentiation order step by step in the Python programming language
You may also check:How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Pascal programming language
You may also check:How to resolve the algorithm Empty program step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Constrained random points on a circle step by step in the Scala programming language