1 Theory of Digital Computation Course material for undergraduate students on IT Department of...

84
1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary 2002

Transcript of 1 Theory of Digital Computation Course material for undergraduate students on IT Department of...

Page 1: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

1

Theory of Digital Computation

Course material for undergraduate students on IT

Department of Computer ScienceUniversity of Veszprem

Veszprem, Hungary

2002

Page 2: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

2

T heory o f D ig ita l C om puta tio n

Navigation Tools

Navigation buttons at the bottom of each page make easy to jump to:

Previous page

Previous chapter

Table of Contents

Next chapter

Next page

The title of the chapter is shown above the title of the page.

Véges automatákNavigation

Page 3: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

3

T heory o f D ig ita l C om puta tio n

Table of Contents

Alphabets and Languages

Finite Automata

Context-free Languages

Turing Machines

Universal Turing Machines

Examples

Problems

Table of Contents

Page 4: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

4

T heory o f D ig ita l C om puta tio n

Alphabets and Languages

Alphabet is a finite set of symbols.

A string over an alphabet is a finite sequence of symbols from the alphabet.

A string may have no symbols at all in this case it is called the empty string and is denoted by e.

The length of a string w, w, is its length as a sequence.

Alphabets and Languages

E xam p le s

Page 5: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

5

T heory o f D ig ita l C om puta tio n

Two strings over the same alphabet can be combined to form a third by the operation concatenation. The concatenation of strings x and y, written xy or simply xy, is the string x followed by the string y:

w(j) = x(j) for j = 1,...,x

w(x+ j) = y(j) for j = 1,...,y

If w = xy then w=x+y.

Alphabets and Languages

E xam p le s

Page 6: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

6

T heory o f D ig ita l C om puta tio n

A string v is a substring of w iff there are strings x and y such that w = xvy.

The reversal of a string w, denoted by wR, is the string “spelling backwards”:

If w= 0, then wR = w = e.

If w= n+1 (>0), then w = ua for some a, and wR = auR.

Any set of string over an alphabet is called language.

Alphabets and Languages

E xam p le s

E xam p le s

Page 7: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

7

T heory o f D ig ita l C om puta tio n

Closure or Kleene star is a language operation of a single language L, denoted by L*.

L* is the set of all strings obtained by concatenating zero or more strings from L.

Alphabets and Languages

E xam p le s

Page 8: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

8

T heory o f D ig ita l C om puta tio n

DefinitionA string over alphabet ( , ) , Ø , , *} is a regular expression over alphabet if it satisfies the following conditions.

(1) Ø and each element of is a regular expression

(2) If and are regular expressions then so is ()

(3) If and are regular expressions then so is ()

(4) If is a regular expression, then so is *.

(5) Nothing is a regular expression unless it follows from (1) through (4).

Alphabets and Languages

E xam p le s

Page 9: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

9

T heory o f D ig ita l C om puta tio n

Every regular expression represents a language.

Formally, the relation between regular expressions and the corresponding languages is established by function L, where L() is the language represented by regular expression .

Thus, L is a function from strings to languages.

Alphabets and Languages

Page 10: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

10

T heory o f D ig ita l C om puta tio n

Function L is defined as follows.

(1) L(Ø) = Ø and L() = a for each = a

(2) If and are regular expressions, then L( () ) = L()L().

(3) If and are regular expressions, then L( () ) = L()L().

(4) If is a regular expression then L(*) = L()*.

Alphabets and Languages

E xam p le s

Page 11: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

11

T heory o f D ig ita l C om puta tio n

Finite Automata

Finite Automata

DefinitionDeterministic finite automaton (DFA) is a quintuple M = (K, , , s, F)

where

K is the set of states (finite set),

is an alphabet,

s K is the initial state,

F is the set of final states (F K), and

, the transition function, is a function from K to K.

E xam p le s

Page 12: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

12

T heory o f D ig ita l C om puta tio n

