Languages and Finite Automata

Similar documents
8 ε. Figure 1: An NFA-ǫ

1.0 Languages, Expressions, Automata

We use L i to stand for LL L (i times). It is logical to define L 0 to be { }. The union of languages L and M is given by

Languages and Strings. Chapter 2

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

Finite automata. III. Finite automata: language recognizers. Nondeterministic Finite Automata. Nondeterministic Finite Automata with λ-moves

MA/CSSE 474. Today's Agenda

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Finite Automata Part Three

CSE 105 THEORY OF COMPUTATION

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

DVA337 HT17 - LECTURE 4. Languages and regular expressions

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Finite Automata Part Three

Glynda, the good witch of the North

ECS 120 Lesson 7 Regular Expressions, Pt. 1

COMP Logic for Computer Scientists. Lecture 25

(Refer Slide Time: 0:19)

Ambiguous Grammars and Compactification

Slides for Faculty Oxford University Press All rights reserved.

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Learn Smart and Grow with world

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

Multiple Choice Questions

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

1.3 Functions and Equivalence Relations 1.4 Languages

Name: Finite Automata

CMSC 132: Object-Oriented Programming II

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

Non-deterministic Finite Automata (NFA)

LECTURE NOTES THEORY OF COMPUTATION

Regular Languages and Regular Expressions

LECTURE NOTES THEORY OF COMPUTATION

Formal Languages and Automata

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course)

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Automating Construction of Lexers

To illustrate what is intended the following are three write ups by students. Diagonalization

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Chapter Seven: Regular Expressions

Regular Expressions & Automata

ECS 120 Lesson 16 Turing Machines, Pt. 2

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

Notes for Comp 454 Week 2

JNTUWORLD. Code No: R

Languages and Compilers

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

Compiler Design. 2. Regular Expressions & Finite State Automata (FSA) Kanat Bolazar January 21, 2010

Formal languages and computation models

Finite Automata Part Three

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

CS402 - Theory of Automata FAQs By

Chapter 1 AUTOMATA & LANGUAGES. Roger Wattenhofer. ETH Zurich Distributed Computing

Converting a DFA to a Regular Expression JP

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

Decision Properties of RLs & Automaton Minimization

CSE 431S Scanning. Washington University Spring 2013

Compilers. Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University

6 NFA and Regular Expressions

AUTOMATA THEORY AND COMPUTABILITY

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

Derivations of a CFG. MACM 300 Formal Languages and Automata. Context-free Grammars. Derivations and parse trees

Final Course Review. Reading: Chapters 1-9

Computer Science 236 Fall Nov. 11, 2010

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

Computer Sciences Department

CS3102 Theory of Computation Problem Set 2, Spring 2011 Department of Computer Science, University of Virginia

CMPSCI 250: Introduction to Computation. Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014

CHAPTER TWO LANGUAGES. Dr Zalmiyah Zakaria

CS6160 Theory of Computation Problem Set 2 Department of Computer Science, University of Virginia

Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

FAdo: Interactive Tools for Learning Formal Computational Models

3.15: Applications of Finite Automata and Regular Expressions. Representing Character Sets and Files

CIT3130: Theory of Computation. Regular languages

Theory of Computation

AUBER (Models of Computation, Languages and Automata) EXERCISES

Dr. D.M. Akbar Hussain

CSE Discrete Structures

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

Computation Engineering Applied Automata Theory and Logic. Ganesh Gopalakrishnan University of Utah. ^J Springer

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Chapter 1 AUTOMATA & LANGUAGES


CS 314 Principles of Programming Languages. Lecture 3

Lecture 4: Syntax Specification

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

THEORY OF COMPUTATION

CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions

TAFL 1 (ECS-403) Unit- V. 5.1 Turing Machine. 5.2 TM as computer of Integer Function

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Quiz 1: Solutions J/18.400J: Automata, Computability and Complexity. Nati Srebro, Susan Hohenberger

Foundations of Computer Science Spring Mathematical Preliminaries

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

Transcription:

Languages and Finite Automata or how to talk to machines... Costas Busch - RPI 1

Languages A language is a set of strings String: A sequence of letters (a word) Examples: cat, dog, house, Defined over an alphaet: set of symols (letters) a,, c,, z Costas Busch - RPI 2

Alphaets and Strings We will use small alphaets Strings a a aa aa aaaaaa u a v aaa w aa Costas Busch - RPI 3

w w String Operations a 1 a 2 an v 1 2 aa v aaa m Concatenation wv wv a1a2 an 1 2 aaaaa m Reverse v v R R m 2 1 aaa Costas Busch - RPI 4

