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

DFA Stanford

The document discusses finite automata which are mathematical machines that can determine if a string is part of a formal language. A finite automaton consists of a set of states connected by transitions and reads input strings one character at a time, transitioning between states. It begins in a designated start state and accepts or rejects the input string depending on what state it ends in after reading the entire string.

Uploaded by

Deepika
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)
117 views

DFA Stanford

The document discusses finite automata which are mathematical machines that can determine if a string is part of a formal language. A finite automaton consists of a set of states connected by transitions and reads input strings one character at a time, transitioning between states. It begins in a designated start state and accepts or rejects the input string depending on what state it ends in after reading the entire string.

Uploaded by

Deepika
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/ 66

Finite Automata

Part One

Problem
Problem SetSet Four
Four checkpoint
checkpoint
due
due in
in the
the box
box up
up front.
front.
Late
Late Problem
Problem Set
Set Three's
Three's
also
also due
due up
up front.
front.
Last Thoughts on First-Order Logic
An Extremely Important Table

When is this true? When is this false?


For any choice of x,
∀x. P(x) P(x) ∃x. ¬P(x)
For some choice of x,
∃x. P(x) P(x) ∀x. ¬P(x)
For any choice of x,
∀x. ¬P(x) ¬P(x) ∃x. P(x)
For some choice of x,
∃x. ¬P(x) ¬P(x) ∀x. P(x)
Negating First-Order Statements
● Use the equivalences
¬∀x. φ ≡ ∃x. ¬φ
¬∃x. φ ≡ ∀x. ¬φ
to negate quantifiers.
● Mechanically:
● Push the negation across the quantifier.
● Change the quantifier from ∀ to ∃ or vice-versa.
● Use techniques from propositional logic to
negate connectives.
Analyzing Relations

“R is a binary relation over set A that is not


reflexive”

¬∀a ∈ A. aRa
∃a ∈ A. ¬aRa

“Some a ∈ A is not related to itself by R.”


Analyzing Relations
“R is a binary relation over A that is not
antisymmetric”

¬∀x ∈ A. ∀y ∈ A. (xRy ∧ yRx → x = y)


∃x ∈ A. ¬∀y ∈ A. (xRy ∧ yRx → x = y)
∃x ∈ A. ∃y ∈ A. ¬(xRy ∧ yRx → x = y)
∃x ∈ A. ∃y ∈ A. (xRy ∧ yRx ∧ ¬(x = y))
∃x ∈ A. ∃y ∈ A. (xRy ∧ yRx ∧ x ≠ y)

“Some x ∈ A and y ∈ A are related to one


another by R, but are not equal”
A Useful Equivalence
● The following equivalences are useful when
negating statements in first-order logic:
¬(p ∧ q) ≡ p → ¬q
¬(p → q) ≡ p ∧ ¬q
● These identities are useful when negating
statements involving quantifiers.
● ∧ is used in existentially-quantified statements.
● → is used in universally-quantified statements.
Negating Quantifiers
● What is the negation of the following
statement?
∃x. (Puppy(x) ∧ Cute(x))
● We can obtain it as follows:
¬∃x. (Puppy(x) ∧ Cute(x))
∀x. ¬(Puppy(x) ∧ Cute(x))
∀x. (Puppy(x) → ¬Cute(x))
● “All puppies are not cute.”
Uniqueness
Uniqueness
● Often, statements have the form “there is a
unique x such that …”
● Some sources use a uniqueness quantifier to
express this:
∃!n. P(n)
● However, it's possible to encode uniqueness
using just the two quantifiers we've seen.
∃!n. P(n) ≡ ∃n. (P(n) ∧ ∀m. (P(m) → m = n))
In CS103, do not use the ∃! quantifier. Just use
∃ andisis∀.
There
There some
some nn And
And whenever
whenever PP isis
where
where P(n)
P(n) isis true
true true,
true, itit must
must be
be for
for n.
n.
Uniqueness
● Often, statements have the form “there is a
unique x such that …”
● Some sources use a uniqueness quantifier to
express this:
∃!n. P(n)
● However, it's possible to encode uniqueness
using just the two quantifiers we've seen.
∃!n. P(n) ≡ ∃n. (P(n) ∧ ∀m. (P(m) → m = n))
● In CS103, do not use the ∃! quantifier. Just use
∃ and ∀.
Summary of First-Order Logic
● Predicates allow us to reason about
different properties of the same object.
● Functions allow us to transform objects
into one another.
● Quantifiers allow us to reason about
properties of some or all objects.
● There are many useful identities for
negating first-order formulae.
An Important
Milestone
Recap: Discrete Mathematics
● The past four weeks have focused exclusively on
discrete mathematics:
Induction Functions
Graphs The Pigeonhole Principle
Relations Logic
Set Theory Cardinality
● These are the building blocks we will use
throughout the rest of the quarter.
● These are the building blocks you will use
throughout the rest of your CS career.
Next Up: Computability Theory
● It's time to switch gears and address the limits of
what can be computed.
● We'll explore
● What is the formal definition of a computer?
● What might computers look like with various resource
constraints?
● What problems can be solved by computers?
● What problems can't be solved by computers?
● Get ready to explore the boundaries of what
computers could ever be made to do.
Computability Theory
What problems can we solve with a computer?

