FABER Formal Languages, Automata. Lecture 2. Mälardalen University

Similar documents
Languages. A language is a set of strings. String: A sequence of letters. Examples: cat, dog, house, Defined over an alphabet:

In English, there are at least three different types of entities: letters, words, sentences.

CSCI 340: Computational Models. Regular Expressions. Department of Computer Science

Chapter 4. Regular Expressions. 4.1 Some Definitions

Author: Vivek Kulkarni ( )

1 Alphabets and Languages

CS 133 : Automata Theory and Computability

Recap from Last Time

Sri vidya college of engineering and technology

Formal Languages, Automata and Models of Computation

CS Automata, Computability and Formal Languages

Nondeterministic Finite Automata and Regular Expressions

Theory of Computer Science

Harvard CS121 and CSCI E-121 Lecture 2: Mathematical Preliminaries

Closure Properties of Regular Languages

Automata Theory CS F-08 Context-Free Grammars

Chapter 1. Introduction

Automata: a short introduction

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

CS 154, Lecture 3: DFA NFA, Regular Expressions

download instant at Assume that (w R ) R = w for all strings w Σ of length n or less.

Automata Theory CS F-04 Non-Determinisitic Finite Automata

Theory of Computation (Classroom Practice Booklet Solutions)

The assignment is not difficult, but quite labour consuming. Do not wait until the very last day.

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

The Binomial Theorem.

Automata Theory and Formal Grammars: Lecture 1

Section 1.3 Ordered Structures

C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1.

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

CMSC 330: Organization of Programming Languages

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

Theory of Computation

COSE312: Compilers. Lecture 2 Lexical Analysis (1)

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata

Theory of Computation

Computational Theory

CMSC 330: Organization of Programming Languages

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

CS 121, Section 2. Week of September 16, 2013

Regular Expressions [1] Regular Expressions. Regular expressions can be seen as a system of notations for denoting ɛ-nfa

HW 3 Solutions. Tommy November 27, 2012

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

What Is a Language? Grammars, Languages, and Machines. Strings: the Building Blocks of Languages

TAFL 1 (ECS-403) Unit- II. 2.1 Regular Expression: The Operators of Regular Expressions: Building Regular Expressions

How do regular expressions work? CMSC 330: Organization of Programming Languages

Text Search and Closure Properties

A canonical semi-deterministic transducer

Text Search and Closure Properties

Lecture 7 Properties of regular languages

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

CS311 Computational Structures Regular Languages and Regular Expressions. Lecture 4. Andrew P. Black Andrew Tolmach

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Computational Learning Theory Learning Patterns (Monomials)

On Parsing Expression Grammars A recognition-based system for deterministic languages

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

Linear conjunctive languages are closed under complement

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

CSE 105 THEORY OF COMPUTATION

BOUNDS ON ZIMIN WORD AVOIDANCE

UNIT II REGULAR LANGUAGES

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Chapter 6. Properties of Regular Languages

Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

The Pumping Lemma and Closure Properties

INSTITUTE OF AERONAUTICAL ENGINEERING

CS6902 Theory of Computation and Algorithms

Automata, Computability and Complexity with Applications Exercises in the Book Solutions Elaine Rich

Theory Of Computation UNIT-II

Question Bank UNIT I

Lecture 1 09/08/2017

Finite Automata and Regular Languages

Context-free Languages and Pushdown Automata

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition

Theoretical Computer Science

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

The Pumping Lemma (cont.) 2IT70 Finite Automata and Process Theory

CS 455/555: Finite automata

Formal Languages. We ll use the English language as a running example.

Finite-State Machines (Automata) lecture 12

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y.

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Formal Languages. We ll use the English language as a running example.

Content. Languages, Alphabets and Strings. Operations on Strings. a ab abba baba. aaabbbaaba b 5. Languages. A language is a set of strings

{a, b, c} {a, b} {a, c} {b, c} {a}

CS A Term 2009: Foundations of Computer Science. Homework 2. By Li Feng, Shweta Srivastava, and Carolina Ruiz.

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

Special Factors and Suffix and Factor Automata

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro Diniz

Homework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0,

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Deciding Representability of Sets of Words of Equal Length

CS375: Logic and Theory of Computing

EXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100

Transcription:

CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010 1

Content Languages, g Alphabets and Strings Strings & String Operations Languages & Language Operations Regular Expressions Finite Automata, FA Deterministic Finite Automata, DFA 2

Languages, Alphabets and Strings 3

