cl the Boolean algebra of languages regular expressions - - PowerPoint PPT Presentation

cl
SMART_READER_LITE
LIVE PREVIEW

cl the Boolean algebra of languages regular expressions - - PowerPoint PPT Presentation

https://app-ca.tophat.com/e/835603 NFA and regex cl the Boolean algebra of languages regular expressions Informatics 1 School of Informatics, University of Edinburgh 1 KISS DFA D eterministic F inite A utomaton Exactly one start


slide-1
SLIDE 1

cl

Informatics 1 School of Informatics, University of Edinburgh

NFA and regex

  • the Boolean algebra of languages
  • regular expressions

1

https://app-ca.tophat.com/e/835603

slide-2
SLIDE 2

KISS – DFA

2

Deterministic Finite Automaton Exactly one start state, and from each state, q, for each token, t, there is exactly one transition from s with label t

slide-3
SLIDE 3

Informatics 1 School of Informatics, University of Edinburgh

Two examples

3

Input sequence is accepted if it ends with a zero. 1

1

1 Input sequence is accepted if it ends with a one.

Even binary numbers Odd binary numbers

1

1 1

×2 ×2 + 1 1 1 1 1 ×2 ×2 + 1 1 1 1 1

slide-4
SLIDE 4

Informatics 1 School of Informatics, University of Edinburgh

The complement of a regular language is regular

4 1

1 1

L0 : even numbers = 0 mod 2 L1 : odd numbers = 1 mod 2

1 1

slide-5
SLIDE 5

Informatics 1 School of Informatics, University of Edinburgh

Three examples

5

Which binary numbers are accepted?

1

1 1

2

1

1

1 1

1

2

1

1

1 1

2

1

2

×2 ×2 + 1 mod 3 1 1 1 2 2 1 2

slide-6
SLIDE 6

Informatics 1 School of Informatics, University of Edinburgh

The complement of a regular language is regular

6

If A ⊆ Σ* is recognised by M then A̅ = Σ* \ A is recognised by M̅ where M̅ and M are identical except that the accepting states

  • f M̅ are the non-

accepting states of M and vice-versa

1

1 1

2

1

1

1 1

1

2

1

2

slide-7
SLIDE 7

Informatics 1 School of Informatics, University of Edinburgh

By three or not by three?

7

divisible by three

1

1 1

2

1

1

1 1

1

2

1

not divisible by three

2

slide-8
SLIDE 8

Informatics 1 School of Informatics, University of Edinburgh

The intersection of two regular languages is regular

8 1

1 1

2

1

L0 = 0 mod 3 L1 = 1 mod 3 L2 = 2 mod 3

slide-9
SLIDE 9

Informatics 1 School of Informatics, University of Edinburgh

The intersection of two regular languages is regular

9

divisible by 6 ≣ divisible by 2 and divisible by 3

1

1 1

2

1

1

1 1

slide-10
SLIDE 10

Informatics 1 School of Informatics, University of Edinburgh

The intersection of two regular languages is regular

10

Run both machines in parallel? Build one machine that simulates two machines running in parallel! Keep track of the state of each machine.

1

1 1

1

1 1

2

1

slide-11
SLIDE 11

Informatics 1 School of Informatics, University of Edinburgh

The intersection of two regular languages is regular

11 1

1 1

1

1 1

2

1

slide-12
SLIDE 12

12 1

1 1

1

1 1

2

1

intersection of languages

run the two machines in parallel when a string is in both languages, both are in an accepting state

slide-13
SLIDE 13

13 1

1 1

intersection of languages

run the two machines in parallel when a string is in both languages, both are in an accepting state

1

1 1

2

1

10 20

1

00 11 21 01

slide-14
SLIDE 14

intersection of two regular languages
 is regular

14

1 1

10 20

1

00

1 1 1

11 21 01

1

1

1 1

2

1

1

1 1

run two machines in synchrony

slide-15
SLIDE 15

Informatics 1 School of Informatics, University of Edinburgh

The regular languages A ⊆ Σ* form a Boolean Algebra

  • Since they are closed under intersection

and complement.

15

slide-16
SLIDE 16

Informatics 1 School of Informatics, University of Edinburgh

Are all languages A ⊆ Σ* regular?

  • A finite machine can only do so much

  • r rather, so little.

16

Consider the language with two symbols Σ = {0,1},
 consisting of the all strings 
 that contain equal numbers of zeros and ones. How can we show that this language is not regular?

−1

1

1 −4 −3 −2 2 3 4

1 1 1 1 1 1 1

slide-17
SLIDE 17

Informatics 1 School of Informatics, University of Edinburgh

Are all languages A ⊆ Σ* regular?

17

Consider the language with two symbols Σ = {0,1}, consisting of the all strings that contain equal numbers of zeros and ones. Suppose we have a DFA that recognises this language. Let sn be the state the machine reaches after an input

  • f n zeros.

If the machine is in state sn and we give it an input of n ones it will be in an accepting state.

slide-18
SLIDE 18

Informatics 1 School of Informatics, University of Edinburgh

Are all languages A ⊆ Σ* regular?

18

A = strings that contain equal numbers of zeros and ones. We have a DFA that recognises this language. sn is the state the machine after an input of n zeros. If the machine is in state sn and we give it an input of n ones it will be in an accepting state. If n ≠ m what can we say about sn and sm ?

slide-19
SLIDE 19

Informatics 1 School of Informatics, University of Edinburgh

Are all languages A ⊆ Σ* regular?

19

A = strings that contain equal numbers of zeros and ones.
 We have a DFA that recognises this language. sn is the state the machine after an input of n zeros. If the machine is in state sn (after an input of n zeros),
 and we give it an input of m ones
 it will be in an accepting state iff m = n. Therefore, if n ≠ m then sn ≠ sm (why?) So our machine must have infinitely many states!! An FSM with n states cannot count beyond n-1.

slide-20
SLIDE 20

Informatics 1 School of Informatics, University of Edinburgh

Which languages A ⊆ Σ* are regular?

20

What kind of answer can we give to a question like this? If we have a machine 
 then the language it recognises is regular. For some languages, L, e.g. our #0s = #1s example,
 we can argue that no FSM can recognise L.
 But that is not a general argument. Instead of finding a property, 
 to characterise the regular languages, 
 we will find a set of rules that generate
 the set of regular languages.

slide-21
SLIDE 21

Informatics 1 School of Informatics, University of Edinburgh

Which languages A ⊆ Σ* are regular?

21

We give a set of rules, 
 and show that they generate all regular languages. First we work with general NFA to show that the rules are
 sound – any language generated by the rules is regular. Then we show that for any NFA, M, there is a DFA, P(M), that recognises the same language. So, any language generated by the rules is recognised by some DFA. Then we show that the rules are complete – any regular language is generated by the rules.

slide-22
SLIDE 22

finite state spaghetti

22

A natural language is a set of finite sequences of words. A formal language is a set of finite sequences of symbols. A formal language is regular iff it is the language recognised by some Finite State Machine.

slide-23
SLIDE 23

Informatics 1 School of Informatics, University of Edinburgh

KISS – start simple

23

NFA any number of start states and accepting states Any NFA with no accepting states,
 e.g. the NFA with no states, 
 recognises the empty language ∅ = {}. The NFA with one state - starting and accepting, 
 and no transitions recognises the empty string {ε}. The NFA with two states and one transition, 
 start to stop recognises {"a"}

a

slide-24
SLIDE 24

Informatics 1 School of Informatics, University of Edinburgh

KISS – the basic regular languages

24

The following languages are regular

  • The empty language ∅ = {}
  • The language that includes only the empty string {ε}.
  • The language that includes only the one-letter string {"a"}
slide-25
SLIDE 25

NFA any number of start states and accepting states

S

25

R

slide-26
SLIDE 26

sequence RS

ε

26

S R

ε

slide-27
SLIDE 27

alternation R|S

27

S R

slide-28
SLIDE 28

iteration R*

ε

28

R

ε ε

slide-29
SLIDE 29

Informatics 1 School of Informatics, University of Edinburgh

rules for regular languages

29

The following languages are regular

  • The empty language ∅ = {}
  • The language that includes only the empty string {ε}.
  • The language that includes only the one-letter string {"a"}

If R and S are regular so are

  • R | S = R ∪ S
  • RS = { rs | r ∈ R and s ∈ S }
  • R* generated by rules
  • ε ∈ R*
  • if x ∈ R* and r ∈ R then xr ∈ R*
slide-30
SLIDE 30

Informatics 1 School of Informatics, University of Edinburgh

patterns for regular languages

30

regular expressions for sets of strings

  • "" empty language ∅ = {}
  • ε empty string {ε}.
  • a one-letter string {"a"}
  • R | S union R ∪ S
  • RS concatenation { rs | r ∈ R and s ∈ S }
  • R* iteration

precedence: R|ST* = R|(S(T*))

slide-31
SLIDE 31

A Decimal Number

d d

+⎮−

.

d d d ε start end sta sta alternative paths repetition skip S

31

((+|-)\d|\d)\d*(ε|.\d*\d) where \d is (0|1|2|3|4|5|6|7|8|9)

slide-32
SLIDE 32

32 1

a alb

1

1

a alb

2

b

2

c

1

a alb

1

2

b c

1

a

1

2

b c d a alb

1 1

slide-33
SLIDE 33

33 1

a alb

1

1

a alb

2

b

2

c

1

a alb

1

2

b c

1

a

1

2

b c d

(a|b)*a (a|b)*ab(cb)* (a|b)*a(bc)* a(a|b)* a(da|bc)*

a alb

1 1

slide-34
SLIDE 34

Informatics 1 School of Informatics, University of Edinburgh

rules for regular languages

34

The following equations hold for any sets of strings R,S,T

  • {} | S =
  • {} S =
  • ε S =
  • ε* =
  • {}* =
  • R (S | T) =
  • S R | T R =
  • S* S | ε =
slide-35
SLIDE 35

Informatics 1 School of Informatics, University of Edinburgh

rules for regular languages

35

The following equations hold for any sets of strings R,S,T

  • {} | S = {}|S = S
  • {} S = S {} = {}
  • ε S = S ε = S
  • ε* = ε
  • {}* = {}
  • R (S | T) = R S | R T
  • (S | T) R = S R | T R
  • S* = S* S | ε = S S* | ε