Inf2A: Kleenes Theorem Stuart Anderson School of Informatics - - PowerPoint PPT Presentation

inf2a kleene s theorem
SMART_READER_LITE
LIVE PREVIEW

Inf2A: Kleenes Theorem Stuart Anderson School of Informatics - - PowerPoint PPT Presentation

Kleenes Theorem Inf2A: Kleenes Theorem Stuart Anderson School of Informatics University of Edinburgh October 10, 2008 university-logo Stuart Anderson Regular Languages 3 Kleenes Theorem Outline Kleenes Theorem 1 Regular


slide-1
SLIDE 1

university-logo Kleene’s Theorem

Inf2A: Kleene’s Theorem

Stuart Anderson

School of Informatics University of Edinburgh

October 10, 2008

Stuart Anderson Regular Languages 3

slide-2
SLIDE 2

university-logo Kleene’s Theorem

Outline

1

Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Stuart Anderson Regular Languages 3

slide-3
SLIDE 3

university-logo Kleene’s Theorem

Stephen Cole Kleene

Born 1909, Died 1994. Worked for most of his career at Univ of Wisconsin-Madison Significant contributor to the development of recursion theory (foundations of computation). Developed regular algebra. Contributions to Intuitionistic Mathematics.

Stuart Anderson Regular Languages 3

slide-4
SLIDE 4

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Non-Deterministic Finite Automata

Conversion Theorem: Every language recognised by an NFA (with or without ε-transitions) is regular.

ε ε ε ε ε 1 1 ε

1 3 4 5 2 6 7

1 0,1 1 1 1 1 1 1 {2,3,5,6} {3,6} {4,6.7} {6,7} {3,4,6} {0,1,2} φ {2,5,6}

Stuart Anderson Regular Languages 3

slide-5
SLIDE 5

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Regular Expressions in Unix

Examples ls a* (lists all names of files in the current directory starting with a) egrep ’(.*aba.*)|(.*x.*y.*)’ /usr/dict/words (extracts all lines from the file /usr/dict/words that either contain aba or an x and after that a y).

Stuart Anderson Regular Languages 3

slide-6
SLIDE 6

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Defining a Language

We take the following steps:

1

We define the syntax of the language by giving a grammar that defines the language. This is often called an abstract syntax for the language.

2

We say how the language will be interpreted, i.e. what kind

  • f things the terms in the language will stand for.

3

We provide a mapping from the language to the things they stand for. Usually we give one rule for each rule in the abstract syntax.

4

Here we have the syntax of regular expresions, they are interpreted as standing for sets of finite strings, and we provide a map from regular expressions to sets of strings.

Stuart Anderson Regular Languages 3

slide-7
SLIDE 7

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Syntax of Regular Expressions

Regular expressions over Σ are produced using the following formation rules: ε is a regular expression. ∅ is a regular expression. Every symbol a in Σ is a regular expression. If R and S are regular expressions then so is R + S. If R and S are regular expressions then so is RS. If R is a regular expression then so is R∗.

Stuart Anderson Regular Languages 3

slide-8
SLIDE 8

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Examples

Let Σ = {a, b, c}. R1 = ab + abc R2 = (a(b + c))∗ R3 = (aaa)∗ + (aaaaa)∗

Stuart Anderson Regular Languages 3

slide-9
SLIDE 9

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Semantics of Regular Expressions

With every regular expression R over the alphabet Σ we associate a language L(R) ⊆ Σ∗ (syntax, semantics): L(ε) = {ε}. L(∅) = ∅. L(a) = {a}. Now suppose that R and S are regular expressions and that we have already defined the languages L(R) and L(S). We define L(R + S), L(RS), and L(R∗) as follows: L(R + S) = L(R) ∪ L(S), L(RS) = {xy | x ∈ L(R), y ∈ L(S)}, L(R∗) = {ε} ∪ {x | x ∈ L(R)} ∪ {x1x2 | x1, x2 ∈ L(R)} ∪ . . . =

  • x1 . . . xn | n ∈ N0, x1, . . . , xn ∈ L(R)
  • .

Stuart Anderson Regular Languages 3

slide-10
SLIDE 10

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Examples

Let Σ = {a, b, c}. R1 = ab + abc L(R1) = {ab, abc} R2 = (a(b + c))∗ L(R2) =

  • ax1ax2ax3 . . . axn | n ∈ N0, x1, . . . , xn ∈ {b, c}
  • =

{ε, ab, ac, abab, abac, acab, acac, ababab, . . .}. R3 = (aaa)∗ + (aaaaa)∗ L(R3) = {an | n ∈ N0 divisible by 3 or 5}

Stuart Anderson Regular Languages 3

slide-11
SLIDE 11

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

From regular expressions to NFAs with ε-transitions