Languages A language is a set of strings A String is a sequence of letters defined d over an alphabet: Σ = { a, b, c, K, z An alphabet is a set of symbols 4

Alphabets and Strings We will use small alphabets: Σ = { a,b, a ab abba bb baba Strings aaabbbaabab u = abb v = bbbaaa w = abba 5

Operations on Strings 6

w v String Operations = a a L x = abba 1 2 1 2 a n = b b Lb y = bbbaaa m Concatenation (sammanfogning) wv = a a 1 2 L a b b 1 2 Lb n b m xy = abbabbbaaa bbb 7

Reverse (reversering) w = a a L ababaaabbb 1 2 a n w R = a nl a 2 a 1 bbbaaababa Example: Longest odd length palindrome in a natural language: g saippuakauppias (Finnish: soap sailsman) 8

String Length w = a 1 Length: a 2 L a n w = n Examples: abba = 4 aa = 2 a =1 9

Recursive Definition of Length For any letter: a = 1 wa wa For any string : = w + 1 Example: abba = abb + 1 = ab + 1 + 1 = a + 1+ 1+ 1 = 1 + 1+ 1+ 1= 4 10

Length of Concatenation uv = u + v Example: u = aab, u = 3 v = abaab, v = 5 uv = aababaab = 8 uv = u + v = 3 + 5 = 8 11

Proof of Concatenation Length Claim: uv = u + v Proof: By induction on the length v Induction basis: v = 1 From definition of length: uv = u + 1 = u + v 12

uv = u + Inductive hypothesis: h + v for v n Inductive step: we will prove uv = u + v for v = n +1 13

Inductive Step Write wa, where v = w = n, a = 1 From definition of length: uv = uwa = uw + 1 wa = w +1 From inductive hypothesis: uw = u + w Thus: uv = u + w + 1 = u + wa = u + v END OF PROOF 14

Empty String A string with no letters: (Also denoted as ε) ) λ Observations: λ = 0 λw = wλ = w λ abba = abbaλ = abba = { { λ 15

Substring of a string: Substring (delsträng) a subsequence of consecutive characters String Substring abbab abbab abbab abbab b ab abba b bbab 16

Prefixes abbab Prefix and Suffix Suffixes λ abbab w = uv a ab abb bbab bab ab prefix suffix abba b abbab λ 17

n w = ww... w Repetition n (String w repeated n times) Example: ( abba ) = abbaabba 2 Definition: 0 w = λ 0 ( abba) = λ 18

The (Kleene* star) Operation Σ * the set of all possible strings from alphabet Σ Σ = { a, b { λ, a, b, aa, ab, ba, bb, aaa, aab,k Σ * = aab [* Kleene is pronounced "clay-knee ] http://en.wikipedia.org/wiki/kleene_star 19

The + (Kleene plus) Operation + Σ : the set of all possible strings from the alphabet Σ except λ Σ = { a,b { λ Σ* =, a, b, aa, ab, ba, bb, aaa, aab,k Σ + = Σ* λ { a, b, aa, ab, ba, bb, aaa, aab,k Σ + = 20

Σ = { oj, fy, usch Example { Σ* = λ, oj, fy, usch, ojoj, fyfy,uschusch, ojfy, ojusch K Σ + = Σ* { λ Σ + = oj, fy, usch, ojoj, fyfy,uschusch, ojfy, ojusch K 21

Operations on Languages 22

Language A language is any subset of Σ* Example: Σ = { a,b, Σ* = { λ, a, b, aa, ab, ba, bb, aaa,k Languages: { λ { a, aa, aab λ {, abba, baba, aa, ab, aaaaaa 23

Example An infinite language L = { a b : n 0 n n λ ab aabb aaaaabbbbb L abb L 24

Operations on Languages The usual set operations { a, ab, aaaa { bb, ab = { a, ab, { a, ab, aaaa { bb, ab = { ab { a, ab, aaaa { bb, ab = { a, aaaa bb, aaaa Complement: L = Σ* LL { λ, a, b, aa, ab, ba, bb, aaa,,k Σ* = aab { a, ba = { λ, b, aa, ab, bb, aaa,k 25

Definition: L R Reverse R = { w : w L Examples: R { ab, aab, baba = { ba, baa, abab L n n = { a b : n 0 L R n n = { b a : n 0 26

Concatenation o Definition: L L = { xy : x L y L 1 2 1, 2 Example { a, ab, ba { b, aa = { ab, aaa, abb, abaa, bab, baaa 27

Repeat Definition: L = 1LL2 L 3L b 3 n { a, b = { a, b { a, b { a, b n = { aaa, aab, aba, abb, baa, bab, bba, bbb Special case: 0 L = { λ { 0 a, bba, aaa = { λ 28

Example L n n = { a b : n 0 L 2 n n m m = { a b a b : n, m 0 2 L aabbaaabbb bbb L 29

Star-Closure (Kleene *) Definition: 0 1 L* = L L L 2 L Example: { a, bb * λ, a, bb, = aa, abb, bba, bbbb, aaa aabb abba,,, abbbb, K 30

Positive Closure Definition L + 1 2 = L U L { λ U L = L* { λ a,bb, +, bb = aa, abb, bba, bbbb { a aaa, aabb, abba, abbbb,, K 31

Regular Expressions 32

Regular Expressions: Recursive Definition iti Primitive regular expressions:, Given regular expressions r 1 and r 2 r + 1 r 2 r 1 r 1 * ( ) r 1 r r 2 λ, λ α are Regular Expressions 33

Examples A regular expression: ( a + b c )* ( c + ) Not a regular expression: ( a + b + ) 34

Building Regular Expressions Σ = { a, b, c Zero or more. a* means "zero or more a's." To say "zero or more ab's," that is, {, ab, abab, ababab,..., you need to say (ab)*. ab* denotes {a, ab, abb, abbb, abbbb,... 35

Building Regular Expressions Σ = { a, b, c One or more. Since a* means "zero or more a's", you can use aa* (or equivalently, a*a) to mean "one or more a's. Similarly, to describe "one or more ab's," that is, {ab, abab, ababab,..., you can use ab(ab)*. 36

Building Regular Expressions Σ = { a, b, c Any string at all. To describe any string at all (with = {a, b, c), you can use (a+b+c)*. Any nonempty string. This can be written as any character from followed by any string at all: (a+b+c)(a+b+c)*. 37

Building Regular Expressions Σ = Any string not containing... { a, b, c To describe any string at all that doesn't contain an a (with = {a, b, c), you can use (b+c)*. Any string containing exactly one... To describe any string that contains exactly one a, put "any string not containing an a," on either side of the a, like this: (b+c)*a(b+c)*. ( ) 38

Languages of Regular Expressions L( r) language of regular expression r Example L (( a + b c)* ) = { λ, a, bc, aa, abc, bca,... 39

Definition For primitive regular expressions: L( L ) = L ( λ ) = { λ L ( a) = { a 40

Definition (continued) For regular expressions r1 and r 2 L ( + ) = ( ) ( ) r r L r L r 1 2 1 2 ( ) ( ) ( ) L = r r L r L r 1 2 1 2 L ( r *) = ( L( r ))* 1 1 (( )) ( ) L = r L r 1 1 41

Example Regular expression: ( a + b ) a * L (( a + b) a *) = L (( a + b) ) L( a *) ( a b) L( a *) = L + = = ( L( L a) L( b) ) ( L( a) )** ( { a { b ) { ( a )* = { a, b { λ, a, aa, aaa,... = { a, aa, aaa,..., b, ba, baa,... 42

Regular expression Example ( a b) ( a bb) r = + * + ( r ) { a, bb, aa, abb, ba, bbb,... L = 43

Example Regular expression = ( aa ) ( bb ) b r = * * L 2n 2 m ( r ) = { a b b : n, m 0 44

Example Σ = { 0,1 L (r) = { all strings with at least two consecutive 0 Regular expression r = ( 0 + 1)*00 (0 + 1)* 45

Example Σ = { 0,1 L (r) = { all strings without two consecutive 0 Regular expression r1 = (1 + 01) * (0 + λ) (consists of repeating 1 s and 01 s). 46

Example L = { all strings without two consecutive 0 Equivalent solution: r 2 = (1*011*)*(0 (0 + λ ) + 1*(0 + λ ) (In order not to get 00 in a string, after each h0 there must be an 1, which means that strings of the form 1...101...1 are repeated. That is the first parenthesis. To take into account strings that end with 0, and those consisting of 1 s solely, the rest of the expression is added.) 47

Equivalent Regular Expressions Definition: Regular expressions r1 and r r 2 are equivalent if L ( r1 ) = L( r2 ) 48

Example L = { all strings without two consecutive 0 r1 = (1 + 01) *(0 + λ) r2 = (1*011*)*(0 *)*( + λ ) + 1*(0 + λ ) ( 1 2 L 1 and 2 are equivalent L r ) = L ( r ) = r r 2 regular expressions. 49