跳转至

Lecture 5 - Turing Machine

Turing Machine

A Turing machine is a mathematical model of computation that defines an abstract machine. It was invented by Alan Turing in 1936. A Turing machine can simulate the logic of any computer algorithm, and is therefore the theoretical foundation of all modern computers.

A Turing machine is a 5-tuple (K,Σ,δ,s,H), where:

  • K is a finite set of states.
  • Σ is a finite set of symbols.
  • s K is the start state.
  • H K is the halt state.
  • δ is the transition function, which maps (KH)(current state)×Σ to K(next state)×(Σ(write){L,R}(moving)).

The transition function δ satisfies the following properties:

  • qKH,δ(q,)=(p,L) for some pK.
  • qKH,aΣ,if δ(q,a)=(p,b), then |b|0. -- Do something.

leftend is a special symbol that is used to indicate the left end of the tape.

blank symbol is a special symbol that is used to indicate the blank symbol.

configuration

A configuration of a Turing machine is a member of

(K×(Σ{}))×((Σ{})(Σ{,}){e})
  • Σ{,} is the last symbol that is not
  • {e} represents the following all symbols are .

We say (q1,w1a1u1)M(q2,w2a2u2) if

  • writing : δ(q1,a1)=(q2,a2)and a2Σ{} and w2=w1 and u2=u1.

  • moving left : δ(q1,u1)=(q2,L) and w1=w2a2 and u2=a1u1.

M halts if it reaches a halting configuration

Acceptance and Rejection

A Turing machine M accepts a string w if (s,w)(yes,aw)

A Turing machine M rejects a string w if (s,w)(no,aw)

Given a Turing machine M, we can define the language accepted by M as L(M)={wΣ|M accepts w}.

  • M seme-decides L
  • But M does not decide L
  • Adding a condition: If M halts on all inputs, then M decides L.

M decides a language L if M accepts all strings in L and rejects all strings not in L.

M semi-decides a language L if M accepts all strings in L and may loop (or reject) on strings not in L.

Reccursive Language

A language L is recursive if there exists a Turing machine that decides L.

Every recursive language is recursively enumerable.

  • Explanation: A language L is recursively enumerable if there exists a Turing machine that semi-decides L.

Multi-tape Turing Machine

1

A multi-tape Turing machine is a Turing machine with multiple tapes. Each tape has its own head and can move independently.

δ:(KH)×ΣkK×((Σ){L,R})k.

Two-way Infinite Tape

2

Multi-head Turing Machine

A multi-head Turing machine is a Turing machine with multiple heads on a single tape.

2D-Tape Turing Machine

  • Simulate a 2D-Tape Turing machine with a 1D-Tape Turing machine.

Random Access Turing Machine

  • A Turing machine which can move to any position on the tape in a single step.

Example

  • L={anbncn|n0} can be decided by a Turing machine.

Turing Machine Construction

Here is a high-level description of a Turing machine that can decide L:

  1. Check if the string consists of only a's, b's, and c's: - The TM scans the input tape to ensure that it only contains a's, b's, and c's in that order. If any other character is found, the machine rejects the string.

  2. Match a's, b's, and c's: - Start by marking the leftmost a and replace it with a special symbol (say X). - Then, scan the tape to find the leftmost b. If one is found, mark it with a different special symbol (say Y). - Next, scan to find the leftmost c, and mark it with another symbol (say Z). - Now, go back to the left end of the tape and repeat the process, continuing to match one a, one b, and one c at a time, until either:

    • All a's, b's, and c's are matched, or
    • A mismatch is found (i.e., a character cannot be found when needed).
  3. Verify the end condition: - Once all the symbols have been marked, check the tape:

    • If all symbols are marked and the tape only contains X's, Y's, and Z's, then the string is in the language L.
    • If there are any unmarked a's, b's, or c's remaining, or if the order of a's, b's, and c's is incorrect, the string is rejected.
  4. Empty string check: - The empty string ϵ is trivially in L, as it satisfies the condition anbncn where n=0.

Non-deterministic Turing Machine (NTM)

  • Deterministic TM: At each step, there is one possible next state, symbols to be written and direction to move the head, or the TM may halt.
  • Nondeterministic TM: At each step, there are finitely many possibilities.
  • So formally, M=(K,Σ,Δδ,s,H), where
  • K,Σ,s,H are the same as in a deterministic TM.

Decides

  • If there is a computation path that leads to qacc, then M accepts w.
  • If every computation path leads to qrej, then M rejects w.

M decides a language L if

  • Fir all wL, there is a integer N, depending on w and M such that every branch halts in at most N steps.
  • If wL, then there exists a branch that halts in an accepting state.
  • If wL, then every branch halts in a rejecting state.

Semi-decides

M semi-decides a language L if for any wL:

  • If wL, then there exists a branch that halts in an accepting state.
  • If wL, then no branch halts in a accepting state. -- No branch accepts w.

Example

