Glynda, the good witch of the North

Similar documents
CHAPTER TWO LANGUAGES. Dr Zalmiyah Zakaria

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

Assignment No.4 solution. Pumping Lemma Version I and II. Where m = n! (n-factorial) and n = 1, 2, 3

Finite Automata Part Three

Notes for Comp 454 Week 2

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

Finite Automata Part Three

Chapter 4: Regular Expressions

1.3 Functions and Equivalence Relations 1.4 Languages

Finite Automata Part Three

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

Compiler Construction

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

Languages and Strings. Chapter 2

ITEC2620 Introduction to Data Structures

JNTUWORLD. Code No: R

CS402 - Theory of Automata FAQs By

DVA337 HT17 - LECTURE 4. Languages and regular expressions

Homework. Context Free Languages. Before We Start. Announcements. Plan for today. Languages. Any questions? Recall. 1st half. 2nd half.

Multiple Choice Questions

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

CMPSCI 250: Introduction to Computation. Lecture #36: State Elimination David Mix Barrington 23 April 2014

Strings, Languages, and Regular Expressions

UNIT I PART A PART B

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

Recursively Defined Functions

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

Languages and Finite Automata

Welcome! CSC445 Models Of Computation Dr. Lutz Hamel Tyler 251

1. Which of the following regular expressions over {0, 1} denotes the set of all strings not containing 100 as a sub-string?

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

QUESTION BANK. Unit 1. Introduction to Finite Automata

Recursive Definitions Structural Induction Recursive Algorithms

Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

AUBER (Models of Computation, Languages and Automata) EXERCISES

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 2: Lexical Analysis 23 Jan 08

Formal Languages. Grammar. Ryan Stansifer. Department of Computer Sciences Florida Institute of Technology Melbourne, Florida USA 32901

A Formal Study of Practical Regular Expressions

MA/CSSE 474. Today's Agenda

Regular Languages. Regular Language. Regular Expression. Finite State Machine. Accepts

Chapter Seven: Regular Expressions

Regular Expressions. Chapter 6

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

CMSC 330 Practice Problem 4 Solutions

Automata Theory CS S-FR Final Review

Learn Smart and Grow with world

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

CMSC 330, Fall 2009, Practice Problem 3 Solutions

Ambiguous Grammars and Compactification

Why Study the Theory of Computation?

LECTURE NOTES THEORY OF COMPUTATION

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

LECTURE NOTES THEORY OF COMPUTATION

ECS 120 Lesson 7 Regular Expressions, Pt. 1

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

Name: Finite Automata

Formal Languages and Automata

Lecture 6,

Lamé s Theorem. Strings. Recursively Defined Sets and Structures. Recursively Defined Sets and Structures

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

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

CMSC 330: Organization of Programming Languages. Context-Free Grammars Ambiguity

Regular Expressions. Regular Expressions. Regular Languages. Specifying Languages. Regular Expressions. Kleene Star Operation

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Chapter 18: Decidability

Automating Construction of Lexers

Come & Join Us at VUSTUDENTS.net

Zhizheng Zhang. Southeast University

Introduction to Syntax Analysis. The Second Phase of Front-End

Data Compression Fundamentals

CSE 105 THEORY OF COMPUTATION

Solutions to Homework 10

Languages and Compilers

Front End: Lexical Analysis. The Structure of a Compiler

Bayesian Networks and Decision Graphs

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

8 ε. Figure 1: An NFA-ǫ

Context-Free Grammars

Mathematical Induction

Actually talking about Turing machines this time

Exact Matching Part III: Ukkonen s Algorithm. See Gusfield, Chapter 5 Visualizations from

Lexical Analysis - 1. A. Overview A.a) Role of Lexical Analyzer

Key to Homework #8. (a) S aa A bs bbb (b) S AB aaab A aab aaaaaaab B bba bbbb

CS 3100 Models of Computation Fall 2011 This assignment is worth 8% of the total points for assignments 100 points total.

Section 1.7 Sequences, Summations Cardinality of Infinite Sets

Lexical Analysis. Sukree Sinthupinyo July Chulalongkorn University

On the Parikh-de-Bruijn grid

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End

2. Lexical Analysis! Prof. O. Nierstrasz!

Section 2.4 Sequences and Summations

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

Turing Machine Languages

Suffix Trees and Arrays

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

Algorithms on Words Introduction CHAPTER 1

Models of Computation II: Grammars and Pushdown Automata

58093 String Processing Algorithms. Lectures, Autumn 2013, period II

Transcription:

Strings and Languages It is always best to start at the beginning -- Glynda, the good witch of the North What is a Language? A language is a set of strings made of of symbols from a given alphabet. An alphabet is a finite set of symbols (usually denoted by Σ) Examples of alphabets: {0, 1} {α, β, χ, δ, ε, φ, γ, η} {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z} {a} What is a string? A string over Σ is a finite sequence (possibly empty) of elements of Σ. ε denotes the null string, the string with no symbols. Example strings over {a, b} ε, a, aa, bb, aba, abbba NOT strings over {a, b} aaaa., abca The length of a string The length of a string x, denoted x, is the number of symbols in the string Example: abbab = 5 a = 1 bbbbbbb = 7 ε = 0 Strings and languages For any alphabet Σ, the set of all strings over Σ is denoted as Σ *. A language over Σ is a subset of Σ * Example {a,b} * = {ε, a, b, aa, bb, ab, ba, aaa, bbb, baa, } Example Languages over {a,b} {ε, a, b, aa, bb} {x {a,b} * x = 8} {x {a,b} * x is odd} {x {a,b} * n a (x) = n b (x)} {ε} {x {a,b} * n a (x) =2 and x starts with b}

Concatenation of String For x, y Σ * xy is the concatenation of x and y. x = aba, y = bbb, xy=ababbb For all x, ε x = xε = x x i for an integer i, indicates concatenation of x, i times x = aba, x 3 = abaabaaba For all x, x 0 = ε Some string related definitions x is a substring of y if there exists w,z Σ * (possibly ε) such that y = wxz. car is a substring of carnage, descartes, vicar, car, but not a substring of charity. x is a suffix of y if there exists w Σ * such that y = wx. x is a prefix of y if there exists z Σ * such that y = xz. Operations on Languages Since languages are simply sets of strings, regular set operations can be applied: For languages L 1 and L 2 over Σ * L 1 L 2 = all strings in L 1 or L 2 L 1 L 2 = all strings in both L 1 and L 2 L 1 L 2 = strings in L 1 that are not in L 2 L = Σ * L Concatenation of Languages If L 1 and L 2 are languages over Σ * L 1 L 2 = {xy x L 1 and y L 2 } Example: L 1 = {hope, fear} L 2 = {less, fully} L 1 L 2 = {hopeless, hopefully, fearless, fearfully} Concatenation of Languages If L is a language over Σ * L k is the set of strings formed by concatenating elements of L, k times. Example: L = {aa, bb} L 3 = {aaaaaa, aaaabb, aabbaa, aabbbb, bbbbbb, bbbbaa, bbaabb, bbaaaa} L 0 = {ε} Kleene Star Operation The set of strings that can be obtained by concatenating any number of elements of a language L is called the Kleene Star, L * * i 0 1 2 3 4 L = L = L L L L L... U i= 0 Note that since, L * contains L 0, ε is an element of L *

Kleene Star Operation The set of strings that can be obtained by concatenating one or more elements of a language L is denoted L + + i 1 2 3 4 L = L = L L L L... U i= 1 Specifying Languages How do we specify languages? If language is finite, you can list all of its strings. L = {a, aa, aba, aca} Using basic Language operations L= {aa, ab} * {b}{bb} * Descriptive: L = {x n a (x) = n b (x)} Specifying Languages Next we will define how to specify languages recursively In future classes, we will describe how to specify languages by defining a mechanism for generating the language Any questions? Recursive Definitions Definition is given in terms of itself Example (factorial) 1 if n = 0 n! = { n*( n 1)! otherwise } 4! = 4 * 3! = 4 * (3 * 2!) = 4 * (3 * (2 * 1!)) = 4 * (3 * (2 * (1 * 0!))) = 4 * (3 * (2 * (1 * 1)))) = 24 Languages can also be described by using a recursive definition 1. Initial elements are added to your set (BASIS) 2. Additional elements are added to your set by applying a rule(s) to the elements already in your set (INDUCTION) 3. Complete language is obtained by applying step 2 infinitely Example: Recursive definition of Σ * 1. ε Σ * 2. For all x Σ * and all a Σ, xa Σ * 3. Nothing else is in Σ * unless it can be obtained by a finite number of applications of rules 1 and 2.