What kind of
computer?
An automaton (plural: automata) is a
mathematical model of a computing device.
Why Build Models?
● The models of computation we will explore in
this class correspond to different conceptions of
what a computer could do.
● Finite automata (this week) are an abstraction
of computers with finite resource constraints.
● Provide upper bounds for the computing machines
that we can actually build.
● Turing machines (later) are an abstraction of
computers with unbounded resources.
● Provide upper bounds for what we could ever hope
to accomplish.
What problems can we solve with a computer?

What is a
“problem?”
Strings
● An alphabet is a finite set of characters.
● Typically, we use the symbol Σ to refer to an
alphabet.
● A string is a finite sequence of characters drawn
from some alphabet.
● Example: If Σ = {a, b}, some valid strings include
● a
● aabaaabbabaaabaaaabbb
● abbababba
● The empty string contains no characters and is
denoted ε.
Languages
● A formal language is a set of strings.
● We say that L is a language over Σ if it is a
set of strings formed from characters in Σ.
● Example: The language of palindromes over
Σ = {a, b, c} is the set
{ε, a, b, c, aa, bb, cc, aaa, aba, aca, bab, … }
● The set of all strings composed from letters in
Σ is denoted Σ*.
● Formally: L is a language over Σ iff L ⊆ Σ*.
The Model
● Goal: Given an alphabet Σ and a
language L over Σ, can we build an
automaton that can determine which
strings are in L?
● Actually a very expressive and powerful
framework; we'll see this over the next
few weeks.
To Summarize
● An automaton is an idealized
mathematical computing machine.
● A language is a set of strings.
● The automata we will study will accept as
input a string and (attempt to) output
whether that string is contained in a
particular language.
What problems can we solve with a computer?
Finite Automata
A finite automaton is a mathematical
machine for determining whether a string
is contained within some language.
Each finite automaton consists of a set
of states connected by transitions.
A Simple Finite Automaton
0
start
q0 q1
0

1 1 1 1

0
q3 q2
0
Each
Each circle
circle
represents aa state
represents state
of
of the
the automaton.
automaton.
A Simple Finite Automaton
0
start
q0 q1
0

1 1 1 1

0
q3 q2
0
One
One special
special state
state isis
designated
designated as as the
the
start
start state.
state.
A Simple Finite Automaton
0
start
q0 q1
0

1 1 1 1
The
The automaton
automaton isis
run
run on an input
on an input 0
string
string and
and answers
answers q3 q2
“yes”
“yes” or
or “no.”
“no.”
0

0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0

The
The automaton
automaton can
can
be in one state at
1a 1 1 1
be in one state at a
time.
time. ItIt begins
begins inin
the start
the start state.
state. 0
q3 q2
0

0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0
The
The automaton
automaton now
now
begins 1 1 1 1
begins processing
processing
characters
characters inin the
the
order
order inin which
which they
they 0
appear.
appear. q3 q2
0

0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0

1 1 1 1
Each
Each arrow
arrow inin this
this
diagram
diagram represents
represents aa
0
q3 q2 transition.
transition. The
The
automaton
automaton always
always
0 follows
follows the
the transition
transition
corresponding
corresponding to to the
0 1 0 1 1 0 the
current
current symbol
symbol being
being
read.
read.
A Simple Finite Automaton
0
start
q0 q1
0
After
After transitioning,
transitioning,
the
the automaton
1 1 1 1 automaton
considers
considers the
the next
next
symbol
symbol inin the
the
0 input.
input.
q3 q2
0

0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0
The
The double
double circle
circle
Now
Now that
that the
the
indicates
indicates that
that this
this
automaton
automaton has
has 1 1 1 1 state
state isis an
an
looked
looked at at all
all this
this
accepting
accepting state,
state,
input,
input, itit can
can decide
decide
so
so the
the automaton
automaton
whether
whether to
to say
say “yes”
“yes” 0
q3 q2 outputs
outputs “yes.”
“yes.”
or
or “no.”
“no.”
0

0 1 0 1 1 0
A Simple Finite Automaton
0
start
q0 q1
0
This
This state
state isis not
not
an
an accepting
accepting state,
state,
1 1 1 1
so
so the
the automaton
automaton
says
says “no.”
“no.”
0
q3 q2
0

