Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

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 Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata and Formal Languages TMV026/DIT321 LP4 2012

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata and Regular Languages

Theory of Computation

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,

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

Finite Automata and Formal Languages

Sri vidya college of engineering and technology

Computational Models #1

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

What we have done so far

Computational Models - Lecture 1 1

Nondeterministic Finite Automata

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

Notes on Pumping Lemma

Automata Theory and Formal Grammars: Lecture 1

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

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Axioms of Kleene Algebra

3515ICT: Theory of Computation. Regular languages

Notes on Inductive Sets and Induction

Warshall s algorithm

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

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

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

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

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

Regular Expressions. Definitions Equivalence to Finite Automata

Computational Models: Class 3

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

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

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

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

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

Computational Models - Lecture 3 1

Formal Languages, Automata and Models of Computation

Ogden s Lemma for CFLs

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

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

Computational Models - Lecture 4

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

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,

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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

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

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

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

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

CS 455/555: Finite automata

Equivalence of DFAs and NFAs

Properties of Context-Free Languages. Closure Properties Decision Properties

Lecture 3: Nondeterministic Finite Automata

Mathematical Preliminaries. Sipser pages 1-28

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

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

Computational Models - Lecture 5 1

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

Theory of Computation

Introduction to Automata

CS 154. Finite Automata, Nondeterminism, Regular Expressions

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

Computer Sciences Department

Finite Automata and Regular languages

Closure under the Regular Operations

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

NPDA, CFG equivalence

Theory of Computation

Theory of Computation

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

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Computational Models - Lecture 3

COMP4141 Theory of Computation

Non-deterministic Finite Automata (NFAs)

Theory of computation: initial remarks (Chapter 11)

Name: Student ID: Instructions:

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

MA/CSSE 474 Theory of Computation. Your Questions? Previous class days' material Reading Assignments

Context-Free Languages (Pre Lecture)

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

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

We define the multi-step transition function T : S Σ S as follows. 1. For any s S, T (s,λ) = s. 2. For any s S, x Σ and a Σ,

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols

FS Properties and FSTs

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

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

Chapter 3. Regular grammars

CS Pushdown Automata

The 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.

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

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

CS 133 : Automata Theory and Computability

Computational Models: Class 1

Transcription:

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 4 Ana Bove March 23rd 2018 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 23rd 2018, Lecture 4 TMV027/DIT321 1/25

