Title: DISCRETE MATHEMATICS Lecture 22
1DISCRETE MATHEMATICSLecture 22
- Dr. Kemal Akkaya
- Department of Computer Science
2Modeling Computation
- We learned earlier the concept of an algorithm.
- A description of a computational procedure.
- Now, how can we model the computer itself, and
what it is doing when it carries out an
algorithm? - For this, we want to model the abstract process
of computation itself.
3Early Models of Computation
- Recursive Function Theory
- Kleene, Church, Turing, Post, 1930s
- Turing Machines Turing, 1940s
- RAM Machines von Neumann, 1940s
- Cellular Automata von Neumann, 1950s
- Finite-state machines, pushdown automata
- various people, 1950s
- VLSI models 1970s
- Parallel RAMs, etc. 1980s
4Turing Finite State Machines
- Any algorithm can be implemented in a Turing
machine - Alan Turing
- Topic of Theory of Computation Programming
Languages - We will give definition of Turing machines
- Finite State machines with external memory
- And briefly look at Finite State Machines
5Turing Machines (TM)
- Alan M. Turing (19121954)
- In 1936, Turing introduced hisabstract model
for computation inhis article On Computable
Numbers, with an - application to the Entscheidungsproblem.
- At the same time, Alonzo Church published
similar ideas and results.
- However, the Turing model has become
thestandard model in theoretical computer
science.
6Informal Description TM
At every step, the head of the TM M reads a
letter xi from the one-way infinite tape.
Depending on its state and the letter xi, the TM
- writes down a letter, - moves its read/write
head left or right, and - jumps to a new state.
7Motivation to use Finite State Machines
- Many applications of FSMs
- Control systems of all sorts
- GUI interaction model
- Elevator, vending machine, car-building robot
- Compilers, interpreters
- Simple parsers for languages
- Let M be a FSM. We say that M accepts a language
L (of finite strings from Ms input alphabet S)
if and only if - For all t in L, FSM on t ends in a final state
- For all t not in L, FSM on t does not end in a
final state
812.2 - What is a Finite State Machine?
- Lets define the idea of a machine
- organism (real or synthetic) that responds to a
countable (finite) set of stimuli (events) by
generating predictable responses (outputs) based
on a history of prior events (current state). - A finite state machine (fsm) is a computational
model of a machine with primitive memory - Similar to Combinational Circuits
- But this time their output also depend on state
- Input is provided
- Base on the state an output is given
- Any circuit with memory is a FSM
- Serial adder example
9Serial Adder
- Gets inputs as bits
- The state here is
- Having a carry bit
- If there is a carry, add it to the sum
- Otherwise do nothing
- So INPUT STATE determine together the OUPUT
10Serial Adder FSM
11Elements of a FSM
- States represent the particular configurations
that our machine can assume. - Events define the various inputs that a machine
will recognize - Transitions represent a change of state from a
current state to another (possibly the same)
state that is dependent upon a specific event. - The Start State is the state of the machine
before it has received any events
12Size of FSMs
- The information capacity of an FSM is C log
S. - Thus, if we represent a machine having an
information capacity of C bits as an FSM, then
its state transition graph will have S 2C
nodes. - Computers can be viewed as huge FSMs
- E.g. suppose your desktop computer has a 512MB
memory, and 60GB hard drive. - Its information capacity, including the hard
drive and memory (and ignoring the CPUs internal
state), is then roughly 512223 60233
519,691,042,816 b. - How many states would be needed to write out the
machines entire transition function graph?
2519,691,042,816 A number having gt1.7 trillion
decimal digits!
13One Problem with FSMs as Models
- The FSM diagram of a reasonably-sized computer is
more than astronomically huge. - Yet, we are able to design and build these
computers using only a modest amount of
industrial resources. - Why is this possible?
- Answer A real computer has regularities in its
transition function that are not captured if we
just write out its FSM transition function
explicitly. - i.e., a transition function can have a small,
simple, regular description, even if its domain
is enormous.
14Vending Machine Example
- Suppose a certain vending machine accepts
nickels, dimes, and quarters. - If gt30 is deposited, change isimmediately
returned. - If the coke button is pressed,the machine
drops a coke. - Can then accept a new payment.
Ignore any otherbuttons, bills,out of
change,etc.
15Modeling the Machine
- Input symbol set I nickel, dime, quarter,
button - We could add nothing or ? as an additional
input symbol if we want. - Representing no input at a given time.
- Output symbol set O ?, 5, 10, 15, 20,
25, coke. - State set S 0, 5, 10, 15, 20, 25, 30.
- Representing how much money has been taken.
16Transition Function Table
17Transition Function Table cont.
18Another Format State Table
Each entryshowsnew state,output symbol
19Directed-Graph State Diagram
- As you can see, these can get kind of busy.
q,5
d,5
q
q
q,20
d
d
d
n
n
n
n
n
n
0
5
10
15
20
25
30
n,5
b
b
b
b
b
b
d,10
q,25
q,15
b,coke
q,10
20Formalizing FSMs
- Just like the general transition-function
definition from earlier, but with the output
function separated from the transition function,
and with the various sets added in, along with an
initial state. - A finite-state machine M(S, I, O, f, g, s0)
- S is the state set.
- I is the alphabet (vocabulary) of input symbols
- O is the alphabet (vocab.) of output symbols
- f is the state transition function
- g is the output function
- s0 is the initial state.
- Our transition function from before is T (f,g).