String Length w a a 1 2 a n Length: w n Examples: aa aa 2 a 1 4 Costas Busch - RPI 5

Recursive Definition of Length For any letter: a 1 For any string wa : wa w 1 Example: aa a 1 a 1 1 a 1 1 1 1 1 1 1 4 Costas Busch - RPI 6

Length of Concatenation uv u v Example: u aa, u 3 v aaa, v 5 uv aaaaa 8 uv u v 3 5 8 Costas Busch - RPI 7

Proof of Concatenation Length Claim: uv u v Proof: By induction on the length v Induction asis: v 1 v is only one symol From definition of length: uv u 1 u v Costas Busch - RPI 8

Inductive hypothesis: uv u v for all v with v 1,2,, n Inductive step: we will prove uv u v for v n 1 Costas Busch - RPI 9

Inductive Step Write v wa, where 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 Costas Busch - RPI 10

Empty String A string with no letters: Oservations: 0 w w w aa aa aa Costas Busch - RPI 11

Definition: Sustring w A sustring of a string consecutive characters is any sequence of Example: aa Sustrings a aa a Costas Busch - RPI 12

Prefix and Suffix aa Prefixes a a a aa aa Suffixes aa a a a prefix w uv suffix Costas Busch - RPI 13

Another Operation n w ww w n Example: 2 aa aaaa Definition w for any : 0 w 0 aa Costas Busch - RPI 14

* The * Operation : the set of all possile strings from alphaet Example: * a,, a,, aa, a, a,, aaa, aa, * a,, aa, a, a,, aaa, aa, Costas Busch - RPI 15

Language A language is any suset of * Examples: * a,, a,, aa, a, a,, aaa, aa,, a, aa, aa {, aa, aa, aa, a, aaaaaa } A string is called sentence Costas Busch - RPI 16

An infinite language Another Example L a n n : n 0 a aa aaaaa L a L Costas Busch - RPI 17

Operations on Languages The usual set operations a, a, aaaa a, a, aaaa, a, a { a, a,, aaaa } { a } a, a, aaaa, a a, aaaa Complement: L * L a, a,, aa, a,, aaa, Costas Busch - RPI 18

Reverse Definition: L R R w : w L Examples: R a, aa, aa a, aa, aa L a n n : n 0 L R n a n : n 0 Costas Busch - RPI 19

Concatenation Definition: L 1 L2 xy x L1, : y L 2 Example: a, a, a, aa a, aaa, a, aaa, a, aaa Costas Busch - RPI 20

Definition: Another Operation n L LL L n Example: a, aaa, aa, aa, a, aa, a, a, 3 a, a, a, Special case: L 0 0 a, a, aaa Costas Busch - RPI 21

Example L a n n : n 0 L 2 n n m m a a : n, m 0 2 aaaaa L Costas Busch - RPI 22

Star-Closure (Kleene *) Definition: 0 2 L* L L L 1 Example: a, *, a,, aa, a, a,, aaa, aa, aa, a, Costas Busch - RPI 23

Positive Closure Definition: L 1 L L 2 L * a, a,, aa, a, a,, aaa, aa, aa, a, Costas Busch - RPI 24

Finite Automata Costas Busch - RPI 25

Finite Automaton Input String Finite Automaton Output String Costas Busch - RPI 26

Finite Accepter Input String Finite Automaton Output Accept or Reject Costas Busch - RPI 27

Transition Graph Aa -Finite Accepter a a a a q 5 q0 q3 q4 initial state state transition final state accept Costas Busch - RPI 28

Initial Configuration Input String a a q 0 a a a a q 5 q3 q4 Costas Busch - RPI 29

Reading the Input a a a a a a q 5 q0 q3 q4 Costas Busch - RPI 30

a a a a a a q 5 q0 q3 q4 Costas Busch - RPI 31

a a a a a a q 5 q0 q3 q4 Costas Busch - RPI 32

a a a a a a q 5 q0 q3 q4 Costas Busch - RPI 33

a a Input finished a a a a q 5 q0 q3 q4 Output: accept Costas Busch - RPI 34

Rejection a a q 0 a a a a q 5 q3 q4 Costas Busch - RPI 35

a a a a a a q 5 q0 q3 q4 Costas Busch - RPI 36

a a a a a a q 5 q0 q3 q4 Costas Busch - RPI 37

a a a a a a q 5 q0 q3 q4 Costas Busch - RPI 38

Input finished a a Output: a a a a q 5 q0 q3 q4 reject Costas Busch - RPI 39

Another Rejection q 0 a a a a q 5 q3 q4 Costas Busch - RPI 40

q 0 a a a a q 5 q3 q4 Output: reject Costas Busch - RPI 41

