Top Banner
The Coke Vending Machine Vending machine dispenses soda for $0.45 a pop. Accepts only dimes ($0.10) and quarters ($0.25). Eats your money if you don’t have correct change. You’re told to “implement” this functionality.
114

Vending machine dispenses soda for $0.45 a pop. Accepts ...

Apr 26, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Vending machine dispenses soda for $0.45 a pop. Accepts ...

The Coke Vending Machine

• Vending machine dispenses soda for $0.45 a pop.

• Accepts only dimes ($0.10) and quarters ($0.25).

• Eats your money if you don’t have correct change.

• You’re told to “implement” this functionality.

Page 2: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Vending Machine Java Code

Soda vend(){int total = 0, coin;while (total != 45){

receive(coin);if ((coin==10 && total==40) ||(coin==25 && total>=25))

reject(coin);else

total += coin;}return new Soda();

} Overkill?!?

Page 3: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Why this was overkill…

• Vending machines have been around long before computers.

– Or Java, for that matter.

• Don’t really need int’s.

– Each int introduces 232

possibilities.

• Don’t need to know how to add integers to model vending machine– total += coin.

• Java grammar, if-then-else, etc. complicate the essence.

Page 4: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Vending Machine “Logics”

Page 5: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Why was this simpler than Java Code?

• Only needed two coin types “D” and “Q”– symbols/letters in alphabet

• Only needed 7 possible current total amounts

– states/nodes/vertices

• Much cleaner and more aesthetically pleasing than Java lingo

• Next: generalize and abstract…

Page 6: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Alphabets and Strings

• Definitions:

• An alphabet is a set of symbols (characters, letters).

• A string (or word) over is a sequence of symbols.

– The empty string is the string containing no symbols at all, and is denoted by

.

– The length of the string is the number of symbols, e.g. || = 0.

Page 7: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Questions:

1) What is ?

2) What are some good or bad strings?

3) What does signify here?

Page 8: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Finite Automaton Example

0

1

0

1

1 1 0 0 1

01

sourceless

arrow

denotes

“start”

double

circle

denotes

“accept”

input put

on tape

read left

to right

What strings are “accepted”?

Page 9: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Formal Definition of a Finite Automaton

A finite automaton (FA) is a 5-tuple (𝑄, Σ, 𝛿, 𝑞0, 𝐹),where

• Q is a finite set called the states

• is a finite set called the alphabet

• 𝛿: 𝑄 × Σ → 𝑄 is the transformation function

• 𝑞0 ∈ 𝑄 is the start state

• 𝐹 ⊆ 𝑄 is the set of accept states (a.k.a. final states).

Page 10: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Formal Definition of a Finite Automaton

A finite automaton (FA) is a 5-tuple (𝑄, Σ, 𝛿, 𝑞0, 𝐹),where

• Q is a finite set called the states

• is a finite set called the alphabet

• 𝛿: 𝑄 × Σ → 𝑄 is the transformation function

• 𝑞0 ∈ 𝑄 is the start state

• 𝐹 ⊆ 𝑄 is the set of accept states (a.k.a. final states).

• The “input string” and the tape containing it are implicit in the definition.The definition only deals with the static view.

Further explaining is needed for understanding how FA’s interact withtheir input.

Page 11: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Accept States

• How does an FA operate on strings?

Imagine an auxiliary tape containing the string.

The FA reads the tape from left to right with each new character

causing the FA to go into another state.

When the string is completely read, the string is accepted

depending on whether the FA’s final state was an accept state.

Page 12: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Accept States

• How does an FA operate on strings?

Imagine an auxiliary tape containing the string.

The FA reads the tape from left to right with each new character

causing the FA to go into another state.

When the string is completely read, the string is accepted

depending on whether the FA’s final state was an accept state.

• Definition: A string u is accepted by an automaton M iff (if and only if )the path starting at q

0 which is labeled by u ends in an accept state.

Page 13: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Accept States

• How does an FA operate on strings?

Imagine an auxiliary tape containing the string.

The FA reads the tape from left to right with each new character

causing the FA to go into another state.

When the string is completely read, the string is accepted

depending on whether the FA’s final state was an accept state.

• Definition: A string u is accepted by an automaton M iff (if and only if )the path starting at q

0 which is labeled by u ends in an accept state.

• This definition is somewhat informal. To really define what it means for a

string to label a path, you need to break u up into its sequence of

characters and apply d repeatedly, keeping track of states.

Page 14: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Language

• Definition:

The language accepted by an finite automaton M is the set of all strings

which are accepted by M. The language is denoted by L(M).

We also say that M recognizes L(M), or that M accepts L(M).

• Think of all the possible ways of getting from the start to any accept state.

Page 15: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Language

• Definition:

The language accepted by an finite automaton M is the set of all strings

which are accepted by M. The language is denoted by L(M).

We also say that M recognizes L(M), or that M accepts L(M).

• Think of all the possible ways of getting from the start to any accept state.

• We will eventually see that not all languages can be described as the

accepted language of some FA.

• A language L is called a regular language if there exists a FA M that

recognizes the language L.

Page 16: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Designing Finite Automata

• This is essentially a creative process…

• “You are the automaton” method– Given a language (for which we must design an automaton).

– Pretending to be automaton, you receive an input string.

– You get to see the symbols in the string one by one.

– After each symbol you must determine whether string

seen so far is part of the language.

– Like an automaton, you don’t see the end of the string,so you must always be ready to answer right away.

• Main point: What is crucial, what defines the language?!

Page 17: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Find the automata for…

1) = {0,1},

Language consists of all strings with odd number of ones.

2) = {0,1},

Language consists of all strings with substring “001”,for example 100101, but not 1010110101.

More examples in the book and in the exercises…

Page 18: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Definition of Regular Language

• Recall the definition of a regular language:

A language L is called a regular language if there exists

a FA M that recognizes the language L.

• We would like to understand what types of languages are regular.

Languages of this type are amenable to super-fast recognition.

Page 19: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Definition of Regular Language

• Recall the definition of a regular language:

A language L is called a regular language if there exists

a FA M that recognizes the language L.

• We would like to understand what types of languages are regular.

Languages of this type are amenable to super-fast recognition.

• Are the following languages regular?

– Unary prime numbers: { 11, 111, 11111, 1111111, 11111111111, … }= {1

2, 1

3, 1

5, 1

7, 1

11, 1

13, … } = { 1p| p is a prime number }

– Palindromic bit strings: {, 0, 1, 00, 11, 000, 010, 101, 111, …}

Page 20: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Finite Languages

• All the previous examples had the following property in common:

infinite cardinality

• Before looking at infinite languages, we should look at finite languages.

Page 21: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Finite Languages

• All the previous examples had the following property in common:

infinite cardinality

• Before looking at infinite languages, we should look at finite languages.

• Question:

Is the singleton language containing one string regular?

For example, is the language {banana} regular?

Page 22: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Languages of Cardinality 1

• Answer: Yes.

Page 23: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Languages of Cardinality 1

• Answer: Yes.

• Question: Huh? What’s wrong with this automaton?!?What if the automation is in state q

1and reads a “b”?

Page 24: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Languages of Cardinality 1

• Answer: Yes.

• Question: Huh? What’s wrong with this automaton?!?What if the automation is in state q

1and reads a “b”?

• Answer:

This a first example of a nondeterministic FA. The difference between a

deterministic FA (DFA) and a nondeterministic FA (NFA) is that every DFA

state has one exiting transition arrow for each symbol of the alphabet.

Page 25: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Languages of Cardinality 1

• Answer: Yes.

• Question: Huh? What’s wrong with this automaton?!?What if the automation is in state q

1and reads a “b”?

• Answer:

This a first example of a nondeterministic FA. The difference between a

deterministic FA (DFA) and a nondeterministic FA (NFA) is that every DFA

state has one exiting transition arrow for each symbol of the alphabet.

• Question: Is there a way of fixing it and making it deterministic?

Page 26: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Arbitrary Finite Number of Finite Strings

• Theorem: All finite languages are regular.

Page 27: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Arbitrary Finite Number of Finite Strings

• Theorem: All finite languages are regular.

• Proof:

One can always construct a tree whose leaves are word-ending.

Make word endings into accept states, add a fail sink-state and

add links to the fail state to finish the construction.

Since there’s only a finite number of finite strings,the automaton is finite.

Page 28: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Arbitrary Finite Number of Finite Strings

• Theorem: All finite languages are regular.

• Proof:

One can always construct a tree whose leaves are word-ending.

Make word endings into accept states, add a fail sink-state and

add links to the fail state to finish the construction.

Since there’s only a finite number of finite strings,the automaton is finite.

• Example for {banana, nab, ban, babba}:

ba a

b

a

n b

a

n

b

an

Page 29: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular Operations

• You may have come across the regular operations when doing advanced

searches utilizing programs such as emacs, egrep, perl, python, etc.

• There are four basic operations we will work with:

– Union

– Concatenation

– Kleene-Star

– Kleene-Plus (which can be defined using the other three)

Page 30: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular Operations – Summarizing Table

Operation Symbol UNIX version Meaning

Union ∪ | Match one of the patterns

Concatenation implicit in UNIX Match patterns in sequence

Kleene-star * * Match pattern 0 or more times

Kleene-plus + + Match pattern 1 or more times

Page 31: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular Operations matters!

Page 32: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Union

• In UNIX, to search for all lines containing vowels in a text one could use

the command

– egrep -i `a|e|i|o|u’– Here the pattern “vowel” is matched by any line containing a vowel.– A good way to define a pattern is as a set of strings, i.e. a language.

The language for a given pattern is the set of all strings satisfying the

predicate of the pattern.

Page 33: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Union

• In UNIX, to search for all lines containing vowels in a text one could use

the command

– egrep -i `a|e|i|o|u’– Here the pattern “vowel” is matched by any line containing a vowel.– A good way to define a pattern is as a set of strings, i.e. a language.

The language for a given pattern is the set of all strings satisfying the

predicate of the pattern.

• In UNIX, a pattern is implicitly assumed to occur as a substring of the

matched strings. In our course, however, a pattern needs to specify

the whole string, not just a substring.

Page 34: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Union

• In UNIX, to search for all lines containing vowels in a text one could use

the command

– egrep -i `a|e|i|o|u’– Here the pattern “vowel” is matched by any line containing a vowel.– A good way to define a pattern is as a set of strings, i.e. a language.

The language for a given pattern is the set of all strings satisfying the

predicate of the pattern.

• In UNIX, a pattern is implicitly assumed to occur as a substring of the

matched strings. In our course, however, a pattern needs to specify

the whole string, not just a substring.

• Computability: Union is exactly what we expect.

If you have patterns A = {aardvark}, B = {bobcat}, C = {chimpanzee},

the union of these is AB C = {aardvark, bobcat, chimpanzee}.

Page 35: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Concatenation

• To search for all consecutive double occurrences of vowels, use:

– egrep -i `(a|e|i|o|u)(a|e|i|o|u)’– Here the pattern “vowel” has been repeated. Parentheses have been

introduced to specify where exactly in the pattern the concatenation is

occurring.

Page 36: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Concatenation

• To search for all consecutive double occurrences of vowels, use:

– egrep -i `(a|e|i|o|u)(a|e|i|o|u)’– Here the pattern “vowel” has been repeated. Parentheses have been

introduced to specify where exactly in the pattern the concatenation is

occurring.

• Computability: Consider the previous result:

L = {aardvark, bobcat, chimpanzee}.

When we concatenate L with itself we obtain:

LL = {aardvark, bobcat, chimpanzee} {aardvark, bobcat, chimpanzee} =

{aardvarkaardvark, aardvarkbobcat, aardvarkchimpanzee,

bobcataardvark, bobcatbobcat, bobcatchimpanzee,

chimpanzeeaardvark, chimpanzeebobcat, chimpanzeechimpanzee}

Page 37: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Kleene-*

• We continue the UNIX example: now search for lines consisting purely of

vowels (including the empty line):

– egrep -i `^(a|e|i|o|u)*$’– Note: ^ and $ are special symbols in UNIX regular expressions which

respectively anchor the pattern at the beginning and end of a line.

The trick above can be used to convert any Computability regular

expression into an equivalent UNIX form.

Page 38: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Kleene-*

• We continue the UNIX example: now search for lines consisting purely of

vowels (including the empty line):

– egrep -i `^(a|e|i|o|u)*$’– Note: ^ and $ are special symbols in UNIX regular expressions which

respectively anchor the pattern at the beginning and end of a line.

The trick above can be used to convert any Computability regular

expression into an equivalent UNIX form.

• Computability: Suppose we have a language B = {ba, na}.

Question: What is the language B*?

Page 39: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Kleene-*

• We continue the UNIX example: now search for lines consisting purely of

vowels (including the empty line):

– egrep -i `^(a|e|i|o|u)*$’– Note: ^ and $ are special symbols in UNIX regular expressions which

respectively anchor the pattern at the beginning and end of a line.

The trick above can be used to convert any Computability regular

expression into an equivalent UNIX form.

• Computability: Suppose we have a language B = {ba, na}.

Question: What is the language B*?

• Answer: B * = { ba,na }* = {, ba, na, baba, bana, naba, nana,

bababa, babana, banaba, banana, nababa, nabana, nanaba, nanana,

babababa, bababana, … }

Page 40: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Kleene-+

• Kleene-+ is just like Kleene-* except that the pattern is forced to

occur at least once.

• UNIX: search for lines consisting purely of vowels (not including the

empty line):

– egrep -i `^(a|e|i|o|u)+$’

Page 41: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Kleene-+

• Kleene-+ is just like Kleene-* except that the pattern is forced to

occur at least once.

• UNIX: search for lines consisting purely of vowels (not including the

empty line):

– egrep -i `^(a|e|i|o|u)+$’

• Computability:

Suppose we have a language B = {ba, na}.

What is B+and how does it defer from B*?

Page 42: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Regular operations: Kleene-+

• Kleene-+ is just like Kleene-* except that the pattern is forced to

occur at least once.

• UNIX: search for lines consisting purely of vowels (not including the

empty line):

– egrep -i `^(a|e|i|o|u)+$’

• Computability:

Suppose we have a language B = {ba, na}.

What is B+and how does it defer from B*?

B+= {ba, na}

+ = {ba, na, baba, bana, naba, nana, bababa, babana,

banaba, banana, nababa, nabana, nanaba, nanana, babababa,

bababana, … }

The only difference is the absence of

Page 43: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Closure of Regular Languages

• When applying regular operations to regular languages, regular languages

result. That is, regular languages are closed under the operations of

union, concatenation, and Kleene-*.

• Goal: Show that regular languages are closed under regular operations.

In particular, given regular languages L1

and L2, show:

1. L1 L

2 is regular,

2. L1 L

2 is regular,

3. L1* is regular.

• No.’s 2 and 3 are deferred until we learn about NFA’s.• However, No. 1 can be achieved immediately.

Page 44: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Union Example

• Problem: Draw the FA for

L = { x {0,1}* | |x|=even or x ends with 11}

Page 45: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Let’s start by drawing M1

and M2,

the automaton recognizing L1

and L2

• L1

= { x {0,1}* | x has even length}

• L2

= { x {0,1}* | x ends with 11 }

Page 46: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Cartesian Product Construction

• We want to construct a finite automaton M that recognizes

any strings belonging to L1

or L2.

• Idea: Build M such that it simulates both M1

and M2

simultaneously

and accept if either of the automatons accepts

Page 47: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Cartesian Product Construction

• We want to construct a finite automaton M that recognizes

any strings belonging to L1

or L2.

• Idea: Build M such that it simulates both M1

and M2

simultaneously

and accept if either of the automatons accepts

• Definition: The Cartesian product of two sets A and B,denoted by 𝐴 × B, is the set of all ordered pairs (a,b)

where aA and bB.

Page 48: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Formal Definition

• Given two automata𝑀1 = (𝑄1, Σ, 𝛿1, 𝑞1, 𝐹1) and 𝑀2 = (𝑄2, Σ, 𝛿2, 𝑞2, 𝐹2)

• Define the unioner of M1 and M2 by:𝑀∪ = (𝑄1 × 𝑄2, Σ, 𝛿1 × 𝛿2, (𝑞1, 𝑞2), 𝐹∪)

- where the accept state 𝑞1, 𝑞2 is the combined start stateof both automata

- where 𝐹∪ is the set of ordered pairs in 𝑄1 × 𝑄2with at least onestate an accept state. That is: 𝐹∪ = 𝑄1 × 𝐹2 ∪ 𝐹1 × 𝑄2

- where the transition function d is defined as𝛿 𝑞1, 𝑞2 , 𝑗 = 𝛿1 𝑞1, 𝑗 , 𝛿2 𝑞2, 𝑗 = 𝛿1 × 𝛿2

Page 49: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Union Example: L1L

2

• When using the Cartesian Product Construction:

01

0 0

0

0

0

11

1

11

Page 50: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Other constructions: Intersector

• Other constructions are possible, for example an intersector:

• Accept only when both ending states are accept states. So the onlydifference is in the set of accept states. Formally the intersector ofM1 and M2 is given by𝑀∩ = 𝑄1 × 𝑄2, Σ, 𝛿1 × 𝛿2, 𝑞0,1, 𝑞0,2 , 𝐹∩ , where 𝐹∩ = 𝐹1 × 𝐹2.

Page 51: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Other constructions: Intersector

• Other constructions are possible, for example an intersector:

• Accept only when both ending states are accept states. So the onlydifference is in the set of accept states. Formally the intersector ofM1 and M2 is given by𝑀∩ = 𝑄1 × 𝑄2, Σ, 𝛿1 × 𝛿2, 𝑞0,1, 𝑞0,2 , 𝐹∩ , where 𝐹∩ = 𝐹1 × 𝐹2.

(b,y)(b,x)

(a,x) (a,y) (a,z)

(b,z)

01

0 0

0

0

0

11

1

11

Page 52: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Other constructions: Difference

• The difference of two sets is defined by A - B = {x A | x B}

• In other words, accept when first automaton accepts andsecond does not

𝑀− = (𝑄1 × 𝑄2, Σ, 𝛿1 × 𝛿2, 𝑞0,1, 𝑞0,2 , 𝐹−),where 𝐹− = 𝐹1 × 𝑄2 − 𝑄1 × 𝐹2

Page 53: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Other constructions: Difference

• The difference of two sets is defined by A - B = {x A | x B}

• In other words, accept when first automaton accepts andsecond does not

𝑀− = (𝑄1 × 𝑄2, Σ, 𝛿1 × 𝛿2, 𝑞0,1, 𝑞0,2 , 𝐹−),where 𝐹− = 𝐹1 × 𝑄2 − 𝑄1 × 𝐹2

(b,y)(b,x)

(a,x) (a,y) (a,z)

(b,z)

01

0 0

0

0

0

11

1

11

Page 54: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Other constructions: Symmetric difference

• The symmetric difference of two sets A, B is AB =AB - AB• Accept when exactly one automaton accepts:

𝑀⊕ = (𝑄1 × 𝑄2, Σ, 𝛿1 × 𝛿2, 𝑞0,1, 𝑞0,2 , 𝐹⊕), where 𝐹⊕ = 𝐹∪ − 𝐹∩

Page 55: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Other constructions: Symmetric difference

• The symmetric difference of two sets A, B is AB =AB - AB• Accept when exactly one automaton accepts:

𝑀⊕ = (𝑄1 × 𝑄2, Σ, 𝛿1 × 𝛿2, 𝑞0,1, 𝑞0,2 , 𝐹⊕), where 𝐹⊕ = 𝐹∪ − 𝐹∩

(b,y)(b,x)

(a,x) (a,y) (a,z)

(b,z)

01

0 0

0

0

0

11

1

11

Page 56: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Complement

• How about the complement? The complement is only definedwith respect to some universe.

• Given the alphabet , the default universe is just the set of allpossible strings *. Therefore, given a language L over , i.e.L * the complement of L is * - L

• Note: Since we know how to compute set difference, and weknow how to construct the automaton for * we can constructthe automaton for L .

Page 57: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Complement

• How about the complement? The complement is only definedwith respect to some universe.

• Given the alphabet , the default universe is just the set of allpossible strings *. Therefore, given a language L over , i.e.L * the complement of L is * - L

• Note: Since we know how to compute set difference, and weknow how to construct the automaton for * we can constructthe automaton for L .

• Question: Is there a simpler construction forL ?

Page 58: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Complement

• How about the complement? The complement is only definedwith respect to some universe.

• Given the alphabet , the default universe is just the set of allpossible strings *. Therefore, given a language L over , i.e.L * the complement of L is * - L

• Note: Since we know how to compute set difference, and weknow how to construct the automaton for * we can constructthe automaton for L .

• Question: Is there a simpler construction forL ?

• Answer: Just switch accept-states with non-accept states.

Page 59: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Complement Example

x y z1

0

0

1

1

Original:

x y z1

0

0

1

1

Complement: yx

Page 60: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Boolean-Closure Summary

• We have shown constructively that regular languages are closed under

boolean operations. I.e., given regular languages L1

and L2

we saw that:

1. L1 L

2 is regular,

2. L1 L

2 is regular,

3. L1-L

2 is regular,

4. L1 L

2 is regular,

5. L1

is regular.

• No. 2 to 4 also happen to be regular operations. We still need to show

that regular languages are closed under concatenation and Kleene-*.

• Tough question: Can’t we do a similar trick for concatenation?

Page 61: Vending machine dispenses soda for $0.45 a pop. Accepts ...

BacktoNondeterministicFA

• Question:DrawanFAwhichacceptsthelanguageL1={xÎ {0,1}*|4th bitfromleftofxis0}

• FAforL1:

• Question:Whataboutthe4th bitfromtheright?

• Looksascomplicated:L2={xÎ {0,1}*|4th bitfromrightofxis0}

0,1

0,1

0,1 0,10

0,11

Page 62: Vending machine dispenses soda for $0.45 a pop. Accepts ...

WeirdIdea

• NoticethatL2isthereverseL1.

• I.e.sayingthat0shouldbethe4th fromtheleftisreverseofsayingthat0shouldbe4th fromtheright.Canwesimplyreverse thepicture(reversearrows,swapstartandaccept)?!?

• Here’sthereversedversion:

0,1

0,1

0,1 0,10

0,11

0,1

0,1

0,1 0,10

0,11

Page 63: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Discussionofweirdidea

1. Sillyunreachablestate.Notpretty,butallowedinmodel.

2. Oldstartstatebecameacrashingacceptstate.Underdeterminism.Couldfixwithfailstate.

3. Oldacceptstatebecameastatefromwhichwedon’tknowwhattodowhenreading0.Overdeterminism.Trouble.

4. (Notinthisexample,but)Therecouldbemorethanonestartstate!Seeminglyoutsidestandarddeterministicmodel.

• Still,thereissomethingaboutourautomaton.ItturnsoutthatNFA’s(=NondeterministicFA)areactuallyquiteusefulandareembeddedinmanypracticalapplications.

• Idea,keepmorethan1activestate ifnecessary.

Page 64: Vending machine dispenses soda for $0.45 a pop. Accepts ...

IntroductiontoNondeterministicFiniteAutomata

• ThestaticpictureofanNFAisasagraphwhoseedgesarelabeledbyS andbye (togethercalledSe)andwithstartvertexq0andacceptstatesF.

• Example:

• AnylabeledgraphyoucancomeupwithisanNFA,aslongasitonlyhasonestartstate.Later,eventhisrestrictionwillbedropped.

0,10

1e

1

Page 65: Vending machine dispenses soda for $0.45 a pop. Accepts ...

6

NFA:FormalDefinition.

• Definition:Anondeterministicfiniteautomaton(NFA) isencapsulatedbyM=(Q,S,d,q0,F)inthesamewayasanFA,exceptthatd hasdifferentdomainandco- domain: !: #×Σ& → ( #

• Here,P(Q)isthepowersetofQsothatd(q,a) isthesetofallendpointsofedgesfromq whicharelabeledbya.

• Example,forNFAofthepreviousslide:

d(q0,0) = {q1,q3},d(q0,1) = {q2,q3}, d(q0,e) = Æ,...d(q3,e) = {q2}.

q1

q0q2

q30,10

1e

1

Page 66: Vending machine dispenses soda for $0.45 a pop. Accepts ...

FormalDefinitionofanNFA:Dynamic

• JustaswithFA’s,thereisanimplicitauxiliarytapecontainingtheinputstringwhichisoperatedonbytheNFA.AsopposedtoFA’s,NFA’sareparallelmachines – abletobeinseveralstatesatanygiveninstant.TheNFAreadsthetapefromlefttorightwitheachnewcharactercausingtheNFAtogointoanothersetofstates.Whenthestringiscompletelyread,thestringisaccepteddependingonwhethertheNFA’sfinalconfigurationcontainsanacceptstate.

• Definition:Astringuisaccepted byanNFAM iff thereexistsapathstartingatq0whichislabeledbyuandendsinanacceptstate.ThelanguageacceptedbyM isthesetofallstringswhichareacceptedbyMandisdenotedbyL(M).• Followingalabele isforfree(withoutreadinganinputsymbol).In

computingthelabelofapath,youshoulddeletealle’s.• TheonlydifferenceinacceptanceforNFA’svs.FA’sarethewords“there

exists”.InFA’sthepathalwaysexistsandisunique.

Page 67: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Example

M4:

Question:Whichofthefollowingstringsisaccepted?1. e2. 03. 14. 0111

q1

q0q2

q30,10

1e

1

Page 68: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFA’svs.RegularOperations

• OnthefollowingfewslideswewillstudyhowNFA’sinteractwithregularoperations.

• WewillusethefollowingschematicdrawingforageneralNFA.

• Theredcirclestandsforthestartstateq0,thegreenportionrepresentstheacceptstatesF,theotherstatesaregray.

Page 69: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFA:Union

• TheunionAÈB isformedbyputtingtheautomataAandBinparallel.Createanewstartstateandconnectittotheformerstartstatesusinge-edges:

Page 70: Vending machine dispenses soda for $0.45 a pop. Accepts ...

UnionExample

• L ={xhasevenlength}È {xendswith11}

c

b

0,1 0,1

d e f

0

1

0

0

1

1

ae e

Page 71: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFA:Concatenation

• TheconcatenationA•B isformedbyputtingtheautomatainserial.ThestartstatecomesfromA whiletheacceptstatescomefromB.A’sacceptstatesareturnedoffandconnectedviae-edgestoB’sstartstate:

Page 72: Vending machine dispenses soda for $0.45 a pop. Accepts ...

ConcatenationExample

• L ={xhasevenlength}• {xendswith11}

• Remark:Thisexampleissomewhatquestionable…

c

b

0,1 0,1

d e f

0

1

0

01

1e

Page 73: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFA’s:Kleene-+.

• TheKleene-+A+ isformedbycreatingafeedbackloop.Theacceptstatesconnecttothestartstateviae-edges:

Page 74: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Kleene-+Example

L={ }+

={ }

x is a streak of one or more 1’s followedby a streak of two or more 0’s

00c d f

1

10

e

e

x starts with 1, ends with 0, and alternatesbetween one or more consecutive 1’s

and two or more consecutive 0’s

Page 75: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFA’s:Kleene-*

• TheconstructionfollowsfromKleene-+constructionusingthefactthatA*istheunionofA+ withtheemptystring.JustcreateKleene-+andaddanewstartacceptstateconnectingtooldstartstatewithane-edge:

Page 76: Vending machine dispenses soda for $0.45 a pop. Accepts ...

ClosureofNFAunderRegularOperations

• TheconstructionsaboveallshowthatNFA’sareconstructively closedundertheregularoperations.Moreformally,

• Theorem:IfL1and L2areacceptedbyNFA’s,thensoareL1È L2, L1•L2,L1+ andL1*.Infact,theacceptingNFA’scanbeconstructedinlineartime.

• Thisisalmostwhatwewant.IfwecanshowthatallNFA’scanbeconvertedintoFA’sthiswillshowthatFA’s– andhenceregularlanguages– areclosedundertheregularoperations.

Page 77: Vending machine dispenses soda for $0.45 a pop. Accepts ...

RegularExpressions(REX)

• Wearealreadyfamiliarwiththeregularoperations.Regularexpressionsgiveawayofsymbolizingasequenceofregularoperations,andthereforeawayofgeneratingnewlanguagesfromold.

• Forexample,togeneratetheregularlanguage{banana,nab}*fromtheatomiclanguages{a},{b}and{n}wecoulddothefollowing:

(({b}•{a}•{n}•{a}•{n}•{a})È({n}•{a}•{b}))*

Regularexpressionsspecifythesameinamorecompactform:

(bananaÈnab)*

Page 78: Vending machine dispenses soda for $0.45 a pop. Accepts ...

RegularExpressions(REX)

• Definition:Thesetofregularexpressions overanalphabetS andthelanguagesinS*whichtheygeneratearedefinedrecursively:– BaseCases:EachsymbolaÎ S aswellasthesymbolse andÆ are

regularexpressions:• ageneratestheatomiclanguageL(a)={a}• e generatesthelanguageL(e)={e}• Æ generatestheemptylanguageL(Æ)={}=Æ

– InductiveCases:ifr1 andr2areregularexpressionssoarer1Èr2,(r1)(r2),(r1)*and(r1)+:• L(r1Èr2)=L(r1)ÈL(r2),sor1Èr2generatestheunion• L((r1)(r2))=L(r1)•L(r2),so(r1)(r2) istheconcatenation• L((r1)*)=L(r1)*, so(r1)* representstheKleene-*• L((r1)+)=L(r1)+,so(r1)+ representstheKleene-+

Page 79: Vending machine dispenses soda for $0.45 a pop. Accepts ...

RegularExpressions:TableofOperationsincludingUNIX

Operation Notation Language UNIX

Union r1Èr2 L(r1)ÈL(r2) r1|r2

Concatenation (r1)(r2) L(r1)•L(r2) (r1)(r2)

Kleene-* (r )* L(r )* (r )*

Kleene-+ (r )+ L(r )+ (r )+

Exponentiation (r )n L(r )n (r ){n}

Page 80: Vending machine dispenses soda for $0.45 a pop. Accepts ...

RegularExpressions:Simplifications

• Justasalgebraicformulascanbesimplifiedbyusinglessparentheseswhentheorderofoperationsisclear,regularexpressionscanbesimplified.Usingthepuredefinitionofregularexpressionstoexpressthelanguage{banana,nab}*wewouldbeforcedtowritesomethingnastylike

((((b)(a))(n))(((a)(n))(a))È(((n)(a))(b)))*

• Usingtheoperatorprecedenceordering*,• ,È andtheassociativityof• allowsustoobtainthesimpler:

(bananaÈnab)*

• Thisisdoneinthesamewayasonewouldsimplifythealgebraicexpressionwithre-orderingdisallowed:

((((b)(a))(n))(((a)(n))(a))+(((n)(a))(b)))4=(banana+nab)4

Page 81: Vending machine dispenses soda for $0.45 a pop. Accepts ...

RegularExpressions:Example

• Question:Findaregularexpressionthatgeneratesthelanguageconsistingofallbit-stringswhichcontainastreakofseven0’sorcontaintwodisjointstreaksofthree1’s.– Legal:010000000011010,01110111001,111111– Illegal:11011010101,10011111001010,00000100000

• Answer:(0È1)*(07È13(0È1)*13)(0È1)*– Anevenbriefervalidansweris:S*(07È13S*13)S*– Theofficial answerusingonlythestandardregularoperationsis:

(0È1)*(0000000È111(0È1)*111)(0È1)*– AbriefUNIXansweris:

(0|1)*(0{7}|1{3}(0|1)*1{3})(0|1)*

Page 82: Vending machine dispenses soda for $0.45 a pop. Accepts ...

RegularExpressions:Examples

1) 0*10*

2) (SS)*

3) 1*Ø

4) S ={0,1},{w|whasatleastone1}

5) S ={0,1},{w|wstartsandendswiththesamesymbol}

6) {w|wisanumericalconstantwithsignand/orfractionalpart}• E.g.3.1415,-.001,+2000

Page 83: Vending machine dispenses soda for $0.45 a pop. Accepts ...

RegularExpressions:Adifferentview…

• Regularexpressionsarejuststrings.Consequently,thesetofallregularexpressionsisasetofstrings,sobydefinitionisalanguage.

• Question:Supposingthatonlyunion,concatenationandKleene-*areconsidered.Whatisthealphabetforthelanguageofregularexpressionsoverthebasealphabet S ?

• Answer:S È {(,),È,*}

Page 84: Vending machine dispenses soda for $0.45 a pop. Accepts ...

REXà NFA

• SinceNFA’sareclosedundertheregularoperationsweimmediatelyget

• Theorem:GivenanyregularexpressionrthereisanNFANwhichsimulatesr.Thatis,thelanguageacceptedbyN ispreciselythelanguagegeneratedbyr sothatL(N)=L(r).Furthermore,theNFAisconstructibleinlineartime.

Page 85: Vending machine dispenses soda for $0.45 a pop. Accepts ...

REXà NFA

• Proof:Theproofworksbyinduction,usingtherecursivedefinitionofregularexpressions.FirstweneedtoshowhowtoacceptthebasecaseregularexpressionsaÎS, e andÆ.ThesearerespectivelyacceptedbytheNFA’s:

• Finally,weneedtoshowhowtoinductivelyacceptregularexpressionsformedbyusingtheregularoperations.Thesearejusttheconstructionsthatwesawbefore,encapsulatedby:

q0 q0q1q0a

Page 86: Vending machine dispenses soda for $0.45 a pop. Accepts ...

REXà NFAexercise:FindNFAfor )* ∪ ) ∗

Page 87: Vending machine dispenses soda for $0.45 a pop. Accepts ...

REXà NFA:Example

• Question:FindanNFAfortheregularexpression(0È1)*(0000000È111(0È1)*111)(0È1)*

ofthepreviousexample.

Page 88: Vending machine dispenses soda for $0.45 a pop. Accepts ...

REXà NFAà FA?!?

• ThefactthatregularexpressionscanbeconvertedintoNFA’smeansthatitmakessensetocallthelanguagesacceptedbyNFA’s“regular.”

• However,theregularlanguagesweredefinedtobethelanguagesacceptedbyFA’s,whicharebydefault,deterministic.ItwouldbeniceifNFA’scouldbe“determinized”andconvertedtoFA’s,forthenthedefinitionof“regular”languages,asbeingFA-acceptedwouldbejustified.

• Let’strythisnext.

Page 89: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFA’shave3typesofnon-determinism

Nondeterminismtype

MachineAnalog

d -function Easy to fix? Formally

Under-determined Crash No output yes, fail-state |d(q,a)|= 0

Over-determined Randomchoice

Multi-valued no |d(q,a)|> 1

ePause reading

Redefine alphabet no |d(q,e)|> 0

Page 90: Vending machine dispenses soda for $0.45 a pop. Accepts ...

DeterminizingNFA’s:Example

• Idea:Wemightkeeptrackofallparallelactivestatesastheinputisbeingcalledout.Ifattheendoftheinput,oneoftheactivestateshappenedtobeanacceptstate,theinputwasaccepted.

• Example,considerthefollowingNFA,anditsdeterministicFA.

1

2 3

a

a

e

a,b

b

Page 91: Vending machine dispenses soda for $0.45 a pop. Accepts ...

One-Slide-RecipetoDerandomize

• InsteadofthestatesintheNFA,weconsiderthepower-states intheFA.(IftheNFAhasnstates,theFAhas2n states.)

• Firstwefigureoutwhichpower-stateswillreachwhichpower-statesintheFA.(UsingtherulesoftheNFA.)

• Thenwemustaddallepsilon-edges:Weredirectpointersthatareinitiallypointingtopower-state{a,b,c}topower-state{a,b,c,d,e,f},ifandonlyifthereisanepsilon-edge-only-pathpointingfromanyofthestatesa,b,ctostatesd,e,f(a.k.a.transitiveclosure).Wedotheverysameforthestartingstate:startingstateofFA={startingstateofNFA,allNFAstatesthatcanrecursivelybereachedfromthere}

• Acceptingstates oftheFAareallstatesthatincludeaacceptingNFAstate.

Page 92: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Remarks

• Thepreviousrecipecanbemadetotallyformal.Moredetailscanbefoundinthereadingmaterial.

• JustfollowingtherecipewilloftenproduceatoocomplicatedFA.Sometimesobvioussimplificationscanbemade.Ingeneralhowever,thisisnotaneasytask.

Page 93: Vending machine dispenses soda for $0.45 a pop. Accepts ...

AutomataSimplification

• TheFAcanbesimplified.States{1,2}and{1},forexample,cannotbereached.StilltheresultisnotassimpleastheNFA.

Page 94: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Derandomization Exercise

• Exercise:Let’sderandomize thesimplifed two-stateNFAfromslide1/70whichwederivedfromregularexpression )* ∪ ) ∗

x na b

aa

Page 95: Vending machine dispenses soda for $0.45 a pop. Accepts ...

REXà NFAà FA

• Summary:StartingfromanyNFA,wecanusesubsetconstructionandtheepsilon-transitive-closuretofindanequivalentFAacceptingthesamelanguage.Thus,

• Theorem:IfLisanylanguageacceptedbyanNFA,thenthereexistsaconstructible[deterministic]FAwhichalsoacceptsL.

• Corollary:Theclassofregularlanguagesisclosedundertheregularoperations.

• Proof:SinceNFA’sareclosedunderregularoperations,andFA’sarebydefaultalsoNFA’s,wecanapplytheregularoperationstoanyFA’sanddeterminizeattheendtoobtainanFAacceptingthelanguagedefinedbytheregularoperations.

Page 96: Vending machine dispenses soda for $0.45 a pop. Accepts ...

REXà NFAà FAà REX…

• WeareonestepawayfromshowingthatFA’s» NFA’s» REX’s;i.e.,allthreerepresentationareequivalent.Wewillbedonewhenwecancompletethecircleoftransformations:

FA

NFA

REX

Page 97: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFAà REXissimple?!?

• ThenFAà REXevensimpler!

• Pleasesolvethissimpleexample:

1

0

0

1

1

11

0

00

Page 98: Vending machine dispenses soda for $0.45 a pop. Accepts ...

REXà NFAà FAà REX…

• InconvertingNFA’stoREX’swe’llintroducethemostgeneralizednotionofanautomaton,thesocalled“GeneralizedNFA”or“GNFA”.InconvertingintoREX’s,we’llfirstgothroughaGNFA:

FA

NFA

REX

GNFA

Page 99: Vending machine dispenses soda for $0.45 a pop. Accepts ...

GNFA’s

• Definition:Ageneralizednondeterministicfiniteautomaton(GNFA) isagraphwhoseedgesarelabeledbyregularexpressions,– withauniquestartstatewithin-degree0,butarrowstoevery

otherstate– andauniqueacceptstatewithout-degree0,butarrowsfrom

everyotherstate(notethatacceptstate¹ startstate)– andanarrowfromanystatetoanyotherstate(includingself).

• AGNFAaccepts astringsifthereexistsapathp fromthestartstatetotheacceptstate suchthatw isanelementofthelanguagegeneratedbytheregularexpressionobtainedbyconcatenatingalllabelsoftheedgesinp.

• Thelanguageaccepted byaGNFAconsistsofalltheacceptedstringsoftheGNFA.

Page 100: Vending machine dispenses soda for $0.45 a pop. Accepts ...

GNFAExample

• ThisisaGNFAbecauseedgesarelabeledbyREX’s,startstatehasnoin-edges,andtheunique acceptstatehasnoout-edges.

• Convinceyourselfthat000000100101100110isaccepted.

b

c

0Èe

000

a

(0110È1001)*

Page 101: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFAà REXconversionprocess

1. ConstructaGNFAfromtheNFA.A. Iftherearemorethanonearrowsfromonestatetoanother,unify

themusing“È”B. Createauniquestartstatewithin-degree0C. Createauniqueacceptstateofout-degree0D. [Ifthereisnoarrowfromonestatetoanother,insertonewith

labelØ]

2. Loop:AslongastheGNFAhasstrictlymorethan2states:Ripoutarbitraryinteriorstateandmodifyedgelabels.

3. Theansweristheuniquelabelr.

acceptstartr

Page 102: Vending machine dispenses soda for $0.45 a pop. Accepts ...

NFAà REX:RippingOut.

• Rippingoutisdoneasfollows.Ifyouwanttoripthemiddlestatevout(forallpairsofneighborsu,w)…

• …thenyou’llneedtorecreateallthelostpossibilitiesfromutow.I.e.,tothecurrentREXlabelr4oftheedge(u,w)youshouldaddtheconcatenationofthe(u,v )labelr1followedbythe(v,v )-looplabelr2repeatedarbitrarily,followedbythe(v,w )labelr3..Thenew(u,w)substitutewouldthereforebe:

v wur3

r2

r1

r4

wur4 È r1 (r2)*r3

Page 103: Vending machine dispenses soda for $0.45 a pop. Accepts ...

FAà REX:Example

Page 104: Vending machine dispenses soda for $0.45 a pop. Accepts ...

FAà REX:Exercise

Page 105: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Summary:FA≈ NFA≈ REX

• Thiscompletesthedemonstrationthatthethreemethodsofdescribingregularlanguagesare:

1. DeterministicFA’s2. NFA’s3. RegularExpressions

• Wehavelearntthatalltheseareequivalent.

Page 106: Vending machine dispenses soda for $0.45 a pop. Accepts ...

RemarkaboutAutomatonSize

• Creatinganautomatonofsmallsizeisoftenadvantageous.– Allowsforsimpler/cheaperhardware,orbetterexamgrades.– Designing/Minimizingautomataisthereforeafunnysport.Example:

a

b

1

d

0,1

e

0,1

1

c

0,1

gf

0

0

0

01

1

Page 107: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Minimization

• Definition:Anautomatonisirreducible if– itcontainsnouselessstates,and– notwodistinctstatesareequivalent.

• Byjustfollowingthesetworules,youcanarriveatan“irreducible”FA.Generally,suchalocalminimumdoesnothavetobeaglobalminimum.

• Itcanbeshownhowever,thattheseminimizationrulesactuallyproducetheglobalminimumautomaton.

• Theideaisthattwoprefixesu,v areindistinguishableiff forallsuffixesx,ux Î Liff vx Î L.Ifuandvaredistinguishable,theycannotendupinthesamestate.Thereforethenumberofstatesmustbeatleastasmanyasthenumberofpairwisedistinguishableprefixes.

Page 108: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Pigeonholeprinciple

• ConsiderlanguageL,whichcontainswordw Î L.• ConsideranFAwhichacceptsL,withn<|w|states.• Then,whenacceptingw,theFAmustvisitatleastonestatetwice.

• Thisisaccordingtothepigeonhole(a.k.a.Dirichlet)principle:– Ifm>npigeonsareputintonpigeonholes,there'saholewith

morethanonepigeon.– That’saprettyfancynameforaboringobservation...

Page 109: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Languageswithunboundedstrings

• Consequently,regularlanguageswithunboundedstringscanonlyberecognizedbyFA(finite!bounded!)automataiftheselongstringsloop.

• TheFAcanenterthelooponce,twice,…,andnotatall.• Thatis,languageLcontainsall {xz,xyz,xy2z,xy3z,…}.

Page 110: Vending machine dispenses soda for $0.45 a pop. Accepts ...

PumpingLemma

• Theorem:GivenaregularlanguageL,thereisanumberp (calledthepumpingnumber)suchthatanystringinLoflength³ pispumpablewithinitsfirstp letters.

• Inotherwords,forallu Î Lwith|u |³ pwecanwrite:– u=xyz (xisaprefix,zisasuffix)– |y|³ 1 (mid-portionyisnon-empty)– |xy|£ p (pumpingoccursinfirstpletters)– xyizÎ Lforalli ³ 0(canpumpy-portion)

• If,ontheotherhand,thereisnosuchp,thenthelanguageisnotregular.

Page 111: Vending machine dispenses soda for $0.45 a pop. Accepts ...

PumpingLemmaExample

• LetLbethelanguage{0n1n |n³ 0}

• Assume(forthesakeofcontradiction)thatLisregular• Letp bethepumpinglength.Letu bethestring0p1p.• Let’scheckstringuagainstthepumpinglemma:

• “Inotherwords,forallu Î Lwith|u |³ pwecanwrite:– u=xyz (xisaprefix,zisasuffix)– |y|³ 1 (mid-portionyisnon-empty)– |xy|£ p (pumpingoccursinfirstpletters)– xyiz Î Lforalli ³ 0(canpumpy-portion)”

à y = 0+

à Then, xz or xyyz is not in L. Contradiction!

Page 112: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Let’smaketheexampleabitharder…

• LetLbethelanguage{w|whasanequalnumberof0sand1s}

• Assume(forthesakeofcontradiction)thatLisregular• Letp bethepumpinglength.Letu bethestring0p1p.• Let’scheckstringuagainstthepumpinglemma:

• “Inotherwords,forallu Î Lwith|u |³ pwecanwrite:– u=xyz (xisaprefix,zisasuffix)– |y|³ 1 (mid-portionyisnon-empty)– |xy|£ p (pumpingoccursinfirstpletters)– xyiz Î Lforalli ³ 0(canpumpy-portion)”

Page 113: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Harderexamplecontinued

• Again,ymustconsistof0sonly!• Pumpitthere!Clearlyagain,ifxyzÎ L,thenxz orxyyz arenotinL.

• There’sanotheralternativeproofforthisexample:– 0*1*isregular.– Ç isaregularoperation.– IfLregular,thenLÇ 0*1*isalsoregular.– However,LÇ 0*1*isthelanguagewestudiedinthepreviousexample(0n1n).

Acontradiction.

Page 114: Vending machine dispenses soda for $0.45 a pop. Accepts ...

Nowyoutry…

• Is-. = 00 0 ∈ 0 ∪ 1 ∗} regular?

• Is-6 = 17 8beingaprimenumber} regular?