0% found this document useful (0 votes)
1 views

Lecture3_Computability

Uploaded by

vysl.genc01
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Lecture3_Computability

Uploaded by

vysl.genc01
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

ÇUKUROVA UNIVERSITY

FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

Lecture 3: Computability

Computability: How to formally specify an algorithm?

➔ Turing (Thue, Post, Klune, Church, …)

3.1. Computability with Turing Machine

A Turing Machine (TM), thought of by the mathematician Alan Turing in 1936, is a


mathematical model which consists of an infinite length tape divided into cells on which input
is given. It consists of a head which reads the input tape. A state register stores the state of the
Turing machine. After reading an input symbol, it is replaced with another symbol, its internal
state is changed, and it moves from one cell to the right or left. If the TM reaches the final
state, the input string is accepted, otherwise rejected. Despite its simplicity, the TM can
simulate ANY computer algorithm, no matter how complicated it is!

Repetition from last week: A TM can be formally described as a 7-tuple (Ʃ, T, S, δ, s0, #, F)
where
• Ʃ is the input alphabet
• T is the tape alphabet (wheras Ʃ ⊂ 𝐓)
• S is a finite set of states
• δ is a transition function; δ : S × T → S × T × {Left_shift, Right_shift, or
no_movement}.
• s0 is the initial state
• # is the blank symbol
• F is the set of final states

CEN 345 Algorithms 1 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

TM Example: Bit Inversion


With the symbols "1 1 0" printed on the tape, let's attempt to convert the 1s to 0s and vice versa.
This is called bit inversion, since 1s and 0s are bits in binary. This can be done by passing the
following instructions to the Turing machine, utilising the machine's reading capabilities to
decide its subsequent operations on its own. These instructions make up a simple program.

TA = (Ʃ, T, S, δ, S0, #, F) with

• Ʃ = {1, 0}
• T = {1, 0, #}
• S = {s0, sf }
• S0 = {s0}
• # = blank symbol
• F = {sf }
δ is given by

Current state Symbol read Symbol written New state Move instruction
s0 Blank (#) → None sf None
s0 0 → Write 1 s0 Move tape to the right
s0 1 → Write 0 s0 Move tape to the right

The automaton will first read the symbol under the head, write a new symbol accordingly, then
move the tape left or right as instructed, before repeating the read-write-move sequence again.

Let's see what this program does to our tape from the previous end point of the instructions:

The current symbol under the head is 0, so we write a 1 and move the tape right by one square.

The symbol being read is now 1, so we write a 0 and move the tape right by one square:

Similarly, the symbol read is a 1, so we repeat the same instructions.

CEN 345 Algorithms 2 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

Finally, a 'blank' symbol is read, so the machine does nothing apart from read the blank symbol
continuously since we have instructed it to repeat the read-write-move sequence without
stopping.

After every instruction, we also specify a state for the machine to transition to. In the example,
the machine is redirected back to its original state, State 0, to repeat the read-write-move
sequence, unless a blank symbol is read. When the machine reads a blank symbol, the machine
is directed to a stop state and the program terminates.

➔ A problem is computable if there is a TM that can solve that problem.


➔ Bit Inversion problem is computable!

CEN 345 Algorithms 3 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

3.2. Computability with Queue and Pushdown automata with 2 stacks

Queue automaton (QA)

QA is similar to Pushdown Automaton (PDA) but has a queue instead of a stack which helps
Queue automaton to recognize languages beyond Context Free Languages. QA works
according to First-in First-out (FIFO) principle.

The working tape is a queue, i.e. a data structure that only allows two types of access−
• enqueue − a new symbol is added at the rear of the queue.
• dequeue − the symbol at the front of the queue is removed.

Figure 2: Design of QA

A QA is a 6-tuple (, , S, , s0, #), where


1.  is a set of finite input alphabet,
2.  is a set of finite queue alphabet,
3. S is a set of states,
4.  ⊆ S    S  *
Configuration c = (s, γ) ∈ S x *
Transition: (S  *)  (S  *) defined through
(s, Aα) ⊢ (s', αβ) iff. (s, A, s', β) ∈ , s, s' ∈ S, A∈, α, β ∈ *
5. s0 is the initial state ∈ S
6. # is the blank symbol ∈  − Σ

Example: 𝐿(𝑄𝐴) = {𝑎𝑛 𝑏𝑛 𝑐 𝑛 | 𝑛 ≥ 1} => abc, aabbcc, aaabbbccc, etc.


Idea: anbncn is processed in rounds: in each round an a, a b and a c are deleted, and all other
letters are added to the end of the word. If the word belongs to the language, the queue is
processed in n rounds. If the input word does not belong to the language, the final configuration
is not reached.
𝑄 = ({𝑎, 𝑏, 𝑐}, {𝑎, 𝑏, 𝑐, #}, {𝑠0 , 𝑠𝑎 , 𝑠𝑏 , 𝑠𝑐 }, , 𝑠0 , #)

CEN 345 Algorithms 4 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

(𝑠0 , #, 𝑠0 , ε),
(𝑠0 , 𝑎, 𝑠𝑎 , ε),
(𝑠𝑎 , 𝑎, 𝑠𝑎 , a),
(𝑠𝑎 , 𝑏, 𝑠𝑏 , ε),
=
(𝑠𝑏 , 𝑏, 𝑠𝑏 , b),
(𝑠𝑏 , 𝑐, 𝑠𝑐 , ε),
(𝑠𝑐 , 𝑐, 𝑠𝑐 , c),
{ (𝑠𝑐 , #, 𝑠0 , #) }

Input word: 𝑎2 𝑏2 𝑐 2
(𝑠0 , 𝑎2 𝑏2 𝑐 2 #) ⊢ (𝑠𝑎 , 𝑎𝑏2 𝑐 2 #) ⊢ (𝑠𝑎 , 𝑏2 𝑐 2 #𝑎) ⊢ (𝑠𝑏 , 𝑏𝑐 2 #𝑎) ⊢ (𝑠𝑏 , 𝑐 2 #𝑎𝑏) ⊢ (𝑠𝑐 , 𝑐#𝑎𝑏)
⊢ (𝑠𝑐 , #𝑎𝑏𝑐) ⊢ (𝑠0 , 𝑎𝑏𝑐#) ⊢ (𝑠𝑎 , 𝑏𝑐#) ⊢ (𝑠𝑏 , 𝑐#) ⊢ (𝑠𝑐 , #) ⊢ (𝑠0 , #) ⊢ (𝑠0 , ε)

Note: It has been proven that a queue machine is equivalent to a Turing machine by showing
that a queue machine can simulate a Turing machine and vice versa.

Furthermore, it has been proved that a PDA with 2 stacks (2PDA) is also equivalent to a Turing
machine.

Consequently (!):
In addition to Turing computability, two further computability terms are the Queue
computability and the 2PDA computability.

QA Ʃ : Queue Automat (First in First out – FIFO)


QA Ʃ = TA Ʃ

Pushdown automata (PDA) with 2 stacks (2PDA)


2PDA Ʃ = TA Ʃ

3.3. Computability with programming language approaches: LOOP, WHILE, GOTO

In this section we introduce further computability concepts. Unlike Turing machines, they are
not based on the formalization of an intuitive concept of computability, but on concepts of
procedural programming languages. We will show that goto and while computability are
equivalent to each other and to Turing computability, and that loop computability is weaker
than these.

The programming language LOOP

We first define the syntax of the LOOP programming language, then we define the semantics
of LOOP programs.

CEN 345 Algorithms 5 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

The LOOP alphabet includes:


• variables x0, xl, x2, … which serve as identifiers for memory locations, each of which
can contain a natural number,
• Constants 0, 1, 2, . . ., which serve as identifiers for natural numbers,
• the separator ;,
• the assignment symbol :=,
• the operator symbols + and -,
• the keywords read, write, loop, do, end.

Character strings with the above alphabet form syntactically correct LOOP statements if they
can only be generated with the following rules:
(i) The value assignments xi := xj + c and xi := xj - c are LOOP statements, where xi
and xj are variables, allowing i = j, and c is a constant identifier.
(ii) Let be A, A1 and A2 LOOP statements, then
a. A1; A2 and
b. loop x do A end;

are also valid LOOP statements:

If A is a LOOP statement, then

𝐫𝐞𝐚𝐝(𝑥1, 𝑥2 , … 𝑥k ); A; write (𝑥0 )

is a LOOP program.

Example LOOP program:


𝐫𝐞𝐚𝐝 (𝑥1 , 𝑥2);
𝑥0 : = 𝑥1 + 0;
loop 𝑥2 do
𝑥0 : = 𝑥0 + 1
end;
write (𝑥0 )

The programming language LOOP has no explicit selection statement, i.e., no statement of the
kind

if 𝐵 then 𝐴1 else 𝐴2 endif

CEN 345 Algorithms 6 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

where B is a condition and 𝐴1 and 𝐴2 are two statements. However, if statements can be
simulated by LOOP statements. For the instruction

if 𝑥𝑝 = 0 then 𝐴1 else 𝐴2 endif

the following LOOP statement sequence represents a possible simulation:

𝑥𝑞 ≔ 1
𝑥𝑟 ≔ 1
loop 𝑥𝑝 do 𝑥𝑞 ≔ 0 end;
loop 𝑥𝑞 do 𝐴1 ; 𝑥𝑟 ≔ 0 end;
loop 𝑥𝑟 do 𝐴2 end ;

Note: Since the counter variable in the loop body cannot be changed, it is an essential property
of LOOP programs that they always terminate. It follows that the functions computed by LOOP
programs are total.

The programming language WHILE

We add another loop statement to the LOOP programming language, the while statement, and
call the extended programming language WHILE. In contrast to the loop statement, the number
of executions of the loop body in the while statement is not fixed before the beginning of the
evaluation, but the number of executions can depend on the results of the loop body executions.
Accordingly, the loop variable in the loop body of the while statement may not only be used,
but also manipulated, i.e., it may also be "write" accessed.

while x ≠0 do A end;

The WHILE programming language is defined as follows:

i. Each LOOP statement is a WHILE statement.

ii. Let A be a WHILE statement, then

while xi ≠0 do A endwhile

is also a WHILE statement.

iii. If A is a WHILE statement, then

read(xi, , xk); A; write(x0)

a WHILE program.

CEN 345 Algorithms 7 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

The programming language GOTO

As a further programming language, we want to consider the language GOTO. In addition to


elementary statements, it does not contain any loop statements, but two jump statements.

label x; A; goto x;

In addition to symbols for variables x0, x1, … and constants c0, c1, …, the alphabet of GOTO
programming language includes symbols for labels, which we denote by l1, l2, ... (l stands for
label), as well as the keywords read, write, goto, if, then, and stop, the assignment symbol :=,
the operation symbols =, +, -, and the separators : and ;. The following statements are unmarked
GOTO statements:
i. the assignments xi := xj + ck and xi := xi - ck,
ii. (unconditional) jumps goto li,
iii. conditional jumps if xi = ci then goto lk,
iv. the stop statement stop.

If A is an unmarked goto statement and l is a mark, then

l:A

is called a marked goto statement.

A syntactically correct GOTO program consists of a sequence of marked GOTO statements


surrounded by a read and write statement:

𝐫𝐞𝐚𝐝 (𝑥1 , … , 𝑥k );
𝑙1 : = 𝐴1 ;
.
.
.
𝑙n : = 𝐴n ;
write (𝑥0)

CEN 345 Algorithms 8 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

Relationship:
 loop ⊂ while = goto = Turing computability

It is known that
 f: loop-computable functions → total computable functions

Question: How about the other direction?

 loop-computable functions  total computable functions ?



Ackermann function

3.4. Primitive Recursive Functions, Composition, µ-Recursion

Primitive Functions:

• Null function: 0: ℕ0 → ℕ0 0(𝑥) = 0

• Successor function: 𝑆: ℕ0 → ℕ0 𝑓(𝑥) = 𝑥 + 1

• Projection: π𝑘𝑖 : ℕ𝑘0 → ℕ0 π𝑘𝑖 (𝑥1 , … , 𝑥𝑘 ) = 𝑥𝑖

Defining Primitive Recursive Functions (PRFs):

Let g: ℕ𝑛0 → ℕ0, h: ℕ𝑛+2


0 → ℕ0 be primitive recursive. Then f: ℕ𝑛+1
0 → ℕ0 with

𝑓(𝑥1 , … , 𝑥𝑛 , 0) = 𝑔(𝑥1 , … , 𝑥𝑛 )

𝑓(𝑥1 , … , 𝑥𝑛 , 𝑆(𝑦)) = ℎ(𝑥1 , … , 𝑥𝑛 , 𝑦, 𝑓(𝑥1, … , 𝑥𝑛 , 𝑦))

is also primitive recursive.

PRF #1: Addition

Definition:
𝑎𝑑𝑑(𝑥, 0) = 𝑥

𝑎𝑑𝑑(𝑥, 𝑆(𝑦)) = 𝑆 (π33 (𝑥, 𝑦, 𝑎𝑑𝑑(𝑥, 𝑦)))

CEN 345 Algorithms 9 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

Example:
𝑎𝑑𝑑(2,3) = 𝑆 (π33 (2,3, 𝑎𝑑𝑑(2,2)))

= 𝑆 (π33 (2,3, 𝑆 (π33 (2,3, 𝑎𝑑𝑑(2,1)))))

= 𝑆 (π33 (2,3, 𝑆 (π33 (2,3, 𝑆 (π33 (2,3, 𝑎𝑑𝑑(2,0)))))))

= 𝑆 (π33 (2,3, 𝑆 (π33 (2,3, 𝑆(π33 (2,3,2))))))

= 𝑆 (π33 (2,3, 𝑆 (π33 (2,3, 𝑆(2)))))

= 𝑆 (π33 (2,3, 𝑆(π33 (2,3,3))))


= 𝑆 (π33 (2,3, 𝑆(3)))
= 𝑆(π33 (2,3,4))
= 𝑆(4)
=5

Composition of Primitive Recursive Functions:

Let h1, …, hn: ℕ0 → ℕ0, g: ℕ𝑛0 → ℕ0 be primitive recursive, then f: ℕ𝑘0 → ℕ0 with

𝑓(𝑥1, … , 𝑥𝑘 ) = 𝑔(ℎ1 (𝑥1 , … , 𝑥𝑘 ), ℎ2 (𝑥1 , … , 𝑥𝑘 ), … , ℎ𝑛 (𝑥1 , … , 𝑥𝑘 ))

is also primitive recursive.

or

h1, …, hn: ℕ0 → ℕ0, g: ℕ𝑛0 → ℕ0 is a primitive rekursive function, then f: ℕ𝑘0 → ℕ0 with

𝑓(𝑥1 , … , 𝑥𝑘 ) = 𝑔 ∘ (ℎ1 , ℎ2 , … , ℎ𝑛 ) (𝑥1 , … , 𝑥𝑛 )

is also primitive recursive.

PRF #2: Multiplication

CEN 345 Algorithms 10 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

Definition:

𝑚𝑢𝑙𝑡(𝑥, 0) = 0

𝑚𝑢𝑙𝑡(𝑥, 𝑆(𝑦)) = 𝑎𝑑𝑑 ∘ (π13 , π33 )(𝑥, 𝑦, 𝑚𝑢𝑙𝑡(𝑥, 𝑦))

Example:

𝑚𝑢𝑙𝑡(3,2) = 𝑎𝑑𝑑 ∘ (π13 , π33 )(3,2, 𝑚𝑢𝑙𝑡(3,1))

= 𝑎𝑑𝑑 ∘ (π13 , π33 ) (3,2, 𝑎𝑑𝑑 ∘ (π13 , π33 )(3,2, 𝑚𝑢𝑙𝑡(3,0)))

= 𝑎𝑑𝑑 ∘ (π13 , π33 )(3,2, 𝑎𝑑𝑑 ∘ (π13 , π33 )(3,2,0))


= 𝑎𝑑𝑑 ∘ (π13 , π33 )(3,2, 𝑎𝑑𝑑(3, 0))
= 𝑎𝑑𝑑 ∘ (π13 , π33 )(3,2,3)
= 𝑎𝑑𝑑(3,3)
=6

PRF #3: Subtraction

𝑥 − 𝑦, 𝑥≥𝑦
𝑠𝑢𝑏: 𝑁0 𝑥 𝑁0 → 𝑁0 𝑠𝑢𝑏(𝑥, 𝑦) = {
0, 𝑥<𝑦

To show that the sub function is primitive recursive, we need a predecessor function 𝑃. The
predecessor function 𝑃 acts as the opposite of the successor function 𝑆 and is recursively
defined by the rules:

𝑥 − 1, 𝑥≥1
𝑃: 𝑁0 → 𝑁0 𝑃(𝑥) = {
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

Definition:
𝑃(0) = 0
𝑃(𝑆(𝑥)) = π12 (𝑥, 𝑃(𝑥))

Example:
Predecessor of 4?

𝑃(𝑆(3)) = π12 (3, 𝑃(2))


= π12 (3, π12 (3, 𝑃(1)))
= π12 (3, π12 (3, π12 (3, 𝑃(0))))

CEN 345 Algorithms 11 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

= π12 (3, π12 (3, π12 (3,0)))


= π12 (3, π12 (3,3))
= π12 (3,3)
=3

With the help of the predecessor function 𝑃, now we can show that the sub function is primitive
recursive:

Definition:
𝑠𝑢𝑏(𝑥, 0) = 𝑥
𝑠𝑢𝑏(𝑥, 𝑆(𝑦)) = 𝑃 (π33 (𝑥, 𝑦, 𝑠𝑢𝑏(𝑥, 𝑦)))

Example:
𝑠𝑢𝑏(4,2) = 𝑃 (π33 (4,2, 𝑠𝑢𝑏(4,1)))

= 𝑃 (π33 (4,2, 𝑃 (π33 (4,2, 𝑠𝑢𝑏(4,0)))))

= 𝑃 (π33 (4,2, 𝑃(π33 (4,2,4))))


= 𝑃 (π33 (4,2, 𝑃(4)))
= 𝑃(π33 (4,2,3))
= 𝑃(3)
=2

PRF #4: Exponent

𝑒𝑥𝑝: 𝑁0 𝑥 𝑁0 → 𝑁0 𝑒𝑥𝑝(𝑏, 𝑦) = 𝑏 𝑦

Definition:
𝑒𝑥𝑝(𝑥, 0) = 1
𝑒𝑥𝑝(𝑥, 𝑆(𝑦)) = 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(𝑥, 𝑦, 𝑒𝑥𝑝(𝑥, 𝑦))

Example:
𝑒𝑥𝑝(2,3) = 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3, 𝑒𝑥𝑝(2,2))

= 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 ) (2,3, 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3, 𝑒𝑥𝑝(2,1)))

= 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 ) (2,3, 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 ) (2,3, 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3, 𝑒𝑥𝑝(2,0))))

= 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 ) (2,3, 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3, 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3,1)))

= 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 ) (2,3, 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3, 𝑚𝑢𝑙𝑡(2,1)))

= 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3, 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3,2))

CEN 345 Algorithms 12 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

= 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3, 𝑚𝑢𝑙𝑡(2,2))


