Theoretical Computer Science (Bridging Course) Regular Languages - - PowerPoint PPT Presentation

theoretical computer
SMART_READER_LITE
LIVE PREVIEW

Theoretical Computer Science (Bridging Course) Regular Languages - - PowerPoint PPT Presentation

Theoretical Computer Science (Bridging Course) Regular Languages Gian Diego Tipaldi Topics Covered Regular languages Deterministic finite automata Nondeterministic finite automata Closure Regular expressions Non-regular


slide-1
SLIDE 1

Theoretical Computer Science (Bridging Course)

Gian Diego Tipaldi

Regular Languages

slide-2
SLIDE 2

Topics Covered

  • Regular languages
  • Deterministic finite automata
  • Nondeterministic finite automata
  • Closure
  • Regular expressions
  • Non-regular languages
  • The pumping lemma
slide-3
SLIDE 3

Finite Automata

  • Supermarket door control
slide-4
SLIDE 4

Finite Automata

  • Supermarket door control

Front Pad Rear Pad

slide-5
SLIDE 5

Finite Automata

  • Supermarket door control

Open Closed

Rear Both Neither Rear Both Front Front Neither

slide-6
SLIDE 6

Finite Automata

  • Supermarket door control

Neither Front Rear Both Closed Closed Open Closed Closed Open Closed Open Open Open

slide-7
SLIDE 7

Finite Automata

  • Supermarket door control
  • Probabilistic counterparts exists
  • Markov chains
  • Bayesian networks

Neither Front Rear Both Closed Closed Open Closed Closed Open Closed Open Open Open

slide-8
SLIDE 8

Finite Automata

  • Supermarket door control
  • Probabilistic counterparts exists
  • Markov chains
  • Bayesian networks

Neither Front Rear Both Closed Closed Open Closed Closed Open Closed Open Open Open

slide-9
SLIDE 9

Finite Automata

slide-10
SLIDE 10

Finite Automata

  • States:
  • Alphabet:
  • Transition function: See edges
  • Start state:
  • Final states:
slide-11
SLIDE 11

Finite Automata

Which kind of input is accepted?

  • “aaaabbbbaaaa” ?
  • “000000” ?
  • An empty string?
  • “1000111” ?
slide-12
SLIDE 12

Finite Automata

Which language is accepted?

  • “aaaabbbbaaaa” ?
  • “000000” ?
  • An empty string?
  • “1000111” ?
slide-13
SLIDE 13

Finite Automata

Which language is accepted?

  • “M recognizes A”
  • “A is the language L(M)”
slide-14
SLIDE 14

Finite Automata – Example

  • Which language recognizes M?

q2 q1

1 1

slide-15
SLIDE 15

Finite Automata – Example

  • And in this case?

q2 q1

1 1

slide-16
SLIDE 16

Finite Automata – Example

  • What about this one?
slide-17
SLIDE 17

Finite Automata – Example

slide-18
SLIDE 18

Finite Automata – Example

  • Sums all numerical

symbols that reads, modulo 3.

  • Resets the count,

every time it receives <RESET>.

  • Accepts, if the sum

is a multiple of 3.

slide-19
SLIDE 19

Definition of Computation

slide-20
SLIDE 20

Designing Finite Automata

We want to accept binary strings with an odd number of 1s

slide-21
SLIDE 21

Designing Finite Automata

We want to accept binary strings with an odd number of 1s

  • 1. Design states

q2 q1

slide-22
SLIDE 22

Designing Finite Automata

We want to accept binary strings with an odd number of 1s

  • 1. Design states
  • 2. Design transitions

q2 q1

1 1

slide-23
SLIDE 23

Designing Finite Automata

We want to accept binary strings with an odd number of 1s

  • 1. Design states
  • 2. Design transitions
  • 3. Design start state and accept states

q2 q1

1 1

slide-24
SLIDE 24

Designing Finite Automata

We want to accept binary strings containing 001 as substring

slide-25
SLIDE 25

Designing Finite Automata

We want to accept binary strings containing 001 as substring

  • 1. No symbols of the string

q

1

slide-26
SLIDE 26

Designing Finite Automata

We want to accept binary strings containing 001 as substring

  • 1. No symbols of the string
  • 2. We have a 0

q0 q

1 1

slide-27
SLIDE 27

Designing Finite Automata

We want to accept binary strings containing 001 as substring

  • 1. No symbols of the string
  • 2. We have a 0
  • 3. We have a 00

q0 q

1 1

q00

1

slide-28
SLIDE 28

Designing Finite Automata

We want to accept binary strings containing 001 as substring

  • 1. No symbols of the string
  • 2. We have a 0
  • 3. We have a 00
  • 4. We have a 001

q0 q

1 1

q00

0,1 1

q001

slide-29
SLIDE 29

Regular Operations

Let A and B be languages, we have:

  • Union:
  • Concatenation:
  • Star:
  • Example
slide-30
SLIDE 30

Closure of Regular Languages

slide-31
SLIDE 31

Proof by Construction

