CSE 105 theory of computation

Slides:



Advertisements
Similar presentations
CS21 Decidability and Tractability
Advertisements

1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Mount Holyoke College 2 Nonregular languages? We now know: –Regular languages may be specified either.
Introduction to Computability Theory
Nonregular languages Sipser 1.4 (pages 77-82). CS 311 Fall Nonregular languages? We now know: –Regular languages may be specified either by regular.
CS5371 Theory of Computation
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.2: Pushdown Automata) Prof. Karen Daniels, Fall 2009 with acknowledgement.
Normal forms for Context-Free Grammars
Theory of Languages and Automata
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
CS355 - Theory of Computation Regular Expressions.
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
CS 203: Introduction to Formal Languages and Automata
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
1 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5.
Theory of Languages and Automata By: Mojtaba Khezrian.
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Context-Free Grammars: an overview
Formal Language & Automata Theory
Properties of Context-Free Languages
CSE 105 theory of computation
CSE 105 theory of computation
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
PROPERTIES OF REGULAR LANGUAGES
FORMAL LANGUAGES AND AUTOMATA THEORY
Context free grammar.
CSE 105 theory of computation
CSE 105 theory of computation
PDAs Accept Context-Free Languages
PARSE TREES.
CSE 105 theory of computation
Context-free Languages
CSE 105 theory of computation
Intro to Data Structures
CHAPTER 2 Context-Free Languages
Context-Free Grammars
Context-Free Languages
CSE 105 theory of computation
فصل دوم Context-Free Languages
Deterministic PDAs - DPDAs
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Chapter 4 Properties of Regular Languages
CS21 Decidability and Tractability
Context-Free Languages
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSCI 2670 Introduction to Theory of Computing
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
CSE 105 theory of computation
Presentation transcript:

CSE 105 theory of computation Fall 2019 https://cseweb.ucsd.edu/classes/fa19/cse105-a/

Today's learning goals Sipser Ch 1.4, 2.1 Apply the Pumping Lemma in proofs of nonregularity Identify some nonregular sets Define context-free grammars Test if a specific string can be generated by a given context-free grammar

Pumping Lemma Sipser p. 78 Theorem 1.70 # states in DFA recognizing A Transition labels along loop

Proof strategy To prove that a language L is not regular Assume towards a contradiction that it is. Use Pumping Lemma to give p, a pumping length for L Show that p actually isn't a pumping length for L.  Conclude that L is not regular.

Another example Claim: The set {anbman | m,n≥ 0} is not regular. Proof: …Consider the string s = …… You must pick s carefully: we want |s|≥p and s in L. Now we will demonstrate that "s cannot be pumped", thereby contradicting the assumption that p is a pumping length. Which choices of s cannot be used to complete the proof? A. s = apbp B. s = abpa C. s = apbpap D. s = apbap E. None of the above (all of these choices work).

Another example Claim: The set {anbman | m,n≥ 0} is not regular. Proof: …Consider the string s = …… You must pick s carefully: we want |s|≥p and s in L. Now we will prove a contradiction with the statement "s can be pumped" Consider an arbitrary choice of x,y,z such that s = xyz, |y|>0, |xy|≤p. This means that...What properties are guaranteed about x,y,z? Consider i=… In this case, xyiz = …, which is not in L, a contradiction with the Pumping Lemma applying to L and so L is not regular.

Regular sets: not the end of the story Many nice / simple / important sets are not regular Limitation of the finite-state automaton model Can't "count" Can only remember finitely far into the past Can't backtrack Must make decisions in "real-time" We know computers are more powerful than this model… Which conditions should we relax?

The next model of computation Idea: allow some memory of unbounded size How? Generalization of regular expressions  Context-free grammars Generalization for DFA  Pushdown Automata

Context-free languages over Σ Birds' eye view All languages over Σ Context-free languages over Σ Regular languages over Σ Finite languages over Σ

Context-free grammar Sipser Def 2.2, page 102 (V, Σ, R, S) Variables: finite set of (usually upper case) variables V Terminals: finite set of alphabet symbols Σ Rules/Productions: finite set of allowed transformations R Start variable: origination of each derivation S