Another Example a a a a, q0 Costas Busch - RPI 42

a a a a, q0 Costas Busch - RPI 43

a a a a, q0 Costas Busch - RPI 44

a a a a, q0 Costas Busch - RPI 45

Input finished a a a Output: accept a, q0 Costas Busch - RPI 46

Rejection a a a, q0 Costas Busch - RPI 47

a a a, q0 Costas Busch - RPI 48

a a a, q0 Costas Busch - RPI 49

a a a, q0 Costas Busch - RPI 50

Input finished a a a, q0 Output: reject Costas Busch - RPI 51

Formalities Deterministic Finite Accepter (DFA) M Q,,, q0, F Q q 0 F : set of states : input alphaet : transition function : initial state : set of final states Costas Busch - RPI 52

Input Alphaet a a a a q 5 q0 q3 q4 Costas Busch - RPI 53

Set of States Q Q q 0 1, 2, 3, 4,, q q q q q 5 a a a a q 5 q0 q3 q4 Costas Busch - RPI 54

Initial State q0 q 0 a a a a q 5 q3 q4 Costas Busch - RPI 55

Set of Final States F F q 4 a a a a q0 q3 q 5 q 4 Costas Busch - RPI 56

Transition Function : Q Q a a a a q 5 q0 q3 q4 Costas Busch - RPI 57

q 0, a q 1 a a a q a q0 1 q 5 q3 q4 Costas Busch - RPI 58

q 0, q 5 q 0 a a a a q 5 q3 q4 Costas Busch - RPI 59

3 2, q q a a a a q 5 q0 q3 q4 Costas Busch - RPI 60

a q q 0 q 1 q 2 q 3 5 q5 Transition Function q q5 3 q q4 5 q 4 q 5 q 5 q 5 q 5 q 5 a a a a q 5 q0 q3 q4 Costas Busch - RPI 61

Extended Transition Function * *: Q * Q a a a a q 5 q0 q3 q4 Costas Busch - RPI 62

q 0, a 2 * q a a a q a q0 2 q 5 q3 q4 Costas Busch - RPI 63

q 0, aa 4 * q a a a a q 5 q0 q3 q4 Costas Busch - RPI 64

q 0, aaa 5 * q q 0 a a a a q 5 q3 q4 Costas Busch - RPI 65

Oservation: There is a walk from with lael w q to q * q, w q q w q q 1 2 w 1 2 k k q Costas Busch - RPI 66

Example: There is a walk from with lael q 0 aaa to q 5 q 0, aaa 5 * q q 0 a a a a q 5 q3 q4 Costas Busch - RPI 67

Costas Busch - RPI 68 Recursive Definition ) ),, *( (, *, * w q w q q q q q w q 1 q q q w q ), (, * 1 1 1, * ), (, * q w q q w q ) ),, *( (, * w q w q

Costas Busch - RPI 69 0 q 1 q 2 q 3 q 4 q a a q 5 a a 2 1 0 0 0 0,,,,,, * ),, * (, * q q a q a q a q a q

Languages Accepted y DFAs Take DFA M Definition: The language L contains all input strings accepted y M M L M M = { strings that drive to a final state} Costas Busch - RPI 70

M aa Example L M a a a a q 5 q0 q3 q4 accept Costas Busch - RPI 71

Another Example M, a aa L, M a a a a q 5 q0 q3 q4 accept accept accept Costas Busch - RPI 72

Formally For a DFA M Q,,, q0, F M Language accepted y : L M w : * q, w * 0 F alphaet transition function initial state final states q0 w q q F Costas Busch - RPI 73

Oservation Language rejected y M : L M w : * q, w * 0 F q0 w q q F Costas Busch - RPI 74

More Examples L n M { a : n 0} a a, q0 accept trap state Costas Busch - RPI 75

L M = { all strings with prefix a } a q0 a accept q 3 Costas Busch - RPI 76

L M = { all strings without sustring 001 } 1 1 0 1 0 00 001 0 0 0, 1 Costas Busch - RPI 77

Regular Languages A language a DFA L is regular if there is M L LM such that All regular languages form a language family Costas Busch - RPI 78

Examples of regular languages: aa,a,aa { a n : n 0} { all strings with prefix } a { all strings with prefix } a { all strings without sustring } 001 There exist automata that accept these Languages (see previous slides). Costas Busch - RPI 79

Another Example The language is regular: L L M L awa a : w a, * a q0 q3 a q 4 Costas Busch - RPI 80

There exist languages which are not Regular: Example: L n n { a : n 0} There is no DFA that accepts such a language Costas Busch - RPI 81