Graphical representation of a DFA: state diagram

state p:

- initial state q:

- final state r:

transition (p, b) = q:

E xam p le s

Finite Automata

Page 13: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

13

T heory o f D ig ita l C om puta tio n

A configuration of a DFA is determined by the current state and the unread part of input. In other words, a configuration of a deterministic finite automaton (K, , , s, F) is an element of K*.

If (q, w) and (q’, w’) are two configurations of M, then (q, w) ├─M (q’, w’) iff w = w’ for some symbol , and

(q, ) = q’. In this case, we say that configuration (q, w) yields configuration (q’, w’) in one step.

Finite Automata

E xam p le s

E xam p le s

Page 14: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

14

T heory o f D ig ita l C om puta tio n

We denote the reflexive, transitive closure of ├─M by ├─M*;

(q, w) ├─M* (q’, w’) is read, configuration (q, w) yields

configuration (q’, w’).

A string w * is said to be accepted by M iff there is a state qF such that (s, w) ├─M* (q, e).

The language accepted by M, L(M), is the set of all strings accepted by M.

Finite Automata

E xam p le s

E xam p le s

E xam p le s

Page 15: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

15

T heory o f D ig ita l C om puta tio n

DefinitionNon-deterministic finite automaton (NFA) is a quintuple M = (K, , , s, F)

where

K is the set of states (finite),

is an alphabet,

s K is the initial state,

F is the set of final states (F K),and

, the transition relation, is a finite subset of K×*×K.

Finite Automata

Page 16: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

16

T heory o f D ig ita l C om puta tio n

Graphical representation of a NFA: state diagram

state p:

- initial state q:

- final state r:

transition (p, ba,q) :

Finite Automata

E xam p le s

Page 17: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

17

T heory o f D ig ita l C om puta tio n

A configuration of M is an element of K×*.

The relation ├─M (yields in one step) between

configurations is defined as follows: (q, w) ├─M (q’, w’) iff

there is a u * such that w = uw’ and (q, u, q’) .

├─M* is the reflexive, transitive closure of ├─M.

w * is accepted by M iff there is a state q F such that (s, w)├─M*(q, e).

The language accepted by M, L(M), is the set of all strings accepted by M.

Finite Automata

E xam p le s

Page 18: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

18

T heory o f D ig ita l C om puta tio n

DefinitionFinite automata M1, and M2 are said to be equivalent iff

L(M1) = L(M2).

TheoremFor each non-deterministic finite automaton, there is an equivalent deterministic finite automaton.

(No proof here)

Finite Automata

Page 19: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

19

T heory o f D ig ita l C om puta tio n

TheoremLanguages accepted by finite automata are closed under union.

Proof:

Let NFA M1= (K1, , 1, s1, F1) and M2= (K2, , 2, s2, F2).

NFA M = (K, , , s, F) will be given such that L(M) = L(M1) L(M2).

s is a new state not in K1K2,

K = K1K2s, (K1 and K2 are disjoint.)

F = F1 F2, and

= 12(s, e, s1), (s, e, s2).

Finite Automata

Page 20: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

20

T heory o f D ig ita l C om puta tio n

TheoremLanguages accepted by finite automata are closed under concatenation.

Proof:

L(M) = L(M1) ○ L(M2)

Construct a NFA M = (K, , , s, F), where

K = K1K2

(K1 and K2 are disjoint.)

s = s1

F = F2

= 12(F1 {e} {s2}).

Finite Automata

Page 21: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

21

T heory o f D ig ita l C om puta tio n

TheoremLanguages accepted by finite automata are closed under Kleen-star.

Proof:

L(M) = L(M1)*

Construct a NFA M = (K, , , s, F), where

K = K1s

s is a new state not in K1

F = F1s

= 1(F {e} {s1})

Finite Automata

Page 22: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

22

T heory o f D ig ita l C om puta tio n

TheoremLanguages accepted by finite automata are closed under complementation.

Proof:

L(M) = L(M1)

Construct a DFA M = (K, , , s, F)

K = K1

s = s1

F = K1 - F1

= 1

Finite Automata

Page 23: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

23

T heory o f D ig ita l C om puta tio n

TheoremLanguages accepted by finite automata are closed under intersection.

Proof:

L(M) = L(M1) L(M2)

Construct a DFA M

L(M) = * - ((* - L(M1)) ( * - L(M2))).

Note:

L(M1) L(M2) = L(M1) L(M2)

Finite Automata

Page 24: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

24

T heory o f D ig ita l C om puta tio n

TheoremThere is an algorithm for answering the following question:Given a finite automaton M, is L(M) = * ?

Proof:

- Tracing the state diagram can answer the question wheather L(M’) = .

- L(M) = * iff L(M) = .

- L(M’) = L(M).

Finite Automata

Page 25: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

25

T heory o f D ig ita l C om puta tio n

TheoremThere is an algorithm for answering the following question:Given two finite automata M1 and M2, is L(M1) L(M2)?

Proof:

L(M1) L(M2) iff

(*-L(M2)) L(M1) = .

Finite Automata

Page 26: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

26

T heory o f D ig ita l C om puta tio n

TheoremThere is an algorithm for answering the following question:Given two finite automata M1 and M2, is L(M1) = L(M2) ?

Proof:

L(M1) = L(M2) iff

(L(M1) L(M2) and L(M2) L(M1)).

Finite Automata

Page 27: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

27

T heory o f D ig ita l C om puta tio n

Context-free Languages

Context-free Languages

DefinitionA context-free grammar (CFG) G is a quadruple (V, , R, S), where

V is an alphabet,

(the set of terminals) is a subset of V,

R (the set of rules) is a finite subset of (V-)V*, and

S (the start symbol) is an element of V-.

The members of V- are called non-terminals.

Page 28: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

28

T heory o f D ig ita l C om puta tio n

For A V- and u V*, A G u if (A, u) R.

For any strings u, v V*, u G v if there are strings

x, y, v’ V* and A V- such that u = xAy, v = xv’y and A G v’.

Relation G* is the reflexive, transitive closure of G.

Language generated by G, is L(G) = {w *: S G* w}; we

also say that G generates each string in L(G).

Context-free Languages

E xam p le s

E xam p le s

Page 29: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

29

T heory o f D ig ita l C om puta tio n

DefinitionA language L is a context-free language if it is equal to L(G) for some context-free grammar G.

DefinitionA context-free grammar G = (V, , R, S) is regular iff R (V-) *((V-) e).

Context-free Languages

Page 30: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

30

T heory o f D ig ita l C om puta tio n

TheoremContext-free languages are closed under union.

Proof:

Let G1 = (V1, 1, R1, S1) and G2 = (V2, 2, R2, S2) context-free grammars, V1-1 and V2-2 disjoint.

CF grammar G = (V, , R, S) will be given such thatL(G) = L(G1) L(G2)

V = V1 V2 {S}

= 1 2

R = R1 R2 {S S1, S S2}

S = a new symbol not in V1 V2.

Context-free Languages

Page 31: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

31

T heory o f D ig ita l C om puta tio n

TheoremContext-free languages are closed under concatenation.

Proof:

L(G) = L(G1) L(G2)

Construct CF grammar G = (V, , R, S)

V = V1 V2 {S}

(V1-1 and V2-2 are disjoint.)

= 1 2

R = R1 R2 {S S1S2}

S = a new symbol not in V1 V2.

Context-free Languages

Page 32: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

32

T heory o f D ig ita l C om puta tio n

TheoremContext-free languages are closed under Kleen-star.

Proof:

L(G) = L(G1)*

Construct CF grammar G = (V, , R, S)

V = V1

= 1

R = R1 {S1 e, S1 S1S1}

S = S1

Context-free Languages

Page 33: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

33

T heory o f D ig ita l C om puta tio n