1 0 1 0 0 0
A Simple Finite Automaton
0
start
q0 q1
0
Try
Try itit yourself!
yourself!
Does
Does the
1 1 1 1 the
automaton accept
automaton accept
(say
(say yes)
yes) or
or
0 reject
reject (say
(say no)?
no)?
q3 q2
0

1 1 0 1 1 1 0 0
The Story So Far
● A finite automaton is a collection of states
joined by transitions.
● Some state is designated as the start state.
● Some states are designated as accepting states.
● The automaton processes a string by beginning in
the start state and following the indicated
transitions.
● If the automaton ends in an accepting state, it
accepts the input.
● Otherwise, the automaton rejects the input.
Time-Out For Announcements
Midterm Exam
● Midterm is October 29 from 7PM – 10PM.
● Location information TBA.
● Need to take the exam at an alternate time? Fill
out the alternate time form ASAP.
● Covers material up through and including DFAs.
● Two practice exams available online.
● Handout: Exam Strategies and Policies
available online.
● Review session later this week; more details
on Wednesday.
Your Questions
“Keith, why did you choose to go into
academia as opposed to industry? Do you
have any advice for students deciding
between the two?”
“What do you think is the coolest
real-world application of CS103-related
material?”
“Why are you taking away the Checkpoint
problems... don't?”
Back to CS103!
A finite automaton does not accept as soon
as the input enters an accepting state.

A finite automaton accepts if it ends in an


accepting state.
What Does This Accept?
start
q0
1 0 No
No matter
matter where
where we
we
start
start in
in the
the automaton,
automaton,
0
after
after seeing
seeing two
two 1's,
1's, we
we
q1 q2
1 end
end up
up in
in accepting
accepting
state
state qq3.3.
1 0
0 1
q3 q5
1 0
What Does This Accept?
start
q0
1 0 No
No matter
matter where
where we
we
start
start in
in the
the automaton,
automaton,
0
after
after seeing
seeing two
two 0's,
0's,
q1 q2
1 we
we end
end up
up in
in accepting
accepting
state
state qq5.5.
1 0
0 1
q3 q5
1 0
What Does This Accept?
start
q0
1 0

0 This
This automaton
automaton
q1 q2 accepts
accepts aa string
string iff
iff
1 itit ends
ends in
in 00
00 or
or 11.
11.
1 0
0 1
q3 q5
1 0
The language of an automaton is the
set of strings that it accepts.

If D is an automaton, we denote the


language of D as ℒ(D).

ℒ(D) = { w ∈ Σ* | D accepts w }
A Small Problem

start
q0
0 0
0 1 1 0

q2 q1
1
Another Small Problem
0, 1
start 0, 1
q0 q1

0 0 0 0
0, 1
q2
The Need for Formalism
● In order to reason about the limits of
what finite automata can and cannot do,
we need to formally specify their behavior
in all cases.
● All of the following need to be defined or
disallowed:
● What happens if there is no transition out of
a state on some input?
● What happens if there are multiple
transitions out of a state on some input?
DFAs
● A DFA is a
● Deterministic
● Finite
● Automaton
● DFAs are the simplest type of automaton
that we will see in this course.
DFAs, Informally
● A DFA is defined relative to some
alphabet Σ.
● For each state in the DFA, there must be
exactly one transition defined for each
symbol in the alphabet.
● This is the “deterministic” part of DFA.
● There is a unique start state.
● There are zero or more accepting states.
Is this a DFA?
0
start
q0 q1
0

1 1 1 1

0
q3 q2
0
Is this a DFA?
start
q0
1 0

0
q1 q2
1

1 0
0 1
q3 q5
1 0
Is this a DFA?

start
q0
0 0

q2 q1
1
Is this a DFA?

start 0, 1
q0 q1

0, 1 0, 1

q3 0, 1 q2
Is this a DFA?

0, 1
start 0, 1
q0 q1

0
0, 1
q2
Designing DFAs
● At each point in its execution, the DFA
can only remember what state it is in.
● DFA Design Tip: Build each state to
correspond to some piece of information
you need to remember.
● Each state acts as a “memento” of what
you're supposed to do next.
● Only finitely many different states ≈ only
finitely many different things the machine
can remember.
Recognizing Languages with DFAs
L = { w ∈ {0, 1}* | w contains 00 as a substring }

1
0, 1
start 0 0
q0 q1 q2
1
Recognizing Languages with DFAs
L = { w ∈ {0, 1}* | w contains 00 as a substring }

1
Σ
start 0 0
q0 q1 q2
1
Recognizing Languages with DFAs
L = { w ∈ {0, 1}*| every other character of w, starting
with the first character, is 0 }

start 0
q0 q1
Σ
1

q2

Σ
Next Time
● Regular Languages
● What is the expressive power of DFAs?
● NFAs
● Automata with magic superpowers!

Nondeterminism
● Nondeterminisic computation.
● Intuitions for nondeterminism.
● Programming with nondeterminism.

You might also like