Automata

Other Automata
Pushdown through Turing
machines
Copyright © 2011-2017 Curt Hill
Introduction
• There is an hierarchy of automata
– They move from weaker to stronger
• This parallels an hierarchy of
languages
– Also weaker to stronger
• In this presentation we consider the
automata
– Another catches the languages
Copyright © 2011-2017 Curt Hill
Finite State Machine
• We have previously seen these
• What can they not do?
• They are unable to handle the
recursive nature of most
programming languages
• Eg. C
– A statement may be a for-statement
– A for-statement contains a statement
• What do we need to do to strengthen
these?
Copyright © 2011-2017 Curt Hill
Finite State Automata
• Two things (and only two things)
determine the next state:
– Current state
– Input symbol
• To strengthen this we add a stack
– The symbols on the stack may be
different than input
• This results in the pushdown
machine
Copyright © 2011-2017 Curt Hill
Pushdown automata
• Three things choose the next state:
– Current state
– Input symbol
– Symbol on top of stack
• Any state transition may push or pop
a symbol on/off the stack
• The stack significantly strengthens
the type of languages that we may
now accept
– We have some sense of history
Copyright © 2011-2017 Curt Hill
Pictures
Input (r/o)
Finite State
Automaton
Finite
Control
a c b a …
State
Input (r/o)
Pushdown
Automaton
Finite
Control
a c b a …
x y w …
Stack (r/w)
State
Copyright © 2011-2017 Curt Hill
Transition Relation
• A finite state automaton has a
transition function
• A pushdown automaton has a
transition relation
• The parameters are:
– The current input value
– The current state
– The top of stack
• The result is:
– The new state
– The action on the stack
Copyright © 2011-2017 Curt Hill
State Transitions
•
•
•
•
•
The form is:
(a, s, t) (s, n)
a is the symbol on the input
s is the state
t is the top of the stack
– 0 means it is ignored
• n is the new action
– 0 means no action
Copyright © 2011-2017 Curt Hill
•
•
•
•
A very simple grammar
V – {X}
T – {a,b,c}
S–X
P
– X ::= b
– X ::= a X c
• This will give expressions of the
form: anbcn
–b
– aaabccc
• Why is this not regular?
Copyright © 2011-2017 Curt Hill
Why is this not regular?
• The best we can do in a regular
language is arbitrary string of a
followed by one b and an arbitrary
string of c
• a*bc*
• There is no way to force the number
of as and cs to match
• The simple grammar above requires
equal numbers
Copyright © 2011-2017 Curt Hill
Grammar State Transitions
•
•
•
•
•
(a, z1, 0) (z1, push x)
(b, z1, 0) (z2, 0)
(c, z2, x) (z3, pop)
(c, z3, x) (z3, pop)
(c, z3, empty) (z4, 0)
Copyright © 2011-2017 Curt Hill
Push Down Automaton
a,0
Push x
s1
b,0
s2
c,x
pop
c,x
pop
s3
s4
c,empty
• Transitions have two pieces to
choose and one action
– First is input, second is stack
– Zero means ignore this input
– Second line is action
Copyright © 2011-2017 Curt Hill
Recursive Descent Parsing
• Not that much different than
pushdown machine language
recognition
– Both require a stack
• Functions correspond to states
• When a construct is started an item
is pushed onto the stack which
signifies node that originated
– Comparable to return address
Copyright © 2011-2017 Curt Hill
Graphics
• Finite State Automata are simple
– There representation is simple
• Push Down Automata are somewhat
more complex
– This makes the picture more
complicated
• We will attempt: : anbcn
Copyright © 2011-2017 Curt Hill
a,0
Push x
s1
b,0
PDA
s2
c,x
pop
c,x
pop
s3
s4
c,empty
• Transitions have two pieces to
choose and one action
– First is input, second is stack
– Zero means ignore this input
– Second line is action
Copyright © 2011-2017 Curt Hill
What’s next?
• Turing machine
• A thought experiment devised by
Alan Turing in 1936
– Original paper is 1937
• Turing wanted to investigate what
was and was not computable
Copyright © 2011-2017 Curt Hill
Description
• A finite state machine
• The input is now a tape that is
infinite in both directions
• The finite automaton may read
forward or backward as many times
as desired
• Input symbol read may be rewritten
– Not read/only like Finite State Machine
or Pushdown machine
Copyright © 2011-2017 Curt Hill
In Practice and Theory
• In practice, this is a terrible way to
make a computer
• In theory, there is no stronger
means of computation
– Strong: ability to compute a result
• This is one of the foundations of the
theoretical computer science
• With the exception of the infinite
storage, a Turing machine is
equivalent to Von Neumann
machines
Copyright © 2011-2017 Curt Hill
Equivalence
• A CPU is a finite state machine
– Very many states
• If we consider the
memory/secondary storage as
equivalent to tape the parallels
should be clear
– We may simulate an array with a list so
random access memory is faster but
not stronger than the tape
Copyright © 2011-2017 Curt Hill
One More
• A Turing machine has an infinite
length tape and may process it any
number of times
• There is an automaton between a
Push Down Automaton and a Turing
machine
– Linear Bounded Automaton
• A Linear Bounded Automaton is a
Turing machine with limited tape
that may make a limited number of
passes through that tape
Copyright © 2011-2017 Curt Hill
Simulators
• There are a variety of simulators for
a Turing machine on the web
• Here are few (2014)
– http://morphett.info/turing/turing.html
– https://martinugarte.com/turingmachin
e/
– http://www.turing.org.uk/turing/scrapb
ook/tmjava.html
– http://www.superutils.com/products/ub
er-turing-machine/
Copyright © 2011-2017 Curt Hill
In Theory
• Any function (and every program
computes a function) that may be
computed may be done so with a
Turing machine
• It is the device that separates (in
theory) computable from noncomputable functions
• Is there a result that cannot be
computed?
Copyright © 2011-2017 Curt Hill
Linear Bounded
• Recall that context sensitive
languages may be handled by linear
bounded automaton
• What is that?
• A Turing machine with limited tape
that may make a limited number of
passes through that tape
Copyright © 2011-2017 Curt Hill
Equivalences
• A Finite State Automaton may
recognize a Type 3 or Regular
Language
• A Push Down Automaton may
recognize a Type 2 or Context Free
Language
• A Linear Bounded Automaton may
recognize a Type 1 or Context
Sensitive Language
• A Turing Machine may recognize a
Type 0 or any phrase structured
language Copyright © 2011-2017 Curt Hill
The Halting Problem
• What I would like to know is if a
program halts or does not
– To not halt is have an infinite loop
• Would like a boolean function Halt(p)
– When given a program, p, will return
true if it is free from infinite loops or
false if not
• What we can prove is that such a
function can not be written
– Not, would take too long
– But is provably impossible to write
Copyright © 2011-2017 Curt Hill
Proof
• Suppose Halt(p) exists
• Construct a program X as follows:
– if Halt(x)
while(true)
cout << “oops\n”;
else
return;
• By contradiction we see that it is
impossible to prove whether a
program halts
Copyright © 2011-2017 Curt Hill
Others
• Clearly, if we cannot determine if a
program halts or not, we cannot
determine if it is correct or not
– We may be able to prove that it meets
its specifications, but then there would
be no way to check the specs
• Thus a whole class of programs that
make statements about other
programs are not computable
• There are many others in other
domains
Copyright © 2011-2017 Curt Hill
Finally
• These are the classes of automatons
• Next we consider the language
hierarchy
– Very practical in regards to parsing
and compiling
Copyright © 2011-2017 Curt Hill