slide-32
SLIDE 32

Proof by Construction

slide-33
SLIDE 33

Example

  • L(M1) = {w|w contains a 1}
  • L(M2) = {w|w contains at least two 0s}

q1 q2 0,1 1 p2 p1 p3 1 0,1 1

slide-34
SLIDE 34

Example

  • L(M1) = {w|w contains a 1}
  • L(M2) = {w|w contains at least two 0s}

q1 q2 0,1 1 p2 p1 p3 1 0,1 1

q1 p1 q1 p2 q1 p3 q2 p1 q2 p2 q2 p3

slide-35
SLIDE 35

Example

  • L(M1) = {w|w contains a 1}
  • L(M2) = {w|w contains at least two 0s}

q1 q2 0,1 1 p2 p1 p3 1 0,1 1

q1 p1 q1 p2 q1 p3 q2 p1 q2 p2 q2 p3

1 1 1 0,1 1 1

slide-36
SLIDE 36

Example

  • L(M1) = {w|w contains a 1}
  • L(M2) = {w|w contains at least two 0s}

q1 q2 0,1 1 p2 p1 p3 1 0,1 1

q1 p1 q1 p2 q1 p3 q2 p1 q2 p2

1 1 1 0,1 1 1

q2 p3

slide-37
SLIDE 37

Closure of Regular Languages

slide-38
SLIDE 38

Closure of Regular Languages

  • Non deterministic

finite automata

slide-39
SLIDE 39

Nondeterministic Automata

  • Deterministic (DFA)
  • One successor state
  • 𝜁 transitions not allowed
  • Nondeterministic (NFA)
  • Several successor states possible
  • 𝜁 transitions possible

q2 q1 q3 q4

0,1 0,1 1 0,ε 1

slide-40
SLIDE 40

Nondeterministic Computation

slide-41
SLIDE 41

Example Run

q1 q1 q3 q2 q1 q3 q1 q2 q1 q3 q4 q4 q4 q2 q1 q3 q3 q1 q4 q4

1 1 1

q2 q1 q3 q4

0,1 0,1 1 0,ε 1

Input: w = 010110

NFA 𝑂1

slide-42
SLIDE 42

Which language is accepted?

slide-43
SLIDE 43

Nondeterministic Automata

slide-44
SLIDE 44

Nondeterministic Automata

slide-45
SLIDE 45

Definition of computation

slide-46
SLIDE 46

A NFA has an equivalent DFA

NFA recognizing language 𝐵 DFA recognizing language 𝐵

slide-47
SLIDE 47

Equivalence NFA and DFA

Theorem 1.39: Every nondeterministic finite automaton has an equivalent deterministic finite automaton. Corollary 1.40: A language is regular if and only if some nondeterministic finite automaton recognizes it.

slide-48
SLIDE 48

Proof: Theorem 1.39

slide-49
SLIDE 49

Proof: Theorem 1.39

slide-50
SLIDE 50

Proof: Theorem 1.39

slide-51
SLIDE 51

Proof: Theorem 1.39 (ctd.)

slide-52
SLIDE 52

Example

  • Consider the following NFA
  • What is the corresponding DFA?
slide-53
SLIDE 53

Example

  • Resulting DFA for the example before
slide-54
SLIDE 54

Example

  • Simplified DFA for the example before
slide-55
SLIDE 55

Closure of Regular Operations

slide-56
SLIDE 56

Closure of Regular Operations

  • Regular languages are closed under

the union operation

slide-57
SLIDE 57

Proof

slide-58
SLIDE 58

Closure of Regular Operations

  • Regular languages are closed under

the concatenation operation

slide-59
SLIDE 59

Proof

slide-60
SLIDE 60

Closure of Regular Operations

  • Regular languages are closed under

the star operation

slide-61
SLIDE 61

Proof

slide-62
SLIDE 62

Regular Expressions

slide-63
SLIDE 63

Regular Expressions – Examples

slide-64
SLIDE 64

Regular Expressions – Examples

slide-65
SLIDE 65

Applications of Regular Expressions

  • Design of compilers
  • Search for strings (awk, grep, …)
  • Programming languages
  • Bioinformatics (repetitive patterns)
slide-66
SLIDE 66

Equivalence of RE and NFA

Theorem 1.54 (page 66): A language is regular if and only if some regular expression describes it.

slide-67
SLIDE 67

Equivalence of RE and NFA

Theorem 1.54 (page 66): A language is regular if and only if some regular expression describes it. Two directions to consider RE <-> NFA

slide-68
SLIDE 68

Equivalence of RE and NFA

Lemma 1.55 (page 67): If a language is described by some regular expression, then it is regular. Lemma 1.60 (page 69): If a language is regular, then it can be described by some regular expression.

slide-69
SLIDE 69

Proof RE -> NFA

slide-70
SLIDE 70

Proof RE -> NFA: Case 1

  • a
slide-71
SLIDE 71

Proof RE -> NFA: Cases 2 & 3

slide-72
SLIDE 72

Proof RE -> NFA: Case 4, 5 & 6

