not everything is regular

41
2 NICTA Researcher, Adjunct at the Australian National University and Griffith University Not Everything is Regular Charles Gretton 2 4 March 2014 NICTA Funding and Supporting Members and Partners Not Everything is Regular Copyright NICTA 2014 Charles Gretton 2 1/41

Upload: others

Post on 24-Jan-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

2NICTA Researcher,Adjunct at the Australian National University and Griffith University

Not Everything is Regular

Charles Gretton2

4 March 2014

NICTA Funding and Supporting Members and Partners

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 1/41

Language Class

• We have spoken about the regular languages.

• Any language described using a regular expression.

• Any language described using a DFA, NFA and ε-NFA.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 2/41

Properties of a Class

1 Closure properties.• The reversal of a regular language is regular.• The star-closure of a regular language is regular.• The union of two regular languages is regular.• The intersection of two regular languages is regular.• The complement of a regular language is regular.• The concatenation of two regular languages is regular.• The difference of two regular languages is regular.• A homomorphism of a regular language is regular.• An inverse homomorphism of a regular language is regular.

2 Decision properties.• Is the language described empty?• Is the language described finite?• Is the string X a member of the language described?• Take two descriptions, do both describe the same language?• Take two descriptions, does one contain the language of the other?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 3/41

Motivating Decision Properties of a Class

• You are given a transaction protocol, does a transaction necessarilyterminate? – i.e. Is the language finite?

• You are given a transaction protocol, can it fail? – i.e. Is thelanguage non-empty?

• Shortest regular expression or minimum-state DFA? – i.e. Are twodescriptions, one smaller than the other, describing the samelanguage?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 4/41

Is the string X a member of the languagedescribed?

• We know how to do this...• Take “ababb”

A B C

D

a

b

ǫa

b

a, b

1

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 5/41

Is the string X a member of the languagedescribed?

• Take “ababb”

bb

epsa

aa,b

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 6/41

Is the string X a member of the languagedescribed?

• Take “ababb”• Starting

bb

epsa

aa,b

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 7/41

Is the string X a member of the languagedescribed?

• Take “ababb”• Reading: a

bb

epsa

aa,b

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 8/41

Is the string X a member of the languagedescribed?

• Take “ababb”• Reading: ab

bb

epsa

aa,b

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 9/41

Is the string X a member of the languagedescribed?

• Take “ababb”• Reading: aba

bb

epsa

aa,b

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 10/41

Is the string X a member of the languagedescribed?

• Take “ababb”• Reading: abab

bb

epsa

aa,b

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 11/41

Is the string X a member of the languagedescribed?

• Take “ababb”• Reading: ababb

bb

epsa

aa,b

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 12/41

Is a Language Empty?

• Regular Expressions↔ DFA↔ NFA↔ ε-NFA

• Assume a DFA representation.

• Compute the set of states R reachable from the starting state q0.

• If R ∩ F 6= ∅, then no, else yes.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 13/41

Is a Language Finite? – DFA example

• If a DFA has N states, and a string with N + i , i ≥ 0, symbols isaccepted, then no.

• Otherwise, yes.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 14/41

Is a Language Finite? – DFA example – proof

• If a DFA has N states, and a string with N + i , i ≥ 0, symbols isaccepted, then no.

• For the N + i length input, clearly one state is traversed twice – i.e.pigeonhole principle.

• Therefore there must be a loop.

• QED

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 15/41

Is a Language Finite? – DFA example – proof

• If a DFA has N states, and a string with N + i , i > 0, symbols isaccepted, then no.

• For the N + i length input, clearly one state is traversed twice – i.e.Pigeon hole argument.

• Therefore there must be a loop.

• Otherwise, yes.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 16/41

Is a Language Finite? – A finite test.

• How do we get a computer to decide if a language is finite?

• What is the finite test to eliminate the infinite strings of length N + i ,i > 0?

• We established that there must be a cycle.

• But that cycle can only be so long.......

• Maximally we traverse all the states twice – i.e. 2N − 1.

• If an automaton accepts a string of length N + i , i > 0, then there is acycle of length at most 2N − 1.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 17/41

Is a Language Finite? – DFA example

• What is a better algorithm than testing all strings of lengthless-than-or-equal 2N − 1?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 18/41

Is a Language Finite? – DFA example

• What is a better algorithm than testing all strings of lengthless-than-or-equal 2N − 1?

• Find cycles between q0 and states in F .

1 Eliminate unreachable states

2 Eliminate states from which the accepting states cannot be reached.

3 If any self loops remain, then it is infinite.

4 Is there a strongly connected component of the directed graph of size2 or greater? If so, again the language is infinite.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 19/41

Language Equivalence. – DFA example

• Remember the product of two automata from the first lecture?

• A1 = 〈Q1,Σ, δ1, q10 ,F

1〉.

• A2 = 〈Q2,Σ, δ2, q20 ,F

2〉.

• A2 × A1 = 〈Q2 × Q1,Σ, δ2×1, (q20 , q

10),F 2 × F 1〉.

• The product has the number of sates Q2 × Q1

• taking q2 ∈ Q2 and q1 ∈ Q1

δ2×1((q2, q1), a) = (δ2(q2, a), δ1(q1, a))

• There is a one-to-one correspondence between pairs of states fromthe source automata, and states in the product.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 20/41

Language Equivalence. – DFA example

• Remember the product of two automata from the first lecture?

• Product example:

ab

a,b

ba

a

b

a a

a

b

bba

b

A B

CD

AC AD

BC BD

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 21/41

Language Equivalence. – DFA example

• Make accepting states in the product where exactly one of thesource machines is accepting.

• This machine accepts strings iff they are in one of the sourcelanguages.

• Product example:

ab

a,b

ba

a

b

a a

a

b

bb a

b

A B

CD

AC AD

BC BD

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 22/41

Language Equivalence. – DFA example

• Product automaton describes the empty language if the two sourceautomata are equivalent.

• Do you recall the empty test?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 23/41

Is a Language Empty?

• Assume a DFA representation.

• Compute the set of states R reachable from the starting state q0.

• If R ∩ F 6= ∅, then no, else yes.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 24/41

Is one language contained in another? – DFAexample

• Two regular languages L1 and L2 described using two automata:

1 A1 = 〈Q1,Σ, δ1, q10 ,F

1〉.

2 A2 = 〈Q2,Σ, δ2, q20 ,F

2〉.

• We want to test L1 ⊆ L2

• What are the accepting states of the product, if we want to testcontainment?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 25/41

Is one language contained in another? – DFAexample

• Two regular languages L1 and L2 described using two automata:

1 A1 = 〈Q1,Σ, δ1, q10 ,F

1〉.2 A2 = 〈Q2,Σ, δ2, q2

0 ,F2〉.

• We want to test L1 ⊆ L2

• What are the accepting states of the product, if we want to testcontainment?

• Accepting in product state: Q1 label is accepting and Q2 label is not.

• If the result describes an empty language, then we can never acceptan A1 string without that also being accepted by A2.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 26/41

Language Containment. – DFA example

• In product state: Q1 label is accepting and Q2 label is not.

• Starting at state “AC” this product accepts no strings, hencecontainment holds.

ab

a,b

ba

a

b

a a

a

b

bb a

b

A B

CD

AC AD

BC BD

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 27/41

Language Class – Is it regular?

• Consider the following language, described using a setcomprehension:

{anbn|n > 0}

• Do you think it is regular?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 28/41

Language Class – Is it regular?

• Consider the following language, described using a setcomprehension:

{anbn|n > 0}

• It is not regular!

• And our job is to prove it.

• We will do this using the pumping lemma.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 29/41

Pumping Lemma

• L is regular.

• There is a finite positive integer constant N(L), so that forall W ∈ LN(L) ≤ |W |W = XYZ satisfying:

1 Y 6= ε

2 |XY | ≤ N(L)

3 ∀k ≥ 0, we have XY k Z ∈ L

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 30/41

Pumping Lemma – Example

• Take |Σ| = 1 and L is the set of strings of prime length.

• Is this a regular language?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 31/41

Pumping Lemma – Example

• Take |Σ| = 1 and L are sequences of prime length.

• Is this a regular language?

• No, the machine would need infinite states.

• But let us prove it using the pumping lemma.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 32/41

Pumping Lemma – Example

• Take |Σ| = 1 and L are sequences of prime length.• Proof by contradiction that this is not a regular language.• N(L) is finite remember.• Take a prime p satisfying p ≥ N(L) + 2.• For |XY | ≤ N(L) take |XYZ | = p with |Y | = m so |XZ | = p −m• The pumping lemma (which is true) tells us XY p−mZ ∈ L

|XY p−mZ | = |XZ |+ (p −m)|Y | = p −m + (p −m)m= (m + 1)(p −m)

(m + 1) > 1m = |Y | ≤ |XY | ≤ N(L); ; therefore

(p −m) > 1

• Oh no, p is nonprime, as it has two factors greater than 1.• QED

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 33/41

Pumping Lemma Continued

• Consider the following language, described using a setcomprehension:

L = {anbn|n > 0}

• It is not regular!

• XYZ = aN(L)bN(L), |XYZ | ≥ N(L), |Y | > 0, |XY | ≤ N(L)

• Hmmm.. XYYZ ∈ L and XYYZ 6∈ {anbn|n > 0}

• QED

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 34/41

Properties of a Language Class

1 Closure properties.• The reversal of a regular language is regular.• The star-closure of a regular language is regular.• The union of two regular languages is regular.• The intersection of two regular languages is regular.• The complement of a regular language is regular.• The concatenation of two regular languages is regular.• The difference of two regular languages is regular.• A homomorphism of a regular language is regular.• An inverse homomorphism of a regular language is regular.

2 Decision properties.• Is the language described empty?• Is the language described finite?• Is the string X a member of the language described?• Take two descriptions, do both describe the same language?• Take two descriptions, does one contain the language of the other?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 35/41

Motivating Closure Properties of a LanguageClass

• e.g. Regular languages as closed under union, concatenation andKleene-star.

• We used those properties to create a representation, namely regularexpressions.

• Properties will also help us show that a language is not regular.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 36/41

Motivating Closure Properties of a LanguageClass

• Consider the following language, described in natural language:

• Any string comprising an equal number of a and b symbols of length≤ 1000.

• Do you think it is regular?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 37/41

Motivating Closure Properties of a LanguageClass

• Consider the following language, described in natural language:• Any string comprising an equal number of a and b symbols of length≤ 1000.

• Yes, it is regular!!• A regular language is a language that can be given by a regular

expression.• A finite language is a finite set of strings:

{X1,X2, ..,Xn}• The regular expression that gives that finite language is:

X1 + X2 + ..+ Xn

• QEDNot Everything is Regular Copyright NICTA 2014 Charles Gretton2 38/41

Motivating Closure Properties of a LanguageClass

• Consider the following language, described in natural language:

• Any string comprising an equal number of a and b symbols.

• Do you think it is regular?

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 39/41

Motivating Closure Properties of a LanguageClass

• Consider the following language, described in natural language:

• Any string comprising an equal number of a and b symbols.

• Do you think it is regular?

• It is not regular!

• And our job is to prove it, using closure properties.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 40/41

Motivating Closure Properties of a LanguageClass

• Consider the following language, described in natural language:

• Any string comprising an equal number of a and b symbols.

• Do you think it is regular?

• It is not regular!

• Property: The intersection of two regular languages is regular.

• Let L1 be the above language.

• Take the language L2 ∩ L(a∗b∗)

• This is not regular, the RHS is regular, therefore L2 is not regular.

Not Everything is Regular Copyright NICTA 2014 Charles Gretton2 41/41