Unrestricted Grammars

Slides:



Advertisements
Similar presentations
Chapter 5 Pushdown Automata
Advertisements

Variants of Turing machines
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
The Big Picture Chapter 3. We want to examine a given computational problem and see how difficult it is. Then we need to compare problems Problems appear.
February 6, 2015CS21 Lecture 141 CS21 Decidability and Tractability Lecture 14 February 6, 2015.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Introduction to Computability Theory
Reducibility A reduction is a way of converting one problem into another problem in such a way that a solution to the second problem can be used to solve.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Decidability continued. 2 Undecidable Problems Halting Problem: Does machine halt on input ? State-entry Problem: Does machine enter state halt on input.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 5 Reducibility Contents Undecidable Problems from Language Theory.
CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG)
Theory of Computing Lecture 20 MAS 714 Hartmut Klauck.
MA/CSSE 474 Theory of Computation
Chapter 9 Turing Machine (TMs).
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
MA/CSSE 474 Theory of Computation The Halting Problem.
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
Pushdown Automata (PDA) Intro
Decidability of Languages That Do Not Ask Questions about Turing Machines Chapter 22.
Context-Free Grammars Normal Forms Chapter 11. Normal Forms A normal form F for a set C of data objects is a form, i.e., a set of syntactically valid.
TM Design Universal TM MA/CSSE 474 Theory of Computation.
1 Section 14.2 A Hierarchy of Languages Context-Sensitive Languages A context-sensitive grammar has productions of the form xAz  xyz, where A is a nonterminal.
The Chomsky Hierarchy and Beyond
MA/CSSE 474 Theory of Computation More Reduction Examples Non-SD Reductions.
MA/CSSE 474 Theory of Computation Enumerability Reduction.
Regular Grammars Chapter 7. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
Regular Grammars Chapter 7 1. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
Turing Machines Chapter 17. Languages and Machines SD D Context-Free Languages Regular Languages reg exps FSMs cfgs PDAs unrestricted grammars Turing.
 2005 SDU Lecture13 Reducibility — A methodology for proving un- decidability.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
1 Turing Machines as Transducers. 2 Turing-computable Functions Function f with domain D is computable if There exists TM M= (Q, D, , , q 0, B, F) Such.
Recursively Enumerable Languages
Decidability and Undecidability Proofs Sections 21.1 – 21.3.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 3 The Church-Turing Thesis Contents Turing Machines definitions, examples,
THE CONVENTIONS 2 simple rules: Rule # 1: Rule # 2: RR “move to the right until you find  “ Note: first check. Then move (think of a “while”) “Never.
Summary of Previous Class There are languages that are not decidable –(we have not proved this yet) Why not extend Turing machines just as we did with.
Turing Machines Sections 17.6 – The Universal Turing Machine Problem: All our machines so far are hardwired. ENIAC
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
The Church-Turing Thesis Chapter Are We Done? FSM  PDA  Turing machine Is this the end of the line? There are still problems we cannot solve:
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY * Read chapter 4 of the book for next time * Lecture9x.ppt.
MA/CSSE 474 Theory of Computation Universal Turing Machine Church-Turing Thesis (Winter 2016, these slides were also used for Day 33)
Universal Turing Machine
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
Chapter 5 Recursive and recursively enumerable functions Phrase-structure grammars.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesTuring.
February 1, 2016CS21 Lecture 121 CS21 Decidability and Tractability Lecture 12 February 1, 2016.
Decidability and Undecidability Proofs
CSCI 2670 Introduction to Theory of Computing
Turing Machines Chapter 17.
CSE 105 theory of computation
CSE 2001: Introduction to Theory of Computation Fall 2013
Turing Machines Acceptors; Enumerators
Intro to Theory of Computation
Turing acceptable languages and Enumerators
Turing Machines Chapter 17.
Chapter 7 Regular Grammars
Turing acceptable languages and Enumerators
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation
CSE 105 theory of computation
Subject Name: FORMAL LANGUAGES AND AUTOMATA THEORY
Variants of Turing machines
MA/CSSE 474 Theory of Computation
MA/CSSE 474 Theory of Computation
CSE 105 theory of computation
Presentation transcript:

Unrestricted Grammars Chapter 23

Grammars, SD Languages, and Turing Machines Accepts Turing Machine

Unrestricted Grammars An unrestricted, or type 0, or phrase structure grammar 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*), ● S (the start symbol) is an element of V - . The language generated by G is: {w  * : S G* w}.

Unrestricted Grammars Example: AnBnCn = {anbncn, n  0}. CFG attempt 1: S  A B C A  aA |  B  bB |  C  cC | 

Unrestricted Grammars Example: AnBnCn = {anbncn, n  0}. CFG attempt 2: S  a b S c |  S a b S c a b S c  ababcc

Unrestricted Grammars Example: AnBnCn = {anbncn, n  0}. S  aBSc S   Ba  aB Bc  bc Bb  bb Proof: ● Only strings in AnBnCn : ● All strings in AnBnCn :

Another Example {w  {a, b, c}* : #a(w) = #b(w) = #c(w)}

Another Example {w  {a, b, c}* : #a(w) = #b(w) = #c(w)} S  ABCS AB  BA BC  CB AC  CA BA  AB CA  AC CB  BC A  a B  b C  c

WW = {ww : w  {a, b}*}

WW = {ww : w  {a, b}*} One idea: Generate a string in wwR, plus delimiters aaabbCbbaaa# Reverse the second half.

WW = {ww : w  {a, b}*} S  T# /* Generate the wall exactly once. T  aTa /* Generate wCwR. T  bTb  T  C  C  CP /* Generate a pusher P Paa aPa /* Push one character to the right to get ready to jump. Pab  bPa  Pba  aPb  Pbb  bPb  Pa#  #a /* Hop a character over the wall. Pb#  #b  C#  

A Strong Procedural Feel Unrestricted grammars have a procedural feel that is absent from most restricted grammars. Derivations often proceed in phases. We make sure that the phases work properly by using nonterminals as flags that we’re in a particular phase. It’s very common to have three main phases: ● Generate the right number of the various symbols. ● Move them around to get them in the right order. ● Clean up and get rid of nonterminals. No surprise: unrestricted grammars are general computing devices.

Equivalence of Unrestricted Grammars and Turing Machines Theorem: A language is generated by an unrestricted grammar if and only if it is in SD. Proof: Only if (grammar  TM): by construction of an NDTM. If (TM  grammar): by construction of a grammar that mimics the behavior of a semideciding TM.

Proof that Grammar  Turing Machine Given G, produce a Turing machine M that semidecides L(G). M will be nondeterministic and will use two tapes: q a b a b q q q 1 0 0 0 0 0 0 q a S T a a b q 1 0 0 0 0 0 0 For each nondeterministic “incarnation”: ● Tape 1 holds the input. ● Tape 2 holds the current state of a proposed derivation. At each step, M nondeterministically chooses a rule to try to apply and a position on tape 2 to start looking for the left hand side of the rule. Or it chooses to check whether tape 2 equals tape 1. If any such machine succeeds, we accept. Otherwise, we keep looking.

Proof that Turing Machine  Grammar Build G to simulate the forward operation of a TM M: The first (generate) part of G: Create all strings over * of the form: w = # q q q000 a1 a1 a2 a2 a3 a3 q q # The second (test) part of G simulates the execution of M on a particular string w. An example of a partially derived string: # q q a 1 b 2 c c b 4 q001 a 3 # Examples of rules: q100 b b  b 2 q101 a a q011 b 4  q011 a a b 4

The Last Step The third (cleanup) part of G erases the junk if M ever reaches any of its accepting states, all of which will be encoded as A. Rules: x x A  A x /* Sweep A to the left. x, y #A x y  x #A /* Erase duplicates. #A#  

An Unrestricted Grammar of Tabla Drumming artdrum.com/TABLA_DRUMS_COPPER_SAJID.HTM

Computing with Grammars We say that G computes f iff: w, v  * (SwS G* v  v = f(w)) Example: f(x) = succ(x) S1S G* 11 S11S G* 111

Computing with Grammars We say that G computes f iff: w, v  * (SwS G* v  v = f(w)) Example: f(x) = succ(x) S1S G* 11 S11S G* 111 Rules: S1  1S or 1S  11 SS  1 S1  1 SS  1

Grammatically Computable A function f is called grammatically computable iff there is a grammar G that computes it. Theorem: A function f is computable iff it is grammatically computable. In other words, iff a Turing machine can do it, so can a grammar. Proof: uses two constructions, analogous to the ones used to prove that a language can be defined with an unrestricted grammar iff it is in SD.

The valuen Functions For any k, valuek(n) returns the nonnegative integer that is encoded, base k, by the string n. Example: value2(101) = 5.

Example of Computing with a Grammar f(n) = m, where value1(m) = 2value1(n). G = ({S, 1}, {1}, R, S), where R = Examples: Input: S111S SS Output:

Example of Computing with a Grammar f(n) = m, where value1(m) = 2value1(n). G = ({S, 1}, {1}, R, S), where R = Examples: Input: S111S SS Output: 111111 

Example of Computing with a Grammar f(n) = m, where value1(m) = 2value1(n). G = ({S, 1}, {1}, R, S), where R = S1  11S SS   Examples: Input: S111S SS Output: 111111 

Another Example f(x) = x with extra blanks squeezed out. Examples: Input: SaaqbqqaaqqqqbqS Output: aaqbqaaqb Input: SqqaabS Output: aab

Another Example f(x) = x with extra blanks squeezed out. G = ({S, T, a, b, q}, {a, b, q}, R, S), where R = SS   /* In case x has no nonblank characters. Sq  S /* Get rid of leading q’s. Sa  aT /* All characters to the left of T will be correct. Sb  bT  Ta  aT /* Sweep T across a’s and b’s. Tb  bT  Tqq Tq /* Squeeze repeated q’s. Tqa qaT /* Once there is a single q, sweep T past it and the first letter after it. Tqb qbT  TqS  /* The Tqq rule will get rid of all but possibly one q at the end of the string. TS   /* If there were no trailing q’s, this rule finishes up.

Decision Problems for Unrestricted Grammars ● Given a grammar G and a string w, is w  L(G)? ● Given a grammar G, is   L(G)? ● Given two grammars G1 and G2, is L(G1) = L(G2)? ● Given a grammar G, is L(G) = ? Or, as languages: ● La = {<G, w> : w  L(G)}. ● Lb = {<G> :   L(G)}. ● Lc = {<G1, G2> : L(G1) = L(G2)}. ● Ld = {<G> : L(G) = }. None of these questions is decidable.

La = {<G, w> : w  L(G)} is not in D. Proof: Let R be a mapping reduction from: A = {<M, w> : Turing machine M accepts w} to La: R(<M, w>) = 1. From M, construct the description <G#> of a grammar G# such that L(G#) = L(M). 2. Return <G#, w>. If Oracle decides La, then C = Oracle(R(<M, w>)) decides A. We have already defined an algorithm that implements R. C is correct: ● If <M, w>  A : M(w) halts and accepts. w  L(M). So w  L(G#). Oracle(<G#, w>) accepts. ● If <M, w>  A : M(w) does not accept. w  L(M). So w  L(G#). Oracle(<G#, w>) rejects. But no machine to decide A can exist, so neither does Oracle.

The Word Problem Given two strings, w and v, and a rewrite system T, determine whether v can be derived from w using T. A key application: Logical reasoning

Semi-Thue Systems A semi-Thue system T is a pair (, R), where:  is an alphabet, R (the set of rules) is a subset of +  *. Note that: There is no unique start symbol. There is no distinction between terminal and nonterminal symbols. Theorem: The word problem for semi-Thue systems is undecidable.