CS 235 Automata etc Rhys Price Jones Introduction to Turing Machines Some Questions are Decidable Given a CFG G and a regular expression r is L(G) ⊂ L(r)? ___ L(G) ∩ L(r) is CF (why?) We can decide if a CF language is empty (how?) L(G) is contained in L(r) if and only if ___ there is empty intersection between L(G) and L(r) (why?) Some Questions are Decidable Given a CFG G, does G generate any odd-length strings? is decidable How? Some Questions are Decidable Given a CFG G, does G generate any odd-length strings? Lodd = L((0+1)(00+01+10+11)*) is regular L(G) ∩ Lodd is CF (why?) G generates an odd-length string if and only if L(G) ∩ Lodd ≠ ∅ and we can decide that (how?) Some Questions are Undecidable Given CFL L, is L = Σ*? Given CFL L, is the complement of L CF? Given CFL L, is L regular? Given two CFLs L1 and L2 is L1 = L2? Given CFLs L1, L2 is L1 ⊆ L2? Given CFLs L1, L2 is L1 ∩ L2 = ∅? Is the CFL L inherently ambiguous? Is the context-free grammar G ambiguous? Let’s build the Math so we can prove things are undecidable? “That is undecidable” is a much better answer than “I don’t know how to do that” We need a formal notion of computability Turing machines! As defined by Sipser A Turing Machine is a 7-tuple (Q ,Σ,Γ,δ,q0,qa,qr) Q is a finite set of states Σ is a finite input alphabet not including the blank symbol ☐ Γ is a finite tape alphabet with ☐∊Γ and Σ⊆Γ δ:Q×Γ → Q×Γ×{L,R} is the transition function q0,qa,qr ∊ Q are the start, the accept and the reject states TM def Continued Initially M receives input from Σ* on the left end of its one-way infinite tape. The rest of the tape is filled with the blank symbol ☐. The head starts on the left end of the tape. The initial state is q0, after which the behavior of M is governed by the transition function δ. but the head cannot move off the left end. TM as recognizer TMs should halt in states qa and qr accept or reject (Rhys ! and JFlap: TM can also reject by crashing) The collection of strings that M accepts is the language recognized by M, denoted L(M) A language is Turing-recognizable if some TM recognizes it TMs don’t have to halt A TM can accept by halting in state qa reject by halting in state qr (Reject by crashing — RPJ and JFlap) loop forever A TM that halts on all inputs is a decider A language is Turing decidable if it’s the language of a decider. Sipser Example 3.7 TM exercises Build TM to recognize {anbmcn+m |n,m >= 0} Look at checkadditionTM.jff try many inputs: aabbcccc, etc TM exercises Build TM to recognize {anbmcn+m |n,m >= 0} Look at checkadditionTM.jff try many inputs: aabbcccc, etc Now try ababcccc ooopps! (checkadditionTMfixed.jff) TM exercises Build TMs to: recognize {anbmcn*m |n,m >= 0} recognize {anbncn |n >= 0} recognize {anbn! |n >= 0} TM as calculator Start with 111+11 on tape, end in qa with 11111 unaryaddition.jff Similar machines for *, -, /, ... For a calculator of a different flavor, try Sipser’s Example 3.12 Variants You will consider some variants in Lab 9 2-way infinite tape multitrack tape ... Wile E Coyote wants to sell me an enhanced Sipser TM with a “Stay Option” Will I buy it? TM as enumerator Start with blank tape to be used as work tape Another blank tape (the printer) The class of all strings that are eventually printed out is the language enumerated by M Note Theorem 3.21 and its proof L is Turing-recognizable iff an enumerator enumerates it Given enumerator E, create recognizer M: Whenever E prints, compare output to w, if == accept Why is the converse direction so complicated? “Less powerful” TMs I can replace the infinite tape with two stacks and still have the same power. I can replace the infinite tape with a single queue and still have the same power. I can replace the infinite tape with a finite random-access memory (as long as I have unlimited external storage and a good replacement algorithm -- “virtual memory” What means “the same power” Busy TMs How many TMs are there with n states and a two element tape alphabet (1 and ◻)? (4(n+1))2n For each of n states there are two transitions out giving 2n transition arrows Each has two choices 0 or ◻ to write Each has two choices for movement L or R and n+1 possible target states (including halt) For n=1 there are 64 TMs Some run forever when started on blank tape: Of the 64 one-state TMs Some make one move and halt Of these, some write a non-blank symbol Some don't There are 20,736 2-state TMs (4(n+1))2n|n=2 gives 124 = 20,736 Of these some run forever when started on blank tape some halt and never write a non-blank some halt and write some non-blanks Tibor Rado (1962): How many? n-state Busy Beaver started on blank tape will halt and write maximal number of non-blank symbols. 2-state busy beaver: makes 6 moves and prints 4 1s 1-state busy beaver? makes one move and writes one 1. Proof ? 3-state busy beaver? Can you improve on? makes 11 moves leaves 4 non-blank (at one stage had 5) Known busy beavers A 3-state busy beaver writes 6 1s A 4-state busy beaver writes 13 1s Nobody knows about the 5-state busy beaver but it does write at least 4,098 1s Nobody knows the 6-state busy beaver but it does write at least 1018267 1s
© Copyright 2024