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

Similar documents
Computational Theory

Lecture 3: Nondeterministic Finite Automata

Closure under the Regular Operations

Equivalence of DFAs and NFAs

Theory of Computation (I) Yijia Chen Fudan University

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

Sri vidya college of engineering and technology

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

CS 455/555: Finite automata

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Inf2A: Converting from NFAs to DFAs and Closure Properties

CS 154, Lecture 3: DFA NFA, Regular Expressions

Regular Languages. Problem Characterize those Languages recognized by Finite Automata.

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Finite Automata and Regular Languages

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

CSC236 Week 10. Larry Zhang

Constructions on Finite Automata

Harvard CS 121 and CSCI E-207 Lecture 4: NFAs vs. DFAs, Closure Properties

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Regular Expressions. Definitions Equivalence to Finite Automata

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

Author: Vivek Kulkarni ( )

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

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

Closure under the Regular Operations

Nondeterministic Finite Automata and Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 133 : Automata Theory and Computability

Formal Models in NLP

CS 455/555: Mathematical preliminaries

Constructions on Finite Automata

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

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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Uses of finite automata

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

Finite Automata and Regular languages

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

Automata: a short introduction

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

Nondeterministic Finite Automata

False. They are the same language.

Computer Sciences Department

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

1 More finite deterministic automata

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Mathematics for linguists

CSE 105 THEORY OF COMPUTATION

Finite Automata and Languages

Theory of Computation (II) Yijia Chen Fudan University

CSE 105 THEORY OF COMPUTATION

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

Automata Theory and Formal Grammars: Lecture 1

CSE 105 THEORY OF COMPUTATION

UNIT-III REGULAR LANGUAGES

Regular Expressions Kleene s Theorem Equation-based alternate construction. Regular Expressions. Deepak D Souza

Intro to Theory of Computation

Closure Properties of Regular Languages

Finite Automata Part Two

Assignment #2 COMP 3200 Spring 2012 Prof. Stucki

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

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

Non-deterministic Finite Automata (NFAs)

TDDD65 Introduction to the Theory of Computation

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

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

Harvard CS 121 and CSCI E-207 Lecture 6: Regular Languages and Countability

Chapter 3. Regular grammars

CSC236 Week 11. Larry Zhang

Regular expressions and Kleene s theorem

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Deterministic Finite Automata (DFAs)

CSCI 2200 Foundations of Computer Science Spring 2018 Quiz 3 (May 2, 2018) SOLUTIONS

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

A Universal Turing Machine

Kleene Algebras and Algebraic Path Problems

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

Name: Student ID: Instructions:

Fooling Sets and. Lecture 5

Mathematical Preliminaries. Sipser pages 1-28

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

Finite Automata and Formal Languages TMV026/DIT321 LP4 2012

UNIT II REGULAR LANGUAGES

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

Finite Automata and Formal Languages

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

acs-04: Regular Languages Regular Languages Andreas Karwath & Malte Helmert Informatik Theorie II (A) WS2009/10

Computational Models Lecture 2 1

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

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Computational Models Lecture 2 1

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

Transcription:

CS 121, Section 2 Week of September 16, 2013 1 Concept Review 1.1 Overview In the past weeks, we have examined the finite automaton, a simple computational model with limited memory. We proved that DFAs, NFAs, and regular expressions are equal in computing power and recognize the regular languages. We also showed that the regular langages are closed under union, concatenation, Kleene Star, intersection, difference, complement, and reversal. We then used a counting argument to show that there are indeed languages which are non-regular. This week in section we will become a little more comfortable with these topics by working with regular expressions, making arguments about countability, and exploring some more closure properties of regular languages. 1.2 Cardinalities We classify the cardinality of a set S as follows. Finite, if there is a bijection between S and {1, 2,, n} for some n 0. Coutably infinite, if there is a bijection between S and N. Countable, if it is finite or countably infinite. Uncountable, otherwise. Examples include the following. Finite: Σ (alphabet), states of a DFA, students in CS121, finite unions of finite sets. Countably infinite: Σ (strings), Z, DFAs, countable unions of countably infinite sets. Uncountable: P(N), set of all languages. Since there are only countably many regular languages and uncountably many languages, most languages are non-regular. 1

2 Exercises Exercise 2.1. Describe in plain English the language represented by the following regular expressions. 1. a b 2. (aaa) 3. Σ aσ bσ aσ 1. Strings that do not contain both a s and b s. 2. Strings of a s that have length equal to some multiple of 3. 3. Strings that contain the subsequence aba. Exercise 2.2. Using the procedure outlined in class, convert the regular expression (((aa) (bb)) ab) to an equivalent NFA. 2

Exercise 2.3. Let L be a language over the alphabet Σ = {a, b}. Define PigLatin(L) = {wσ : σ Σ, w Σ, σw L}. Informally, PigLatin(L) is the language containing all strings in L except that each string has had its first character moved to its end. (For example, PigLatin({abc, a, aab}) = {bca, a, aba}.) Show that if L is regular, then PigLatin(L) is regular. Specifically, given a DFA for L, show how to construct an NFA for PigLatin(L). (Your proof for this problem should involve finite automata and not regular expressions.) Let D = (Q, Σ, δ, s, F ) be the DFA accepting L. We will construct an NFA N = (Q, Σ, δ, s, F ) accepting PigLatin(L). Formally, Q = {s, f } (Q {a, b}) {(δ(q 0, a), a), (δ(q 0, b), b)} if q = s and σ = ε, {f, (δ(p, a), a)} if q = (p, a) for some p F and σ = a, {f, (δ(p, b), b)} if q = (p, b) for some p F and σ = b, δ {(δ(p, σ), a)} if q = (p, a) for some p F and σ ε, or (q, σ) = if q = (p, a) for some p F and σ = b, {(δ(p, σ), b)} if q = (p, b) for some p F and σ ε, or if q = (p, b) for some p F and σ = a, otherwise. F = {f } Informally, our NFA consists of 2 copies of the original DFA, one for a and one for b. We represent the states of the a-copy with Q {a}, respectively for b. There will be a new start state s which will have ε-transitions to two states: to (δ(q 0, a), a) and to (δ(q 0, b), b) that is, to the state in the a-copy that the DFA would be in after reading an a as the first character, and to the state in the b-copy it would be in after reading b as the first character. The transitions within each copy then mimic that of the DFA. Finally, we have a transition on an a (resp. b) from any old final state in the a-copy (resp. b) to the new final state f. Informal justification: Given that σw is accepted by D, we accept wσ by non-deterministically jumping to either the state it might be in after reading σ. We then process all of w, and then accept the string only if w puts the NFA in an original final state, and then the appropriate σ is the last character left. If the string is in PigLatin(L), then there is an appropriate place for it to jump. Conversely, if the NFA accepts a string, then there must have been some place it jumped to, and so for it to get to the final state it must have looked like wσ for some σw L. 3

Exercise 2.4. Prove or disprove the following statements about regular expressions: 1. L((RS R) R) = L(R(SR R) ). 2. L((RS R) RS) = L((RR S) ). 1. L((RS R) R) = L(R(SR R) ). True. Suppose w (RS R) R, then w = r 1 s 1 r 2 s 2... r n s n r n+1 where r 1,..., r n+1 R and s 1,... s n S {ε}. Thus w R(SR R). The other direction is similar. 2. L((RS R) RS) = L((RR S) ). True. Suppose w (RS S) RS, then w = r 1 s 1 r 2 s 2... r n s n r n+1 s n+1 where r 1,..., r n+1 R, s 1,..., s n S {ε} and s n+1 S. Let k be the smallest number such that s k S; k exists because s n+1 S. Then r 1 s 1... r k s k RR S. Now repeating for the next smallest k, and we can show by induction that w (RR S). The other direction is similar. Exercise 2.5. Are the following sets finite (if so, how large), countably infinite, or uncountably infinite? Justify your answer. 1. The set of all infinite binary sequences {0, 1} N 2. The set of real numbers R. 3. The set of rational numbers Q. 4. The set of all English words. 5. The set of all English sentences. 1. Uncountable. Define f : P(N) {0, 1} N by f(s) i = 1 i S. We claim that f is one-to-one. Since P(N) is uncountable, the result follows. Let S and S be distinct subsets of N. Then there exists i such that i S and i / S or vice versa. Either way, f(s) i f(s ) i. So f(s) f(s ). 2. Uncountable. Define f : {0, 1} N R by f(x) = i x i 3 i. We claim that f is one-to-one. (Thus f is a bijection with a subset of R.) Since {0, 1} N is uncountable, this implies that R is uncountable. 4

Suppose x and x are two distinct sequences in {0, 1}. We must show that f(x) f(x ). Let n be the smallest index different between x and x. That is, x n x n, but x i = x i for i < n. Without loss of generality x n = 1 and x n = 0. Now f(x) f(x ) = i (x i x i)3 i =3 n + (x i x i)3 i i>n 3 n i>n 3 i =3 n 3 n 1 1 3 1 = 3 n 2 >0, as required. 3. Countably Infinite. A finite language can be written down. That is, you can just concatenate all the words in the language into one string (with a special separator symbol $). So there is a one-to-one map from finite languages over {a, b} to strings over {a, b, $}. There are only countably many strings, so there are countably many finite languages. As finite languages can be arbitrarily large, there are infinitely many. 4. Finite. The Oxford English Dictionary (supposedly) lists all english words. There are about 300,000 in total. 5. Countably Infinite. This is open to debate. While arbitrarily long sentences may not make much sense, rather than drawing a line in the sand, we accept the possibility of arbitrarily long sentences. Thus there are infinitely many valid English sentences. Since this is a subset of Σ, where Σ is the English alphabet plus space and punctuation, it is countable. 5