Download as pdf or txt
Download as pdf or txt
You are on page 1of 63

BIL308 - Biçimsel Diller ve

Otomata Teorisi

Lecture 8: Turing Machine


Assist. Prof. Dr. Duygu SİNANÇ TERZİ

Amasya University
Faculty of Engineering
Department of Computer Engineering
In-class Test - 7

2
Answer of In-class Test - 7

3
Answer of In-class Test - 7

4
Turing Machine

5
Turing Machine
◎ Around 1936, when there were no computers, Alen Turing proposed a model of
an abstract machine called the Turing machine which could perform any
computational process carried out by the present day’s computer.
◎ The Turing machine is the machine format of unrestricted language, i.e., all
types of languages are accepted by the Turing machine.
◎ Based on the Turing machine, a new theory called the ‘theory of undecidable
problems’ is developed. These types of problems cannot be solved by any
computer.

6
Turing Machine

7
Mechanical Diagram of Turing Machine

8
Mechanical Diagram of TM
◎ A TM consists of an input tape, a read–write head, and finite control.
◎ The input tape contains the input alphabets with an infinite number of blanks at the
left and the right hand side of the input symbols.
◎ The read–write head reads an input symbol from the input tape and sends it to the
finite control. The machine must be in some state.
◎ In the finite control, the transitional functions are written. According to the present
state and the present input, a suitable transitional function is executed. Upon
execution of a suitable transitional function, the following operations are
performed.
○ The machine goes into some state.
○ The machine writes a symbol in the cell of the input tape from where the input
symbol was scanned.
○ The machine moves the reading head to the left or right or halts.
9
Two-way FA vs TM
◎ Two-way finite automata has a movement in both the left and right side like
the TM. But, in the TM, both the read and write operations are done from and
on the input tape, but for two-way finite automata only the read operation is
done, and no write operation is done.
◎ A string is accepted by a TM if the string is totally traversed and the machine
halts. A string is accepted by a two-way finite automata if the string is totally
traversed and the machine reaches to a final state.

10
Instantaneous Description (ID) of TM
The ID of the TM remembers the following at a given instance of time.

◎ The contents of all the cells of the tape, starting from the rightmost cell up to
at least the last cell, containing a non-blank symbol and containing all cells up
to the cell being scanned
◎ The cell currently being scanned by the read–write head
◎ The state of the machine

11
Instantaneous Description (ID) of TM – Example1

12
Instantaneous Description (ID) of TM – Example1

13
Instantaneous Description (ID) of TM – Example1

14
Instantaneous Description (ID) of TM – Example2

15
Instantaneous Description (ID) of TM – Example2

16
Instantaneous Description (ID) of TM – Example2

17
Instantaneous Description (ID) of TM – Example2

18
Instantaneous Description (ID) of TM – Example2

19
Instantaneous Description (ID) of TM – Example2

20
Instantaneous Description (ID) of TM – Example2

21
Instantaneous Description (ID) of TM – Example2

22
Instantaneous Description (ID) of TM – Example2

23
Instantaneous Description (ID) of TM – Example3

24
Instantaneous Description (ID) of TM – Example3

25
Instantaneous Description (ID) of TM – Example3

26
Instantaneous Description (ID) of TM – Example3

27
Instantaneous Description (ID) of TM – Example3

28
Instantaneous Description (ID) of TM – Example3

29
Instantaneous Description (ID) of TM – Example4

30
Instantaneous Description (ID) of TM – Example4
• For each ‘a’, search for ‘b’ and ‘c’ and again traverse back to the left to search
for the leftmost ‘a’.
• ‘a’ is replaced by ‘X’, ‘b’ is replaced by ‘Y’, and ‘c’ is replaced by ‘Z’.
• When all the ‘a’ are traversed and replaced by ‘X’, the machine traverses the
right side to find if any untraversed ‘b’ or ‘c’ is left or not.
• If not, the machine gets Y and Z and at last a blank.
• Upon getting the blank symbol, the machine halts.

31
Instantaneous Description (ID) of TM – Example4

32
Instantaneous Description (ID) of TM – Example4

33
Instantaneous Description (ID) of TM – Example5

34
Instantaneous Description (ID) of TM – Example5
• For each ‘a’, there are two ‘b’s.
• Getting ‘a’ in initial state, replace it by X with the state changed and traverse
right.
• Getting first ‘b’, replace it by Y with the state changed and traverse right to
replace the second ‘b’ by ‘Y’.
• Then, traverse left. By this process, if it gets Y in initial state, it means no ‘a’ is
left.
• Traverse right to check whether any ‘b’ is left or not. If not, halt.

35
Instantaneous Description (ID) of TM – Example5

36
Instantaneous Description (ID) of TM – Example6

37
Instantaneous Description (ID) of TM – Example6
• The TM does the concatenation operation on two strings.
• These two strings are placed on the tape of the TM separated by the blank
symbol B.
• After traversal, the blank symbol is removed and the two strings are
concatenated.

38
Instantaneous Description (ID) of TM – Example6

39
Instantaneous Description (ID) of TM – Example6

40
Instantaneous Description (ID) of TM – Example7

41
Instantaneous Description (ID) of TM – Example7

42
Instantaneous Description (ID) of TM – Example8

43
Instantaneous Description (ID) of TM – Example8

44
Instantaneous Description (ID) of TM – Example9

45
Instantaneous Description (ID) of TM – Example9
• An infinite loop means the machine does not halt.
• It can be designed in the following way.
• Let the string consist of only ‘a’. If ‘a’ is traversed in state q1, the machine
moves right.
• After all the ‘a’ of the string are traversed, B is traversed and the machine
moves left and changes the state to q2.
• Getting ‘a’ in state q2, the machine moves left again to find the beginning of
the string.
• When the machine gets ‘B’, it moves right again with changed state from q2 to
q1.
• This process continues and the machine falls in an infinite loop.
46
Instantaneous Description (ID) of TM – Example9

47
Transitional Representation of TM
◎ In the graphical notation of the TM, there are states.
◎ Among them, a circle with an arrow indicates a beginning state and a state
with double circle indicates a final state, where the machine halts finally.
◎ The state transitions are denoted by arrows.
◎ The labels of the state transitions consist of the input symbol, the symbol
written on the tape after traversal, and the direction of movement of the read–
write head (left, right, or halt).

48
Transitional Representation of TM – Example1

49
Transitional Representation of TM – Example1

50
Transitional Representation of TM – Example2

51
Transitional Representation of TM – Example2

52
Non-deterministic Turing Machine
◎ Unlike a deterministic TM, which follows a single deterministic transition from
one state to another, an non-deterministic TM can have multiple possible
transitions for a given input symbol and machine state.
◎ Non-deterministic TM are mainly used in theoretical discussions and proofs,
such as establishing theorems about computational complexity classes.
◎ They help in understanding the theoretical limits and capabilities of
computation.

53
Non-deterministic Turing Machine - Example

54
Non-deterministic Turing Machine - Example
In regular expression, it can be written as (a+b)*abb(a+b)*. In this expression, the
substring is important. The string may be abb only. In that case, the machine gets ‘a’ as
input in the beginning state. Before traversing the substring ‘abb’, there is a chance to
traverse ‘a’ of {a, b}*. The transitional functions are:

55
Conversion of RE to TM
◎ Regular expression can be converted to an equivalent TM.
◎ The process is as follows.
• Convert the regular expression to an equivalent automata without the ∈
move.
• Change both the initial and final states of the automata to an
intermediate state.
• Insert a new initial state with a transition (B, B, R) to the automata’s initial
state.
• Convert the transitions with label ‘ip’ to (ip, ip, R).
• Insert a new final state with a transition (B, B, R) from the automata’s final
state to the new final state.

56
Conversion of RE to TM - Example

57
Conversion of RE to TM - Example

58
Conversion of RE to TM - Example

59
Conversion of RE to TM - Example

60
Minsky Theorem
◎ Any language accepted by a two-stack PDA can also be accepted by some TM
and vice versa.
◎ Minsky's Theorem is a foundational result in theoretical computer science,
illustrating the power and flexibility of different computational models.
◎ It underscores the idea that even with seemingly limited resources, one can
achieve the full computational power of a TM.

61
Minsky Theorem - Example
Design PDA and TM for
L= {𝑎𝑛 𝑏 𝑛 𝑐 𝑛 𝑑𝑛 , 𝑛 ≥ 1}.

62
Minsky Theorem - Example
PDA TM

Traversing ‘a’, X are put into stack Mark an 'a' (replace it with X),
S1. Traversing ‘b’ with the stack then move right to find the first
top ‘X’ in S1, ‘X’ is popped from S1, 'b', mark it (replace it with Y), then
and ‘Y’ is pushed into S2. move right to find the first 'c',
Traversing ‘c’ with the stack top mark it (replace it with Z), then
‘Y’ in S2, ‘Y’ is popped from S2, move right to find the first 'd', and
and ‘Z’ is pushed into S1. mark it (replace it with W). Repeat
Traversing ‘d’, ‘Z’ is popped from the marking phase until all 'a's,
S1. 'b's, 'c's, and 'd's are marked.

63

You might also like