Regular languages, regular expressions, & finite automata (intro) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

Similar documents
How do regular expressions work? CMSC 330: Organization of Programming Languages

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

Deterministic Finite Automaton (DFA)

CS 154, Lecture 3: DFA NFA, Regular Expressions

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

Lecture 3: Nondeterministic Finite Automata

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

Sri vidya college of engineering and technology

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Regular Expressions (Pre Lecture)

TDDD65 Introduction to the Theory of Computation

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

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

CMSC 330: Organization of Programming Languages

CS 455/555: Finite automata

Theory of Computation (II) Yijia Chen Fudan University

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Theory of Computation (I) Yijia Chen Fudan University

Computational Models Lecture 2 1

Nondeterministic Finite Automata and Regular Expressions

Computational Theory

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Computational Models Lecture 2 1

Nondeterminism and Epsilon Transitions

COM364 Automata Theory Lecture Note 2 - Nondeterminism

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

The Pumping Lemma and Closure Properties

Closure under the Regular Operations

Kleene Algebras and Algebraic Path Problems

CS21 Decidability and Tractability

CMSC 330: Organization of Programming Languages

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

CS21 Decidability and Tractability

Theory of computation: initial remarks (Chapter 11)

Non-deterministic Finite Automata (NFAs)

CSE 105 THEORY OF COMPUTATION

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

Fooling Sets and. Lecture 5

CSE 105 THEORY OF COMPUTATION

Foundations of

Nondeterministic Finite Automata

CISC 4090 Theory of Computation

CSC236 Week 10. Larry Zhang

CS 154 Formal Languages and Computability Assignment #2 Solutions

Uses of finite automata

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

front pad rear pad door

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

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

Intro to Theory of Computation

3515ICT: Theory of Computation. Regular languages

CSE 105 Theory of Computation Professor Jeanne Ferrante

Computational Models #1

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

Finite Automata and Languages

Theory of computation: initial remarks (Chapter 11)

Regular Expressions. Definitions Equivalence to Finite Automata

Kleene Algebra and Arden s Theorem. Anshul Kumar Inzemamul Haque

COMP4141 Theory of Computation

Theory of Languages and Automata

Regular Expressions and Language Properties

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

Finite Automata and Regular languages

Decision, Computation and Language

Recap from Last Time

CSE 355 Homework One Sample Solutions

Text Search and Closure Properties

Deterministic Finite Automata (DFAs)

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

Automata: a short introduction

CS 322 D: Formal languages and automata theory

CSC173 Workshop: 13 Sept. Notes

Some useful tasks involving language. Finite-State Machines and Regular Languages. More useful tasks involving language. Regular expressions

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

Johns Hopkins Math Tournament Proof Round: Automata

Finite Automata Part Two

Text Search and Closure Properties

Concatenation. The concatenation of two languages L 1 and L 2

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

Equivalence of Regular Expressions and FSMs

Equivalence of DFAs and NFAs

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

UNIT-III REGULAR LANGUAGES

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

acs-04: Regular Languages Regular Languages Andreas Karwath & Malte Helmert Informatik Theorie II (A) WS2009/10

Formal Languages, Automata and Models of Computation

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

Computational Models - Lecture 1 1

1 Alphabets and Languages

Deterministic Finite Automata (DFAs)

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,

Name: Student ID: Instructions:

CHAPTER 1 Regular Languages. Contents

Harvard CS 121 and CSCI E-207 Lecture 6: Regular Languages and Countability

CSE 105 THEORY OF COMPUTATION

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

Transcription:

Regular languages, regular expressions, & finite automata (intro) CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/ 1

L = {hello, bonjour, konnichiwa, } Σ = {a, b, c,, y, z}!2

Σ = {a, b, c,, y, z} Σ* = {w 0 w k k, i N. w i Σ}!3

Σ = {a, b, c,, y, z} Σ* = {w 0 w k k, i N. w i Σ} Examples: abcabc Σ* ϵ Σ* aaaa Σ*!4

Regular languages!5

Regular expressions: E!6

a Σ. L(a) = {a}!7

The interpretation of regex a is the singleton set containing just the string a. a Σ. L(a) = {a}!8

All characters in the alphabet are regular expressions. a Σ. L(a) = {a}!9

There is also an empty/null language,, ϵ and an empty-string language,. Ø L(Ø) = {} L(ϵ) = {ϵ}!10

Composite forms of regular expressions can be derived, from other composite forms, and terminally, from null, empty, or single-character REs. A minimal and sufficient set of derived forms is: disjunction of REs, composition of REs, and kleene star of REs.!11

Ø E, ϵ E, a Σ a E e E (e) E e 0 E e 1 E e 0 e 1 E e 0 E e 1 E e 0 e 1 E e E e* E!12

e E ::= w Ø ϵ (e) e e 0 1 e + e 0 1 e* w Σ = { } There is one base case defining regexes and four inductive cases. Both and + are commonly used to signify disjunction in regexes.!13

