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

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.
Week 13 - Wednesday.  What did we talk about last time?  Exam 3  Before review:  Graphing functions  Rules for manipulating asymptotic bounds  Computing.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Strings and Languages Operations
CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
1 Regular Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
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.
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.
Regular Expressions. Notation to specify a language –Declarative –Sort of like a programming language. Fundamental in some languages like perl and applications.
Theory Of Automata By Dr. MM Alam
CSC312 Automata Theory Lecture # 2 Languages.
CSC312 Automata Theory Lecture # 2 Languages.
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.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions.
Two examples English-Words English-Sentences alphabet S ={a,b,c,d,…}
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Language Definitions Lecture # 2. Defining Languages The languages can be defined in different ways, such as Descriptive definition, Recursive definition,
Recap Lecture-2 Kleene Star Closure, Plus operation, recursive definition of languages, INTEGER, EVEN, factorial, PALINDROME, {anbn}, languages of strings.
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Language Recognition Rosen, Chapter 12.4.
Automata, Computability, & Complexity by Elaine Rich ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Slides provided by author Slides edited for.
1 Chapter 1 Introduction to the Theory of Computation.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
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.
Module 2 How to design Computer Language Huma Ayub Software Construction Lecture 8.
L ECTURE 3 Chapter 4 Regular Expressions. I MPORTANT T ERMS Regular Expressions Regular Languages Finite Representations.
COMP313A Programming Languages Lexical Analysis. Lecture Outline Lexical Analysis The language of Lexical Analysis Regular Expressions.
Week 14 - Wednesday.  What did we talk about last time?  Regular expressions  Introduction to finite state automata.
What is a language? An alphabet is a well defined set of characters. The character ∑ is typically used to represent an alphabet. A string : a finite.
1 Module 14 Regular languages –Inductive definitions –Regular expressions syntax semantics.
Recursive Definitions & Regular Expressions (RE)
Lecture 5 Regular Expressions CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
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.
Lecture 02: Theory of Automata:08 Theory of Automata.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010.
Brian Mitchell - Drexel University MCS680-FCS 1 Patterns, Automata & Regular Expressions int MSTWeight(int graph[][], int size)
CS355 - Theory of Computation Regular Expressions.
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.
CS 203: Introduction to Formal Languages and Automata
Recursive Definations Regular Expressions Ch # 4 by Cohen
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Theory of computation Introduction theory of computation: It comprises the fundamental mathematical properties of computer hardware, software,
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.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
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.
Lecture 02: Theory of Automata:2014 Asif Nawaz Theory of Automata.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Lecture 03: Theory of Automata:2014 Asif Nawaz Theory of Automata.
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
Week 13 - Friday.  What did we talk about last time?  Regular expressions.
Theory of Computation Lecture #
LANGUAGES Prepared by: Paridah Samsuri Dept. of Software Engineering
Week 14 - Friday CS221.
REGULAR LANGUAGES AND REGULAR GRAMMARS
Chapter Seven: Regular Expressions
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.
Compiler Construction
Chapter 1 Introduction to the Theory of Computation
Introduction and Chapter One: Fundamentals
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  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  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 also 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)?

Student Lecture

 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

 Finite state automata  Simplifying FSA's

 Keep reading Chapter 12