REGular and Context-Free Grammars
|
|
- Lee May
- 5 years ago
- Views:
Transcription
1 REGular and Context-Free Grammars Nicholas Mainardi 1 Dipartimento di Elettronica e Informazione Politecnico di Milano nicholas.mainardi@polimi.it March 26, Partly Based on Alessandro Barenghi s material, largely enriched with some additional exercises
2 Grammars What are grammars? Another formalism to define a language Generative approach: the grammar points out how a sentence (i.e. an element of the language) is generated For some grammar classes, automated algorithms to derive the recogniser automaton are available (and pretty widely used!) Possible to define grammar classes corresponding to a precise computing model (FSA, [N D]PDA, TM)
3 Formalization A formal definition A grammar is defined by a 4-tuple (V n, V t, P, S) where: V n is the non-terminal symbol alphabet V t is the terminal symbol alphabet P V n + (V t V n ) is the set of syntactic productions S V n is the starting symbol, known as the axiom a production rule maps one or more symbols from V n into zero or more symbols from V = (V t V n ) More formally, a derivation α β, with α V n +, α = α 1 α 2 α 3 and β V, β = α 1 β 2 α 3 exists if and only if there is a p P such that p = α 2 β 2 indicates the reflexive and transitive closure of A grammar generates the language L G = {x x V t S x}
4 Notation Common Conventions Non terminal symbols are UPPERCASE, terminal symbols are lowercase S is the axiom of the grammar Single character symbols are used (no tokenization needed) Concatenation. mark is omitted Regular expressions in the RHS of the rule are not used except for the symbol employed to shorten the notation
5 Recognizer automaton Equivalences Grammar Language Generic Recognizer Type Class Rule Form Automaton 3 Regular A ab B ɛ FSA 2 Context Free A ABC NPDA 1 Context-sensitive α β, α β lin-bounded TM 0 Recursively enumerable any α β TM
6 First examples Warming up Regular: L = (aa) Sample grammar generating the language S ɛ (zero is even) S aa (when the first a is produced...) A as (make a pair and continue, or...) A a (make a pair and stop) Context Free: L = a n b n c m a m ; n 0, m 1 Sample grammar generating the language S S 1 S 2 (concatenation is easy) S 1 as 1 b ɛ (grow the pairs from within) S 2 cs 2 a ca (avoid generating no ca pairs)
7 Union With Grammars Union of languages is straightforward too! Big/Little Endian Encodings Consider the language L defined on the alphabet {0, 1, a}, as the union of 2 sublanguages L l and L b : L l = {(na n ) + 0 n 3} Here, n is written with little endian binary representation (first digit is the least significant one) L b = {(na n ) + 0 n 3} Here, n is written with big endian binary representation (first digit is the most significant one) For instance, for a sequence of 2 a: Little endian: 01aa Big Endian: 10aa
8 Union With Grammars Grammar for L l S l 0Z 1U Z 0N 0 1N 2 U 0N 1 1N 3 N 0 ɛ S l N 1 an 0 N 2 an 1 N 3 an 2 Grammar for L b S b 0Z 1U Z 0N 0 1N 1 U 0N 2 1N 3 N 0 ɛ S b N 1 an 0 N 2 an 1 N 3 an 2 Grammar for L = L l L b S S l S b
9 Union With Grammars Problem: There are conflicting non-terminal symbols in the sub-grammars! Hence, the grammar generates strings as 01a10a: S S b S b 0Z 0Z 01N 1 01N 1 01aN 0 01aN 0 01aS b 01aS b 01a1U 01a1U 01a10N 1 01a10N 1 01a10aN 0 01a10N 0 01a10a This derivation is possible since the merging operation transforms the U rule in: U 0N 1 0N 2 1N 3 Before performing union, the sets of non-terminal symbols of the sub-grammars must be disjoint
10 Union With Grammars L is a regular language defined on the alphabet Σ = {a, b, 0, 1} as: L 1 = {x = a.y y Σ y 0 = 2k + 1 y 1 = 2h, h, k 0} L 2 = {x = b.y y Σ y 0 = 2k y 1 = 2h + 1, h, k 0} L 3 = {x = (0 1).y y Σ } Idea: We can easily handle the 3 sub-languages with 3 sub-grammars, with axioms S 1, S 2, and S 3, and then choose among these sub-languages depending on the first character: Grammar for L S as 1 bs 2 0S 3 1S 3
11 Union With Grammars Grammar For L 1 S 1 as 1 bs 1 0O e 1E o O e 0S 1 1O o ao e bo e ɛ E o 0O o 1S 1 ae o be o O o 0E o 1O e ao o bo o Grammar For L 2 S 2 as 2 bs 2 0O 2 e 1E 2 o O 2 e 0S 2 1O 2 o ao 2 e bo 2 e E 2 o 0O 2 o 1S 2 ae 2 o be 2 o ɛ O 2 o 0E 2 o 1O 2 e ao o bo 2 o Grammar for L 3 is easier: S 3 as 3 bs 3 0S 3 1S 3 ɛ
12 A Left-Linear Version The grammar for the language L can be written in a more compact form using left-linear productions. With a left-linear grammar, we generate a string from the end to the beginning! Therefore, right linear grammars are often easier to be conceived Idea for this language: generates the string up to the second character, then allows replacement of the non-terminal symbol based on the parities of 0 and 1: 1 S Sa Sb O e 0 E o The first character must be 0 or 1 2 O e O e a O e b S0 O o 1 a 0 1. The first character cannot be b 3 E o E o a E o b O o 0 S1 b 0 1. The first character cannot be a 4 O o O o a O o b E o 0 O e The first character must be 0 or 1
13 Simplifying a Grammar Consider the language L = {s = c m.y y L Y m > 0} L Y = {a m.x x L X m > 0} ɛ L X = {b m.y y L Y m > 0} ɛ A Grammar for L 1 S cs cy 2 Y aa ax ɛ 3 X bb by ɛ 4 A aa ax 5 B bb by
14 Simplifying a Grammar: Transforming to FSA We can generate a FSA from a grammar: Q = V n q f I = V t δ(q, i) = q q i q P δ(q, i) = q f q i P F = {q q ɛ P} q f ND-FSA for L b c a start S Y A a B c b a X a b b
15 Simplifying a Grammar: Determinization Generally, it is likely that the automaton derived from a grammar is non-deterministic We can make it deterministic with the known algorithm: Deterministic FSA for L c a b start S c SY a AX b BY a
16 Simplifying a Grammar: FSA Minimization Given a FSA, it is always possible to get the FSA recognizing the same language with the minimum number of states There is an algorithm, which is based on the concept of indistinguishable states Indistinguishable States Given a FSA, 2 states q, q Q are indistinguishable if: q F q F i I(δ(q, i) = δ(q, i)) Idea of the algorithm: 1 Search for indistinguishable states 2 If there are indistinguishable states, merge them in a unique state and go back to 1 3 Otherwise, the minimum automaton has been reached NB Indistinguishability is transitive!
17 Simplifying a Grammar: FSA Minimization Are there any indistinguishable states in our FSA? Yes! AX and BY! Indeed: 1 AX F BY F 2 δ(ax, a) = δ(by, a) = AX 3 δ(by, b) = δ(ax, b) = BY Minimum Deterministic FSA for L c a, b c a start S SY F
18 Simplifying a Grammar: Getting Back to the Grammar Once we have our minimum deterministic FSA, we can transform it back to a grammar: V n = Q V t = I q i q P δ(q, i) = q q ɛ P q F Simplified Grammar for L 1 S cs y 2 S y cs y af ɛ 3 F af bf ɛ
19 Counting with grammars Position independent counting Target language L = (a b) +, x L, x a = x b Context-free language, we only need to count one kind of symbols S aabg bbag G aabg bbag ɛ A aab bba ɛ G B aab bba ɛ G or, in a more compact form, S agbg bgag G agbg bgag ɛ The arbitrary choice of the production rule allows to generate every combination
20 Counting With Grammars Example of derivations for the string bbaabaaababb: S bbag. It starts with a sequence of b bbag bbbaag. Dealing with the first sequence of b bbbaag bbaag. The sequence is finished, thus get rid of B bbaag bbaabbag. Another pair starting with b bbaabbag bbaabag.the sequence is finished, thus get rid of B bbaabag bbaabaaabg. This time we have a sequence of a bbaabaaabg bbaabaaaabbg. Dealing with the sequence of a bbaabaaaabbg bbaabaaagbbg. There are other sequences between the second a and the matching b, thus we need a new non-terminal G before the b bbaabaaagbbg bbaabaaabbagbbg. We need to generate a pair ba. bbaabaaabbagbbg bbaabaaabagbbg. The sequence is finished, thus get rid of B. bbaabaaabagbbg bbaabaaababb. We generate all the necessary A and B, thus we can get rid of G.
21 The Generative Approach of Grammars Consider the language L = {a m b n m n, m, n 0}. We want to write a grammar for this language. A Possible Solution 1 S asb aa bb (Generate balanced a, b pairs until an unbalanced character is generated) 2 A aa aab ɛ (Generate balanced and unbalanced a) 3 B bb abb ɛ (Generate balanced and unbalanced b) Basic idea of the design: non-terminal symbols A and B allows to recognize a string respectively with m n and with m n. In order to generate an A or B symbol, we generate an unbalanced a or b, thus ensuring that the generated strings have either m > n or m < n.
22 The Generative Approach of Grammars Grammars are a generative model! We do not need to allow a grammar to generate both balanced and unbalanced characters, but we can decide to split the generated string in 2 parts: the first where a and b are balanced, the second when we add either a or b. A Simplified Solution 1 S asb aa bb (Generate balanced a until an unbalanced character is generated) 2 A aa ɛ (Add unbalanced a after balanced a) 3 B bb ɛ (Add unbalanced b before balanced b) Easier to design the grammar, since we have two simpler separated generation phases
23 The Generative Approach of Grammars Consider the language: L = {ab n 1 ab n 2... ab n k i, n i > 0 k 2 j, h(1 j < h k n j = n h )} That is, the strings of the form (ab + )(ab + ) + where at least two substrings (ab + ) have the same number of b. A Grammar For L S GaXG (This defines the structure of a string) X bxb bgab (Generate the substrings with the same number of b) G ah ɛ (Generate a sequence (possibly empty) of substrings ab + ) H bh bg (Generate b + ) The strategy is again forcing the grammar to generate a substring with the require property (2 substrings with the same number of b) somewhere on the string, but without specifying when this substring should be generated Sooner or later the substring will be generated, and this is enough! Again, grammars have more free will than automata
24 Proofs on grammars Mathematical induction on generation Goal: prove that S 1S1 0S0 1 0 ɛ generates all, and only, the palindromes over Σ = {0, 1} The theorem we want to prove is a double implication: 1 x = w(0 1 ɛ)w R, w Σ = S x 2 S x = x = w(0 1 ɛ)w R, w Σ We will use thus two different induction steps : 1 Since the hypothesis is defined on words, induction on word length 2 Since the hypothesis is defined on the grammar, induction on the number of productions
25 Proofs on grammars - Part 1 Is a palindrome is generated by the grammar Base Case : ɛ (length 0) is a palindrome ɛ is generated by the grammar Induction Step: the theorem holds for x = k 1, k N, prove that it holds for x = k Split into two cases : 1 k is odd: x = u(0 1)u R. 2 k is even: x = ww R.
26 Proofs on grammars - Part 1 1 x = u(0 1)u R. By induction hypothesis, S uu R. We argue that S usu R. Indeed, the string uu R has an even number of characters, and since all the productions rewriting S generates 2 characters, we cannot stop generation with the productions S 1 or S 0, since we would get a string with an odd number of characters. Therefore, S ɛ must be employed to get uu R, in turn implying that the grammar generates the string usu R. We can get x from this string by applying one of the productions S 1 or S 0. 2 x = ww R = uaau R, a {0, 1}. By induction hypothesis, S uau R. From the previous case, we know also S usu R, since uau R is necessarily obtained through applying one of the S a productions. Then, if we apply one of the S asa productions and S ɛ one, we can generate x
27 Proofs on grammars - Part 2 Is generated by the grammar is a palindrome Base Case : the productions S 0 1 ɛ ɛ, 0, 1 are palindromes Induction Step: the theorem holds for S x w, x < k N, prove that it holds for S k w We need to check that all the grammar productions preserve the palindrome property. For a 0, 1, by inductive hypothesis: S k 1 x, x L = S k 2 wsw R = S k 1 wasaw R S k 1 wasaw R = S k waaw R L (using S ɛ). S k 1 wasaw R = S k wa(0 1)aw R L (using S 0 or S 1) All the possible productions leading to a valid word at k steps preserve the palindrome property, thus the theorem holds for k
Finite State Automata Design
Finite State Automata Design Nicholas Mainardi 1 Dipartimento di Elettronica e Informazione Politecnico di Milano nicholas.mainardi@polimi.it March 14, 2017 1 Mostly based on Alessandro Barenghi s material,
More informationFoundations of Informatics: a Bridging Course
Foundations of Informatics: a Bridging Course Week 3: Formal Languages and Semantics Thomas Noll Lehrstuhl für Informatik 2 RWTH Aachen University noll@cs.rwth-aachen.de http://www.b-it-center.de/wob/en/view/class211_id948.html
More informationcse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska
cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska LECTURE 5 CHAPTER 2 FINITE AUTOMATA 1. Deterministic Finite Automata DFA 2. Nondeterministic Finite Automata NDFA 3. Finite Automata
More informationPlease give details of your answer. A direct answer without explanation is not counted.
Please give details of your answer. A direct answer without explanation is not counted. Your answers must be in English. Please carefully read problem statements. During the exam you are not allowed to
More informationAutomata: a short introduction
ILIAS, University of Luxembourg Discrete Mathematics II May 2012 What is a computer? Real computers are complicated; We abstract up to an essential model of computation; We begin with the simplest possible
More informationClarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.
CMSC 330: Organization of Programming Languages Last Lecture Languages Sets of strings Operations on languages Finite Automata Regular expressions Constants Operators Precedence CMSC 330 2 Clarifications
More informationNODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY
No part of this publication may be reproduced or distributed in any form or any means, electronic, mechanical, photocopying, or otherwise without the prior permission of the author. GATE SOLVED PAPER Computer
More informationPart 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
Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu Part 4 out of 5 ETH Zürich (D-ITET) October, 12 2017 Last week, we showed the equivalence of DFA, NFA and REX
More informationAC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014
Q.2 a. Show by using Mathematical Induction that n i= 1 i 2 n = ( n + 1) ( 2 n + 1) 6 b. Define language. Let = {0; 1} denote an alphabet. Enumerate five elements of the following languages: (i) Even binary
More informationEinführung in die Computerlinguistik
Einführung in die Computerlinguistik Context-Free Grammars (CFG) Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Summer 2016 1 / 22 CFG (1) Example: Grammar G telescope : Productions: S NP VP NP
More informationFundamentele Informatica II
Fundamentele Informatica II Answer to selected exercises 5 John C Martin: Introduction to Languages and the Theory of Computation M.M. Bonsangue (and J. Kleijn) Fall 2011 5.1.a (q 0, ab, Z 0 ) (q 1, b,
More informationClosure under the Regular Operations
September 7, 2013 Application of NFA Now we use the NFA to show that collection of regular languages is closed under regular operations union, concatenation, and star Earlier we have shown this closure
More informationAutomata Theory CS F-08 Context-Free Grammars
Automata Theory CS411-2015F-08 Context-Free Grammars David Galles Department of Computer Science University of San Francisco 08-0: Context-Free Grammars Set of Terminals (Σ) Set of Non-Terminals Set of
More informationTheory of Computation - Module 3
Theory of Computation - Module 3 Syllabus Context Free Grammar Simplification of CFG- Normal forms-chomsky Normal form and Greibach Normal formpumping lemma for Context free languages- Applications of
More informationCMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata
: Organization of Programming Languages Theory of Regular Expressions Finite Automata Previous Course Review {s s defined} means the set of string s such that s is chosen or defined as given s A means
More informationThe Pumping Lemma. for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.
The Pumping Lemma For every regular language L, there is a number l 1 satisfying the pumping lemma property: All w L with w l can be expressed as a concatenation of three strings, w = u 1 vu 2, where u
More informationCS500 Homework #2 Solutions
CS500 Homework #2 Solutions 1. Consider the two languages Show that L 1 is context-free but L 2 is not. L 1 = {a i b j c k d l i = j k = l} L 2 = {a i b j c k d l i = k j = l} Answer. L 1 is the concatenation
More informationLanguages, regular languages, finite automata
Notes on Computer Theory Last updated: January, 2018 Languages, regular languages, finite automata Content largely taken from Richards [1] and Sipser [2] 1 Languages An alphabet is a finite set of characters,
More informationSolutions to Problem Set 3
V22.0453-001 Theory of Computation October 8, 2003 TA: Nelly Fazio Solutions to Problem Set 3 Problem 1 We have seen that a grammar where all productions are of the form: A ab, A c (where A, B non-terminals,
More informationIntroduction to Formal Languages, Automata and Computability p.1/51
Introduction to Formal Languages, Automata and Computability Finite State Automata K. Krithivasan and R. Rama Introduction to Formal Languages, Automata and Computability p.1/51 Introduction As another
More informationNondeterministic Finite Automata
Nondeterministic Finite Automata Not A DFA Does not have exactly one transition from every state on every symbol: Two transitions from q 0 on a No transition from q 1 (on either a or b) Though not a DFA,
More informationFORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY REVIEW for MIDTERM 1 THURSDAY Feb 6 Midterm 1 will cover everything we have seen so far The PROBLEMS will be from Sipser, Chapters 1, 2, 3 It will be
More informationSri vidya college of engineering and technology
Unit I FINITE AUTOMATA 1. Define hypothesis. The formal proof can be using deductive proof and inductive proof. The deductive proof consists of sequence of statements given with logical reasoning in order
More informationNote: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).
Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). 1a) G = ({R, S, T}, {0,1}, P, S) where P is: S R0R R R0R1R R1R0R T T 0T ε (S generates the first 0. R generates
More informationHow do regular expressions work? CMSC 330: Organization of Programming Languages
How do regular expressions work? CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata What we ve learned What regular expressions are What they can express, and cannot
More informationCMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata
CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata CMSC330 Spring 2018 1 How do regular expressions work? What we ve learned What regular expressions are What they
More informationComputational Models - Lecture 4 1
Computational Models - Lecture 4 1 Handout Mode Iftach Haitner. Tel Aviv University. November 21, 2016 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice Herlihy, Brown University.
More informationFormal Definition of a Finite Automaton. August 26, 2013
August 26, 2013 Why a formal definition? A formal definition is precise: - It resolves any uncertainties about what is allowed in a finite automaton such as the number of accept states and number of transitions
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata CMSC 330 Spring 2017 1 How do regular expressions work? What we ve learned What regular expressions are What they
More informationSeptember 11, Second Part of Regular Expressions Equivalence with Finite Aut
Second Part of Regular Expressions Equivalence with Finite Automata September 11, 2013 Lemma 1.60 If a language is regular then it is specified by a regular expression Proof idea: For a given regular language
More informationTheory of Computation Turing Machine and Pushdown Automata
Theory of Computation Turing Machine and Pushdown Automata 1. What is a Turing Machine? A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type
More informationCS 455/555: Finite automata
CS 455/555: Finite automata Stefan D. Bruda Winter 2019 AUTOMATA (FINITE OR NOT) Generally any automaton Has a finite-state control Scans the input one symbol at a time Takes an action based on the currently
More informationChapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009
Chapter 1 Formal and View Lecture on the 28th April 2009 Formal of PA Faculty of Information Technology Brno University of Technology 1.1 Aim of the Lecture 1 Define pushdown automaton in a formal way
More informationPushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen
Pushdown automata Twan van Laarhoven Institute for Computing and Information Sciences Intelligent Systems Version: fall 2014 T. van Laarhoven Version: fall 2014 Formal Languages, Grammars and Automata
More informationHW 3 Solutions. Tommy November 27, 2012
HW 3 Solutions Tommy November 27, 2012 5.1.1 (a) Online solution: S 0S1 ɛ. (b) Similar to online solution: S AY XC A aa ɛ b ɛ C cc ɛ X axb aa b Y by c b cc (c) S X A A A V AV a V V b V a b X V V X V (d)
More informationHarvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs
Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harry Lewis October 8, 2013 Reading: Sipser, pp. 119-128. Pushdown Automata (review) Pushdown Automata = Finite automaton
More informationChapter 3. Regular grammars
Chapter 3 Regular grammars 59 3.1 Introduction Other view of the concept of language: not the formalization of the notion of effective procedure, but set of words satisfying a given set of rules Origin
More informationINSTITUTE OF AERONAUTICAL ENGINEERING
INSTITUTE OF AERONAUTICAL ENGINEERING DUNDIGAL 500 043, HYDERABAD COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name : FORMAL LANGUAGES AND AUTOMATA THEORY Course Code : A40509 Class :
More informationIntroduction to Formal Languages, Automata and Computability p.1/42
Introduction to Formal Languages, Automata and Computability Pushdown Automata K. Krithivasan and R. Rama Introduction to Formal Languages, Automata and Computability p.1/42 Introduction We have considered
More informationIntroduction to Theory of Computing
CSCI 2670, Fall 2012 Introduction to Theory of Computing Department of Computer Science University of Georgia Athens, GA 30602 Instructor: Liming Cai www.cs.uga.edu/ cai 0 Lecture Note 3 Context-Free Languages
More information5 Context-Free Languages
CA320: COMPUTABILITY AND COMPLEXITY 1 5 Context-Free Languages 5.1 Context-Free Grammars Context-Free Grammars Context-free languages are specified with a context-free grammar (CFG). Formally, a CFG G
More informationDeterministic Finite Automata (DFAs)
Algorithms & Models of Computation CS/ECE 374, Fall 27 Deterministic Finite Automata (DFAs) Lecture 3 Tuesday, September 5, 27 Sariel Har-Peled (UIUC) CS374 Fall 27 / 36 Part I DFA Introduction Sariel
More informationEXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100
EXAMPLE CFG L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa S asa L = {a n b : n 0 } L = {a n b : n 1 } S as b S as ab L { a b : n 0} L { a b : n 1} S asb S asb ab n 2n n 2n L {1 0 : n 0} L {1 0 : n 1} S
More informationTheory of Computation (II) Yijia Chen Fudan University
Theory of Computation (II) Yijia Chen Fudan University Review A language L is a subset of strings over an alphabet Σ. Our goal is to identify those languages that can be recognized by one of the simplest
More information1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.
Code No: R09220504 R09 Set No. 2 II B.Tech II Semester Examinations,December-January, 2011-2012 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 75 Answer
More informationCS481F01 Solutions 6 PDAS
CS481F01 Solutions 6 PDAS A. Demers 2 November 2001 1. Give a NPDAs that recognize the following languages: (a) The set of all strings in {0, 1} that contain twice as many 1s as 0s. (answer a) We build
More informationPS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010
University of Virginia - cs3102: Theory of Computation Spring 2010 PS2 - Comments Average: 77.4 (full credit for each question is 100 points) Distribution (of 54 submissions): 90, 12; 80 89, 11; 70-79,
More informationCS 275 Automata and Formal Language Theory
CS 275 Automata and Formal Language Theory Course Notes Part II: The Recognition Problem (II) Chapter II.4.: Properties of Regular Languages (13) Anton Setzer (Based on a book draft by J. V. Tucker and
More informationCSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.
CSE 5 Homework Due: Monday October 9, 7 Instructions Upload a single file to Gradescope for each group. should be on each page of the submission. All group members names and PIDs Your assignments in this
More informationClosure under the Regular Operations
Closure under the Regular Operations Application of NFA Now we use the NFA to show that collection of regular languages is closed under regular operations union, concatenation, and star Earlier we have
More informationCS243, Logic and Computation Nondeterministic finite automata
CS243, Prof. Alvarez NONDETERMINISTIC FINITE AUTOMATA (NFA) Prof. Sergio A. Alvarez http://www.cs.bc.edu/ alvarez/ Maloney Hall, room 569 alvarez@cs.bc.edu Computer Science Department voice: (67) 552-4333
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Theory of Regular Expressions DFAs and NFAs Reminders Project 1 due Sep. 24 Homework 1 posted Exam 1 on Sep. 25 Exam topics list posted Practice homework
More informationAC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013
Q.2 a. Prove by mathematical induction n 4 4n 2 is divisible by 3 for n 0. Basic step: For n = 0, n 3 n = 0 which is divisible by 3. Induction hypothesis: Let p(n) = n 3 n is divisible by 3. Induction
More informationCS 121, Section 2. Week of September 16, 2013
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,
More informationDeterministic Finite Automata (DFAs)
CS/ECE 374: Algorithms & Models of Computation, Fall 28 Deterministic Finite Automata (DFAs) Lecture 3 September 4, 28 Chandra Chekuri (UIUC) CS/ECE 374 Fall 28 / 33 Part I DFA Introduction Chandra Chekuri
More informationDeterministic Finite Automata (DFAs)
Algorithms & Models of Computation CS/ECE 374, Spring 29 Deterministic Finite Automata (DFAs) Lecture 3 Tuesday, January 22, 29 L A TEXed: December 27, 28 8:25 Chan, Har-Peled, Hassanieh (UIUC) CS374 Spring
More informationPart I: Definitions and Properties
Turing Machines Part I: Definitions and Properties Finite State Automata Deterministic Automata (DFSA) M = {Q, Σ, δ, q 0, F} -- Σ = Symbols -- Q = States -- q 0 = Initial State -- F = Accepting States
More informationMiscellaneous. Closure Properties Decision Properties
Miscellaneous Closure Properties Decision Properties 1 Closure Properties of CFL s CFL s are closed under union, concatenation, and Kleene closure. Also, under reversal, homomorphisms and inverse homomorphisms.
More informationComputational Models - Lecture 4 1
Computational Models - Lecture 4 1 Handout Mode Iftach Haitner and Yishay Mansour. Tel Aviv University. April 3/8, 2013 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice
More informationFormal Definition of Computation. August 28, 2013
August 28, 2013 Computation model The model of computation considered so far is the work performed by a finite automaton Finite automata were described informally, using state diagrams, and formally, as
More informationCS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa
CS:4330 Theory of Computation Spring 2018 Regular Languages Finite Automata and Regular Expressions Haniel Barbosa Readings for this lecture Chapter 1 of [Sipser 1996], 3rd edition. Sections 1.1 and 1.3.
More informationCS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)
CS5371 Theory of Computation Lecture 7: Automata Theory V (CFG, CFL, CNF) Announcement Homework 2 will be given soon (before Tue) Due date: Oct 31 (Tue), before class Midterm: Nov 3, (Fri), first hour
More informationHow to write proofs - II
How to write proofs - II Problem (Ullman and Hopcroft, Page 104, Exercise 4.8). Let G be the grammar Prove that S ab ba A a as baa B b bs abb L(G) = { x {a, b} x contains equal number of a s and b s }.
More informationTuring machines and linear bounded automata
and linear bounded automata Informatics 2A: Lecture 29 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 27 November 2015 1 / 15 The Chomsky hierarchy: summary Level Language
More informationFORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
5-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY NON-DETERMINISM and REGULAR OPERATIONS THURSDAY JAN 6 UNION THEOREM The union of two regular languages is also a regular language Regular Languages Are
More informationProperties of Context Free Languages
1 Properties of Context Free Languages Pallab Dasgupta, Professor, Dept. of Computer Sc & Engg 2 Theorem: CFLs are closed under concatenation If L 1 and L 2 are CFLs, then L 1 L 2 is a CFL. Proof: 1. Let
More informationConcordia University Department of Computer Science & Software Engineering
Concordia University Department of Computer Science & Software Engineering COMP 335/4 Theoretical Computer Science Winter 2015 Assignment 3 1. In each case, what language is generated by CFG s below. Justify
More informationTuring machines and linear bounded automata
and linear bounded automata Informatics 2A: Lecture 30 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 25 November 2016 1 / 17 The Chomsky hierarchy: summary Level Language
More informationCOMP4141 Theory of Computation
COMP4141 Theory of Computation Lecture 4 Regular Languages cont. Ron van der Meyden CSE, UNSW Revision: 2013/03/14 (Credits: David Dill, Thomas Wilke, Kai Engelhardt, Peter Höfner, Rob van Glabbeek) Regular
More informationCS481F01 Prelim 2 Solutions
CS481F01 Prelim 2 Solutions A. Demers 7 Nov 2001 1 (30 pts = 4 pts each part + 2 free points). For this question we use the following notation: x y means x is a prefix of y m k n means m n k For each of
More informationDefinition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where
Recitation 11 Notes Context Free Grammars Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x A V, and x (V T)*. Examples Problem 1. Given the
More informationCISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata
CISC 4090: Theory of Computation Chapter Regular Languages Xiaolan Zhang, adapted from slides by Prof. Werschulz Section.: Finite Automata Fordham University Department of Computer and Information Sciences
More informationChapter 6. Properties of Regular Languages
Chapter 6 Properties of Regular Languages Regular Sets and Languages Claim(1). The family of languages accepted by FSAs consists of precisely the regular sets over a given alphabet. Every regular set is
More informationAutomata Theory - Quiz II (Solutions)
Automata Theory - Quiz II (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV {ksmani@csee.wvu.edu} 1 Problems 1. Induction: Let L denote the language of balanced strings over Σ =
More informationTheory of Computation
Fall 2002 (YEN) Theory of Computation Midterm Exam. Name:... I.D.#:... 1. (30 pts) True or false (mark O for true ; X for false ). (Score=Max{0, Right- 1 2 Wrong}.) (1) X... If L 1 is regular and L 2 L
More informationCPSC 421: Tutorial #1
CPSC 421: Tutorial #1 October 14, 2016 Set Theory. 1. Let A be an arbitrary set, and let B = {x A : x / x}. That is, B contains all sets in A that do not contain themselves: For all y, ( ) y B if and only
More informationHKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed
HKN CS/ECE 374 Midterm 1 Review Nathan Bleier and Mahir Morshed For the most part, all about strings! String induction (to some extent) Regular languages Regular expressions (regexps) Deterministic finite
More informationFABER Formal Languages, Automata. Lecture 2. Mälardalen University
CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010 1 Content Languages, g Alphabets and Strings Strings & String Operations Languages & Language Operations
More informationCOM364 Automata Theory Lecture Note 2 - Nondeterminism
COM364 Automata Theory Lecture Note 2 - Nondeterminism Kurtuluş Küllü March 2018 The FA we saw until now were deterministic FA (DFA) in the sense that for each state and input symbol there was exactly
More informationChapter Five: Nondeterministic Finite Automata
Chapter Five: Nondeterministic Finite Automata From DFA to NFA A DFA has exactly one transition from every state on every symbol in the alphabet. By relaxing this requirement we get a related but more
More information3515ICT: Theory of Computation. Regular languages
3515ICT: Theory of Computation Regular languages Notation and concepts concerning alphabets, strings and languages, and identification of languages with problems (H, 1.5). Regular expressions (H, 3.1,
More information(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},
Code No: 07A50501 R07 Set No. 2 III B.Tech I Semester Examinations,MAY 2011 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 80 Answer any FIVE Questions All
More informationCS375 Midterm Exam Solution Set (Fall 2017)
CS375 Midterm Exam Solution Set (Fall 2017) Closed book & closed notes October 17, 2017 Name sample 1. (10 points) (a) Put in the following blank the number of strings of length 5 over A={a, b, c} that
More informationFooling Sets and. Lecture 5
Fooling Sets and Introduction to Nondeterministic Finite Automata Lecture 5 Proving that a language is not regular Given a language, we saw how to prove it is regular (union, intersection, concatenation,
More informationCS 154. Finite Automata, Nondeterminism, Regular Expressions
CS 54 Finite Automata, Nondeterminism, Regular Expressions Read string left to right The DFA accepts a string if the process ends in a double circle A DFA is a 5-tuple M = (Q, Σ, δ, q, F) Q is the set
More informationEmbedded systems specification and design
Embedded systems specification and design David Kendall David Kendall Embedded systems specification and design 1 / 21 Introduction Finite state machines (FSM) FSMs and Labelled Transition Systems FSMs
More informationTheory of Computation (Classroom Practice Booklet Solutions)
Theory of Computation (Classroom Practice Booklet Solutions) 1. Finite Automata & Regular Sets 01. Ans: (a) & (c) Sol: (a) The reversal of a regular set is regular as the reversal of a regular expression
More informationTheory of computation: initial remarks (Chapter 11)
Theory of computation: initial remarks (Chapter 11) For many purposes, computation is elegantly modeled with simple mathematical objects: Turing machines, finite automata, pushdown automata, and such.
More informationTheory of Languages and Automata
Theory of Languages and Automata Chapter 1- Regular Languages & Finite State Automaton Sharif University of Technology Finite State Automaton We begin with the simplest model of Computation, called finite
More informationWhat Is a Language? Grammars, Languages, and Machines. Strings: the Building Blocks of Languages
Do Homework 2. What Is a Language? Grammars, Languages, and Machines L Language Grammar Accepts Machine Strings: the Building Blocks of Languages An alphabet is a finite set of symbols: English alphabet:
More informationContext Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.
Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer. Language Generator: Context free grammars are language generators,
More informationProperties of Context-Free Languages
Properties of Context-Free Languages Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr
More informationBefore we show how languages can be proven not regular, first, how would we show a language is regular?
CS35 Proving Languages not to be Regular Before we show how languages can be proven not regular, first, how would we show a language is regular? Although regular languages and automata are quite powerful
More informationProofs, Strings, and Finite Automata. CS154 Chris Pollett Feb 5, 2007.
Proofs, Strings, and Finite Automata CS154 Chris Pollett Feb 5, 2007. Outline Proofs and Proof Strategies Strings Finding proofs Example: For every graph G, the sum of the degrees of all the nodes in G
More informationGEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I
GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I Internal Examination 2017-18 B.Tech III Year VI Semester Sub: Theory of Computation (6CS3A) Time: 1 Hour 30 min. Max Marks: 40 Note: Attempt all three
More informationPushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen
Pushdown Automata Notes on Automata and Theory of Computation Chia-Ping Chen Department of Computer Science and Engineering National Sun Yat-Sen University Kaohsiung, Taiwan ROC Pushdown Automata p. 1
More informationContext Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages
Context Free Languages Automata Theory and Formal Grammars: Lecture 6 Context Free Languages Last Time Decision procedures for FAs Minimum-state DFAs Today The Myhill-Nerode Theorem The Pumping Lemma Context-free
More information60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor
60-354, Theory of Computation Fall 2013 Asish Mukhopadhyay School of Computer Science University of Windsor Pushdown Automata (PDA) PDA = ε-nfa + stack Acceptance ε-nfa enters a final state or Stack is
More informationAutomata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) October,
Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu ETH Zürich (D-ITET) October, 5 2017 Part 3 out of 5 Last week, we learned about closure and equivalence of regular
More informationPart 3 out of 5. Automata & languages. A primer on the Theory of Computation. Last week, we learned about closure and equivalence of regular languages
Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu Part 3 out of 5 ETH Zürich (D-ITET) October, 5 2017 Last week, we learned about closure and equivalence of regular
More information