https://docs.python.org/3/reference/grammar.html!14

Interpreting Regexes!15

Precedence: kleene star (*), concatenation (ab), then disjunction (a b). Thus, a bc bcd* is the same as (a) (bc) (bc(d*))!16

L(a) = {a} L(ϵ) = {ϵ} L(Ø) = {} Juxtaposition is language concatenation, disjunction is language union, kleene star is interpreted as kleene closure: L(e 0 e 1 ) = L(e 0 ) L(e 1 ) L(e 0 e 1 ) = L(e 0 ) L(e 1 ) L(e* 0 ) = L(e 0 )*!17

Language concatenation: L L = {s 0 s 1 s 0 L s 1 L } Kleene-closure of a Language: L* = {s 0 s 1 s k k N s i L}!18

Kleene-closure can also be defined as a fixed point! L(e)* = L, where f e (L) = L f e (L) = L L(e) {ϵ}!19

(L*)* = L* This means kleene star is idempotent L(e)* = L, where f e (L) = L f e (L) = L L(e) {ϵ}!20

Try an example: L is the language of odd-length strings of zeros. Give a regex for L. L = {s 1 s 2k+1 k N s i = 0}!21

Try an example: L is the language of odd-length strings of zeros. Give a regex for L. 0(00)*!22

Try an example: L is the language of all strings over alphabet {0,1} where every 1 has an adjacent 1.!23

Try an example: L is the language of all strings over alphabet {0,1} where every 1 has an adjacent 1. (0 111*)* = (0 11 + )* e + is syntactic sugar for ee*!24

Try an example: L is the language of odd decimal integers greater than zero. Give a regex for L.!25

Try an example: L is the language of odd decimal integers greater than zero. Give a regex for L. (1 2 3 4 5 6 7 8 9)(0 1 2 3 4 5 6 7 8 9) * (1 3 5 7 9) 1 3 5 7 9!26

Try an example: L is the language of odd decimal integers greater than zero. Give a regex for L. [1 9][0 9] * (1 3 5 7 9) 1 3 5 7 9 [a-g] is a character class, and is syntactic sugar for (a b c d e f g)!27

Try an example: L is the language of odd decimal integers greater than zero. Give a regex for L. ([1 9][0 9] * )?(1 3 5 7 9) e? is syntactic sugar for (e ϵ)!28

Regexes in Python import re r a a r ab ab r b b r a b a b!29

Regexes in Python import re r a* r b+ a* b + r c? c?!30

Regexes in Python import re r \d r [0-9] (0 1 2 3 4 5 6 7 8 9) (0 1 2 3 4 5 6 7 8 9) r z{2,4} (zz zzz zzzz)!31

Regexes in Python import re >>> m = re.match(r \d, 5 ) >>> m.group(0) 5!32

Regexes in Python import re >>> m = re.match(r \d, ) >>> m == None True!33

Regexes in Python import re >>> m = re.match(r (\d)\d\d, 456 ) >>> m.group(0) 456 >>> m.group(1) 4!34

Regexes in Python import re >>> m = re.match(r (\d)\d\d, 4567 ) >>> m.group(0) 456 >>> m.group(1) 4!35

Regexes in Python import re >>> m = re.match(r (\d)\d\d, 4567 ) >>> m.group(0) 456 >>> m.group(1) 4 >>> m = re.match(r ^(\d)\d\d$, 4567 ) >>> m == None True!36

Finite Automata!37

Every automata has a set of states, one of which must be a designated start state. This state is marked by an incoming arrow, like so. q0!38

There may also be zero or more final states also called accept states. These are shown with an extra circle around them. q0 q1!39

q0 The starting state may also be an accept state.!40

L(Ø) L(ϵ) q0 q0 These are also two of the simplest languages.!41

Edges are labeled with characters from. This DFA is equivalent to the RE: a Σ a q0 q1 it reads the character a, and then accepts it.!42

a q0 q1 b q2 This encodes the language {a, ab}!43

a b a q0 q1 b q2 This encodes the language a + b*!44

Edges not shown implicitly reach a dead state. a b a q0 q1 b q2 b a dead a,b!45

Try an example: L is the language of all strings over {0,1} where there are an even number of 1s.!46

Try an example: L is the language of all strings over {0,1} where there are an even number of 1s. 1 1 q0 q1 0 0!47

Try an example: L is the language of all strings over {0,1,2} where there are an odd number of 1s and no 2s.!48

Try an example: L is the language of all strings over {0,1,2} where there are an odd number of 1s and no 2s. 1 1 q0 q1 0 0!49

Deterministic Finite Automata (DFA) Non-deterministic Finite Automata (NFA)!50

Equivalent models of regular languages Converts to GNFA Converts to RE DFA Minimizes to Converts to NFA Converts to!51