CS3102 Theory of Computation

Total Page:16

File Type:pdf, Size:1020Kb

CS3102 Theory of Computation CS3102 Theory of Computation Warm up: What’s the language of this NFA? 0, 휀 start final 1 Logistics 2 Last Time • Non-determinism 3 Showing Regex ≤ FSA • Show how to convert any regex into a FSA for the same language • Idea: show how to build each “piece” of a regex using FSA 4 Proof “Storyboard” FSA = Regex Computability by How to build FSA closed under 휀, literal, union, a Regex concat, * Makes that easy Non- determinism 5 “Pieces” of a Regex • Empty String: – Matches just the string of length 0 – Notation: 휀 or “” • Literal Character – Matches a specific string of length 1 – Example: the regex 푎 will match just the string 푎 • Alternation/Union – Matches strings that match at least one of the two parts – Example: the regex 푎|푏 will match 푎 and 푏 • Concatenation – Matches strings that can be dividing into 2 parts to match the things concatenated – Example: the regex 푎 푏 푐 will match the strings 푎푐 and 푏푐 • Kleene Star – Matches strings that are 0 or more copies of the thing starred ∗ – Example: 푎 푏 푐 will match 푎, 푏, or either followed by any number of 푐’s 6 Non-determinism • Things could get easier if we “relax” our automata • So far: – Must have exactly one transition per character per state – Can only be in one state at a time • Non-deterministic Finite Automata: – Allowed to be in multiple (or zero) states! – Can have multiple or zero transitions for a character – Can take transitions without using a character – Models parallel computing 7 Nondeterminism Driving to a friend’s house Friend forgets to mention a fork in the directions Which way do you go? Why not both? ? 8 Example Non-deterministic Finite Automaton • 푆푒푐표푛푑퐿푎푠푡1 = ∗ 푤 ∈ 0,1 the second from last character is a 1} 0,1 1 0,1 start 표푛푒 푛푒푥푡 9 Non-Deterministic Finite State Automaton • Implementation: – Finite number of states – One start state – “Final” states – Transitions: (partial) function mapping state-character (or epsilon) pairs to sets of states • Execution: – Start in the initial “state” – Enter every state reachable without consuming input (휺-transitions) – Read each character once, in order (no looking back) – Transition to new states once per character (based on current states and character) – Enter every state reachable without consuming input (휺-transitions) – Return True if any state you end is final • Return False if every state you end in is non-final 10 NFA = DFA • DFA ≤ NFA: – Can we convert any DFA into an NFA? • NFA ≤ DFA: – Can we convert any NFA into a DFA? – Strategy: NFAs can be in any subset of states, make a DFA where each state represents a set of states 11 Powerset Construction 0,1 1 0,1 start one next start one next Start, {} One, next Start, Start, One, one next next 12 Powerset Construction 0,1 1 0,1 start one next 0 start one next 1 Start, {} One, 0 next 1 1 Start, Start, One, one next next 0 0 1 13 Powerset Construction (symbolic) • NFA 푀 = (푄, Σ, 훿, 푞0, 퐹) • As a DFA: 푄 – 푀퐷 = (2 , Σ, 훿퐷, 푞퐷, 퐹퐷) • 푞퐷 = 푞0 ∪ 훿(푞0, 휀) – start state and everything reachable using empty transitions 푄 • 퐹퐷 = 푠 ∈ 2 ∃푞 ∈ 푠 . 푞 ∈ 퐹} – All states with a start state in them • 훿퐷 푠, 휎 = 푞∈푠 훿 푠, 휎 – Transition to the stateset of everything any current state transitions to 14 Union Using Non-Determinism Some 0s 0,1 Goal: Return 1 if either machine 0 returns 1 new Strategy: Run both machines in start 0 parallel (non-deterministically) by transitioning to the start states 1 for both without using input No 0s 1 1 0 Even Odd 0 15 1 Union Using Non-Determinism 푀1 Some 0s 0,1 0 e 휀 e new 푀2 start 0 휀 푀∪ = 푄1 ∪ 푄2 ∪ 푛푒푤 , Σ, 훿∪, 푛푒푤, 퐹1 ∪ 퐹2 1 훿1 푞, 휎 if 푞 ∈ 푄1 No 0s 1 훿∪(푞, 휎) = {훿2 푞, 휎 } if 푞 ∈ 푄2 1 훿∪ 푛푒푤, 휀 = {푠푡푎푟푡, 푒푣푒푛} 0 Even Odd 0 16 1 Language Concatenation ∗ • 퐿1퐿2 = {푤 ∈ Σ |∃푥 ∈ 퐿1, ∃푦 ∈ 퐿2. 푥푦 = 푤} • The set of all strings I can create by concatenating a string from 퐿1 with a string from 퐿2 (in that order) • 휀, 0, 10 ⋅ 0,00 = {0, 00, 000, 100, 1000} 17 Concatenation using NFA 푀2 푀1 e e Goal: Return 1 if the input Some 0s 0,1 can be broken into 2 0 chunks, 푀1 returns 1 on the 1 first chunk, 푀2 on the 0 second start 0 Even Odd 0 Strategy: Every time we enter a final state in 푀1, 1 1 non-deterministically run No 0s 1 the rest of the string on 푀2. Return 1 if 푀2 does. 18 Concatenation using NFA 푀2 푀1 e e 푀푐 = 푄1 ∪ 푄2, Σ, 훿푐, 푞01, 퐹2 훿1 푞, 휎 if 푞 ∈ 푄1 − 퐹1 Some 0s 0,1 훿 (푞, 휎) = 훿 푞, 휎 , 푞 if 푞 ∈ 퐹 0 푐 1 0,2 1 1 {훿2 푞, 휎 } if 푞 ∈ 푄2 0 start 휀 Even Odd 0 0 1 휀 1 No 0s 1 19 Kleene Star • 퐿∗ = 퐿0 ∪ 퐿1 ∪ 퐿2 ∪ ⋯ • 퐿0 = {휀} • 퐿푘 = (퐿 concatenated 푘 times) • 00, 11 ∗ = {휀, 00, 11, 0011, 1100, 0000, 1111, 110011, … } 20 e Kleene Star using NFA 푀1 e e Goal: Return 1 if the input can Some 0s 0,1 be broken into chunks such that 0 푀1 returns 1 for every chunk Strategy: Every time we enter a start 0 final state in 푀1, non- deterministically “restart” the 1 machine to run on the rest of 1 No 0s the string, make sure we return 1 on 휀 21 e Kleene Star using NFA 푀1 e e Goal: Return 1 if the input can Some 0s 0,1 be broken into chunks such that 0 푀1 returns 1 for every chunk 휀 start 0 Strategy: Every time we enter a 휀 final state in 푀1, non- deterministically “restart” the 휀 1 machine to run on the rest of 1 No 0s the string, make sure we return empty 1 on 휀 22 Conclusion • Any language expressible as a regular expression is computable by a NFA • Any language computable by a NFA is computable by a DFA • NFA = Regex = DFA • Call any such language a “regular language” 23 Characterizing What’s computable • Things that are computable by FSA: – Functions that don’t need “memory” – Languages expressible as Regular Expressions • Things that aren’t computable by FSA: – Things that require more than finitely many states – Intuitive example: Majority 24 Majority with FSA? • Consider an inputs with lots of 0s 000...0000 111...1111 000...0000 111...1111 000...0000 111...1111 ×49,999 ×50,000 ×50,000 ×50,000 ×50,000 ×50,001 • Recall: we read 1 bit at a time, no going back! • To count to 50,000, we'll need 50,000 states! 25 .
Recommended publications
  • Theory of Computation
    Theory of Computation Alexandre Duret-Lutz [email protected] September 10, 2010 ADL Theory of Computation 1 / 121 References Introduction to the Theory of Computation (Michael Sipser, 2005). Lecture notes from Pierre Wolper's course at http://www.montefiore.ulg.ac.be/~pw/cours/calc.html (The page is in French, but the lecture notes labelled chapitre 1 to chapitre 8 are in English). Elements of Automata Theory (Jacques Sakarovitch, 2009). Compilers: Principles, Techniques, and Tools (A. Aho, R. Sethi, J. Ullman, 2006). ADL Theory of Computation 2 / 121 Introduction What would be your reaction if someone came at you to explain he has invented a perpetual motion machine (i.e. a device that can sustain continuous motion without losing energy or matter)? You would probably laugh. Without looking at the machine, you know outright that such the device cannot sustain perpetual motion. Indeed the laws of thermodynamics demonstrate that perpetual motion devices cannot be created. We know beforehand, from scientic knowledge, that building such a machine is impossible. The ultimate goal of this course is to develop similar knowledge for computer programs. ADL Theory of Computation 3 / 121 Theory of Computation Theory of computation studies whether and how eciently problems can be solved using a program on a model of computation (abstractions of a computer). Computability theory deals with the whether, i.e., is a problem solvable for a given model. For instance a strong result we will learn is that the halting problem is not solvable by a Turing machine. Complexity theory deals with the how eciently.
    [Show full text]
  • Automata Theory 4Th
    AUTOMATA THEORY Digital Notes By BIGHNARAJ NAIK Assistant Professor Department of Master in Computer Application VSSUT, Burla Syllabus 4th SEMESTER MCA F.M : 70 MCA 207 AUTOMATA THEORY (3-1-0)Cr.-4 Module – I Introduction to Automata : The Methods Introduction to Finite Automata, Structural Representations, Automata and Complexity. Proving Equivalences about Sets, The Contrapositive, Proof by Contradiction, Inductive Proofs : General Concepts of Automata Theory: Alphabets Strings, Languages, Applications of Automata Theory. Module – II Finite Automata : The Ground Rules, The Protocol, Deterministic Finite Automata: Definition of a Deterministic Finite Automata, How a DFA Processes Strings, Simpler Notations for DFA’s, Extending the Transition Function to Strings, The Language of a DFA Nondeterministic Finite Automata : An Informal View. The Extended Transition Function, The Languages of an NFA, Equivalence of Deterministic and Nondeterministic Finite Automata. Finite Automata With Epsilon-Transitions: Uses of ∈-Transitions, The Formal Notation for an ∈-NFA, Epsilon-Closures, Extended Transitions and Languages for ∈-NFA’s, Eliminating ∈- Transitions. Module – III Regular Expressions and Languages : Regular Expressions: The Operators of regular Expressions, Building Regular Expressions, Precedence of Regular-Expression Operators, Precedence of Regular-Expression Operators Finite Automata and Regular Expressions: From DFA’s to Regular Expressions, Converting DFA’s to Regular Expressions, Converting DFA’s to Regular Expressions by Eliminating
    [Show full text]
  • The Verification of Conversion Algorithms Between Finite Automata
    SCIENCE CHINA Information Sciences . Supplementary File . The Verification of Conversion Algorithms between Finite Automata Dongchen JIANG1* & Wei LI2 1School of Information Science & Technology, Beijing Forestry University, Beijing 100083, China; 2State Key Laboratory of Software Development Environment, Beihang University, Beijing 100191, China Automata theory is fundamental to computer science, and it has broad applications in lexical analysis, compiler imple- mentation, software design and program verification [8,9]. As an indispensable part of automata theory, the conversion algorithms between finite automata are frequently used to construct decision procedures for language recognition. In recent years, there is a tendency to formalize and verify the correctness of various conversion algorithms using interactive theorem provers. One of the motivations is to obtain verified decision procedures for language recognitions. In 1964, Brzozowski firstly introduced the notion of derivatives and proposed an algorithm to convert a regular expression into a deterministic finite automaton [3]. Then there come many researches on this subject. In practice, the classical approach normally contains four steps: firstly, to obtain a non-deterministic finite automaton with epsilon-transitions ("- NFA) from the regular expression; secondly, to remove the epsilon-transitions and get a non-deterministic automaton (NFA); thirdly, to convert the NFA into a DFA; and finally to minimize the DFA. The formalization of finite automata was first accomplished by Jean-Christophe Filli^atreusing Coq [6]. A constructive proof of the equivalence between regular expressions and "-NFA was also proposed. In 2010, Braibaut and Pous first verified the complete procedure of converting the regular expressions into automata [2]. With the help of matrix, their implementation is efficient.
    [Show full text]
  • Theoretical Computer Science Real-Time Reversible Iterative Arrays
    Theoretical Computer Science 411 (2010) 812–822 Contents lists available at ScienceDirect Theoretical Computer Science journal homepage: www.elsevier.com/locate/tcs Real-time reversible iterative arrays Martin Kutrib ∗, Andreas Malcher Institut für Informatik, Universität Giessen, Arndtstr. 2, 35392 Giessen, Germany article info a b s t r a c t Keywords: Iterative arrays are one-dimensional arrays of interconnected interacting finite automata. Iterative arrays The cell at the origin is equipped with a one-way read-only input tape. We investigate Real-time reversibility iterative arrays as acceptors for formal languages. In particular, we consider real-time Language recognition Decidability devices which are reversible on the core of computation, i.e., from initial configuration Closure properties to the configuration given by the time complexity. This property is called real-time reversibility. It is shown that real-time reversible iterative arrays can simulate restricted variants of stacks and queues. It turns out that real-time reversible iterative arrays are strictly weaker than real-time reversible cellular automata. On the other hand, a non- semilinear language is accepted. We show that real-time reversibility itself is not even semidecidable, which extends the undecidability for cellular automata and contrasts with the general case, where reversibility is decidable for one-dimensional devices. Moreover, we prove the non-semidecidability of several other properties. Several closure properties are also derived. ' 2009 Elsevier B.V. All rights reserved. 1. Introduction Reversibility in the context of computing devices means that deterministic computations are also backward deterministic. Roughly speaking, in a reversible device no information is lost and every configuration occurring in any computation has at most one predecessor.
    [Show full text]
  • SDSU Template, Version 11.1
    FORMAL LANGUAGES – EDUCATIONAL DATABASE _______________ A Thesis Presented to the Faculty of San Diego State University _______________ In Partial Fulfillment of the Requirements for the Degree Master of Science in Computer Science _______________ by Deepika Devaraje Urs Fall 2015 iii Copyright © 2015 by Deepika Devaraje Urs All Rights Reserved iv ABSTRACT OF THE THESIS Formal Languages – Educational Database by Deepika Devaraje Urs Master of Science in Computer Science San Diego State University, 2015 This thesis focuses on developing an application which can be used to generate finite automata from a given grammar. The main purpose of this application is to assist the learning experience for the classes CS562(Finite Automata) CS620(Formal Languages) offered at San Diego State University. The system is using web-based technologies to generate automata. The reason for a web based system is that once deployed on a server, the system can be accessed anywhere on web and can be used to generate automata in any environment irrespective of the platform used on a machine. A well defined grammar has to be provided to the system which consists of – A definite set of alphabets (V and T) Production rules to generate the language Grammar(G) is represented as G = (V, T, P, S) where, V = finite set of letters called Variables T = finite set of letters called Terminal Symbols S = start variables, belongs to set V P = finite set of productions The system then uses those alphabets and the production rules to generate words of the language and then will use code to generate the finite automaton graph.
    [Show full text]
  • Introduction to Formal Languages and Automata
    Theory of Computation I: Introduction to Formal Languages and Automata Noah Singer April 8, 2018 1 Formal language theory Definition 1.1 (Formal language). A formal language is any set of strings drawn from an alphabet Σ. We use " to denote the \empty string"; that is, the string that contains precisely no characters. Note: the language containing the empty string, f"g, is not the same as the empty language fg. Definition 1.2 (Language operations). Given formal languages A and B: 1. The concatenation of A and B, denoted A · B or AB, is defined as fab j a 2 A; b 2 Bg, where ab signifies \string a followed by string b". 2. The union of A and B, denoted A [ B, is defined as fc j c 2 A _ c 2 Bg. 3. The language A repeated n times, denoted An, is defined as An = A · A · A ··· A · A | {z } n times if n > 0 or f"g if n = 0. 4. The Kleene star of a language A, denoted A?, is defined as [ A? = Ai = f"g [ A [ A · A [ A · A · A [··· i2N . Exercise .1: Language operations 1. Let A = fa; bg and B = fc; d; eg. Compute the following: (a) A · B (d) A [ B [; (g) B?A3 (b) A ·; (e)( BA) [ A3 (h) BA?B (c) A · f"g (f) A? (i)( AB)?A 2. Consider the operations [ and · on formal languages. In abstract algebra terms, are they associative and/or commutative? Do they have identities and/or inverses? Definition 1.3 (Formal grammar).
    [Show full text]
  • Foundations of Computing
    An Introduction to the Theory of Computing Dennis Komm Lecture Notes Foundations of Computing II Autumn Term 2020, University of Zurich Version: December 3, 2020 Contact: [email protected] omputers allow us to automate many tasks of everyday life. There is, however, a strict limit as to what kind of work can be automated. The aim of this lecture C is to study these limits. In 1936, Alan Turing showed that there are well-defined problems that cannot be solved by computers (more specifically, by algorithms); this does not address a lack of computational power in the sense of stating that today’s computers are too slow, but as computers get faster, we may hope to solve these problems eventually. The inability to solve these problems will prevail, no matter how the performance of computers will improve. It is noteworthy that the modern computers were not present in Turing’s time. Following his footsteps, we ask “Which problems can be solved automatically and which cannot?” In order to do this, we introduce a formalization of the term “algorithm.” We start with a restricted class, the finite automata, which we then extend by making the underlying model more and more powerful, eventually arriving at the Turing machine model. We then prove the existence of problems that cannot be solved by Turing machines. The proof uses arguments similar to proving that there are more real numbers than natural numbers and to Gödel’s incompleteness theorem. One of the most famous such problems is the halting problem, e.g., to decide for a given Turing machine whether it finishes its work on a given input within finite time or runs forever.
    [Show full text]