Week 13 - Wednesday.  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing.

Slides:



Advertisements
Similar presentations
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of the FSA is easy for us to understand, but difficult.
Advertisements

Finite-State Machines with No Output Ying Lu
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Languages, grammars, and regular expressions
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
1 Languages and Finite Automata or how to talk to machines...
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
Topics Automata Theory Grammars and Languages Complexities
Copyright © Cengage Learning. All rights reserved.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Copyright © Cengage Learning. All rights reserved.
Chapter 2 Languages.
Week 14 - Friday.  What did we talk about last time?  Exam 3 post mortem  Finite state automata  Equivalence with regular expressions.
Finite-State Machines with No Output Longin Jan Latecki Temple University Based on Slides by Elsa L Gunter, NJIT, and by Costas Busch Costas Busch.
Finite-State Machines with No Output
::ICS 804:: Theory of Computation - Ibrahim Otieno SCI/ICT Building Rm. G15.
CMPS 3223 Theory of Computation
Formal Methods in SE Theory of Automata Qasiar Javaid Assistant Professor Lecture # 06.
Lecture Two: Formal Languages Formal Languages, Lecture 2, slide 1 Amjad Ali.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Language Recognition Rosen, Chapter 12.4.
An ordered n-tuple is a set of n objects with an order associated with them. If n objects are represented by x 1, x 2,..., x n, then we write the ordered.
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
1 Computability Five lectures. Slides available from my web page There is some formality, but it is gentle,
Lexical Analysis I Specifying Tokens Lecture 2 CS 4318/5531 Spring 2010 Apan Qasem Texas State University *some slides adopted from Cooper and Torczon.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2006.
Week 14 - Wednesday.  What did we talk about last time?  Regular expressions  Introduction to finite state automata.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
Regular Expressions CIS 361. Need finite descriptions of infinite sets of strings. Discover and specify “regularity”. The set of languages over a finite.
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.
Regular Expressions Chapter 6 1. Regular Languages Regular Language Regular Expression Finite State Machine L Accepts 2.
2. Regular Expressions and Automata 2007 년 3 월 31 일 인공지능 연구실 이경택 Text: Speech and Language Processing Page.33 ~ 56.
CHAPTER 1 Regular Languages
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
Brian Mitchell - Drexel University MCS680-FCS 1 Patterns, Automata & Regular Expressions int MSTWeight(int graph[][], int size)
CS 203: Introduction to Formal Languages and Automata
Recursive Definations Regular Expressions Ch # 4 by Cohen
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
Finite Automata Chapter 1. Automatic Door Example Top View.
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
1 Chapter 3 Regular Languages.  2 3.1: Regular Expressions (1)   Regular Expression (RE):   E is a regular expression over  if E is one of:
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Week 13 - Wednesday.  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
Week 14 - Wednesday.  What did we talk about last time?  Exam 3 post mortem  Finite state automata  Equivalence with regular expressions.
Week 13 - Friday.  What did we talk about last time?  Regular expressions.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Theory of Computation Lecture #
Languages.
Week 14 - Friday CS221.
REGULAR LANGUAGES AND REGULAR GRAMMARS
Chapter Seven: Regular Expressions
Some slides by Elsa L Gunter, NJIT, and by Costas Busch
Specifying Languages Our aim is to be able to specify languages for use in the computer. The sketch of the FSA is easy for us to understand, but difficult.
Principles of Computing – UFCFA3-30-1
Compiler Construction
Presentation transcript:

Week 13 - Wednesday

 What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing bounds for running time functions

 Ten people are marooned on a deserted island  During their first day they gather many coconuts and put them all in a community pile  They are so tired that they decide to divide them into ten equal piles the next morning  That night one castaway wakes up hungry and decides to take his share early  After dividing up the coconuts he finds he is one coconut short of ten equal piles  He notices a monkey holding one coconut  He tries to take the monkey's coconut so that the total is evenly divisible by 10  However, when he tries to take it, the monkey hits him on the head with it, killing him  Later, another castaway wakes up hungry and decides to take his share early  On the way to the coconuts he finds the body of the first castaway and realizes that he is now be entitled to 1/9 of the total pile  After dividing them up into nine piles he is again one coconut short of an even division and tries to take the monkey's (slightly) bloody coconut  Again, the monkey hits the second man on the head and kills him  Each of the remaining castaways goes through the same process, until the 10 th person to wake up realizes that the entire pile for himself  What is the smallest number of coconuts in the original pile (ignoring the monkey's)?

 Computer science grew out a lot of different pieces  Mathematics  Engineering  Linguistics  Describing an algorithm precisely requires that it be framed in terms of some formal language with exact rules

 We say that a language is a set of strings  A string is an ordered n-tuple of elements of an alphabet Σ or the empty string ε (which has no characters)  An alphabet Σ is a finite set of characters

 Let alphabet Σ = {a, b}  Define a language L 1 over Σ to be the set of all strings that begin with the character a and have length at most three characters  Write out L 1  A palindrome is a string which stays the same if the order of its characters is reversed  Define a language L 2 over Σ to be the set of all palindromes made up of characters from Σ  Write 10 strings in L 2

 Let Σ be some alphabet  For any nonnegative integer n, let  Σ n be the set of all strings over Σ that have length n  Σ + be the set of all strings over Σ that have length at least 1  Σ * be the set of all strings over Σ  Σ * is called the Kleene closure of Σ and the * operator is often called the Kleene star

 Let alphabet Σ = {x, y, z}  Find Σ 0, Σ 1, and Σ 2  What is A = Σ 0  Σ 1 ? What is B = Σ 1  Σ 2 ? How would you describe these sets and set A  B in words?  Describe a systematic way of writing out Σ +  How would you have to change your system to write out Σ * ?

 Let Σ be a finite alphabet  Given strings x and y over Σ, the concatenation of x and y is the string made by writing x with y appended afterwards  With languages L and L' over Σ, we can define the following new languages:  Concatenation of L and L', written LL' ▪ LL' = { xy | x  L and y  L' }  Union of L and L', written L  L' ▪ L  L' = { x | x  L or x  L' }  Kleene closure of L, written L * ▪ L * = { x | x is a concatenation of any finite number of strings in L }

 Let alphabet Σ = {a, b}  Let L 1 be the set of all strings consisting of an even number of a's (including the empty string)  Let L 2 = {b, bb, bbb}  Find L1L2L1L2 L1  L2L1  L2 (L1  L2)*(L1  L2)*

 It's getting annoying trying to describe infinite languages using ellipses  Notation called a regular expression can allow us to express languages precisely and compactly  Given a finite alphabet Σ, we can define regular expressions recursively: I. Base: The empty set, the empty string ε, and any individual character in Σ is a regular expression II. Recursion: If r and s are regular expressions over Σ, then the following are too: a)Concatenation: (rs) b)Alternation: (r | s) c)Kleene star: (r*) III. Restriction: Nothing else is a regular expression

 For a finite alphabet Σ, the language L(r) defined by a regular expression r is as follows  Base: L(  ) = , L(ε) = {ε}, L(a) = {a} for every a  Σ  Recursion: If L(r) and L(r') are the languages defined by the regular expressions r and r' over Σ, then  L(r r') = L(r)L(r')  L(r | r') = L(r)  L(r')  L(r * ) = (L(r)) *

 Let Σ = {a, b, c}  Let language L = a | (b | c)* | (ab)*  Write 5 strings in L  Let language M = ab * (c |ε)  Write 5 strings in M

 For the sake of consistency, regular expressions obey a particular order of precedence  * is the highest precedence  Concatenation is the next highest  Alternation is the lowest  Parentheses can be omitted if there is no ambiguity  Write (a((bc)*)) with as few parentheses as possible  Write a | b* c, using parentheses to mark the precedence of each operation

 As before, let Σ = {a, b}  Can you describe (a | b)* in another way?  What about ( ε | a* | b* )*?  Given that L = a*b(a | b)*, write 5 strings that belong to L  Let M = a* | (ab)*  Which of the following belong to M? ▪a▪a ▪b▪b ▪ aaaa ▪ abba ▪ ababab

 Let Σ = {0, 1}  Find regular expressions for the following languages:  The language of all strings of 0's and 1's that have even length and in which the 0's and 1's alternate  The language consisting of all strings of 0's and 1's with an even number of 1's  The language consisting of all strings of 0's and 1's that do not contain two consecutive 1's  The language that gives all binary numbers written in normal form (that is, without leading zeroes, and the empty string is not allowed)

 Regular expressions are used in some programming languages (notably Perl) and in grep and other find and replace tools  The notation is generally extended to make it a little easier, as in the following:  [ A – C] means any character in that range,  [A – C] means ( A | B | C )  [0 – 9] means ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 )  [ABC] means (A | B | C )  ABC means the concatenation of A, B, and C  A dot stands for any letter: A.C could match AxC, A&C, ABC  ^ means NOT, thus [^D – Z] means not the characters D through Z  Repetitions:  R? means 0 or 1 repetitions of R  R* means 0 or more repetitions of R  R+ means 1 or more repetitions of R  Notations vary and have considerable complexity  Use this notation to describe the regular expression for legal C++ identifiers

 A finite-state automaton is an idealized machine composed of five objects: 1. A finite set I, called the input alphabet, of input symbols 2. A set S of states the automaton can be in 3. A designated state s 0 called the initial state 4. A designed set of states called the set of accepting states 5. A next-state function N: S x I  S that maps a current state with current input to the next state

 FSA's are often described with a state transition diagram  The starting state has an arrow  The accepting states are marked with circles  Each rule is represented by a labeled transition arrow  The following FSA represents a vending machine 0¢ 25¢ 75¢ 50¢ $1 $1.25 half-dollar quarter half-dollar quarter half-dollar quarter

 Consider this FSA:  What are its states?  What are its input symbols?  What is the initial state of A?  What are the accepting states of A?  What is N(s 1, 1)?  What's a verbal description for the strings accepted? s0s0 s0s0 s1s1 s1s1 s2s2 s2s

 Consider the same FSA:  We can also describe an FSA using an annotated next-state table  A next-state table gives shows what the transition is for each state for all possible input  An annotated next-state table also marks the initial state and accepting states  Find the annotated next-state table for this FSA s0s0 s0s0 s1s1 s1s1 s2s2 s2s

 Consider the following annotated next-state table   marks initial state   marks accepting states):  Draw the corresponding transition state diagram abc  UZYY  VVVV YZVY  ZZZZ

 Consider this FSA again:  Which state will be reached on the following inputs: i. 01 ii iii iv  What's a verbal description for the strings accepted? s0s0 s0s0 s1s1 s1s1 s2s2 s2s

 Let A be a FSA with a set of states S, set of input symbols I, and next-state function N: X x I  S  Let I * be the set of all strings over I  The eventual-state function N * : S x I *  S is the following  N * (s,w) = the state that A goes to if the symbols of w are input to A in sequence, starting with A in state s  All of this is just a notational convenience so that we have a way of talking about the state that a string will transition an FSA to  We say that w is accepted by A iff N * (s 0, w) is an accepting state of A  The language of A, L(A) = { w  I * | w is accepted by A }

 Design a finite-state automaton that accepts the set of all strings of 0's and 1's such that the number of 1's in the string is divisible by 3  Make a regular expression for this language  Design a finite-state automaton that accepts the set of all strings of 0's and 1's that contain exactly one 1  Make a regular expression for this language

 More on finite state automata  Simplifying FSA's

 Read Chapter 12