LING/C SC/PSYC 438/538 Lecture 14 Sandiway Fong. Administrivia Homework 6 graded.

Slides:



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

Lecture 9,10 Theory of AUTOMATA
LING/C SC/PSYC 438/538 Lecture 12 Sandiway Fong. Administrivia We'll postpone Homework 4 review until next week …
3.2 Pumping Lemma for Regular Languages Given a language L, how do we know whether it is regular or not? If we can construct an FA to accept the language.
CS21 Decidability and Tractability
LING 438/538 Computational Linguistics Sandiway Fong Lecture 8: 9/29.
Automata and Formal Languages Tim Sheard 1 Lecture 8 Pumping Lemma & Distinguishability Jim Hook Tim Sheard Portland State University.
Courtesy Costas Busch - RPI1 More Applications of the Pumping Lemma.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/4.
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (more on Section 1.4) David Martin This work is licensed under.
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.
CS 310 – Fall 2006 Pacific University CS310 Pumping Lemma Sections:1.4 page 77 September 27, 2006.
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
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 Lecture 11 10/7/03 Sandiway FONG.
1 More Applications of the Pumping Lemma. 2 The Pumping Lemma: Given a infinite regular language there exists an integer for any string with length we.
Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Context Free Pumping Lemma Zeph Grunschlag. Agenda Context Free Pumping Motivation Theorem Proof Proving non-Context Freeness Examples on slides Examples.
Lecture 8 Sept 29, 2011 Regular expressions – examples Converting DFA to regular expression. (same works for NFA to r.e. conversion.) Converting R.E. to.
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Extra on Regular Languages and Non-Regular Languages
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 7 Mälardalen University 2010.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
LING/C SC/PSYC 438/538 Lecture 7 9/15 Sandiway Fong.
Lecture # 5 Pumping Lemma & Grammar
Solution Exercise 1.43 a A r r s q q > b b e b s’ q r q’ b r’ a A’
LING/C SC/PSYC 438/538 Lecture 12 10/4 Sandiway Fong.
Complexity, etc. Homework. Comparison to computability. Big Oh notation. Sorting. Classwork/Homework: prepare presentation on specific sorts. Presentation.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong. Administrivia Reading Homework – Chapter 3 of JM: Words and Transducers.
LING/C SC/PSYC 438/538 Lecture 8 Sandiway Fong. Adminstrivia Homework 4 not yet graded …
Properties of Regular Languages
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
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
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,
1 Find as many examples as you can of w, x, y, z so that w is accepted by this DFA, w = x y z, y ≠ ε, | x y | ≤ 7, and x y n z is in L for all n ≥ 0.
LING/C SC/PSYC 438/538 Online Lecture 7 Sandiway Fong.
CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
1 Advanced Theory of Computation Finite Automata with output Pumping Lemma Theorem.
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,[]).
Nonregular Languages Section 2.4 Wed, Oct 5, 2005.
Pumping Lemma.
Standard Representations of Regular Languages
CSE322 PUMPING LEMMA FOR REGULAR SETS AND ITS APPLICATIONS
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Intro to Theory of Computation
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
Pumping Lemma.
Chapter 4 Properties of Regular Languages
Nonregular languages & the pumping lemma
Recap lecture 26 Example of nonregular language, pumping lemma version I, proof, examples,
LING/C SC/PSYC 438/538 Lecture 18 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Recap lecture 25 Intersection of two regular languages is regular, examples, non regular languages, example.
CHAPTER 1 Regular Languages
Regular Expressions.
Presentation transcript:

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

Administrivia Homework 6 graded

Applications of FSA Let’s take a look at one application of regular language technology: – Efficient String Matching

String Matching Example: – Pattern (P): aaba – Corpus (C): aaabbaabab Naïve algorithm: – compare Pattern against Corpus from left to right a character at a time – P: aaba – C: aaabbaabab – P: _aaba – C: aaabbaabab – P: __aaba – C: aaabbaabab – P: ___aaba – C: aaabbaabab – P: ____aaba – C: aaabbaabab – P: _____aaba – C: aaabbaabab Matched!

Knuth-Morris-Pratt (KMP) can do better (i.e. use fewer comparisons) if we use a FSA to represent the Pattern plus extra links for restarts in the event of a failure Example Pattern: aaba aaba ^a ^b all backpointers are restarts for failed character ^a Suppose the alphabet was limited to just {a,b}, then restarts can be for the character following the failed character aaba b b a b

Knuth-Morris-Pratt (KMP) Example: – Pattern: aaba – Corpus {a,b}: aaabbaabab KMP: – P: aaba – C: aaabbaabab (mismatch at state 2) – P: _aaba – C: aaabbaabab (mismatch at state 3) – P: _____aaba – C: aaabbaabab(matched) aaba b b a b Other possible algorithms: e.g. Boyer-Moore (start match from the back of the pattern) Other possible algorithms: e.g. Boyer-Moore (start match from the back of the pattern)

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 Regular Grammar) 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)

Beyond Regular Languages L = a + b + sx y a a b b Having a frequency table is not permitted. Not allowed: %freq = (); … $freq{$state}++;

A Formal Tool: The Pumping Lemma [See also discussion in JM , pages 533–534] Let L be a regular language, 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. BTW: there is also a pumping lemma for Context-Free Languages

A Formal Tool: The Pumping Lemma Restated: For every (sufficiently long) string w in a regular language there is always a way to split the string into three adjacent sections, call them x, y and z, (y nonempty), i.e. w is x followed by y followed by z And y can be repeated as many times as we like (or omitted) And the modified string is still a member of the language Essential Point! To prove a language is non-regular: show that no matter how we split the string, there will be modified strings that can't be in the language

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?

anbnanbn In Perl? – we could use (?{…Perl code...}) can it be done wholly inside the Perl regex?

A Formal Tool: The Pumping Lemma Prime number testing prime number testing using Perl’s extended “regular expressions” Using unary notation, e.g. 5 = “11111” /^(11+?)\1+$/ will match anything that’s greater than 1 that’s not prime 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 For any split of the string Pump y such that i = length(x+z), giving y i What is the length of string w=xy i z now? In x y xz z, how many copies of xz do we have? Answer is y+1 i.e. pumped number can be factorized into (1+|y|)|xz| The resulting length is non-prime since it can be factorized

A Formal Tool: The Pumping Lemma 1 n = such that n is a prime number yxz Illustration of the calculation: (eleven) *7 + 3 = 5*7 which isn't prime

A Formal Tool: The Pumping Lemma Another angle to reduce the mystery, let's think in terms of FSA. We know: 1.we can't control the loops 2.we are restricted to a finite number of states 3.assume (without loss of generality) there are no e- transitions Suppose there are a total of p states in the machine Supose we have a string in the language longer than p What can we conclude? Answer: we must have visited some state(s) more than once! Also: there must be a loop (or loops) in the machine! Also: we can repeat or skip that loop and stay inside the language!

Homework 7

SWI Prolog Install on your laptop (Mac or PC): –

SWI Prolog Mac problems: option-click on application

SWI Prolog Control-D (EOF) to terminate. halt. 1.every command ends in a period 2.case sensitive: variables begin with an uppercase letter

SWI Prolog Install on your laptop (Linux, Debian-based): – sudo apt-add-repository ppa:swi-prolog/stable sudo apt-get update sudo apt-get install swi-prolog

SWI Prolog