Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017

Similar documents
Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP Recap: Logic, Sets, Relations, Functions

Finite Automata and Regular Languages

Finite Automata and Formal Languages TMV026/DIT321 LP4 2012

Theory of Computation

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Regular Expressions [1] Regular Expressions. Regular expressions can be seen as a system of notations for denoting ɛ-nfa

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,

Sri vidya college of engineering and technology

Finite Automata and Formal Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Nondeterministic Finite Automata

Computational Models #1

Computational Models - Lecture 1 1

Warshall s algorithm

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove

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

What we have done so far

Regular Expressions. Definitions Equivalence to Finite Automata

Fall, 2017 CIS 262. Automata, Computability and Complexity Jean Gallier Solutions of the Practice Final Exam

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

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

3515ICT: Theory of Computation. Regular languages

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

Notes on Pumping Lemma

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Axioms of Kleene Algebra

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

Lecture 3: Nondeterministic Finite Automata

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Computational Models: Class 3

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

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

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

Formal Languages, Automata and Models of Computation

Computational Models - Lecture 3 1

Automata Theory and Formal Grammars: Lecture 1

Finite Automata and Regular languages

CS5371 Theory of Computation. Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)

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

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

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

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

Closure under the Regular Operations

Equivalence of DFAs and NFAs

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

Computational Models - Lecture 4

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

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

CS 455/555: Finite automata

Name: Student ID: Instructions:

Notes on Inductive Sets and Induction

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

Finite Automata and Formal Languages TMV026/DIT321 LP Testing Equivalence of Regular Languages

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

Computational Models - Lecture 5 1

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

Closure under the Regular Operations

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

COMP4141 Theory of Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Computer Sciences Department

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

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

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

FS Properties and FSTs

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Non-deterministic Finite Automata (NFAs)

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

Chapter Five: Nondeterministic Finite Automata

Regular Expressions and Language Properties

Introduction to Theoretical Computer Science. Motivation. Automata = abstract computing devices

Theory of Computation

CS243, Logic and Computation Nondeterministic finite automata

Computational Models - Lecture 3

Intro to Theory of Computation

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

Mathematical Preliminaries. Sipser pages 1-28

CMPSCI 250: Introduction to Computation. Lecture #29: Proving Regular Language Identities David Mix Barrington 6 April 2012

Subset construction. We have defined for a DFA L(A) = {x Σ ˆδ(q 0, x) F } and for A NFA. For any NFA A we can build a DFA A D such that L(A) = L(A D )

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

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

Computational Theory

Regular expressions and Kleene s theorem

CSci 311, Models of Computation Chapter 4 Properties of Regular Languages

1 More finite deterministic automata

Constructions on Finite Automata

ECS120 Fall Discussion Notes. October 25, The midterm is on Thursday, November 2nd during class. (That is next week!)

More on Finite Automata and Regular Languages. (NTU EE) Regular Languages Fall / 41

Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Proving languages to be nonregular

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

Uses of finite automata

Transcription:

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017 Lecture 4 Ana Bove March 24th 2017 Structural induction; Concepts of automata theory. Overview of today s lecture: Recap: Formal Proofs How formal should a proof be? Depends on its purpose...... but should be convincing...... and the validity of each step should be easily understood; One proves the conclusions assuming the validity of the hypotheses! Different kind of proofs (contradiction, contrapositive, counterexample, induction,...) Simple/strong induction allows to prove a property over all Natural numbers; Sometimes we prove several properties that depend on each other (mutual induction); Inductive definitions generate possibly infinite sets with finite elements: Booleans, Natural numbers, lists, trees,... We can recursively defined functions over inductive sets. March 24th 2017, Lecture 4 TMV027/DIT321 1/24