DefinitionA pushdown automaton (PDA) is a sixtuple M = (K, , , , s, F), where

K is a finite set of states,

is an alphabet (the input symbols),

is an alphabet (the stack symbols),

s is the initial state (s K),

F is the set of final states (F K), and

is the transition relation, is a finite subset of (K**)(K*).

Context-free Languages

Page 34: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

34

T heory o f D ig ita l C om puta tio n

Graphical representation of a NFA: state diagram

state p:

- initial state q:

- final state r:

transition (p, ba, cd, q, dc) :

E xam p le s

Context-free Languages

Page 35: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

35

T heory o f D ig ita l C om puta tio n

Intuitively, if ((p, u, ), (q, )) , then M, whenever it is in state p with at the top of the stack, may read u from the input tape, replaced by on the top of the stack, and enter state q. ((p, u, ), (q, )) is called a transition of M.

To “push” a symbol is to add it to the top of the stack, to “pop” a symbol is to remove it form the top of the stack.

A configuration is defined to be an element of K**:

The first component is the state of the machine, the second is the partition of the input yet to be read, and the third is the content of the pushdown store.

Context-free Languages

Page 36: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

36

T heory o f D ig ita l C om puta tio n

For every transition ((p, u, ),(q, )) , and for every x * and *, we define (p, ux, ) ├─M (q, x, )),

moreover, ├─M (yields in one step) holds only between

configurations that can be represented in this form for some transition, some x, and some .

The reflexive, transitive closure of ├─M is denoted by ├─M*.

We say that M accepts a string w * iff (s, w, e) ├─M*

(p, e, e) for some p F.

Language accepted by M, L(M), is the set of all strings accepted by M.

Context-free Languages

E xam p le s

Page 37: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

37

T heory o f D ig ita l C om puta tio n

Turing Machines

Turing Machines

DefinitionA Turing machine is a quadruple (K, , , s) where

K: is a finite set of states, not containing the halt state h; (h K),

: is an alphabet, containing the blank symbol #, but not containing the symbols L and R;

s: is the initial state;

: is a function from K to (K {h})( {L, R}).

