150 likes | 249 Views
Formal Languages Wrap-up. Recursively Enumerable Languages. A language is recursively enumerable if there is a Turing Machine that accepts it. This allows the TM to go into an infinite loop if the string is not in the language. Recursive Languages.
E N D
Recursively Enumerable Languages • A language is recursively enumerable if there is a Turing Machine that accepts it. • This allows the TM to go into an infinite loop if the string is not in the language.
Recursive Languages • A language is Recursive if there is a TM that accepts the language and it halts on every string in Σ+. • That is, a recursive language has to have a membership algorithm.
Recursively Enumerable, contd • Not all languages are recursively enumerable. • Some languages are recursively enumerable but not recursive. • Unrestricted grammars produce recursively enumerable languages. These statements are proven, yet examples are hard to come by...
Context-Sensitive Grammars • All productions are of the form x -> y, where x and y are elements of (VUT)+ and |x| <= |y| Example: S -> ABCAB -> aaabC -> DFDF -> cccab
Context-Sensitive Languages • CSL example: anbncn • Automata for CSLs are linear-bounded automata: TM’s where only the area of tape used by the input is allowed as storage. • All CSL’s are recursive, but not all recursive languages are context-sensitive.
Chomsky’s Hierarchy Recursively Enumerable Recursive Context-Sensitive Non-det Context-Free Det Context-Free Regular
So can anything be computed?No! • Computability – the study of which problems can and which cannot be solved by a Turing Machine.
The Halting Problem • Given an algorithm decide will it halt? • Assume it can be done: Halt(M,w) = yes if algorithm (TM) M halts on input w, and no if it doesn’t. That is: • Halt(M,w) = yes if M(w) halts, else no. • Create new algorithm:Strange(String s): if Halt(s,s)= “no” then return yes else while(true){ }
Halting Problem Strange(String s): if Halt(s,s)= “no” then return yes else while(true){ } So, for any program P, if P(P) halts then Strange(P) doesn’t halt. if P(P) doesn’t halt then Strange(P) does halt. But that means: if Strange(Strange) halts then Strange(Strange) doesn’t halt. if Strange(Strange) doesn’t halt then Strange(Strange) does halt. Contradiction!
Computability • So, not all problems can be solved with a computer. • The Halting Problem is said to be “undecidable”. • DO NOT confuse this with an NP-complete problem! Remember, problems in NP are solvable by non-deterministic TMs and therefore also solvable by TMs, just not necessarily in polynomial time.
Reducing one problem to another... • The state-entry problem: Given a TM and string w, tell whether or not a given state q is ever entered when processing w. • Is it decidable? Why or why not?
Other Undecidable Problems • Given a TM M, letter a, and string w, determine if the letter a ever gets written when processing M(w). • Determine if two TMs are equal • Determine if a CFG is ambiguous • Given 2 CFGs, G1 and G2, determine if L(G1) L(G2) = {}
Rice’s Theorem • Any non-trivial property of a recursively enumerable language is undecidable. • Particularly, the following are undecidable. • For language G, is L(G) = {}? • For language G, is string w in L(G)? • Is TM M finite? • Does TM M accept 2 different strings of the same length?
The moral of the story... • Researchers first find the properties of the problem before trying to solve it. • Know beforehand the possibilities of the best answer, or even that an answer is possible. • Often leads to a definition of assumptions or concessions to make the problem solvable in a more practical way.