0% found this document useful (0 votes)
33 views

Finite State Automata

computability theory
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Finite State Automata

computability theory
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Finite State

Automata
Natalie Parde
UIC CS 421
• Computational models that can generate
regular languages (such as those
specified by a regular expression)
What are • Also used in other NLP applications that
function by transitioning between finite
finite state states
• Dialogue systems
automata? • Morphological parsing
• Singular: Finite State Automaton (FSA)
• Plural: Finite State Automata (FSAs)

Natalie Parde - UIC CS 421


Key Components

• Finite set of states


• Start state
• Final state
• Set of transitions from one state to another

Natalie Parde - UIC CS 421


How do FSAs work?
• For a given sequence of items (characters, words, etc.) to match, begin in
the start state
• If the next item in the sequence matches a state that can be
transitioned to from the current state, go to that state
• Repeat
• If no transitions are possible, stop
• If the state you stopped in is a final state, accept the sequence

Natalie Parde - UIC CS 421


FSAs are often represented
graphically.
• Nodes = states
• Arcs = transitions

b a a !

q0 q1 q2 q3 q4

Natalie Parde - UIC CS 421


• Five states
• q0 is the start state
• q4 is the final (accept) state
• Five transitions
What do • Alphabet = {a, b, !}

we know
about this b a a !

FSA? q0 q1 q2 q3 q4

Natalie Parde - UIC CS 421


Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baabaa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baabaa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baabaa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baabaa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baabaa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baabaa!
Natalie Parde - UIC CS 421
Regex that this FSA matches: baa+!

b a a !

q0 q1 q2 q3 q4

a
Test String: baabaa!
Natalie Parde - UIC CS 421
Note: More than one FSA can correspond
to the same regular language!
b a a !

Test String: q0 q1 q2 q3 q4
baaa!

a
b a a !

Test String: q0 q1 q2 q3 q4
baaa!

a
Natalie Parde - UIC CS 421
• A finite state automaton can be specified by
enumerating the following properties:
• The set of states, Q
• A finite alphabet, Σ
Formal • A start state, q0
Definition • A set of accept/final states, F⊆Q
• A transition function or transition matrix
between states, δ(q,i)
• δ(q,i): Given a state q∈Q and input i∈Σ,
δ(q,i) returns a new state q’∈Q.

Natalie Parde - UIC CS 421


Example: FSA for Dollar Amounts
One Six Ten Sixty Eleven Sixteen One Six Ten Sixty Eleven Sixteen
Two Seven Twenty Seventy Twelve Seventeen Two Seven Twenty Seventy Twelve Seventeen
Three Eight Thirty Eighty Thirteen Eighteen Three Eight Thirty Eighty Thirteen Eighteen
Four Nine Forty Ninety Fourteen Nineteen Four Nine Forty Ninety Fourteen Nineteen
Five Fifty Fifteen Five Fifty Fifteen

q0 q1 q2 q4 q5 q6 q7

dollars cents

Twenty Sixty One Six Twenty Sixty One Six


Thirty Seventy Two Seven cents Thirty Seventy Two Seven
Forty Eighty Three Eight Forty Eighty Three Eight
Fifty Ninety Four Nine Fifty Ninety Four Nine
Five Five
q3

Accept States
Natalie Parde - UIC CS 421
State transitions in FSAs can be
represented using tables.
b a a !

q0 q1 q2 q3 q4

a
Next Item in Sequence
b a ! <end>
Currently in State

q0
q1
q2
q3
q4
Natalie Parde - UIC CS 421
State transitions in FSAs can be
represented using tables.
b a a !

q0 q1 q2 q3 q4

a
Next Item in Sequence
b a ! <end>
Currently in State

q0 q1
q1
q2 Go to State
q3
q4
Natalie Parde - UIC CS 421
State transitions in FSAs can be
represented using tables.
b a a !

q0 q1 q2 q3 q4

a
Next Item in Sequence
b a ! <end>
Currently in State

q0 q1 L L L
q1
q2 Go to State
q3
q4
Natalie Parde - UIC CS 421
State transitions in FSAs can be
represented using tables.
b a a !

q0 q1 q2 q3 q4

a
Next Item in Sequence
b a ! <end>
Currently in State

q0 q1 L L L
q1 L q2
q2 Go to State
q3
q4
Natalie Parde - UIC CS 421
State transitions in FSAs can be
represented using tables.
b a a !

q0 q1 q2 q3 q4

a
Next Item in Sequence
b a ! <end>
Currently in State

q0 q1 L L L
q1 L q2 L L
q2 L q3 Go to State
q3
q4
Natalie Parde - UIC CS 421
State transitions in FSAs can be
represented using tables.
b a a !