Configuration of a Turing machine M = (K, , ,s) is an element of (K {h})* (*(-{#}){e}).

Page 38: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

38

T heory o f D ig ita l C om puta tio n

Let (q1, w1, a1, u1) and (q2, w2, a2, u2) be configurations of Turing

machine M. Then (q1, w1, a1, u1) ├─M (q2,w2, a2, u2)

iff for some b {L, R}, (q1, a1) = (q2, b) and either

(1) b , w1 = w2, u1= u2, and a2 = b; or

(2) b = L, w1 = w2a2, and either

(a) u2 = a1u1, if (a1 # or u1 e), or

(b) u2 = e, if a1 = # and u1= e; or

(3) b = R, w2 = w1 a1 and either

(a) u1 = a2u2, or

(b) u1 = u2 = e and a2 = #.

Turing Machines

Page 39: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

39

T heory o f D ig ita l C om puta tio n

For any Turing machine M, relation ├─M* is the reflexive,

transitive closure of relation ├─M; We say configuration C1

yields configuration C2 if C1├─*M C2.

A computation by M is a sequence of configurations C0, C1,

C2,..., Cn (n0) such that

C0 ├─M C1 ├─M C2├─M … ├─M Cn .

Turing Machines

Page 40: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

40

T heory o f D ig ita l C om puta tio n

DefinitionLet f be a function from 0* to 1*. Turing machine M = (K,

, , s) , where 0, 1 , computes f if w 0* and

f(w) = u, then

(s, #w, #, e) ├─M* (h, #u, #, e).

If such a Turing machine exists, the function is called Turing computable.

Turing Machines

Page 41: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

41

T heory o f D ig ita l C om puta tio n

Let 0 an alphabet not containing the blank symbol. Let Y

and N be two fixed symbols not in 0. Then, language L

0* is Turing decidable iff function xL: 0* {Y, N} is Turing

computable, where for each w 0*,

xL(w) = Y if w L

N if w L

Turing Machines

{

Page 42: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

42

T heory o f D ig ita l C om puta tio n

Let 0 be an alphabet not containing #. M accepts string w

0* if M halts on input w.

Thus, M accepts language L 0* iff L = {w 0*: M

accepts w}.

DefinitionA language is Turing acceptable if there is some Turing machine that accepts it.

Turing Machines

Page 43: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

43

T heory o f D ig ita l C om puta tio n

Symbol writing Turing machines

For alphabet and symbol a ,

let Turing machine a = (K, , , s) =({p}, , {(p, b, h, a): for any b }, p)

Head moving Turing machines

For alphabet ,

let Turing machine L be defined as L = (K, , , s) =({p}, , {(p, b, h, L): for any b }, p), and

let Turing machine R be defined as R = (K, , , s) =({p}, , {(p, b, h, R): for any b }, p).

Turing Machines

Page 44: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

44

T heory o f D ig ita l C om puta tio n

DefinitionA machine schema is a triplet (m, M0) where

mis a finite set of Turing machines with common alphabet and disjoint sets of states;

M0 m is the initial machine; and

is a function from subset of m to m.

Turing Machines

Page 45: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

45

T heory o f D ig ita l C om puta tio n

Let m= {M0, M1, …, Mm} (m≥0), where

Mi = (Ki, , i, si) for i = 0, 1, …, m.

Let q0, q1, …, qm be new states not in any of the Ki.

Then machine schema (m, M0) is defined asTuring

machine M, where M = (K, , , s)

K = K0 ... Km {q0, q2, …, qm},

s = s0, and

is defined as follows.

Turing Machines

Page 46: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

46

T heory o f D ig ita l C om puta tio n

Definition of

(a) if q Ki (0 ≤ i ≤ m), a , i(q, a) = (p, b), and p h,

then (q, a) = i(q, a) = (p, b);

(b) if q Ki (0 ≤ i ≤ m), a , and i(q, a) = (h, b) then

(q, a) = (qi, b);

(c) if a and (Mi , a) (0 ≤ i ≤ m) is not defined, then

(q, a) = (h, a);

(d) if a and (Mi , a) = Mj (0 ≤ i ≤ m) and

j(sj, a) = (p, b), then

(qi, a) = (p, b) if p h and

(qj, b) if p = h.

Turing Machines

E xam p le s

Page 47: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

47

T heory o f D ig ita l C om puta tio n

TheoremEvery Turing decidable language is Turing acceptable.

Proof:

TheoremIf L Turing decidable language, then it’s complement L is also Turing-decidable.

Proof:

Turing Machines

Page 48: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

48

T heory o f D ig ita l C om puta tio n

A language is Turing-decidable if and only if both it and its complement are Turing acceptable .

Proof:

(only if)

L is a Turing decidable L is also Turing decidable.

L, L is Turing decidable L, L is Turing acceptable.

(if)

  2-tape machine: M1 accepts L, M2 accepts L.

Parallel simulation: Which halts?

Turing Machines

Page 49: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

49

T heory o f D ig ita l C om puta tio n

Universal Turing Machines

Universal Turing Machines

The only feature possessed by electronic computers that missing from the capability of Turing machines is the programmability.

Difficulties:

The alphabet of any Turing machine must be finite.

The set of states of any Turing machine must be finite.

Universal Turing Machines

Page 50: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

50

T heory o f D ig ita l C om puta tio n

Hints:

Assume that there are fixed countably infinite sets 

K = {q1, q2, q3, ...}, and

= {a1, a2, a3, ...}

such that for every Turing machine, the set of states is a subset of K and the alphabet is a subset of .

Universal Turing Machines

Page 51: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

51

T heory o f D ig ita l C om puta tio n

Encode the alphabet and states of the Turing machine as

()

qi Ii+1

h I

L I

R II

ai Ii+2

Universal Turing Machines

Page 52: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

52

T heory o f D ig ita l C om puta tio n

Encode the Turing machine M over the alphabet {c, I}.

p(M) = cS0cS11S12 ... S1lS21S22 ... Sk1 ... Sklc

S0 encodes the initial state, S0 = (s).

Spr encodes the values of the transition function,

Spr = cw1cw2cw3cw4, where

w1 = (qi p), w2 = (qj r), w3 = (q’), w4 = (b)

for each

(qi p, qj r) = (q’, b).

Universal Turing Machines

Page 53: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

53

T heory o f D ig ita l C om puta tio n

The symbols on the tape must also be in encoded form.

p(w) = c(b1)c(b2)c ... c(bn)c

for each

w = b1b2 ... bn.

Universal Turing Machines

Page 54: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

54

T heory o f D ig ita l C om puta tio n

Universal Turing machine U simulates Turing machine M on a three tape Turing machine.

Tape 1: encoding of the tape of Turing machine M.

Tape 2: encoding of Turing machine M (i.e., it is the “program”).

Tape 3: encoding of the current state of Turing machine M during the simulation.

Universal Turing Machines

Page 55: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

55

T heory o f D ig ita l C om puta tio n

Examples

Examples

Symbol

Every character is a symbol, e. g., a, b, and c, etc.

Alphabet

= {a, b, c} is an alphabet.

String

cab, abaca, a, and the empty string e are strings over the alphabet = {a, b, c}.

Length of a string

cab= 3, abaca= 5, a= 1, and e=0.

Alphabets and Languages

Page 56: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

56

T heory o f D ig ita l C om puta tio n Examples

Concatenation of strings

Strings cab and abaca can be concatenated to form string

cababaca.

Formally:

cababaca = cababaca

Alphabets and Languages

Page 57: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

57

T heory o f D ig ita l C om puta tio n Examples

Substring

Strings e, a, b, c, ab, ba, ac, ca, aba, bac, aca, abac, baca, and abaca are the substrings of the string abaca.

Reversal of a string

eR = e

aR = a

abR = ba

bacR = cab

abacaR = acaba

Alphabets and Languages

Page 58: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

58

T heory o f D ig ita l C om puta tio n Examples

Language

Set L = {e, a, cab, abaca} is a language over the alphabet = {a, b, c}.

Thus, language L is a subset of * = {e, a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, aab, aab, aba, …}.

Alphabets and Languages

Page 59: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

59

T heory o f D ig ita l C om puta tio n Examples

Language operation Kleene star

Closure or Kleene star of language L = {a, cab, abaca} the language L* =

{e, a, cab, abaca, aa, acab, aabaca, caba, cabcab, cababaca, …, abacaaa, abacaacab, …} =

{e, a, cab, abaca, aa, acab, aabaca, caba, cabcab, cababaca, …, abacaaa, abacaacab, …}

Alphabets and Languages

Page 60: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

60

T heory o f D ig ita l C om puta tio n Examples

Regular expressions

Expressions

Ø, a, b,

(ab), ((ab)a),

(ab), (a(ab)), ((ab)((ab)a)), ((ab)c),

((ab)a), ((ab)(ab)),

a*, (ab)*, (ab)*,

(a*b), (a*b), ((ab)*((ab*)a)), and ((ab)*c*)

are regular expressions over the alphabet = {a, b, c}.

Alphabets and Languages

Page 61: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

61

T heory o f D ig ita l C om puta tio n Examples

Language represented by regular expression

L(((ab)c)*) = ?

L(a) = {a}; L(b) = {b}; L(c) = {c};

L((ab)) = L(a) L(b) = {a} {b} = {a, b};

L(((ab)c)) = L((ab))L(c) = {a, b} {c} = {ac, bc};

L(((ab)c)*) = L(((ab)c))* = {ac, bc}* =

{e, ac, bc, acac, acbc, bcac, bcbc, acacac, acacbc, acbcac,

…, acbcacbcac, acbcacbcbc, … }

Alphabets and Languages

Page 62: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

62

T heory o f D ig ita l C om puta tio n Examples

Deterministic finite automaton

M1= (K, , , s, F) =

(K= {p, q},

= {a, b},

= {(p, a, p), (p, b, q), (q, a, q), (q, b, p)},

s = p,

F = {q})

Finite Automata

Page 63: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

63

T heory o f D ig ita l C om puta tio n Examples

Graphical representation of DFA

M1= (K= {p, q},

= {a, b},

= {(p, a, p), (p, b, q), (q, a, q), (q, b, p)},

s = p,

F = {q})

is the state diagram:

Finite Automata

Page 64: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

64

T heory o f D ig ita l C om puta tio n Examples

Configuration of DFA M1

is: (p, babaa)

Finite Automata

Page 65: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

65

T heory o f D ig ita l C om puta tio n Examples

Yields in one step

(p, babaa) ├─M (q, abaa)

Finite Automata

Page 66: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

66

T heory o f D ig ita l C om puta tio n Examples

Yields

(p, babaa) ├─M* (p, aa)

Finite Automata

Page 67: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

67

T heory o f D ig ita l C om puta tio n Examples

String accepted by DFA M1: abbba

(p, abbba) ├─M* (q, e)

Finite Automata

Page 68: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

68

T heory o f D ig ita l C om puta tio n Examples

Language accepted by DFA

M1= (K= {p, q},

= {a, b},

= {(p, a, p), (p, b, q), (q, a, q), (q, b, p)},

s = p,

F = {q})

L(M1) = {w {a, b}*: the number of b’s in w is odd}

Finite Automata

Page 69: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

69

T heory o f D ig ita l C om puta tio n Examples

Graphical representation of NFA

M2= (K= {p, q},

= {a, b},

= {(p, ab, q), (p, e, q), (q, ba, q)},

s = p,

F = {q})

is the state diagram:

Finite Automata

Page 70: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

70

T heory o f D ig ita l C om puta tio n Examples

Language accepted by NFA

M2= (K= {p, q},

= {a, b},

= {(p, ab, q), (p, e, q), (q, ba, q)},

s = p,

F = {q})

is L(M2) = L( ((ab) e)(ba)*) ).

Finite Automata

Page 71: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

71

T heory o f D ig ita l C om puta tio n Examples

For context-free grammar

G = (V = {a, b, A, B, S},

= {a, b},

R = {(S, aSb), (S, e)},

S)

we can write

SaSb, Se

SaSbaaSbbaaaSbbbaaabbb

S * aaSbb * aaabbb, and S * aaabbb

Context-free Languages

Page 72: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

72

T heory o f D ig ita l C om puta tio n Examples

Language generated by CFG

G = (V = {a, b, A, B, S},

= {a, b},

R = {(S, aSb), (S, e)},

S)

is L(G) = {anbn: n 0}.

Context-free Languages

Page 73: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

73

T heory o f D ig ita l C om puta tio n Examples

Graphical representation of PDA

M3= (K= {p, q},

= {a, b},

= {c},

= {(p, a, e, p, c), (p, e, q), (q, b, c, q, e)},

s = p,

F = {q})

is the state diagram:

Context-free Languages

Page 74: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

74

T heory o f D ig ita l C om puta tio n Examples

Language accepted by PDA

M3= (K= {p, q},

= {a, b},

= {c},

= {(p, a, e, p, c), (p, e, q), (q, b, c, q, e)},

s = p,

F = {q})

is L(M2) = {anbn: n 0}.

Context-free Languages

Page 75: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

75

T heory o f D ig ita l C om puta tio n Examples

Turing machine represented by the following machine schema operates as follows: (s, #w, #, e) ├─M* (h, #u, #, e),

where w {a, b}* and u is derived from w by replacing each a in w to b and each b in w to a.

Turing Machines

Page 76: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

76

T heory o f D ig ita l C om puta tio n

Problems

Problems

Alphabets and Languages

Which strings are the elements of the following languages?

- {w: for some u{a, b}{a, b}, w = uuRu}

- {w: ww = www}

- {w: for some u, wuw = uwu}

- {w: for some u, www = uu}

Page 77: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

77

T heory o f D ig ita l C om puta tio n Problems

Is it true or false?

- baa {a}*{b}*{a}*{b}*

- {b}*{a}*{a}*{b}* = {a}*{b}*

- {a}*{b}*{c}*{d}* =

- abcd ({a} ({c}{d})* {b})*

Page 78: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

78

T heory o f D ig ita l C om puta tio n Problems

Write regular expression R with

- L(R) = {w{a, b}*: there is at most three a's in w}

- L(R) = {w{a, b}*: there is no ab substring in w}

- L(R) = {w{a, b}*: w has exactly one aaa substring}

- L(R) = {w{a, b}*: in w every a is preceded and followed by a b}

- L(R) = {w{a, b, c}*: in w there is no aa, bb, cc substring in w}

Page 79: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

79

T heory o f D ig ita l C om puta tio n Problems

Finite Automata

Draw state diagram of DFA M with

- L(M) = {w{a, b}*: in w the number of a's is even and the number of b's is odd}

- L(M) = {w{a}*: in w the number of a's is even, but not divisible by 4}

- L(M) = {w{a}*: in w the number of a's is either even or divisible by 3}

- L(M) = {w{a}*: in w the number of a's is divisible by 3}

Page 80: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

80

T heory o f D ig ita l C om puta tio n Problems

Draw state diagram of NFA M with L(M) = L(R) where

- R = (a*b*)*(ab)

- R = (aba)*(aab)*

- R = ( (a*b*)(ab) )*

- R = ((ab)(ab))*

- R = (ab*)(a*b)

Page 81: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

81

T heory o f D ig ita l C om puta tio n Problems

Context-free Languages

Which words can be derived in at most four steps in G = (V, , R, S) from S?

V = {a, b, A, B, S},

= {a, b}, and

- R = {SA, SabA, SaB, ASa, Bb}

- R = {SA, SabA, SaB, Aa, BSb}

- R = {SABS, AaA, BbB, Se, Aa, Bb}

- R = {SaSB, SbSA, Sa, Sb, AaS, BbS}

Page 82: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

82

T heory o f D ig ita l C om puta tio n Problems

Give a CF grammar G with

- L(G) = {w{a, b}*: in w the number of b's is even}

- L(G) = {anbman: n, m > 0}

- L(G) = {ancbnc: n 0}

- L(G) = {bnan: n 0} {a3nbn: n 0}

- L(G) = {ambncpdr: m+n = p+r}

Page 83: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

83

T heory o f D ig ita l C om puta tio n Problems

Give a pushdown automaton M with

- L(M) = {w{a, b}*: in w the number of a's is larger than the number of b's}

- L(M) = {w{a, b}*: w = wR}

- L(M) = {w{a, b}*: in w the number of b's is odd}

- = {a, +, *, (, )} L(M) = {syntactically correct arithmetic expressions involving + and * over the variable a}

- L(M) = {ambncp: m = n or m = p or n = p}

- L(M) = {ambncndm: m, n > 0}

Page 84: 1 Theory of Digital Computation Course material for undergraduate students on IT Department of Computer Science University of Veszprem Veszprem, Hungary.

84

T heory o f D ig ita l C om puta tio n Problems

Turing machines

Give a Turing machine which decides language L

- L = {w{a, b}*: in w the number of a's is the double of the number of b's}

- L = {w{a, b}*: in w the number of a's is larger than the number of b's}

- L = {w{a, b}*: in w the number of b's is even}

- L = {w{a, b}*: w = wR}

- L = {anbncn: n > 0}