Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Fall 2011.

Slides:



Advertisements
Similar presentations
CS 3240: Languages and Computation
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Deterministic Finite Automata (DFA)
YES-NO machines Finite State Automata as language recognizers.
Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Fall 2009.
Chapter Two: Finite Automata
Finite Automata Section 1.1 CSC 4170 Theory of Computation.
January 5, 2015CS21 Lecture 11 CS21 Decidability and Tractability Lecture 1 January 5, 2015.
CS21 Decidability and Tractability
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
CS5371 Theory of Computation
Fall 2006Costas Busch - RPI1 Deterministic Finite Automata And Regular Languages.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Fall 2008.
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...
CS 310 – Fall 2006 Pacific University CS310 Finite Automata Sections: September 1, 2006.

Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 1 Regular Languages Contents Finite Automata (FA or DFA) definitions, examples,
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
CS 490: Automata and Language Theory Daniel Firpo Spring 2003.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
Topics Automata Theory Grammars and Languages Complexities
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Grammars, Languages and Finite-state automata Languages are described by grammars We need an algorithm that takes as input grammar sentence And gives a.
Great Theoretical Ideas in Computer Science.
1 An Introduction to Formal Languages and Automata Provided by : Babak Salimi webAdd:
CSCI 2670 Introduction to Theory of Computing September 28, 2005.
CS/IT 138 THEORY OF COMPUTATION Chapter 1 Introduction to the Theory of Computation.
1 Unit 1: Automata Theory and Formal Languages Readings 1, 2.2, 2.3.
Theory of Languages and Automata
By: Er. Sukhwinder kaur.  What is Automata Theory? What is Automata Theory?  Alphabet and Strings Alphabet and Strings  Empty String Empty String 
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
Lecture 1 Computation and Languages CS311 Fall 2012.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 Theory of Computation 計算理論 2 Instructor: 顏嗣鈞 Web: Time: 9:10-12:10 PM, Monday Place: BL.
Deterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.2)
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
August 23, 2005 CSCI 2670 Introduction to Theory of Computing August 23, 2005.
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
1 Course Overview Why this course “formal languages and automata theory?” What do computers really do? What are the practical benefits/application of formal.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Theory of Languages and Automata By: Mojtaba Khezrian.
CSCI 3130: Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Decidable.
Costas Busch - LSU1 Deterministic Finite Automata And Regular Languages.
Theory of Computation Automata Theory Dr. Ayman Srour.
Theory of Computation. Introduction We study this course in order to answer the following questions: What are the fundamental capabilities and limitations.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Formal Foundations-II [Theory of Automata]
CSCI 2670 Introduction to Theory of Computing
CIS Automata and Formal Languages – Pei Wang
G. Pullaiah College of Engineering and Technology
THEORY OF COMPUTATION Lecture One: Automata Theory Automata Theory.
Chapter Two: Finite Automata
Finite Automata.
Principles of Computing – UFCFA3-30-1
Pushdown automata The Chinese University of Hong Kong Fall 2011
Lecture One: Automata Theory Amjad Ali
Chapter # 5 by Cohen (Cont…)
Formal Languages and Automata Theory BODDEDA HARITHA LAKSHMI,
Automata theory and formal languages COS 3112 – AUTOMATA THEORY PRELIM PERIOD WEEK 1 AND 2.
Nondeterminism The Chinese University of Hong Kong Fall 2010
Presentation transcript:

Formal languages and automata theory Andrej Bogdanov The Chinese University of Hong Kong Fall 2011

Google is amazing

What else? Fly Is there anything a computer cannot do? Search Play chess

Impossibilities Why do we care about the impossible?

Perpetual motion In the middle ages, people wanted a machine that does not use any energy Perpetual motion is a futile endeavor Understanding the impossible helps us channel our energies towards the more useful. Later, discoveries in physics showed that energy cannot be created out of thin air

The laws of computation Just like the laws of physics tell us what is (im)possible for nature to do......the laws of computation tell us what is (im)possible for computers.

Automata theory Automata theory studies the laws of computation. In reality, the laws of computation are not understood, but automata theory is a good start.

A gumball machine 一五 machine takes $5 and $10 coins a gumball costs $15 actions: +5, +10, Release +5, , +10 RRR R $ $5$10

Slot machine =

What is the difference? Such questions are difficult to reason about, because devices can be designed in infinitely many ways Automata theory will help answer (some of) them

What can automata do They can describe the operation of a small device They can be used to verify (simple) software* They are used in lexical analyzers to recognize expressions in programming languages: ab1 is a legal name of a variable in java 5u= is not

Different kinds of machines This was only one example of a machine We will look at different kinds of machines and ask: –What kinds of problems can this kind of machine solve? –What things are impossible for this kind of machine? –Is machine A more powerful than machine B? +5, , +10RRR R $ $5$10

Some kinds of machines finite automataDevices with a small amount of memory. Used to model very simple things. push-down automata Devices with infinite memory that can be accessed in a restricted way. Used to parse grammars Turing MachinesDevices with infinite memory. These are the real computers time-bounded Turing Machines Infinite memory, but bounded running time. These are computers that run reasonably fast.