Context-free language Sipser p. 104 The language generated by a CFG (V, Σ, R, S) is { w in Σ* | Starting with the Start variable and applying one or more rules, can derive w on RHS} If G = (V, Σ, R, S) the language generated by G is denoted L(G). Notation: Terminology: sequence of rule applications is derivation

An example? Consider the CFG ({S}, {0}, R, S) where R is the following set of rules S  0S S  0 Is this a well-formed definition? No: there's more than one rule No: the same LHS gets sent to two different strings. No: one of the string in the RHS has both variables and literals Yes. I don't know.

Context-free language Sipser p. 104 For CFG G = (V, Σ, R, S), L(G) = { w in Σ* | Starting with the Start variable and applying one or more rules, can derive w on RHS}. What is the language of the CFG ({S}, {0}, R, S) with R = {S  0S, S  0} ? A. {0} B. {0, 0S} C. {0, 00, 000, …} D. {ε, 0, 00, 000, …} E. I don't know.

Context-free language Sipser p. 104 What is the language of the CFG ({S}, {0,1}, R, S) with R = the set of rules S  0S S  1S S  ε A. L(0*1*) B. L(0* U 1*) C. L( (0 U 1) *) D. L ( (0*1*) )* E. I don't know. S  0S | 1S | ε

Can CFGs describe simple sets? Designing a CFG Can CFGs describe simple sets? Building a CFG to describe the language { abba } V = { S, T, V, W } Σ = { a,b } R = { S  aT T  bV V  bW W  a } S

Can CFGs describe simple sets? Designing a CFG Can CFGs describe simple sets? Building a CFG to describe the language { abba } V = Σ = R = S = What's the set of terminals of this CFG? {a,b} V U S U Σ {S, a, b} {a,b, ε} I don't know.

Can CFGs describe simple sets? Designing a CFG Can CFGs describe simple sets? Building a CFG to describe the language { abba } ( { S, T, V, W } , { a,b } , { S  aT , T  bV , V  bW , W  a }, S ) OR ( { S } , { a,b } , { S  abba } , S )

Is every regular language a CFL? Approach 1: start with an arbitrary DFA M, build a CFG that generates L(M). Approach 2: build CFGs for {a}, {ε}, {}; then show that the class of CFL is closed under the regular operations (union, concatenation, Kleene star).

Approach 1 Claim: Given any DFA M, there is a CFG whose language is L(M). Construction: Trace computation using variables to denote state Given M = (Q,Σ,δ,q0,F) a DFA, define the CFG V = { Si | qi is in Q } Σ R = { Si  aSj | δ(qi,a) = qj } U { Si  ε | qi is in F} S = S0 Then prove correctness…

Approach 2 If G1 = (V1, Σ, R1, S1) and G2 = (V2, Σ, R2, S2) are CFGs and G1 describes L1, G2 describes L2, how can we combine the grammars so we describe L1 U L2 ? G = (V1 U V2, Σ, R1 U R2, S1 U S2) G = (V1 x V2, Σ, R1 x R2, (S1, S2) ) We might not always be able to: the class of CFG describable languages might not be closed under union. I don't know.

Approach 2 If G1 = (V1, Σ, R1, S1) and G2 = (V2, Σ, R2, S2) are CFGs and G1 describes L1, G2 describes L2, how can we combine the grammars so we describe L1 U L2 ?

We know this set is not regular! Designing a CFG We know this set is not regular! Building a CFG to describe the language { anbn | n ≥ 0 }

Designing a CFG Building a CFG to describe the language { anbn | n ≥ 0 } One approach: what is shortest string in the language? how do we go from shorter strings to longer ones?

Designing a CFG Building a CFG to describe the language { anbn | n ≥ 0 } V = { S } Σ = { a,b } R = S Which rules would complete this CFG? S  ε | ab S  ε | aS | Sb S  ε | aSb We need another variable other than S. I don't know.

Designing a CFG Also not a regular set Building a CFG to describe the language { 0n1m2n | n,m ≥ 0 } Hint: work from the outside in.

Designing a CFG Also not a regular set Building a CFG to describe the language { 0n1m2n | n,m ≥ 0 } Hint: work from the outside in. V = { S, T } Σ = { 0,1,2 } R = { S  0S2 | T | ε , T  1T | ε } S