q0 q1 q2 q3 q4

a
Next Item in Sequence
b a ! <end>
Currently in State

q0 q1 L L L
q1 L q2 L L
q2 L q3 L L Go to State
q3 L q3
q4
Natalie Parde - UIC CS 421
State transitions in FSAs can be
represented using tables.
b a a !

q0 q1 q2 q3 q4

a
Next Item in Sequence
b a ! <end>
Currently in State

q0 q1 L L L
q1 L q2 L L
q2 L q3 L L Go to State
q3 L q3 q4
q4
Natalie Parde - UIC CS 421
State transitions in FSAs can be
represented using tables.
b a a !

q0 q1 q2 q3 q4

a
Next Item in Sequence
b a ! <end>
Currently in State

q0 q1 L L L
q1 L q2 L L
q2 L q3 L L Accept!
q3 L q3 q4 L
q4 L L L J
Natalie Parde - UIC CS 421
State transition tables simplify the
process of determining whether your input
will be accepted by the FSA.
• For a given sequence of items to match, begin in the start
state with the first item in the sequence
• Consult the table …is a transition to any other state
permissible with the current item?
• If so, move to the state indicated by the table
• If you make it to the end of your sequence and to a final state,
accept

Natalie Parde - UIC CS 421


Formal Algorithm
index ← beginning of sequence
current_state ← initial state of FSA
loop:
if end of sequence has been reached:
if current_state is an accept state:
return accept
else:
return reject
else if transition_table[current_state, sequence[index]] is empty:
return reject
else:
current_state ← transition_table[current_state, sequence[index]]
index ← index + 1
end

Natalie Parde - UIC CS 421


Deterministic vs. Non-Deterministic
FSAs

Non-Deterministic
Deterministic FSA: At
FSA: At one or more
each point in processing
points in processing a
a sequence, there is one
sequence, there are
unique thing to do (no
multiple permissible next
choices!)
steps (choices!)

Natalie Parde - UIC CS 421


Deterministic or Non-Deterministic?

b a a !

q0 q1 q2 q3 q4

a
b a a !

q0 q1 q2 q3 q4

a
Natalie Parde - UIC CS 421
Deterministic or Non-Deterministic?

b a a !
If input is !, do this
Deterministic! q0 q1 q2 q3 q4

If input is a, do this
a
b a a !

q0 q1 q2 q3 q4

a
Natalie Parde - UIC CS 421
Deterministic or Non-Deterministic?

b a a !
If input is !, do this
Deterministic! q0 q1 q2 q3 q4

If input is a, do this
a
b a a !

If input is a, do ?
Non-Deterministic! q0 q1 q2 q3 q4

a
Natalie Parde - UIC CS 421
Every non-
deterministic • This means that both are equally
FSA can be powerful!
converted to a • Deterministic FSAs can accept as many
deterministic languages as non-deterministic ones
FSA.

Natalie Parde - UIC CS 421


• Two approaches:
Non-Deterministic 1. Convert the non-deterministic
FSA to a deterministic FSA and
FSAs: How to check then check that version
for input acceptance?
2. Manage the process as a state-
space search

Natalie Parde - UIC CS 421


There exists at least one path through
the FSA for an item that is part of the
language defined by the machine

Non- Not all paths directed through the FSA


Deterministic for an accept item lead to an accept
FSA Search state
Assumptions
No paths through the FSA lead to an
accept state for an item not in the
language

Natalie Parde - UIC CS 421


Non-Deterministic FSA Search
Assumptions

• Success: Path is found for a given item that ends in an accept


• Failure: All possible paths for a given item lead to failure

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


Example: Non-Deterministic FSA
Search
b a a !

q0 q1 q2 q3 q4

Test Input: baaa!

Natalie Parde - UIC CS 421


• States in the search space are pairings of
Non- sequence indices and states in the FSA

Deterministic • By keeping track of which states have and


have not been explored, we can
FSA Search systematically explore all the paths through
an FSA given an input

Natalie Parde - UIC CS 421


• You can apply set operations to any FSA
• Union
• Concatenation
• Negation
• For non-deterministic FSAs, first
Compositional convert to a deterministic FSA
FSAs • Intersection
• To do so, you may need to utilize an ϵ
transition
• ϵ transition: Move from one state to
another without consuming an item from
the input sequence

Natalie Parde - UIC CS 421


Summary: Finite State Automata

• FSAs are computational models that describe regular languages


• To determine whether an input item is a member of an FSA’s language, you can process it
sequentially from the start to (hopefully) the final state
• State transitions in FSAs can be represented using tables
• FSAs can be either deterministic or non-deterministic

Natalie Parde - UIC CS 421

You might also like