Auto Maeta Theroi
Auto Maeta Theroi
A simple computer
BATTERY
input: switch
output: light bulb actions: flip switch
A simple computer
f
BATTERY
start
off
f
on
input: switch
output: light bulb actions: f for flip switch bulb is on if and only if there was an odd number of flips
Another computer
1 1 start off
1 2
1 2
off
BATTERY
2 2
off
on
A design problem
1
BATTERY
2 3
4 5
Can you design a circuit where the light is on if and only if all the switches were flipped exactly the same number of times?
A design problem
Such devices are difficult to reason about, because they can be designed in an infinite number of ways
By representing them as abstract computational devices, or automata, we will learn how to answer such questions
Used to model parsers, etc. Turing Machines Devices with infinite memory.
Used to model any computer. time-bounded Turing Machines Infinite memory, but bounded running time. Used to model any computer program that runs in a reasonable amount of time.
Push-down automata
These devices are related to grammars, which describe the structure of programming (and natural) languages
Chengdu
Shanghai
Easy in principle: Try the cities in every possible order Hard in practice: For 100 cities, this would take 100+ years even on the fastest computer!
Problems
Examples of problems we will consider
Given a word s, does it contain the subword fool? Given a number n, is it divisible by 7? Given a pair of words s and t, are they the same? Given an expression with brackets, e.g. (()()), does every left bracket match with a subsequent right bracket?
Strings
A string over alphabet S is a finite sequence of symbols in S.
Languages
A language is a set of strings over an alphabet. Languages can be used to describe problems with yes/no answers, for example:
L1 = The set of all strings over S1 that contain the substring fool The set of all strings over S2 that are divisible by
L2 = 7 = {7, 14, 21, } L3 = The set of all strings of the form s#s where s is any string over {a, b, , z} L4 = The set of all strings over S4 where every ( can
Finite Automata
off
There are states off and on, the automaton starts in off and tries to reach the good state on
Example
0 q0 1 q1 1 0 q2 0,1
states
alphabet S = {0, 1} start state Q = {q0, q1, q2} initial state q0 accepting states F = {q0, q1}
transition function d:
inputs
q0 q1 q2
0 q0 q2 q2
1 q1 q1 q2
Language of a DFA
The language of a DFA (Q, S, d, q0, F) is the set of all strings over S that, starting from q0 and following the transitions as the string is read left to right, will reach some accepting state.
f
M:
off
on
Examples
0 q0 0 q0 1 0 1 1 q1 0 q2 q1 1 1 q1 1 0
0 q0
0,1
Examples
Construct a DFA that accepts the language
L = {010, 1} ( S = {0, 1} )
Examples
Construct a DFA that accepts the language
L = {010, 1} ( S = {0, 1} )
Answer
0
qe
q0
q01
q010
0 1
q1 0, 1
1 0, 1
qdie 0, 1
Examples
Construct a DFA over alphabet {0, 1} that accepts all strings that end in 101
Examples
Construct a DFA over alphabet {0, 1} that accepts all strings that end in 101 Hint: The DFA must remember the last 3 bits of the string it is reading
Examples
Construct a DFA over alphabet {0, 1} that accepts all strings that end in 101
Sketch of answer:
0 0 0 qe 1 0 q1 1 q0 1 q00 q01 q10 q11 1 q000 1 q001 0
q111
q101