Inductively Defined Sets (Recap) To define a set S by induction we need to specify: Base cases: e 1,..., e m S; Inductive steps: Given s 1,..., s ni S, then c 1 [s 1,..., s n1 ],..., c k [s 1,..., s nk ] S; Closure: There is no other way to construct elements in S. (We will usually omit this part.) March 24th 2017, Lecture 4 TMV027/DIT321 2/24 Proofs by Structural Induction Generalisation of mathematical induction to other inductively defined sets such as lists, trees,... VERY useful in computer science: it allows to prove properties over the (finite) elements in a data type! Given an inductively defined set S, to prove s S. P(s) then: Base cases: We prove that P(e 1 ),..., P(e m ); Inductive steps: Assuming P(s 1 ),..., P(s ni ) (our inductive hypotheses IH), we prove P(c 1 [s 1,..., s n1 ]),..., P(c k [s 1,..., s nk ]); Closure: s S. P(s). (We will usually omit this part.) March 24th 2017, Lecture 4 TMV027/DIT321 3/24

Inductive Sets and Structural Induction Inductive definition of S: e 1 S e m S s 1,..., s n1 S c 1 [s 1,..., s n1 ] S s 1,..., s nk S c k [s 1,..., s nk ] S Inductive principle associated to S: P(e 1 ) base cases inductive steps. P(e m ) s 1,..., s n1 S. IH {}}{ P(s 1 ),, P(s n1 ) P(c 1 [s 1,..., s n1 ]). s 1,..., s nk S. P(s 1 ),, P(s nk ) P(c k [s k1,..., s nk ]) s S. P(s) March 24th 2017, Lecture 4 TMV027/DIT321 4/24 Example: Structural Induction over Lists We can now use recursion to define functions over an inductively defined set and then prove properties of these functions by structural induction. Let us (recursively) define the append and length functions over lists: [] ++ ys = ys len [] = 0 (a : xs) ++ ys = a : (xs ++ ys) len (a : xs) = 1 + len xs Proposition: xs, ys List A. len (xs ++ ys) = len xs + len ys. Proof: By structural induction on xs List A. P(xs) is ys List A. len (xs ++ ys) = len xs + len ys. Base case: We prove P[]. Inductive step: We show xs List A, a A.P(xs) P(a : xs). Closure: xs List A. P(xs). March 24th 2017, Lecture 4 TMV027/DIT321 5/24

Example: Structural Induction over Lists Let us (recursively) define the append and reverse functions over lists: [] ++ ys = ys rev [] = [] (a : xs) ++ ys = a : (xs ++ ys) rev (a : xs) = rev xs ++[a] Assume append is associative and that ys ++ [] = ys. Proposition: xs, ys List A. rev (xs ++ ys) = rev ys ++rev xs. Proof: By structural induction on xs List A. P(xs) is ys List A. rev (xs ++ ys) = rev ys ++rev xs. Base case: We prove P[]. Inductive step: We show xs List A, a A.P(xs) P(a : xs). Closure: xs List A. P(xs). March 24th 2017, Lecture 4 TMV027/DIT321 6/24 Example: Structural Induction over Trees Let us (recursively) define functions counting the number of edges and of nodes of a tree: ne(x) = 0 nn(x) = 1 ne(x, t 1,..., t k ) = k+ nn(x, t 1,..., t k ) = 1+ ne(t 1 ) +... + ne(t k ) nn(t 1 ) +... + nn(t k ) Proposition: t Tree A. nn(t) = 1 + ne(t). Proof: By structural induction on t Tree A. P(t) is nn(t) = 1 + ne(t). Base case: We prove P(x). Inductive step: We show t 1,..., t k Tree A, x A.P(t 1 ),..., P(t k ) P(x, t 1,..., t k ). Closure: t Tree A. P(t). March 24th 2017, Lecture 4 TMV027/DIT321 7/24

Proofs by Induction: Overview of the Steps to Follow 1 State property P to prove by induction. Might be more general than the actual statement we need to prove! 2 Determine and state the method to use in the proof!!!! Example: Mathematical induction on the length of the list, course-of-values induction on the height of a tree, structural induction over a certain element,... 3 Identify and state base case(s). Could be more than one! Not always trivial to determine. 4 Prove base case(s). 5 Identify and state IH! Will depend on the method to be used (see point 2). 6 Prove inductive step(s). 7 (State closure.) 8 Deduce your statement from P (if needed). March 24th 2017, Lecture 4 TMV027/DIT321 8/24 Central Concepts of Automata Theory: Alphabets Definition: An alphabet is a finite, non-empty set of symbols, usually denoted by Σ. The number of symbols in Σ is denoted as Σ. Notation: We will use a, b, c,... to denote symbols. Note: Alphabets will represent the observable events of the automata. Example: Some alphabets: on/off-switch: Σ = {Push}; complex vending machine: Σ = {5 kr, 10 kr, tea, coffee}; parity counter: Σ = {p 0, p 1 }. March 24th 2017, Lecture 4 TMV027/DIT321 9/24

Strings or Words Definition: Strings/Words are finite sequence of symbols from some alphabet. Notation: We will use w, x, y, z,... to denote words. Note: Words will represent the behaviour of an automaton. Example: Some behaviours: on/off-switch: Push Push Push Push; comlex vending machine: 5 kr 5 kr coffee 10 kr coffee 5 kr tea; parity counter: p 0 p 1 or p 0 p 0 p 0 p 1 p 1 p 0. Note: Some words do NOT represent behaviour though... Example: complex vending machine: tea 5 kr coffee. March 24th 2017, Lecture 4 TMV027/DIT321 10/24 Inductive Definition of Σ Definition: Σ is the set of all words for a given alphabet Σ. This can be described inductively in at least 2 different ways: 1 Base case: ɛ Σ ; Inductive step: if a Σ and x Σ then ax Σ. (We will usually work with this definition.) 2 Base case: ɛ Σ ; Inductive step: if a Σ and x Σ then xa Σ. Note: Recall the definition of lists! Notation: We will often write just a instead of aɛ. We can (recursively) define functions over Σ and (inductively) prove properties about those functions. March 24th 2017, Lecture 4 TMV027/DIT321 11/24

Concatenation Definition: Given the strings x and y, the concatenation xy is defined as: ɛy = y (ax )y = a(x y) Note: Recall ++ on lists. Example: Observe that in general xy yx. If x = 010 and y = 11 then xy = 01011 and yx = 11010. Lemma: If Σ has more than one symbol then concatenation is not commutative. March 24th 2017, Lecture 4 TMV027/DIT321 12/24 Prefix and Suffix Definition: Given x and y words over a certain alphabet Σ: x is a prefix of y iff there exists z such that y = xz; x is a suffix of y iff there exists z such that y = zx. Note: x. ɛ is both a prefix and a suffix of x. Note: x. x is both a prefix and a suffix of x. March 24th 2017, Lecture 4 TMV027/DIT321 13/24

Length and Reverse Definition: The length function : Σ N is defined as: ɛ = 0 ax = 1 + x Example: 01010 = 5. Definition: The reverse function rev( ) : Σ Σ as: rev(ɛ) = ɛ rev(ax) = rev(x)a Intuitively, rev(a 1... a n ) = a n... a 1. Note: Recall len and rev on lists. March 24th 2017, Lecture 4 TMV027/DIT321 14/24 Power Of a string: We define x n as follows: Example: (010) 3 = 010010010. x 0 = ɛ x n+1 = xx n Of an alphabet: We define Σ n, the set of words over Σ with length n, as follows: Σ 0 = {ɛ} Σ n+1 = {ax a Σ, x Σ n } Example: {0, 1} 3 = {000, 001, 010, 011, 100, 101, 110, 111}. Notation: Σ = Σ 0 Σ 1 Σ 2... and Σ + = Σ 1 Σ 2 Σ 3... March 24th 2017, Lecture 4 TMV027/DIT321 15/24

Some Properties The following properties can be proved by induction: Lemma: Concatenation is associative: x, y, z. x(yz) = (xy)z. We shall simply write xyz. Lemma: x, y. xy = x + y. See proof on slide 5. Lemma: x. xɛ = ɛx = x. Lemma: n. x. x n = n x. Lemma: n. Σ. Σ n = Σ n. Lemma: x, y. rev(xy) = rev(y)rev(x). Lemma: x.rev(rev(x)) = x. March 24th 2017, Lecture 4 TMV027/DIT321 16/24 Languages Definition: Given an alphabet Σ, a language L is a subset of Σ, that is, L Σ. Note: If L Σ and Σ then L. Note: A language can be either finite or infinite. Example: Some languages: Swedish, English, Spanish, French,... ; Any programming language;, {ɛ} and Σ are languages over any Σ; The set of prime Natural numbers {1, 3, 5, 7, 11,...}. March 24th 2017, Lecture 4 TMV027/DIT321 17/24

Some Operations on Languages Definition: Given L, L 1 and L 2 languages, we define the following languages: Union, Intersection,... : As for any set. Concatenation: L 1 L 2 = {x 1 x 2 x 1 L 1, x 2 L 2 }. Closure: L = n N Ln where L 0 = {ɛ}, L n+1 = L n L. Note: = {ɛ} and L = L 0 L 1 L 2... = {ɛ} {x 1... x n n > 0, x i L} Notation: L + = L 1 L 2 L 3... Example: Let L = {aa, b}, then L 0 = {ɛ}, L 1 = L, L 2 = LL = {aaaa, aab, baa, bb}, L 3 = L 2 L,... L = {ɛ, aa, b, aaaa, aab, baa, bb,...}. March 24th 2017, Lecture 4 TMV027/DIT321 18/24 How to Prove the Equality of Languages? Given the languages M and N, how can we prove that M = N? A few possibilities: Languages are sets so we prove that M N and N M; Transitivity of equality: M = L 1 =... = L m = N ; We can reason about the elements in the language: Example: {a(ba) n n 0} = {(ab) n a n 0} can be proved by induction on n. March 24th 2017, Lecture 4 TMV027/DIT321 19/24

Algebraic Laws for Languages All laws presented in slide 14 lecture 2 are valid. In addition, we have all these laws on concatenation: Associativity: Concatenation is not commutative: L(MN ) = (LM)N LM ML Distributivity: L(M N ) = LM LN (M N )L = ML N L Identity: Annihilator: Other Rules: L{ɛ} = {ɛ}l = L L = L = = {ɛ} = {ɛ} L + = LL = L L (L ) = L March 24th 2017, Lecture 4 TMV027/DIT321 20/24 Algebraic Laws for Languages (Cont.) Note: While L(M N ) LM LN and (M N )L ML N L both hold, in general LM LN L(M N ) and ML N L (M N )L don t. Example: Consider the case where L = {ɛ, a}, M = {a}, N = {aa} Then LM LN = {aa} but L(M N ) = L =. March 24th 2017, Lecture 4 TMV027/DIT321 21/24

Functions between Languages Definition: A function f : Σ between 2 languages should satisfy f (ɛ) = ɛ f (xy) = f (x)f (y) Intuitively, f (a 1... a n ) = f (a 1 )... f (a n ). Note: f (a) if a Σ. March 24th 2017, Lecture 4 TMV027/DIT321 22/24 Overview of next Week Mon 27 Tue 28 Wed 29 Thu 30 Fri 31 Lec 13-15 HB3 DFA. Ex 10-12 EA Proofs, induction. Ex 15-17 EC Proofs, induction. 15-17 EL41 Consultation 10-12 6213 6215 Individual help. Lec 13-15 HB3 NFA. Subset construction. Assignment 1: Formal proofs. Deadline: Sunday April 2nd 23:59. March 24th 2017, Lecture 4 TMV027/DIT321 23/24

Overview of Next Lecture Sections 2 2.2: DFA: deterministic finite automata. March 24th 2017, Lecture 4 TMV027/DIT321 24/24