Proposition 1: For every regular expression R there exists an NFA with ε-transitions N such that L(R) = L(N). The proof is by induction on the structure of the regular expression R. For every regular expression R we construct an NFA with ε-transitions N, following the rules that were used to construct R.

Stuart Anderson Regular Languages 3

slide-12
SLIDE 12

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Induction on the structure of regular expressions

To show that some proposition P(R) is true for all regular expressions we often use induction on the structure of regular

  • expressions. To do this, we show: The base cases:

P(∅) is true P(ε) is true P(a) is true for each a ∈ Σ Then we assume that P(R) and P(S) are both true and we show that: P(R + S) is true P(RS) is true P(R∗) is true Example to try now - show for all regular expressions R, if R has no subexpression of the form S∗ then L(R) is a finite set.

Stuart Anderson Regular Languages 3

slide-13
SLIDE 13

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

The base cases

R = ε N R = ∅ N R = a

a

N

Stuart Anderson Regular Languages 3

slide-14
SLIDE 14

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Addition

R = R1 + R2

N 2 N1

q q q 2 1

ε ε

N

Stuart Anderson Regular Languages 3

slide-15
SLIDE 15

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Concatenation

R = R1R2

N1 N 2

q2 q1

ε ε ε

N

Stuart Anderson Regular Languages 3

slide-16
SLIDE 16

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Kleene Star - (Asterate in Kozen)

R = R∗

1 N1 ε ε ε

q1 q

ε

N

Stuart Anderson Regular Languages 3

slide-17
SLIDE 17

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Example R = (a(b + c))∗a

NFAs with ε-transitions for a, b, c:

a b c Stuart Anderson Regular Languages 3

slide-18
SLIDE 18

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Example (cont’d) R = (a(b + c))∗a

An NFA with ε-transitions for b + c:

b c

ε ε

Stuart Anderson Regular Languages 3

slide-19
SLIDE 19

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Example (cont’d) R = (a(b + c))∗a

An NFA with ε-transitions for a(b + c):

c b

ε ε

a

ε

Stuart Anderson Regular Languages 3

slide-20
SLIDE 20

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Example (cont’d) R = (a(b + c))∗a

An NFA with ε-transitions for (a(b + c))∗:

c

ε

b

ε ε

a

ε ε ε Stuart Anderson Regular Languages 3

slide-21
SLIDE 21

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Example (concluded) R = (a(b + c))∗a

An NFA with ε-transitions for (a(b + c))∗a:

c

ε

a a b

ε ε ε ε ε ε

Stuart Anderson Regular Languages 3

slide-22
SLIDE 22

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

From FSAs to Regular Expressions

Proposition 2: For every FSM M there exists a regular expression R such that L(M) = L(R). We construct a set of equations with one variable Ri for each state i of M For each variable we construct a sum of terms derived as follows:

If state i is accepting then ε is one of the summands If there is a transition labelled a from state i to state j, then aRj is one of the summands We solve using the equations of regular algebra plus the

  • bservation that A∗B is a solution to equations of the form

R = AR + B (try it!!)

The regular expression we derive for the initial state q0 satisfies L(Rq0) = L(M)

Stuart Anderson Regular Languages 3

slide-23
SLIDE 23

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Example: From FSA to Regular Expression

Consider the FSM:

  • 1

b

  • a
  • 2

a

  • b
  • We construct the following equations:

R1 = ε + bR1 + aR2 (1) R2 = bR2 + aR1 (2) Solving for R2: R2 = b∗aR1 Substitute for R2: R1 = ε + bR1 + ab∗aR1 = (b + ab∗a)R1 + ε Solve for R1: R1 = (b + ab∗a)∗ε = (b + ab∗a)∗

Stuart Anderson Regular Languages 3

slide-24
SLIDE 24

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

R = AR + B

We claim a solution of R = AR + B is A∗B. Substitute the solution into the RHS of the equation A(A∗B) + B = AA∗B + εB = (AA∗ + ε)B We know that from the definition of A∗ that A∗ = AA∗ + ε, so (AA∗ + ε)B = A∗B and we are done. A∗B is the smallest set solving this equation (try taking anything out of it!)

Stuart Anderson Regular Languages 3

slide-25
SLIDE 25

university-logo Kleene’s Theorem Regular Expressions From Regular Expressions to NFAs From FSAs to Regular Expressions

Summary

Taken together Propositions 1 and 2 make Kleene’s theorem, which tell us that every regular expresion has a corresponding FSA that recognizes the language of the regular expression and every FSA has a regular expression whose language is exactly that recognised by the FSA. This tells us that despite looking quite different FSAs and REs define the same set of languages and we can use them interchangably. Having two different representations is often useful. For example proving something by induction on the structure of the RE form of a regular language is often easier than trying to consider all possible FSMs and sometimes (e.g. in proving the pumping lemma) the finiteness of the stateset makes a proof easier than it would be with REs.

Stuart Anderson Regular Languages 3