Overview of Today s Lecture Structural induction; Concepts of automata theory. Contributes to the following learning outcome: Prove properties of languages, grammars and automata with rigorously formal mathematical methods. March 23rd 2018, Lecture 4 TMV027/DIT321 2/25 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... and s 1,..., s ki S, then c 1 [..., s 1,..., s k1 ],..., c n [..., s 1,..., s kn ] S; Closure: There is no other way to construct elements in S. (We will usually omit this part.) Alternatively, e 1 [...] S e m [...] S s 1,..., s k1 S c 1 [..., s 1,..., s k1 ] S s 1,..., s kn S c n [..., s 1,..., s kn ] S March 23rd 2018, Lecture 4 TMV027/DIT321 3/25

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 ki ) (our inductive hypotheses IH), we prove P(c 1 [..., s 1,..., s k1 ]),..., P(c n [..., s 1,..., s kn ]); Closure: s S. P(s). (We will usually omit this part.) March 23rd 2018, Lecture 4 TMV027/DIT321 4/25 Inductive Sets and Structural Induction Inductive definition of S: e 1 [...] S e m [...] S s 1,..., s k1 S c 1 [..., s 1,..., s k1 ] S s 1,..., s kn S c n [..., s 1,..., s kn ] S Inductive principle associated to S: P(e 1 [...]) base cases inductive steps. P(e m [...])..., s 1,..., s k1 S. IH {}}{ P(s 1 ),, P(s k1 ) P(c 1 [..., s 1,..., s k1 ])...., s 1,..., s kn S. P(s 1 ),, P(s kn ) P(c n [..., s 1,..., s kn ]) s S. P(s) March 23rd 2018, Lecture 4 TMV027/DIT321 5/25

Example: Structural Induction over Lists We can now use recursion to define functions over an inductively defined set and then prove properties about these functions by structural induction. Recall recursive definitions of append and length functions over lists: [] ++ ys = ys len [] = 0 (x : xs) ++ ys = x : (xs ++ ys) len (x : xs) = 1 + len xs Proposition: xs, ys List A. len (xs ++ ys) = len xs ++ len ys. Proof: By structural induction on xs. P(xs) is ys List A. len (xs ++ ys) = len xs ++ len ys. Base case: We prove P[]. Inductive step: We show x A. xs List A. P(xs) P(x : xs). Closure: xs List A. P(xs). March 23rd 2018, Lecture 4 TMV027/DIT321 6/25 Example: Structural Induction over Lists Proposition: xs List A. xs ++ [] = xs. Proof: By structural induction on xs. P(xs) is xs ++ [] = xs. Base case: We prove P[]. Inductive step: We show x A. xs List A. P(xs) P(x : xs). Closure: xs List A. P(xs). Proposition: xs, ys, zs List A. (xs ++ ys) ++ zs = xs ++ (ys ++ zs). Proof: By structural induction on xs. P(xs) is ys, zs List A. (xs ++ ys) ++ zs = xs ++ (ys ++ zs). Base case: We prove P[]. Inductive step: We show x A. xs List A. P(xs) P(x : xs). Closure: xs List A. P(xs). March 23rd 2018, Lecture 4 TMV027/DIT321 7/25

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. P(t) is nn(t) = 1 + ne(t). Base case: We prove P(x). Inductive step: We show x A. t 1,..., t k Tree A. P(t 1 ),..., P(t k ) P(x, t 1,..., t k ). Closure: t Tree A. P(t). March 23rd 2018, Lecture 4 TMV027/DIT321 8/25 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 23rd 2018, Lecture 4 TMV027/DIT321 9/25

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 an automaton. Example: Some alphabets: on/off-switch: Σ = {Push}; parity counter: Σ = {p 0, p 1 }; complex vending machine: Σ = {5 kr, 10 kr, tea, coffee}. March 23rd 2018, Lecture 4 TMV027/DIT321 10/25 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; parity counter: p 0 p 1 or p 0 p 0 p 0 p 1 p 1 p 0 ; comlex vending machine: 5 kr 5 kr coffee 10 kr coffee 5 kr tea. Note: Some words do NOT represent behaviour though... Example: complex vending machine: tea 5 kr coffee. March 23rd 2018, Lecture 4 TMV027/DIT321 11/25

Inductive Definition of Σ Definition: Σ is the set of all words for a given alphabet Σ. This can be described inductively in the following two ways: 1 Base case: ɛ Σ ; Inductive step: if a Σ and x Σ then ax Σ. (We will usually work with this definition.) Note: Recall the definition of lists! 2 Base case: ɛ Σ ; Inductive step: if a Σ and x Σ then xa Σ. Note: We can prove that both definitions define exactly the same set of words. Notation: We will often write just a instead of aɛ. We can (recursively) define functions over Σ and (inductively) prove properties about those functions. March 23rd 2018, Lecture 4 TMV027/DIT321 12/25 Concatenation Definition: Given the words 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 23rd 2018, Lecture 4 TMV027/DIT321 13/25

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 23rd 2018, Lecture 4 TMV027/DIT321 14/25 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 23rd 2018, Lecture 4 TMV027/DIT321 15/25

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 23rd 2018, Lecture 4 TMV027/DIT321 16/25 Some Properties The following properties can be proved by induction: (See some of the proofs on lists in slides 6 7.) Lemma: Concatenation is associative: x, y, z Σ. x(yz) = (xy)z. We shall simply write xyz. Lemma: x, y Σ. xy = x + y. Lemma: x Σ. xɛ = ɛx = x. Lemma: n N. x Σ. x n = n x. Lemma: n N. Σ. Σ n = Σ n. Lemma: x, y Σ. rev(xy) = rev(y)rev(x). Lemma: x Σ. rev(rev(x)) = x. March 23rd 2018, Lecture 4 TMV027/DIT321 17/25

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 23rd 2018, Lecture 4 TMV027/DIT321 18/25 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 23rd 2018, Lecture 4 TMV027/DIT321 19/25

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 23rd 2018, Lecture 4 TMV027/DIT321 20/25 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 23rd 2018, Lecture 4 TMV027/DIT321 21/25

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 23rd 2018, Lecture 4 TMV027/DIT321 22/25 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 23rd 2018, Lecture 4 TMV027/DIT321 23/25

Overview of Next Lecture Sections 2 2.2: DFA: deterministic finite automata. March 23rd 2018, Lecture 4 TMV027/DIT321 24/25 Overview of next Week Mon 26 Tue 27 Wed 28 Thu 29 Fri 30 Ex 10-12 EA Proofs, induction. Lec 13-15 HB3 DFA. Ex 15-17 EA Proofs, induction. 8-10 ES51 Individual help 15-17 EL41 Consultation Assignment 1: Formal proofs. Deadline: Thursday 29th March 23:59. March 23rd 2018, Lecture 4 TMV027/DIT321 25/25