LING/C SC/PSYC 438/538 Lecture 12 10/4 Sandiway Fong.

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 Computational Linguistics Sandiway Fong Lecture 13: 10/9.
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.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
LING 438/538 Computational Linguistics Sandiway Fong Lecture 16: 10/19.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 8: 9/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
CS 3240 – Chapter 3.  How would you delete all C++ files from a directory from the command line?  How about all PowerPoint files that start with the.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 10: 9/27.
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.
LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.
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.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
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.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.
LING 388: Language and Computers Sandiway Fong Lecture 11: 10/3.
Fall 2005 CSE 467/567 1 Formal languages regular expressions regular languages finite state machines.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/5.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
LING/C SC/PSYC 438/538 Midterm 10/11. Instructions It is recommended that you attempt all questions –Submit your answers in one file by to
LING 388: Language and Computers Sandiway Fong Lecture 10: 9/26.
LING 388 Language and Computers Lecture 6 9/18/03 Sandiway FONG.
CMSC 330 Exercise: Write a Ruby function that takes an array of names in “Last, First Middle” format and returns the same list in “First Middle Last” format.
Finite-State Machines with No Output
::ICS 804:: Theory of Computation - Ibrahim Otieno SCI/ICT Building Rm. G15.
1 Section 3.3 Grammars A grammar is a finite set of rules, called productions, that are used to describe the strings of a language. Notational Example.
1 Chapter Construction Techniques. 2 Section 3.3 Grammars A grammar is a finite set of rules, called productions, that are used to describe the.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,
LING/C SC/PSYC 438/538 Lecture 7 9/15 Sandiway Fong.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/15.
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 8.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
LING 388: Language and Computers Sandiway Fong 9/27 Lecture 10.
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong. Administrivia Reading Homework – Chapter 3 of JM: Words and Transducers.
Discrete Mathematical Structures 4 th Edition Kolman, Busby, Ross © 2000 by Prentice-Hall, Inc. ISBN
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
LING/C SC/PSYC 438/538 Lecture 14 Sandiway Fong. Administrivia Homework 6 graded.
CSC312 Automata Theory Lecture # 3 Languages-II. Formal Language A formal language is a set of words—that is, strings of symbols drawn from a common alphabet.
Recursive Definations Regular Expressions Ch # 4 by Cohen
LING/C SC/PSYC 438/538 Lecture 18 Sandiway Fong. Adminstrivia Homework 7 out today – due Saturday by midnight.
Regular Grammars Reading: 3.3. What we know so far…  FSA = Regular Language  Regular Expression describes a Regular Language  Every Regular Language.
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.
Lecture # 4.
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
 2004 SDU Lecture4 Regular Expressions.  2004 SDU 2 Regular expressions A third way to view regular languages. Say that R is a regular expression if.