slide-73
SLIDE 73

Example

Let consider the expression (ab U a)*

  • Convert the expression into a NFA
  • Start from the smallest subexpression
  • Include the other subexpressions
  • Note: The states might be redundant!
slide-74
SLIDE 74

Example: (ab U a)*

  • a
  • b
  • ab
  • ab U a
  • (ab U a)*

a b a b ε a b ε a ε ε a b ε a ε ε ε ε ε

slide-75
SLIDE 75

Exercise: (ab U a)*

  • Let’s do it together!
slide-76
SLIDE 76

Exercise: (a U b)*aba

a b ε ε ε a b ε a ε a b ε a ε ε ε ε

slide-77
SLIDE 77

Proof NFA -> RE

Lemma 1.60 (page 69): If a language is regular, then it can be described by a regular expression. Two steps:

  • Convert DFA into GNFA
  • Convert GNFA into regular expression
slide-78
SLIDE 78

Generalized NFA

  • Labels are regular expressions
  • States connected in both directions
  • Start state only exit transitions
  • Accept state only incoming transitions
  • Only one accept state
slide-79
SLIDE 79

Generalized NFA

qstart qaccept b ab Ø b* ab* ab∪ba a* (aa)* aa

slide-80
SLIDE 80

Generalized NFA

slide-81
SLIDE 81

Generalized NFA

slide-82
SLIDE 82

Proof DFA -> GNFA

  • Add a new start state
  • Connect it with 𝜁 transitions
  • Add a new accept state
  • Connect it with 𝜁 transitions
  • Replace multiple labels with unions
  • Add transitions with ∅ when not present

in the original DFA

slide-83
SLIDE 83

Proof DFA -> GNFA

  • DFA
  • GNFA
slide-84
SLIDE 84

Convert GNFA into RE

3 state DFA 5 state GNFA 4 state GNFA 2 state GNFA 3 state GNFA Regular Expression

slide-85
SLIDE 85

Convert GNFA into RE

slide-86
SLIDE 86

Ripping of States

Replace one state with the corresponding regular expression

q2 q1 q2 qrip q1 R4 R1 R2 R3 (R1)(R2)* (R3) ∪ R4

slide-87
SLIDE 87

Example: From DFA to GNFA

slide-88
SLIDE 88

Example: Rip State 2

slide-89
SLIDE 89

Example: Rip State 1

slide-90
SLIDE 90

Another Example

1 2

a a

3

b b a b

s 1 2

a a

3

b b a b

ε

a

ε ε

s 2 3 a

ε ε

a aa ∪b ab b ba ∪a bb

Rip 1: Rip 2: GNFA: DFA: s 3 a

a(aa ∪b)* a(aa ∪b)*ab ∪b (ba ∪a) (aa ∪b)* ∪ε (ba ∪a) (aa ∪b)*ab ∪ bb

s a Rip 3:

(a(aa ∪b)*ab ∪b)((ba ∪a) (aa ∪b)*ab ∪ bb)*((ba ∪a) (aa ∪b)* ∪ε) ∪a(aa ∪b)*

slide-91
SLIDE 91

Equivalence Proof

slide-92
SLIDE 92

Equivalence Proof

slide-93
SLIDE 93

Equivalence Proof

  • q2

q1 q2 qrip q1 R4 R1 R2 R3 (R1)(R2)* (R3) ∪ R4

slide-94
SLIDE 94

Nonregular Languages

  • Finite automata have finite memory
  • Are the following language regular?
  • How can we prove it mathematically?

{0 1 | 0} { | h as an eq u al n u m b er o f 0 s an d 1 s} { | h as an eq u al n u m b er o f o ccu ren ces o f 0 1 an d 1 0 }

n n

B n C w w D w w    

slide-95
SLIDE 95

The Pumping Lemma

slide-96
SLIDE 96

Proof Idea

  • Let M be a DFA recognizing A
  • Let p be the numbers of states in M
  • Show that s can be broken into xyz
  • Prove the conditions holds
slide-97
SLIDE 97

Proof Idea

  • Let M be a DFA recognizing A
  • Let p be the numbers of states in M
  • Show that s can be broken into xyz
  • Prove the conditions holds
slide-98
SLIDE 98

Proof Idea

  • Let M be a DFA recognizing A
  • Let p be the numbers of states in M
  • Show that s can be broken into xyz
  • Prove the conditions holds
slide-99
SLIDE 99

Proof of the Pumping Lemma

slide-100
SLIDE 100

Use of the Pumping Lemma

slide-101
SLIDE 101

Nonregular Languages

slide-102
SLIDE 102

Nonregular Languages

slide-103
SLIDE 103

Nonregular Languages

slide-104
SLIDE 104

Nonregular Languages

slide-105
SLIDE 105

Example Exam Question

slide-106
SLIDE 106

Summary

  • Deterministic finite automata
  • Regular languages
  • Nondeterministic finite automata
  • Closure operations
  • Regular expressions
  • Nonregular languages
  • The pumping lemma