Finite Automata Part One

Similar documents
Finite Automata Part One

Finite Automata Part One

Finite Automata Part One

Announcements. Problem Set Four due Thursday at 7:00PM (right before the midterm).

Finite Automata Part Two

Turing Machines Part One

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

Turing Machines Part Two

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Finite Automata Part Two

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Chapter Two: Finite Automata

Turing Machines Part III

Nonregular Languages

CSC236 Week 10. Larry Zhang

CSE 105 THEORY OF COMPUTATION

Nondeterministic Finite Automata and Regular Expressions

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

Griffith University 3130CIT Theory of Computation (Based on slides by Harald Søndergaard of The University of Melbourne) Turing Machines 9-0

Nondeterminism. September 7, Nondeterminism

CSE 311 Lecture 23: Finite State Machines. Emina Torlak and Kevin Zatloukal

CS 154, Lecture 3: DFA NFA, Regular Expressions

CHAPTER 1 Regular Languages. Contents

Theory of computation: initial remarks (Chapter 11)

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

CSC236 Week 11. Larry Zhang

Nondeterministic Finite Automata

Theory of Computation

Automata: a short introduction

Author: Vivek Kulkarni ( )

Formal Definition of Computation. August 28, 2013

UNIT-III REGULAR LANGUAGES

CSC173 Workshop: 13 Sept. Notes

Chapter Five: Nondeterministic Finite Automata

UNIT-I. Strings, Alphabets, Language and Operations

Nondeterministic finite automata

Theory of computation: initial remarks (Chapter 11)

Languages, regular languages, finite automata

Formal Definition of a Finite Automaton. August 26, 2013

Recap from Last Time

CSE 105 THEORY OF COMPUTATION

Grade 6 Math Circles October 20/21, Formalism and Languages: Beyond Regular Languages

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

CMP 309: Automata Theory, Computability and Formal Languages. Adapted from the work of Andrej Bogdanov

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

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

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

CSE 105 THEORY OF COMPUTATION

Finite Automata (contd)

Computer Sciences Department

Mathematical Logic Part One

CS 154 Introduction to Automata and Complexity Theory

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

Turing machines and linear bounded automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Join. Visit us at the HMC club fair and the 5c turf dinner. Company sponsored tech talks and events Resume Workshops / Interview Prep

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Chapter 5. Finite Automata

CSE 105 THEORY OF COMPUTATION

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

Fooling Sets and. Lecture 5

CSE 105 THEORY OF COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

CISC4090: Theory of Computation

CS 133 : Automata Theory and Computability

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

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

Finite-state machines (FSMs)

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

Recap from Last Time

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

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

CSE 105 THEORY OF COMPUTATION

CISC 4090 Theory of Computation

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Deterministic Finite Automaton (DFA)

Takeaway Notes: Finite State Automata

CSE 311: Foundations of Computing. Lecture 26: More on Limits of FSMs, Cardinality

September 7, Formal Definition of a Nondeterministic Finite Automaton

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

Accept or reject. Stack

(Refer Slide Time: 0:21)

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Turing Machines Part Three

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

Proofs, Strings, and Finite Automata. CS154 Chris Pollett Feb 5, 2007.

Automata Theory (2A) Young Won Lim 5/31/18

Decision, Computation and Language

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

Equivalence of DFAs and NFAs

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

Finite Automata. Finite Automata

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

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

Theory of Computation (II) Yijia Chen Fudan University

Turing machines and linear bounded automata

Automata and Computability

Transcription:

Finite Automata Part One

Computability Theory

What problems can we solve with a computer? What kind of computer?

Computers are Messy http://en.wikipedia.org/wiki/file:eniac.jpg

Computers are Messy That messiness makes it hard to rigorously say what we intuitively know to be true: that, on some fundamental level, diferent brands of computers or programming languages are more or less equivalent in what they are capable of doing. C vs C++ vs Java vs Python

We need a simpler way of discussing computing machines.

An automaton (plural: automata) is a mathematical model of a computing device.

Automata are Clean q q q 3 q 2

Why Build Models? Mathematical simplicity. It is signifcantly easier to manipulate our abstract models of computers than it is to manipulate actual computers. Intellectual robustness. If we pick our models correctly, we can make broad, sweeping claims about huge classes of real computers by arguing that they're just special cases of our more general models.

Why Build Models? The models of computation we will explore in this class correspond to diferent conceptions of what a computer could do. Finite automata (next two weeks) are an abstraction of computers with fnite resource constraints. Provide upper bounds for the computing machines that we can actually build. Turing machines (later) are an abstraction of computers with unbounded resources. Provide upper bounds for what we could ever hope to accomplish.

