Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Finite and Bank Automata with the informal Examples | CS A385, Study notes of Computer Graphics

Material Type: Notes; Class: Computer Graphics; Subject: Computer Science ; University: University of Alaska - Anchorage; Term: Spring 2010;

Typology: Study notes

2009/2010

Uploaded on 03/28/2010

koofers-user-0pq
koofers-user-0pq 🇺🇸

10 documents

1 / 24

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Finite Automata
Finite Automata
Two types – both describe what are called regular
languages
Deterministic (DFA) – There is a fixed number of states and we
can only be in one state at a time
Nondeterministic (NFA) –There is a fixed number of states but we
can be in multiple states at one time
While NFA’s are more expressive than DFA’s, we will see
that adding nondeterminism does not let us define any
language that cannot be defined by a DFA.
One way to think of this is we might write a program using
a NFA, but then when it is “compiled” we turn the NFA
into an equivalent DFA.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18

Partial preview of the text

Download Finite and Bank Automata with the informal Examples | CS A385 and more Study notes Computer Graphics in PDF only on Docsity!

Finite Automata

Finite Automata

  • Two types – both describe what are called regular

languages

  • Deterministic (DFA) – There is a fixed number of states and we can only be in one state at a time
  • Nondeterministic (NFA) –There is a fixed number of states but we can be in multiple states at one time
  • While NFA’s are more expressive than DFA’s, we will see

that adding nondeterminism does not let us define any

language that cannot be defined by a DFA.

  • One way to think of this is we might write a program using

a NFA, but then when it is “compiled” we turn the NFA

into an equivalent DFA.

Informal Example

• Customer shopping at a store with an electronic

transaction with the bank

  • The customer may pay the e-money or cancel the e-

money at any time.

  • The store may ship goods and redeem the electronic

money with the bank.

  • The bank may transfer any redeemed money to a

different party, say the store.

• Can model this problem with three automata

Bank Automata

Start

Cancel

Pay

Customer

Start Bank

Cancel

Redeem Transfer

a b^ d^ f

c e (^) g

Start

pay redeem transfer

redeem transfer

ship ship ship

Store

Actions in bold are initiated by the entity. Otherwise, the actions are initiated by someone else and received by the specified automata

Entire System as Automaton

  • When there are multiple automata for a system, it is useful to incorporate all of the automata into a single one so that we can better understand the interaction.
  • Called the product automaton. The product automaton creates a new state for all possible states of each automaton.
  • Since the customer automaton only has one state, we only need to consider the pair of states between the bank and the store. - For example, we start in state (a,1) where the store is in its start state, and the bank is in its start state. From there we can move to states (a,2) if the bank receives a cancel, or state (b,1) if the store receives a pay.
  • To construct the product automaton, we run the bank and store automaton “in parallel” using all possible inputs and creating an edge on the product automaton to the corresponding set of states.

Product Automaton

a b c d e f g

start

C C C

P

P

S

S

R

R

S

T

T

S

Product Automaton

  • How is this useful? It can help validate our protocol.
  • It tells us that not all states are reachable from the start

state.

  • For example, we should never be in state (g,1) where we have shipped and transferred cash, but the bank is still waiting for a redeem.
  • It allows us to see if potential errors can occur.
  • We can reach state (c, 2). This is problematic because it allows a product to be shipped but the money has not been transferred to the store.
  • In contrast, we can see that if we reach state (d, 3) or (e, 3) then the store should be okay – a transfer from the bank must occur
  • assuming the bank automaton doesn’t “die” which is why it is useful to add arcs for all possible inputs to complete the automaton

Simple Example – 1 way door

  • As an example, consider a

one-way automatic door.

This door has two pads

that can sense when

someone is standing on

them, a front and rear pad.

We want people to walk

through the front and

toward the rear, but not

allow someone to walk the

other direction:

Front

Pad

Rear

Pad

One Way Door – Formal Notation

Using our formal notation, we have:

Q = {C, O} (usually we’ll use q 0 and q 1 instead)

F = {} There is no final state

q 0 = C This is the start state

 = {a,b,c,d}

The transition function, δ , can be specified by the table:

a b c c

 C C O C C

O C O O O

The start state is indicated with the 

If there are final accepting states, that is indicated with a * in the proper row.

Write each (state,symbol)?

Exercise

• Using ={0,1} a “clamping” circuit waits for a 1

input, and forever after makes a 1 output

regardless of the input. However, to avoid

clamping on spurious noise, design a DFA that

waits for two 1's in a row, and “clamps” only then.

• Write the transition function in table format as

well as graph format.

Formal Definition of Computation

• Let M = (Q, , ,q 0 , F) be a finite

automaton and let w = w 1 w 2 …wn be a string

where each wi is a member of alphabet .

• M accepts w if a sequence of states r 0 r 1 …rn

in Q exists with three conditions:

1. r 0 = q 0

2. (ri, wi+1) = ri+1 for i=0, … , n-

3. rn ∈ F

We say that M recognizes language A if A = {w | M accepts w }

In other words, the language is all of those strings that are accepted

by the finite automata.

DFA Example

• Here is a DFA for the

language that is the set

of all strings of 0’s

and 1’s whose

numbers of 0’s and 1’s

are both even:

q 3

q 0 q 1

q 2

Start

1

1

1

1

0 0 0 0

Marble Rolling Game

x

x

x

A B

C D

Marble Game Notation

  • The inputs and outputs (A-D) become the alphabet of the automaton, while the levers indicate the possible states.
  • If we define the initial status of each lever to be a 0, then if the levers change direction they are in state 1.
  • Let’s use the format x 1 x 2 x 3 to indicate a state. The initial state is 000. If we drop a marble down B, then the state becomes to 011 and the marble exits at C.
  • Since we have three levers that can take on binary values, we have 8 possible states for levers, 000 to 111.
  • Further identify the states by appending an “a” for acceptance, or “r” for rejection.
  • This leads to a total of 16 possible states. All we need to do is start from the initial state and draw out the new states we are led to as we get inputs from A or B.

Messy Marble DFA

Start (^) 000r 011r B

100r

A

010r

A

111r B

110r

A

B 001a

000a 101a

A

B

A

B

A

010a

B

A

110a B

B

A 101r

A

B A

B

A

B^ 100a

B

A

To 010r A To 111r B

Marble DFA – Table Format

• Easier to see in table

format. Note that not

all states are

accessible.

A B

  • 000r 100r 011r *000a 100r 011r *001a 101r 000a 010r 110r 001a *010a 110r 001a 011r 111r 010a 100r 010r 111r *100a 010r 111r 101r 011r 100a *101a 011r 100a 110r 000a 101a *110a 000a 101a 111r 001a 110a

Algebra for Languages

  1. The closure, star, or Kleene star of a language L is denoted L* and represents the set of strings that can be formed by taking any number of strings from L with repetition and concatenating them. It is a unary operator.

More specifically, L^0 is the set we can make selecting zero strings from L. L^0 is always {  }.

L^1 is the language consisting of selecting one string from L. L^2 is the language consisting of concatenations selecting two strings from L. … L* is the union of L^0 , L^1 , L^2 , … L∞ For example, if L = {0 , 10} then L^0 = {  }. L^1 = {0, 10 } L^2 = {00, 010, 100, 1010} L^3 = {000, 0010, 0100, 01010, 10010, 1000, 10100, 101010} … and L* is the union of all these sets, up to infinity.

Closure Properties of Regular

Languages

  • Closure refers to some operation on a language, resulting

in a new language that is of the same “type” as those

originally operated on

  • i.e., regular in our case
  • We won’t be using the closure properties extensively here;

consequently we will state the theorems and give some

examples. See the book for proofs of the theorems.

  • The regular languages are closed under union,

concatenation, and *. I.e., if A 1 and A 2 are regular

languages then

  • A 1 ∪ A 2 is also regular
  • A 1 A 2 is also regular
  • A 1 *^ is also regular Later we’ll see easy ways

to prove the theorems

Nondeterministic Finite Automata

  • A NFA (nondeterministic finite automata) is able to be in

several states at once.

  • In a DFA, we can only take a transition to a single deterministic state
  • In a NFA we can accept multiple destination states for the same input.
  • You can think of this as the NFA “guesses” something about its input and will always follow the proper path if that can lead to an accepting state.
  • Another way to think of the NFA is that it travels all possible paths, and so it remains in many states at once. As long as at least one of the paths results in an accepting state, the NFA accepts the input.
  • NFA is a useful tool
  • More expressive than a DFA.
  • BUT we will see that it is not more powerful! For any NFA we can construct a corresponding DFA
  • Another way to think of this is the DFA is how an NFA would actually be implemented (e.g. on a traditional computer)

NFA Example

• This NFA accepts

only those strings that

end in 01

• Running in “parallel

threads” for string

Start q 0 q 1 q 2 0 1

0,

q q q q q

1 1 0 0

q1 - stuck

q q

1

1

0

q

q q2 - stuck q q2 - accept

q q q q q

1 1 0 0

q1 - stuck

q q

1

1

0

q

q q2 - stuck q q2 - accept

NFA Example

• Practice with the following NFA to satisfy

yourself that it accepts , a, baba, baa, and

aa, but that it doesn’t accept b, bb, and

babba.

q

q2 q

b a

a

a,b

NFA Exercise

• Construct an NFA that will accept strings over

alphabet {1, 2, 3} such that the last symbol

appears at least twice, but without any intervening

higher symbol, in between:

  • e.g., 11, 2112, 123113, 3212113, etc.

• Trick: use start state to mean “I guess I haven't

seen the symbol that matches the ending symbol

yet.” Use three other states to represent a guess

that the matching symbol has been seen, and

remembers what that symbol is.

NFA Exercise

You should be able to generate the transition table

Formal Definition of an NFA

• Same idea as the DFA

• Let N = (Q, , ,q 0 , F) be an NFA and let w =

w 1 w 2 …wn be a string where each wi is a member

of alphabet .

• N accepts w if a sequence of states r 0 r 1 …rn in Q

exists with three conditions:

1. r 0 = q 0

2. ri+1 ∈ (ri, wi+1) for i=0, … , n-

3. rn ∈ F

Observe that (ri, wi+1) is the set of allowable next states

We say that N recognizes language A if A = {w | N accepts w }

Subset Construction Example (1)

• Consider the NFA:

Start q 0 q 1 q 2 0 1

0,

The power set of these

states is: { Ø, {q 0 }, {q 1 },

{q 2 }, {q 0 , q 1 }, {q 0 , q 2 },{q 1 ,

q 2 }, {q 0 , q 1 , q 2 } }

New transition function

with all of these states and

go to the set of possible

inputs:

*{q 0 , q 1 , {q 0 , q 1 } {q 0 , q 2 } q 2 }

*{q 1 , q 2 } Ø {q 2 }

*{q 0 , q 2 } {q 0 , q 1 } {q 0 }

{q 0 , q 1 } {q 0 , q 1 } {q 0 , q 2 }

*{q 2 } Ø Ø

{q 1 } Ø {q 2 }

 {q 0 } {q 0 , q 1 } {q 0 }

Ø Ø Ø

0 1

Subset Construction (2)

  • Many states may be unreachable from our start state. A good way to construct the equivalent DFA from an NFA is to start with the start states and construct new states on the fly as we reach them.

0 1 Ø Ø Ø  {q 0 } {q 0 , q 1 } {q 0 } {q 0 , q 1 } {q 0 , q 1 } {q 0 , q 2 } *{q 0 , q 2 } {q 0 , q 1 } {q 0 }

Graphically: {q

Start 0 } {q 0 , q 1 }^ {q 0 ,q 2 } 0 1

1

1 0

0

NFA to DFA Exercises

• Convert the following

NFA’s to DFA’s

Start q 0 q 1

a,b

a

b

15 possible states on

this second one (might

be easier to represent in

table format)

Corollary

• A language is regular if and only if some

nondeterministic finite automaton

recognizes it

• A language is regular if and only if some

deterministic finite automaton recognizes it