Discourse 01
Introduction
Fundamental Questions
Theory of Computation seeks to answer fundamental
questions about computing
What is computation?
Ex:
={A, G, C , T }
Automaton (Machine): abstract (=simplified) model of a
computing device. Used to recognize strings of a
language L
b
Finite Automaton
Ex:
Ex:
S SS
Sx
Context-Free Grammar
(CFG)
Languages
L1 {aa, ab, ba, bb} {a, b}
L2 { , a, aa, aaa, aaaa,K } {a}
L3 {e : e is a well-formed arithmetic expression in C}
={0-9,a-z,A -Z,+,-,*,/,(,),.,&,!,L }
L4 { p : p is a well-formed C program} {ASCII}
L5 { p : p is a w.-f. C program that halts for all inputs}
L6 ={(x, y): x is a decimal integer and y is its binary representation}
Types of Machines
Logic circuit
Circuit size = 5
Circuit depth = 3
q1 / 1
a
q2 / 2
Mod 3 counter
state/ouput (Moore) machine
(q1 , a) (q2 , 2)
a
models programs with a finite number of bounded registers
reducible to 0 registers
{ # : 1}
, $
b, A
(q2 , a, ) (q2 , A)
b, A
#, $
Example:
R0 R0 R1
L0 : JMPZ R1 L1
4
3
2
1
0
INC R0
DEC R1
JMP L0
L1 : CONTINUE
Finitestate
control
( q, X ) ( p, Y , R )
9
Theory of Computation
Study of languages and functions that can be described by
computation that is finite in space and time
Grammar Theory
Context-free grammars
Right-linear grammars
Unrestricted grammars
Capabilities and limitations
Application: programming language specification
Automata Theory
FA
PDA
Turing Machines
Capabilities and limitations
Characterizing what is computable?
Application: parsing algorithms
10
11
={a,,z,A,Z, _ } ={0,,9}
q0
qacc
qreject
Regular Expression
(_ a K A K ) (_ a K A K 0 K 9) *
Right-Linear Grammar
S aT | K | zT T aT | K | zT
| AT | K | ZT
| AT | K | ZT
| _T
| 0T | K | 9T | _ T
12
13
d 0|1|K 9
e, E
d
e, E
Either the integer part or the fraction part (not both) may be missing;
either the decimal point or the e and the exponent (not both) may be missing
14
20*30-12=
Numerals 3 40
Digits 0 1 9
Expressions 3*9 40-3*3
Commands 3*9= 40-3*3=
Context-Free Grammar
C E=
E N
E+N
E-N
EN
N ND
N D
D 0...
9
terminals
rules
R
variables
= ,,0,,9
V=
start variable
grammar
N,D,E,C
= C
G (V, , R, C)
15
Expressions E
Commands C
3*9=
N
3
40-3*3=
E
E
3
Is this the parse
you expected?
16
Halting
Decider
1 if P(x)
0 if P(x)
17
programs as
nat P(nat x)
{
if (x=3)
return(6);
else {
while(x=x) do x=x+1;
return x;
}
}
18
indexprogram: given i 0, convert to binary. Divide into 8bit blocks. If such division is impossible (e.g., 3 bits) or if some
block is not an ASCII code, or if the string is not a legal program,
Pi
will be the default junk program {nat x;
read(x); while(x=x) do x=x+1;write(x)} which is
undefined (diverges ) for every legal input.
Conclusions about enumeration P0, P1, P2, K
19
nat diagonal(nat n)
{ nat y;
if halt(n)=0
y:=1;
else {
y:=1;
while (y!=0) do
y:=y+1;}
return y;
}
Consequences
Pe = diagonal
21
22