1 1. Eliminate all  -transitions from the following FA without changing the number of states and the language accepted by the automaton. You should also.
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,[]).
Recap lecture 5 Different notations of transition diagrams, languages of strings of even length, Odd length, starting with b, ending in a (with different.
Theory of Computation Lecture #
Even-Even Devise a grammar that generates strings with even number of a’s and even number of b’s.
LING/C SC/PSYC 438/538 Lecture 11 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Chapter 7 Regular Grammars
CS 350 — Fall 2018 gilray.org/classes/fall2018/cs350/
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
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.
Recap Lecture 4 Regular expression of EVEN-EVEN language, Difference between a* + b* and (a+b)*, Equivalent regular expressions; sum, product and closure.
Presentation transcript:

LING/C SC/PSYC 438/538 Lecture 12 10/4 Sandiway Fong

Administrivia Homework 3 out today – Usual rules, due next Monday (11 th October)

XKCD Acknowledgement: Erwin Chan

Let’s write a regular grammar Example from Lecture 10 Regular expression: b+(ab+)* | ε > b ab b b ε FSA:

Let’s write a regular grammar Test cases (* denotes string not in the language): – *ab *ba [a,b][b,a] – bab [b,a,b] – λ (empty string) [] – bb [b,b] – *baba [b,a,b,a] – babab [b,a,b,a,b]

Let’s write a regular grammar Regular Grammar in Prolog notation: –s --> []. ( s = ”start state”) –s --> [b], b. ( b = ”seen a b ”) –s --> [b], s. –b --> [a], c. ( c = ”expect a b ”) –c --> [b]. –c --> [b], b. –c --> [b], c.

Let’s write a regular grammar Compare the FSA with our Regular Grammar (RG) –s --> []. ( s = ”start state”) –s --> [b], b. ( b = ”seen a b ”) –s --> [b], s. –b --> [a], c. ( c = ”expect a b ”) –c --> [b]. –c --> [b], b. –c --> [b], c > b ab b b ε There is a straightforward correspondence between right recursive RGs and FSA

RG to FSA Informally, we can convert RG to a FSA – by treating – non-terminals as states – and introducing (new) states for rules of the form x --> [a]. s s > b c c a b b b e e b b b 1.s --> []. 2.s --> [b], b. 3.s --> [b], s. 4.b --> [a], c. 5.c --> [b]. 6.c --> [b], b. 7.c --> [b], c. 1.s --> []. 2.s --> [b], b. 3.s --> [b], s. 4.b --> [a], c. 5.c --> [b]. 6.c --> [b], b. 7.c --> [b], c. [Powerpoint animation] in order of the RG rules

Let’s write a regular grammar Test cases (* denotes string not in the language): – *ab *ba [a,b][b,a] – bab [b,a,b] – λ (empty string) [] – bb [b,b] – *baba [b,a,b,a] – babab [b,a,b,a,b] Output: Licensed to SP4arizona.edu [g]. % compiling /Users/sandiway/Desktop/g.pl... % compiled /Users/sandiway/Desktop/g.pl in module user, 0 msec -16 bytes yes | ?- s([a,b],[]). no | ?- s([b,a],[]). no | ?- s([b,a,b],[]). yes | ?- s([],[]). yes | ?- s([b,b],[]). yes | ?- s([b,a,b,a],[]). no | ?- s([b,a,b,a,b],[]). yes

Set Enumeration using Prolog Regular Grammar 1.s --> []. 2.s --> [b], b. 3.s --> [b], s. 4.b --> [a], c. 5.c --> [b]. 6.c --> [b], b. 7.c --> [b], c. Normally, we ask the set membership question when posing a Prolog query: – e.g. ?- s([a,b],[]). no Prolog enumeration: ?- s(X,[]). –X is a Prolog variable – asks the question for what values of X is s(X,[]) true? –; is disjunction (look for alternative answers) why? Prolog matches rules in the order in which they’re written

Set Enumeration using Prolog Let’s swap rules 2 and 3 Regular Grammar 1.s --> []. 2.s --> [b], s. 3.s --> [b], b. 4.b --> [a], c. 5.c --> [b]. 6.c --> [b], b. 7.c --> [b], c. Prolog enumeration: ?- s(X,[]).

Set Enumeration using Prolog Similarly, if we swap rules 6 and 7 Regular Grammar –s --> []. –s --> [b], b. –s --> [b], s. –b --> [a], c. –c --> [b]. –c --> [b], c. –c --> [b], b. Prolog enumeration: ?- s(X,[]).

Set Enumeration using Prolog Regular Grammar 1.s --> []. 2.s --> [b], b. 3.s --> [b], s. 4.b --> [a], c. 5.c --> [b]. 6.c --> [b], b. 7.c --> [b], c. Unfortunately, the default Prolog grammar rule matching convention does not permit us to properly enumerate the set (language). Enumeration (in order of size): – Length: 0 –[] – Length: 1 –[b] – Length: 2 –[b,b] – Length: 3 –[b,b,b][b,a,b] – Length: 4 –[b,b,b,b][b,b,a,b] –[b,a,b,b] – Length: 5 –[b,b,b,b,b] [b,b,b,a,b] –[b,b,a,b,b] [b,a,b,b,b] –[b,a,b,a,b] – etc.

Converting FSA to REs Example: – Give a RE for the FSA: State by-pass method: – Delete one state at a time – Calculate the possible paths passing through the deleted state – E.g. eliminate state 3 then 2… >

Converting FSA to REs eliminate state 3 eliminate state > > (1 + 0|1)* > 0(1 + 0|1)*1 + 1 | 1 [Powerpoint animation] (0(1 + 0|1)*1 + 1 | 1)*

Homework 3 Consider the language L given by – L = a*b*  (ab)* We can express this as: – L = L 1  L 2 – L 1 = a*b* – L 2 = (ab)* Question 1 (438/538) 15 points Part 1 – Give a regular grammar for L 1 in Prolog Part 2 – Give a regular grammar for L 2 in Prolog Part 3 – Give a regular grammar for L (=L 1  L 2 ) in Prolog Instruction: – In each case show your program and sample output

Homework 3 Consider the language L given by – L = a*b*  (ab)* We can express this as: – L = L 1  L 2 – L 1 = a*b* – L 2 = (ab)* Question 2 (438/538) 15 points Give a deterministic FSA for L – Draw a diagram – Implement it in Perl – show your program and sample output

Homework 3 Question 3 (538 obligatory, 438 extra credit) 15 points – Give a FSA that accepts strings of a’s and b’s (in any order) such that the total number of a’s in the string must be even and the total number of b’s in string must be odd e.g. – aab baababa – *b *ab *aabbbb *aa (* indicates string not in the language)