LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong. Administrivia Reading Homework – Chapter 3 of JM: Words and Transducers.

Slides:



Advertisements
Similar presentations
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.
Advertisements

LING/C SC/PSYC 438/538 Lecture 12 Sandiway Fong. Administrivia We'll postpone Homework 4 review until next week …
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27.
LING 388: Language and Computers Sandiway Fong 9/29 Lecture 11.
CSCI 2670 Introduction to Theory of Computing September 15, 2004.
CS21 Decidability and Tractability
LING 438/538 Computational Linguistics Sandiway Fong Lecture 8: 9/29.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/22.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
Fall 2004COMP 3351 Undecidable problems for Recursively enumerable languages continued…
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/4.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 8: 9/18.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/11.
Courtesy Costas Busch - RPI1 The Pumping Lemma for Context-Free Languages.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/25.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/6.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 11: 10/3.
1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/5.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
LING 388 Language and Computers Lecture 11 10/7/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 10: 9/26.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 5: 9/5.
CS 3240 – Chapter 8.  Is a n b n c n context-free? CS Properties of Context-Free Languages2.
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia.
1 The Pumping Lemma for Context-Free Languages. 2 Take an infinite context-free language Example: Generates an infinite number of different strings.
LING 388 Language and Computers Lecture 6 9/18/03 Sandiway FONG.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
1 13. LANGUAGE AND COMPLEXITY 2007 년 11 월 03 일 인공지능연구실 한기덕 Text: Speech and Language Processing Page.477 ~ 498.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
1 Introduction to Parsing Lecture 5. 2 Outline Regular languages revisited Parser overview Context-free grammars (CFG’s) Derivations.
Decidability A decision problem is a problem with a YES/NO answer. We have seen decision problems for - regular languages: - context free languages: [Sections.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Context Free Grammars CIS 361. Introduction Finite Automata accept all regular languages and only regular languages Many simple languages are non regular:
LING/C SC/PSYC 438/538 Lecture 7 9/15 Sandiway Fong.
1 Computability Five lectures. Slides available from my web page There is some formality, but it is gentle,
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/15.
Lecture # 5 Pumping Lemma & Grammar
LING/C SC/PSYC 438/538 Lecture 12 10/4 Sandiway Fong.
Introduction to Parsing
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
LING/C SC/PSYC 438/538 Lecture 14 Sandiway Fong. Administrivia Homework 6 graded.
Properties of Regular Languages
Conversions & Pumping Lemma CPSC 388 Fall 2001 Ellen Walker Hiram College.
CS 203: Introduction to Formal Languages and Automata
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
LING/C SC/PSYC 438/538 Lecture 16 Sandiway Fong. SWI Prolog Grammar rules are translated when the program is loaded into Prolog rules. Solves the mystery.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
CSCI 2670 Introduction to Theory of Computing September 14, 2005.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong. Last Time Talked about: – 1. Declarative (logical) reading of grammar rules – 2. Prolog query: s(String,[]).
1 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5.
Standard Representations of Regular Languages
Context free grammar.
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
PARSE TREES.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Context-Free Languages
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
CS21 Decidability and Tractability
LING/C SC/PSYC 438/538 Lecture 18 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Applications of Regular Closure
CHAPTER 1 Regular Languages
Presentation transcript:

LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong

Administrivia Reading Homework – Chapter 3 of JM: Words and Transducers

Today Topics Left recursive regular grammars The limits of regular grammars (RG), FSA and Res

Left Recursion and Set Enumeration Example: s --> a, [!]. a --> ba, [a]. a --> a, [a]. ba --> b, [a]. b --> [b]. Grammar is: – a regular grammar – left recursive Question – What is the language of this grammar? Answer: Sheeptalk ! Sentential forms: s a! baa! Underscoring used here to indicate a nonterminal Underscoring used here to indicate a nonterminal

Left Recursion and Set Enumeration Example: s --> a, [!]. a --> ba, [a]. a --> a, [a]. ba --> b, [a]. b --> [b]. Prolog query: ?- s([b,a,a,!],[]). Yes ?- s([b,a,a,a,a,!],[]). yes But it doesn’t halt when faced with a string not in the language ?- s([b,a,!],[]). ! Resource error: insufficient memory

Left Recursion and Set Enumeration Example: 1.s --> a, [!]. 2.a --> ba, [a]. 3.a --> a, [a]. 4.ba --> b, [a]. 5.b --> [b]. –?- s([b,a,!],[]). –! Resource error: insufficient memory Why?

Left Recursion and Set Enumeration left recursive regular grammar: 1.s --> a, [!]. 2.a --> ba, [a]. 3.a --> a, [a]. 4.ba --> b, [a]. 5.b --> [b]. Behavior – halts when presented with a string that is in the language – doesn’t halt when faced with a string not in the language – unable to decide the language membership question Surprisingly, the query: ?- s(L,[]). enumerates the strings in the language just fine.

Left Recursion and Set Enumeration left recursive regular grammar: 1.s --> a, [!]. 2.a --> ba, [a]. 3.a --> a, [a]. 4.ba --> b, [a]. 5.b --> [b]. Behavior – halts when presented with a string that is in the language – doesn’t halt when faced with a string not in the language derivation tree for ?- s(L,[]). s a ba b b a a ! s a a b b a a a ! and so on L =L = [b|..] L = [b,a|..] L = [b,a,a|..]L = [b,a,a,!] [Powerpoint animation] Choice point

Left Recursion and Set Enumeration However, this slightly re- ordered left recursive regular grammar: 1.s --> a, [!]. 2.a --> a, [a]. 3.a --> ba, [a]. 4.ba --> b, [a]. 5.b --> [b]. won’t halt when enumerating Why? s a a a a... descends infinitely using rule 2 descends infinitely using rule 2 [Powerpoint animation]

Beyond Regular Languages Beyond regular languages – a n b n = {ab, aabb, aaabbb, aaaabbbb,... } n≥1 – is not a regular language That means no FSA, RE or RG can be built for this set Informally, let’s think about a FSA implementation … 1.We only have a finite number of states to play with … 2.We’re only allowed simple free iteration (looping) 1.We only have a finite number of states to play with … 2.We’re only allowed simple free iteration (looping)

Beyond Regular Languages Language – a n b n = {ab, aabb, aaabbb, aaaabbbb,... } n>=1 A regular grammar extended to allow both left and right recursive rules can accept/generate it: 1.a --> [a], b. 2.b --> [b]. 3.b --> a, [b]. Example: Set membership Set enumeration

Beyond Regular Languages Language – a n b n = {ab, aabb, aaabbb, aaaabbbb,... } n>=1 A regular grammar extended to allow both left and right recursive rules can accept/generate it: 1.a --> [a], b. 2.b --> [b]. 3.b --> a, [b]. Intuition: – grammar implements the stacking of partial trees balanced for a’s and b’s: B A b a A B A b a

Beyond Regular Languages Language – a n b n = {ab, aabb, aaabbb, aaaabbbb,... } n>=1 A regular grammar extended to allow both left and right recursive rules can accept/generate it: 1.a --> [a], b. 2.b --> [b]. 3.b --> a, [b]. A context-free grammar (CFG) (aka type-2) has no restrictions on what can go on the RHS of a grammar rule Note: – CFGs still have a single nonterminal limit for the LHS of a rule Example: 1.s --> [a], [b]. 2.s --> [a], s, [b].

A Formal Tool: The Pumping Lemma A tool used to prove languages are NOT regular – based on the intuition that if a language is regular and non-trivial (infinite), – it “pumps” (iterates freely) – Recall: for any given # states, if the (accepted) input string is long enough, you’ll need to loop Note: – can’t be used to prove a language is regular – to show something is regular: proof by exhibition describe a FSA (or regular expression or regular grammar)

A Formal Tool: The Pumping Lemma [See also discussion in JM , pages 533–534] If a language L is regular, then there exists a number p > 0 –where p is a pumping length –(sometimes called a magic number) such that every string w in L with | w | ≥ p can be written in the following form w = xyz with strings x, y and z such that | xy | ≤ p, | y | > 0 and xy i z is in L for every integer i ≥ 0.

A Formal Tool: The Pumping Lemma Example: – show that a n b n is not regular Proof (by contradiction): – pick a sufficiently long string in the language – e.g. a..aab..bb (#a’s = #b’s) – Partition it according to w = xyz – then show xy i z is not in L –i.e. string does not pump

A Formal Tool: The Pumping Lemma aaaa..aabbbb..bb Case 1: w = xyz, y straddles the ab boundary what happens when we pump y? yyy Case 2: w = xyz, y is wholly within the a’s what happens when we pump y? Case 3: w = xyz, y is wholly within the b’s what happens when we pump y?

A Formal Tool: The Pumping Lemma Prime number testing (from lecture 9) prime number testing using Perl’s so-called “regular expressions” Using unary notation, e.g. 5 = “11111” /^(11+?)\1+$/ will match anything that’s greater than 1 that’s not prime Key to making this work: backreference \1 L = {1 n | n is prime} is not a regular language

A Formal Tool: The Pumping Lemma 1 n = such that n is a prime number yxz Pump y such that i = length(x+z), giving y i What is the length of string w=xy i z now? Pump y such that i = length(x+z), giving y i What is the length of string w=xy i z now? The resulting length is non-prime since it can be factorized