Let C=100,110,1000,... C is composed of all binary numbers that are not prime. -- Construct a NTM that semi-decides C.

3

Theorem

Theorem 1

Every NTM can be simulated by a DTM.

A NTM semi-decides a language L if and only if there exists a DTM that semi-decides L.

  • A NTM semi-decides a language L There exists a DTM that semi-decides L.

  • Use a three-tape DTM to simulate a NTM.

6 5 7

Church-Turing Thesis

  • Every algorithm can be simulated by a Turing machine.
  • Intuition of Algorithm is equivalent to Turing machine.

Description of a Turing Machine

A Turing machine can be described by high-level pseudocode.

Fact

  • Any Finite Set can be encoded.
  • Any Finite Tuple whose elemnets are finite stes can be encoded.

Example

  • G=(V,E) is a graph. V is a finite set of vertices and E is a finite set of edges.
  • L={G|G is connected}

M on input G:

  1. If the input is illegal (not a graph), reject.
  2. select a node of G and mark it.
  3. repeat the following until no new nodes are marked: * For each marked node, mark all its neighbors.
  4. If all nodes are marked, accept; otherwise, reject.

Exercise

ADFA

Input: D,w, where D is a DFA and w is a string.

Output: Accept if D accepts w; reject otherwise.

Solution:Construct a Turing machine that simulates the DFA D on input w.

MR1 = on input D,w:

  1. run D on input w.
  2. If D accepts w, accept; otherwise, reject.

ANFA

Input: B,w, where B is a NFA and w is a string.

Output: Accept if B accepts w; reject otherwise.

Solution: Construct a Turing machine that simulates the NFA B on input w.

MR2 = on input B,w:

  1. Convert NFA B to a DFA B.
  2. run MR1 on input B,w.
  3. If MR1 accepts, accept; otherwise, reject.

This involves the process of reduction. 8

AREX

Input: R,w, where R is a regular expression and w is a string.

Output: Accept if R accepts w; reject otherwise.

Solution: Construct a Turing machine that simulates the NFA B on input w.

  • A REX can be converted to a NFA.
  • Use MR2 to simulate the NFA.

MR3 = on input R,w:

  1. Convert REX R to a NFA B.
  2. run MR2 on input B,w.
  3. If MR2 accepts, accept; otherwise, reject.

EDFA

Input: B, where B is a DFA.

Output: Accept if L(B)=; reject otherwise.

Solution: Construct a Turing machine that simulates the DFA B on input w.

MR4 = on input B:

  1. Run DFS on the state diagram of B.
  2. If there is a path from the start state to an accepting state, reject; otherwise, accept.

EQDFA

Input: B1,B2, where B1 and B2 are DFAs.

Output: Accept if L(B1)=L(B2); reject otherwise.

Solution: Construct a Turing machine that simulates the DFA B on input w.

  • Symmetric difference -- (L(B1)L(B2))(L(B1)L(B2))
  • Convert the problem to whether the symmetric difference is empty.

MR5 = on input B1,B2:

  1. Construct a DFA B that recognizes the symmetric difference of L(B1) and L(B2). (L(B)=(L(B1)L(B2))(L(B1)L(B2))
  2. Run MR4 on input B.

ACFG

Input: G,w, where G is a CFG and w is a string.

Output: Accept if G generates w; reject otherwise.

ACFG={G,w|G is a CFG and G generates w}

Chonsky Normal Form

A CFG G is in Chonsky Normal Form if every rule is of the form:

  • Se
  • ABC B and C are non-terminal symbols. BC VΣS
  • Aa.

So if final w has length n, the number of steps of subtitution is 2n1.

MC1 = on input G,w: 1. Convert CFG G to Chonsky Normal Form G. 2. Enumerate all derivations of length at most |R|2n1. 3. Acscept if any derivation generates w; otherwise, reject.

APDA

Input: P,w, where P is a PDA and w is a string.

Output: Accept if P accepts w; reject otherwise.

APDA={P,w|P is a PDA and P accepts w}

MC2 = on input P,w: 1. Convert PDA P to a CFG G. 2. Run MC1 on input G,w. 3. If MC1 accepts, accept; otherwise, reject.

ECFG

Input: G, where G is a CFG.

Output: Accept if L(G)=; reject otherwise.

ECFG={G|L(G)=}

MC3 = on input G: 1. Mark all terminals and e. 2. Look through all rules and if there is a rule that all symbols on the right side are marked , mark the left side. 3. Repeat step 2 until no new symbols are marked. 4. If S is marked, reject; otherwise, accept.

EPDA

Input: P, where P is a PDA.

Output: Accept if L(P)=; reject otherwise.

EPDA={P|L(P)=}

MC4 = on input P: 1. Convert PDA P to a CFG G. 2. Run MC3 on input G. 3. If MC3 accepts, accept; otherwise, reject.

ADFA is recursive L(D) is recursive.


最后更新: 2024年11月11日 23:05:25
创建日期: 2024年10月16日 00:17:47
Is this page helpful?