What problems can we solve with a computer? What is a problem?

Problems with Problems Before we can talk about what problems we can solve, we need a formal defnition of a problem. We want a defnition that corresponds to the problems we want to solve, captures a large class of problems, and is mathematically simple to reason about. No one defnition has all three properties.

Formal Language Theory

Strings An alphabet is a fnite, nonempty set of symbols called characters. Typically, we use the symbol Σ to refer to an alphabet. A string over an alphabet Σ is a fnite sequence of characters drawn from Σ. Example: If Σ = {a, b}, here are some valid strings over Σ: a aabaaabbabaaabaaaabbb abbababba The empty string has no characters and is denoted ε. Calling attention to an earlier point: since all strings are fnite sequences of characters from Σ, you cannot have a string of infnite length.

Languages A formal language is a set of strings. We say that L is a language over Σ if it is a set of strings over Σ. Example: The language of palindromes over Σ = {a, b, c} is the set {ε, a, b, c, aa, bb, cc, aaa, aba, aca, bab, } The set of all strings composed from letters in Σ is denoted Σ*. Formally, we say that L is a language over Σ if L Σ*.

How How many many of of the the following statements are are true? true? Alphabets are are sequences of of characters. Languages are are sets sets of of strings. Strings are are sets sets of of characters. Characters are are individual symbols. Languages are are sequences of of characters. Answer Answer at at PollEv.com/cs3 PollEv.com/cs3 or or text text CS3 CS3 to to 22333 22333 once once to to join, join, then then a a number. number.

To Recap Languages are sets of strings. Strings are sequences of characters. Characters are individual symbols. Alphabets are sets of characters. Languages Alphabets are sets of are nonempty, finite sets of Strings are finite sequeences of Characters

The Model Fundamental Question: For what languages L can you design an automaton that takes as input a string, then determines whether the string is in L? The answer depends on the choice of L, the choice of automaton, and the defnition of determines. In answering this question, we ll go through a whirlwind tour of models of computation and see how this seemingly abstract question has very real and powerful consequences.

To Summarize An automaton is an idealized mathematical computing machine. A language is a set of strings, a string is a (fnite) sequence of characters, and a character is an element of an alphabet. Goal: Figure out in which cases we can build automata for particular languages.

What problems can we solve with a computer?

Finite Automata

A fnite automaton is a simple type of mathematical machine for determining whether a string is contained within some language.

Each fnite automaton consists of a set of states connected by transitions.

A Simple Finite Automaton q q q 3 q 2

A Simple Finite Automaton q q q 3 q 2 Each Each circle circle represents represents a a state state of of the the automaton. automaton.

A Simple Finite Automaton q q q 3 q 2 One One special special state state is is designated designated as as the the state. state.

A Simple Finite Automaton q q The The automaton automaton is is run run on on an an input input string string and and answers answers yes yes or or no. no. q 3 q 2

A Simple Finite Automaton q q The The automaton automaton can can be be in in one one state state at at a a time. time. It It begins begins in in the the state. state. q 3 q 2

A Simple Finite Automaton q q The The automaton automaton now now begins begins processing processing characters characters in in the the order order in in which which they they appear. appear. q 3 q 2

A Simple Finite Automaton q q q 3 q 2 Each Each arrow arrow in in this this diagram diagram represents represents a a transition. transition. The The automaton automaton always always follows follows the the transition transition corresponding corresponding to to the the current current symbol symbol being being read. read.

A Simple Finite Automaton q q q 3 q 2 After After transitioning, transitioning, the the automaton automaton considers considers the the next next symbol symbol in in the the input. input.

A Simple Finite Automaton q q q 3 q 2

A Simple Finite Automaton Now Now that that the the automaton automaton has has looked looked at at all all this this input, input, it it can can decide decide whether whether to to say say yes yes or or no. no. q q q 3 q 2 The The double double circle circle indicates indicates that that this this state state is is an an accepting accepting state, state, so so the the automaton automaton outputs outputs yes. yes.

A Simple Finite Automaton q q q 3 q 2

A Simple Finite Automaton This This state state is is not not an an accepting accepting state state (it s (it s a a rejecting rejecting state), state), so so the the automaton automaton says says no. no. q q q 3 q 2

A Simple Finite Automaton q q Try Try it it yourself! yourself! Does Does this this automaton automaton accept accept (vote (vote A) A) or or reject reject (vote (vote R)? R)? q 3 q 2 Answer Answer at at PollEv.com/cs3 PollEv.com/cs3 or or text text CS3 CS3 to to 22333 22333 once once to to join, join, then then A or or R. R.