= 𝑚𝑢𝑙𝑡 ∘ (π13 , π33 )(2,3,4)
= 𝑚𝑢𝑙𝑡(2,4)
=8

➔ Primitive Recursive Functions (PRF) = Loop-Computable Functions

µ-Operator (Mikro-Operator):

f: ℕ𝑛+1
0 → ℕ0 µ[f]: ℕ𝑛0 → ℕ0

µ[f] (𝑥1 , … , 𝑥𝑘 ) = 𝑚𝑖𝑛{𝑧 | (𝑥1 , … , 𝑥𝑛 , 𝑦) ∈ 𝐷𝑒𝑓(𝑓) 𝑓𝑜𝑟 𝑦 ≤ 𝑧 𝑎𝑛𝑑 𝑓(𝑥1 , … , 𝑥𝑛 , 𝑧) = 0}

Example:

𝑙𝑜𝑔: ℕ20 → ℕ0 𝑙𝑜𝑔𝑏 (𝑥, 𝑦) = 𝑥 − 𝑒𝑥𝑝(𝑏, 𝑦)

Assumption: b is constant. The µ-recursive computation of 𝑙𝑜𝑔: ℕ20 → ℕ0 with the following
definition:

µ[log] (𝑥) = 𝑚𝑖𝑛{𝑧 | 𝑙𝑜𝑔(𝑥, 𝑦) ∈ 𝐷𝑒𝑓(𝑓) 𝑓𝑜𝑟 𝑦 ≤ 𝑧 𝑎𝑛𝑑 𝑙𝑜𝑔(𝑥, 𝑧) = 0}