Some highlights of the course Finite automata –Automata are closely related to the task of searching for patterns in text Grammars –Grammars describe the meaning of sentences in English, and the meaning of programs in Java –We will see how to extract the meaning out of a program find (ab)*(ab) in abracadabra

Some highlights of the course Turing Machines –This is a general model of a computer, capturing anything we could ever hope to compute –But there are many things that computers cannot do: Given the code of a computer program, can you tell if the program prints the string “ banana ”? #include main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_, main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13? main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t, ;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \ q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \ ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \ iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \ ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \ }'+}##(!!/") :t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1) :0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a, "!ek;dc banana ?

Some highlights of the course Time-bounded Turing Machines –Many problems are possible to solve on a computer in principle, but take too much time in practice –Traveling salesman: Given a list of cities, find the shortest way to visit them and come back home –Hard in practice: For 100 cities, this would take 100+ years even on the fastest computer! Hong Kong Beijing Shanghai Xian Guangzhou Chengdu

Preliminaries of automata theory How do we ask the question First, we need a way of describing the problems that we are interested in solving Can machine A solve problem B?

Problems Examples of problems we will consider –Given a word s, does it contain “ to ” as a subword? –Given a number n, is it divisible by 7? –Given two words s and t, are they the same? All of these have “yes/no” answers. There are other types of problems, like “Find this” or “How many of that” but we wont look at them.

Alphabets and strings A common way to talk about words, numbers, pairs of words, etc. is by representing them as strings To define strings, we start with an alphabet Examples An alphabet is a finite set of symbols.  1 = {a, b, c, d, …, z} : the set of letters in English  2 = {0, 1, …, 9} : the set of (base 10) digits  3 = {a, b, …, z, #} : the set of letters plus the special symbol #

Strings The empty string will be denoted by  We write  * for the set of all strings over  A string over alphabet  is a finite sequence of symbols in . abfbz is a string over  1 = {a, b, c, d, …, z} 9021 is a string over  2 = {0, 1, …, 9} ab#bc is a string over  3 = {a, b, …, z, #}

Languages Languages describe problems with “yes/no” answers: A language is a set of strings (over the same alphabet). L 1 = All strings that contain the substring “to”  1 = {a, b, …, z} stop, to, toe are in L 1 , oyster are not in L 1 L 1 = {x  1 *: x contains the substring “to”}

Examples of languages L 2 = {x  2 *: x is divisible by 7}  2 = {0, 1, …, 9} L 3 = {s#s: s  {a, b, …, z}*} = {7, 14, 21, …}  3 = {a, b, …, z, #} ab#ab a##a# ab#ba in L 3 not in L 3

Finite Automata

Example of a finite automaton There are states $0, $5, $10, go, the start state is $0 The automaton takes inputs from {+5, +10, R} The state go is an accepting state There are transitions saying what to do for every state and every alphabet symbol +5, , +10RRR R $ $5$10go

Deterministic finite automata A finite automaton (DFA) is a 5-tuple (Q, , , q 0, F) where – Q is a finite set of states –  is an alphabet –  : Q ×  → Q is a transition function – q 0  Q is the initial state – F  Q is a set of accepting states (or final states). In diagrams, the accepting states will be denoted by double loops

Example q0q0 q1q1 q2q ,11 alphabet  = {0, 1} states Q = {q 0, q 1, q 2 } initial state q 0 accepting states F = {q 0, q 1 } states inputs 0 1 q0q0 q1q1 q2q2 q0q0 q1q1 q2q2 q2q2 q2q2 q1q1 table of transition function 

Language of a DFA The language of a DFA (Q, , , q 0, F) is the set of all strings over  that, starting from q 0 and following the transitions as the string is read left to right, will reach some accepting state. M:M: +5, , +10RRR R $ $5$10go , +5 R R are in the language +5, R are not

q0q0 q1q1 b a a b What are the languages of these DFAs? Examples q0q0 q1q1 q2q2 q3q3 q4q4 a a a a a b b b b b q0q0 q1q q2q2 0, 1  = {a, b}  = {0, 1}

Examples Construct a DFA over alphabet {0, 1} that accepts all strings with at most three 1 s

Examples Construct a DFA over alphabet {0, 1} that accepts all strings with at most three 1 s Answer q0q0 q1q q2q2 0 q3q3 1 q 4+ 0,

Examples Construct a DFA for the language L = {010, 1} (  = {0, 1} )

Examples Construct a DFA that accepts the language Answer L = {010, 1} (  = {0, 1} ) qq q0q0 q1q1 q 01 q 010 q die 0,

Examples Construct a DFA over alphabet {0, 1} that accepts all strings that end in 01

Examples Construct a DFA over alphabet {0, 1} that accepts all strings that end in 01 Hint: The DFA must “remember” the last 2 bits of the string it is reading

Examples Construct a DFA over alphabet {0, 1} that accepts all strings that end in 01 Answer: qq 0 1 qq qq q  q  q  q 

Examples Construct a DFA over alphabet {0, 1} that accepts all strings that end in 101 Answer: