Top Banner
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong
23

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

Dec 14, 2015

Download

Documents

Cristal Straker
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

LING/C SC/PSYC 438/538

Lecture 11Sandiway Fong

Page 2: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Administrivia

• Homework 3 graded

Page 3: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Last Time

1. Introduced Regular Languages– can be generated by regular expressions – or Finite State Automata (FSA)– or regular grammars --- not yet introduced

2. Deterministic and non-deterministic FSA3. DFSA can be easily encoded in Perl:

– hash table for the transition function– foreach loop over a string (character by character)– conditional to check for end state

4. NDFSA can be converted into DFSA– example of the set of states construction– Practice: ungraded homework exercise

Page 4: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Ungraded Homework Exercise

• do not submit, do the following exercise to check your understanding

– apply the set-of-states construction technique to the two machines on the ε-transition slide (repeated below)

– self-check your answer: • verify in each case that the machine produced is deterministic and

accurately simulates its ε-transition counterpart

a

ε

b>

a

ε

b>

Page 5: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Ungraded Homework Exercise Review

• Converting a NDFSA into a DFSA

1

a

ε

2 3

b>

{1,3} {2}a b {3}>

Note: this machine with an ε-transitionis non-deterministic

Note: this machine isdeterministic

Page 6: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Ungraded Homework Exercise Review

• Converting a NDFSA into a DFSA

1

a

ε

2 3

b>

{1,2} {2}a b {3}

b

Note: this machine with an ε-transitionis non-deterministic

Note: this machine isdeterministic >

Page 7: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Last TimeRegular Languages• Three formalisms

– All formally equivalent (no difference in expressive power)– i.e. if you can encode it using a RE, you can do it using a FSA or regular grammar, and so

on …

Regular Grammars

FSA Regular Expressions

Regular Languages

talk more about formalequivalence later today…

Perl regular

expressions

stuff out here

Page 8: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Perl Regular Expressions• Perl regex can include backreferences to groupings (i.e. \1, etc.)

– backreferences give Perl regexs expressive power beyond regular languages:

• the set of prime numbers is not a regular languageLprime = {2, 3, 5, 7, 11, 13, 17, 19, 23,.. }

can be proved using the Pumping Lemma for regular languages

(later)

can have regular Perl

code inside a regex

Page 9: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Backreferences and FSA• Deep question:

– why are backreferences impossible in FSA?

s x

y

aa

b

b

>

Example:Suppose you wanted a machine that accepted /(a+b+)\1/

One idea: link two copies of the machine together

x2

y2

a

a

b

b

y

Doesn’t work!Why?

• Perl implementation:– how to modify it get the backreference effect?

Page 10: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Languages and FSA• Formal (constructive) set-theoretic definition of a regular language

• Correspondence between REs and Regular Languages• concatenation (juxtaposition)• union (| also [ ])• Kleene closure (*) = (x+ = xx*)

• Note:• backreferences are memory devices and thus are too powerful• e.g. L = {ww} and prime number testing (earlier slides)

Page 11: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Languages and FSA

• Other closure properties:

• Not true higher up: e.g. context-free grammars as we’ll see later

Page 12: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Equivalence: FSA and RegexsTextbook gives one direction only• Case by case:

a) Empty stringb) Empty setc) Any character from the alphabet

Page 13: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Equivalence: FSA and Regexs

• Concatenation:

– Link final state of FSA1 to initial state of FSA2 using an empty transition

Note: empty transition can be eliminated using the set of states construction(see earlier slides in this lecture)

Page 14: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Equivalence: FSA and Regexs

• Kleene closure:

– repetition operator: zero or more times– use empty transitions for loopback and bypass

Page 15: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Equivalence: FSA and Regexs• Union: aka disjunction

– Non-deterministically run both FSAs at the same time, accept if either one accepts

Page 16: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Languages and FSA

• Other closure properties:

Let’s consider building the FSA machinery for each of these guys in turn…

Page 17: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Languages and FSA

• Other closure properties:

Page 18: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Languages and FSA

• Other closure properties:

Page 19: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Languages and FSA

• Other closure properties:

Page 20: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Languages and FSA

• Other closure properties:

Page 21: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Expressions from FSA

Textbook Exercise: find a RE for

Examples (* denotes string not in the language):*ab *bababλ (empty string)bb*babababab

Page 22: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Expressions from FSA

• Draw a FSA and convert it to a RE:

1 2 3 4>

b

ab b

b

ε

b* ab+( )+

[PowerpointAnimation]

= b+(ab+)*| ε

b

Page 23: LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong. Administrivia Homework 3 graded.

Regular Expressions from FSA

• Perl implementation:

$s = "ab ba bab bb baba babab";

while ($s =~ /\b(b+(ab+)*)\b/g) { print "<$1> match!\n";}

• Output:

perl test.perl<bab> match!<bb> match!<babab> match!

Note:doesn’t include the empty stringcase

Note: /../g global flagfor multiple matches