The Story So Far A fnite automaton is a collection of states joined by transitions. Some state is designated as the state. Some states are designated as accepting states. The automaton processes a string by beginning in the state and following the indicated transitions. If the automaton ends in an accepting state, it accepts the input. Otherwise, the automaton rejects the input.

Time-Out For Announcements!

Girl Code @Stanford This summer, I ll be running our sixth iteration of Girl Code @Stanford from July 9 th July 2 st. We invite high-school girls (primarily from low- to middle-income schools in majority-minority areas) to come to campus for two weeks to learn CS, meet researchers, and talk to folks from industry. We re looking for Stanford students to serve as Workshop Assistants during the program. We pay competitively (roughly $3, over two weeks). Interested? Learn more and apply using this link: https://goo.gl/forms/y76akbvwuyvnppr2 All current Stanford students are invited to apply. Feel free to forward this link around!

Back to CS3!

Just Passing Through q q q 2 q 3 q 4

Just Passing Through q q q 2 q 3 q 4

A fnite automaton does not accept as soon as it enters an accepting state. A fnite automaton accepts if it ends in an accepting state.

What Does This Accept? q q 3 q q 2 q 4 No No matter matter where where we we in in the the automaton, automaton, after after seeing seeing two two 's, 's, we we end end up up in in accepting accepting state state q 3. 3.

What Does This Accept? q q 3 q q 2 q 4 No No matter matter where where we we in in the the automaton, automaton, after after seeing seeing two two 's, 's, we we end end up up in in accepting accepting state state q 5. 5.

What Does This Accept? q q q 2 This This automaton accepts accepts a string string in in {, {, }* }* if if the the string string ends ends in in or or.. q 3 q 4

The language of an automaton is the set of strings that it accepts. If D is an automaton that processes characters from the alphabet Σ, then L(D) is formally defned as L(D) = { w Σ* D accepts w }

How How many of of the the following statements are are true? true? -- A language of of an an automaton can can have have an an infnitely long long string string (or (or many many of of them) them) in in it. it. -- A language of of an an automaton can can contain infnitely many many strings. -- A language of of an an automaton can can contain no no strings. Answer Answer at at PollEv.com/cs3 PollEv.com/cs3 or or text text CS3 CS3 to to 22333 22333 once once to to join, join, then then a a number. number.

A Small Problem q q 2 q

Another Small Problem, q, q, q 2

The Need for Formalism In order to reason about the limits of what fnite automata can and cannot do, we need to formally specify their behavior in all cases. All of the following need to be defned or disallowed: What happens if there is no transition out of a state on some input? What happens if there are multiple transitions out of a state on some input?

DFAs A DFA is a Deterministic Finite Automaton DFAs are the simplest type of automaton that we will see in this course.

DFAs A DFA is defned relative to some alphabet Σ. For each state in the DFA, there must be exactly one transition defned for each symbol in Σ. This is the deterministic part of DFA. There is a unique state. There are zero or more accepting states.

How How many many of of these these are are DFAs DFAs over over {, {, }? }? q q q 3 q 2 q q 2 q q q 3 q q 2 q 4, q q q, q,, q 3, q 2,, q 2 Answer Answer at at PollEv.com/cs3 PollEv.com/cs3 or or text text CS3 CS3 to to 22333 22333 once once to to join, join, then then a a number. number.

Is this a DFA? Drinking Family of Aardvarks

Designing DFAs At each point in its execution, the DFA can only remember what state it is in. DFA Design Tip: Build each state to correspond to some piece of information you need to remember. Each state acts as a memento of what you're supposed to do next. Only fnitely many diferent states means only fnitely many diferent things the machine can remember.

Recognizing Languages with DFAs L = { w {a, b}* the number of b's in w is congruent to two modulo three } a a a q b b q q 2 b Each Each state state remembers remembers the the remainder remainder of of the the number number of of bs bs seen seen so so far far modulo modulo three. three.

Recognizing Languages with DFAs L = { w {a, b}* w contains aa as a substring } q b a a q q 2 Σ b

More Elaborate DFAs L = { w {a, *, /}* w represents a C-style comment } Let s Let s have have the the a symbol symbol be be a a placeholder placeholder for for some some character character that that isn t isn t a a star star or or slash. slash. Try Try designing designing a a DFA DFA for for comments! comments! Here s Here s some some test test cases cases to to help help you you check check your your work: work: Accepted: Rejected: /*a*/ /**/ /***/ /*aaa*aaa*/ /*a/a*/ /** /**/a/*aa*/ aaa/**/aa /*/ /**a/ //aaaa

More Elaborate DFAs L = { w {a, *, /}* w represents a C-style comment } Σ a, * q 5 Σ /, a q / q * q 2 * a q 3 / q 4 a, / *