Let s iterate through the rules for Σ = {a,b} i=0 Σ * = {ε} i=1 Σ * = {ε, a, b} i=2 Σ * = {ε, a, b, aa, ab, ba, bb} i=3 Σ * = {ε, a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, bab, bba, bbb} and so on Example: Recursive definition of L * 1.ε L * 2.For all x L and all y L, xy L * 3.Nothing else is in L * unless it can be obtained by a finite number of applications of rules 1 and 2. Let s iterate through the rules for L = {aa,bb} i=0 L * = {ε} i=1 L * = {ε, aa, bb} i=2 L * = {ε, aa, bb, aaaa, aabb, bbbb, bbaa} i=3 L * = {ε, aa, bb, aaaa, aabb, bbbb, bbaa, aaaaaa, aaaabb, aabbaa, aabbbb, bbbbaa, bbbbbb, } and so on Recursive Definitions another Example Example: Palindromes A palindrome is a string that is the same read left to right or right to left First half of a palindrome is a mirror image of the second half Examples: a, b, aba, abba, babbab. Recursive Definitions another Example Recursive definition for palindromes (pal) over Σ 1. ε pal 2. For any a Σ, a pal 3. For any x pal and a Σ, axa pal 4. No string is in pal unless it can be obtained by rules 1-3 Recursive Definitions another Example Let s iterate through the rules for pal over Σ = {a,b} i=0 pal = {ε, a, b} i=1 pal = {ε, a, b, aaa, aba, bab, bbb} i=2 pal = {ε, a, b, aaa, aba, bab, bbb, aaaaa, aabaa, ababa, abbba, baaab, ababa, bbabb, bbbbb}

Recursive Definitions yet another Example Example: Fully parenthesized algebraic expressions (AE) Σ = { a, (, ), +, - } All expressions where the parens match correctly are in the language Examples: a, (a + a), (a + (a a)), ( (a + a) (a + a)), etc. Recursive Definitions yet another Example Recursive definition for AE 1.a AE 2.For any x, y AE (x + y) and (x y) AE 3.No string is in pal unless it can be obtained by rules 1-2 Recursive Definitions yet another Example Let s iterate through the rules for AE i=0 AE = {a} i=1 AE = { a, (a+a), (a-a) } i=2 AE = {a, (a+a), (a-a), (a + ( a + a)), (a (a + a)), ( a + ( a a)), ( a ( a a)), ((a + a) + a), ( (a + a) a), } Recursive Definitions a final Example L = {x {0,1} * x = 0 i 1 j and i j 0} In English: strings over the alphabet {0,1} each string contains zero or more 0 s followed by a zero or more 1 s the number of 1 s is greater than or equal to the number of 0 s Recursive Definitions a final Example L = {x {0,1} * x = 0 i 1 j and i j 0} A recursive definition 1. ε L 2. For any x L, both 0x and 0x1 L 3. No strings are in L unless it can be obtained using rules 1-2. Questions on Recursive Definition? Functions on strings and languages can also be defined recursively. Later we will prove that this definition does indeed describe L.

When dealing with languages, it is sometime cumbersome to restate the problems in terms of an integer. For languages described using a recursive definition, another type of induction, structural induction, is useful. Principles Suppose U is a set, I is a subset of U (BASIS), Op is a set of operations on U (INDUCTION). L is a subset of U defined recursively as follows: I L L is closed under each operation in Op L is the smallest set satisfying 1 & 2 Then To prove that every element of L has some property P, it is sufficient to show: 1. Every element of I has property P 2. The set of elements of L having property P is closed under Op #2: If x L has property P, Op(x) also must have property P Recall this recursive definition of a language L 1. ε L 2. For any x L, both 0x and 0x1 L 3. No strings are in L unless it can be obtained using rules 1-2. And: A = {x {0,1} * x = 0 i 1 j and i j 0} Show L A by structural induction Principles Suppose U is a set U = {a,b} * I is a subset of U, I = {ε} Op is a set of ops on U. Op = {0x, 0x1} L is a subset of U defined recursively as follows: I L L is closed under each operation in Op L is the smallest set satisfying 1 & 2. To prove that every element of L has some property P: Our property is: A = {x {0,1} * x = 0 i 1 j and i j 0} P(x) is true if x A.

To prove that every element of L has some property P, it is sufficient to show: 1.Every element of I has property P In our case, must show that ε has property P, I.e. ε A, ε = 0 i 1 j, i j 0 Once again, this is the case where i=j=0 2. The set of elements of L having property P is closed under Op If x L has property P, Op(x) also must have property P Assume x has property P, x A, x = 0 i 1 j, i j 0 Op1(x) = 0x, which is an element of A Op2(x) = 0x1 which is an element of A Similar proof to induction with no mention of an integer Questions? Summary Languages = set of strings Recursive Definition of Languages Any questions? Questions? Next Time: Our first machine: The Finite Automata!