The procedure for b = 2, x = 4

µ[log] (4, 0) = 3
µ[log] (4, 1) = 2
µ[log] (4, 2) = 0  The correct result (Note: The log function is not total)

 The class that comes together by combining/nesting primitive recursion, composition,


and/or the µ-operator, is called as the class of µ-recursive functions ℙ (also referred
to as the class of partial recursive functions).

 A distinction is made between the set of µ-recursive functions that are total, i.e. ℝ.

Ackermann Function

We know that
 f: loop-computable functions → total computable functions

Question: How about the other direction?

CEN 345 Algorithms 13 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

 loop-computable functions  total computable functions ?



Ackermann function

Ackermann function, referred to as 𝑎𝑐𝑘(𝑛, 𝑚) or 𝑎𝑐𝑘𝑛 (𝑚), is defined as follows:

𝑎𝑐𝑘(0, 𝑚) = 𝑚 + 1
𝑎𝑐𝑘(𝑛, 0) = 𝑎𝑐𝑘(𝑛 − 1,1)
𝑎𝑐𝑘 (𝑛, 𝑚) = 𝑎𝑐𝑘(𝑛 − 1, 𝑎𝑐𝑘 (𝑛, 𝑚 − 1))

Example #1:

𝑎𝑐𝑘(1,2) = 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,1))


= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,0)))
= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,1)))
= 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,2))
= 𝑎𝑐𝑘(0, 3)
=4

Example #2:

𝑎𝑐𝑘(2,2) = 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(2,1))


= 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(2,0))
= 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(1,1))
= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,0)))
= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,1)))
= 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(0,2))
= 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(1,3))
= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,2)))
= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,1))))

= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,0)))))

= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,1)))))

= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,2))))


= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,3)))

CEN 345 Algorithms 14 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

= 𝑎𝑐𝑘 (1, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,3)))


= 𝑎𝑐𝑘(1, 𝑎𝑐𝑘(0,4))
= 𝑎𝑐𝑘(1,5)
= 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,4))
= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,3)))
= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,2))))

= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,1)))))

= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(1,0))))))

= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,1))))))

= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,2)))))

= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,3))))


= 𝑎𝑐𝑘 (0, 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,4)))
= 𝑎𝑐𝑘(0, 𝑎𝑐𝑘(0,5))
= 𝑎𝑐𝑘(0,6)
=7

Growth of the Ackerman function:

The Ackermann function is a tremendously increasing function. For example, for all y:

𝑎𝑐𝑘(1, 𝑦) = 𝑦 + 2,

𝑎𝑐𝑘(2, 𝑦) = 2𝑦 + 3,

𝑎𝑐𝑘(3, 𝑦) = 2𝑦+3 − 3

…2
𝑎𝑐𝑘(4, 𝑦) = 22 −3

The number of twos in the last equation is 𝑦 + 3. It applies e.g.

ack(4,0) = 16 − 3 = 13,

𝑎𝑐𝑘(4,1) = 216 − 3 = 65.533,


16
𝑎𝑐𝑘(4,2) = 22 − 3 = 265.536 − 3 > 1019.660 =?

CEN 345 Algorithms 15 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

Ackermann's function, while Turing computable, grows faster than any primitive recursive
function. The reason can be seen from the table: the index for the next value is also growing.

Properties of Ackermann function:

𝑎𝑐𝑘(𝑚, 𝑛)

𝑎𝑐𝑘𝑚 (𝑛) → Family of Ackermann functions with m=0, m=1, m=2, etc.

 It applies to all primitive recursive functions: In this sequence of Ackermann


functions, there is a particular function that grows faster than the primitive recursive
function being considered.

1. 𝑎𝑐𝑘𝑖 (𝑥) ≤ 𝑎𝑐𝑘𝑖+𝑗 (𝑥 + 𝑦), 𝑗, 𝑦 ≥ 0

2. 𝑎𝑐𝑘𝑖 (𝑥 + 1) ≤ 𝑎𝑐𝑘𝑖+1 (𝑥), 𝑥 ≥ 𝑥0

𝑎𝑐𝑘𝑖 (𝑥 + 𝑗) ≤ 𝑎𝑐𝑘𝑖+𝑗 (𝑥), 𝑥 ≥ 𝑥0  Generalization of the 2. expression above

3. ∀f ∈ loop ∃i, 𝑥0: 𝑓(𝑥) ≤ 𝑎𝑐𝑘𝑖 (𝑥), 𝑥 ≥ 𝑥0

CEN 345 Algorithms 16 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

Use the Ackerman function as benchmark

The Ackermann function, due to its definition in terms of extremely deep recursion, can be used
as a benchmark of a compiler’s ability to optimize recursion. The first use of Ackermann's
function in this way was by Yngve Sundblad, The Ackermann function. A Theoretical,
computational and formula manipulative study.

• For example, a compiler which, in analyzing the computation of A(3, 30), is able to save
intermediate values like A(3, n) and A(2, n) in that calculation rather than recomputing
them, can speed up computation of A(3, 30) by a factor of hundreds of thousands.

• Also, if A(2, n) is computed directly rather than as a recursive expansion of the form
A(1, A(1, A(1,...A(1, 0)...))), this will save significant amounts of time.

• Instead, shortcut formulas such as A(3, n) = 8×2n-3 are used as an optimization to


complete some of the recursive calls.

Conclusion:

So far, we have seen five formal concepts for the notion of computability: Turing, loop, while
and goto computability as well as µ-recursive functions. Turing computability starts from an
intuitive understanding of computability, 'calculating with pencil and paper'. Loop, while, and
goto computability are programming language-like concepts, and the µ-recursive functions
describe computability using only mathematical functions.

Note that they are many other computability concepts available, including Universal Register
Machines (URM), λ calculus, and Markov.

Church’s thesis: The class of functions that can be calculated in the intuitive sense is precisely
the class of functions that can be calculated by Turing-computable (and thus while-, goto,
Queue-, 2PDA-computable, …) functions.

CEN 345 Algorithms 17 Assoc. Prof. Dr. Fatih ABUT


ÇUKUROVA UNIVERSITY
FACULTY OF ENGINEERING
COMPUTER ENGINEERING DEPARTMENT

Homework:

1) Design a TM to add 1 to a binary number (with a 0 in front)

2) Show that the following functions are computable via PRF!

1, 𝑥≥1
𝑠𝑖𝑔𝑛: 𝑁0 → 𝑁0 𝑠𝑖𝑔𝑛(𝑥) = {
0 𝑥=0
1, 𝑥 = 𝑦
𝑒𝑞𝑢𝑎𝑙: 𝑁0 𝑥 𝑁0 → 𝑁0 𝑒𝑞𝑢𝑎𝑙(𝑥, 𝑦) = {
0 𝑥 ≠𝑦

fac(𝑛) = 𝑛!

3) Calculate 𝑎𝑐𝑘(2,3) = ?

CEN 345 Algorithms 18 Assoc. Prof. Dr. Fatih ABUT

You might also like