Upload
laura-gorostidi
View
215
Download
0
Embed Size (px)
Citation preview
8/19/2019 While Programs
1/106
WHILE PROGRAMS
Computability
8/19/2019 While Programs
2/106
2/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Understand the concept of Computation Model! Design While Programs and Turing Machines.!
Use Church Thesis.
Goals
What can computers do in principle; and, more important,what is it that they in principle cannot?
1
8/19/2019 While Programs
3/106
3/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! What is the nature of computation?
! What can be computed?!
What can be computed efficiently?! How can we build computing devices?
! What is an algorithm?! What is a function?
Questions addressed by Computability
A function is computable if it isdetermined by some algorithm
8/19/2019 While Programs
4/106
4/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Etymology of the word Algorithm
Muhammad ibn Musa abu Djafar Al'Khwarizmi.(a.k.a Al'Khorezmi).
He was born around 780 aC in Khorezm, (south of
Aral sea, known nowadays as Khiva, Uzbekistán).He dead in Bagdad around 850 aC.
•
Algoritmi de numero Indorum.• Kitab al-jabr wa'l-muqabala (The art of solving equations).
8/19/2019 While Programs
5/106
5/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! It is the problem of determining, given an arbitrary computerprogram and an input, whether the program will finish runningor continue to run forever.
! Turing proved that a general algorithm to solve the haltingproblem for all possible program-input pairs cannot exist.
! It is a decision problem about properties of computer programson a fixed model of computation
! It is an abstract framework, there are no resource limitations onthe amount of memory or time required for the program'sexecution
Motivation: The Halting Problem
8/19/2019 While Programs
6/106
6/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Context for computation.! Basic operations.! Combination rules.
Models of Computation
! While Programs.!
Turing Machines.
8/19/2019 While Programs
7/106
7/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! While Programs.
! Turing Machines.
Models of Computation
8/19/2019 While Programs
8/106
8/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
Variable names: An Arbitrary finite string of upper case letters and decimalnumbers provided it also starts with an upper case letter
E.g. X1, X2, TEMP, LIST1
! Operator symbols:
" To denote basic operators
" succ ( successor function ) , pred ( predecessor function ), 0 ( constant zero
function )
! Relation symbol “!” for the inequality which compares the values of
pairs of variables
! Program Symbols := ( assigment ), ; ( semi-colon ), begin, end , while, do,
( , ),
WHILE Programs: Basic Components
8/19/2019 While Programs
9/106
9/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! AssigmentX:=0
X:=succ(Y)X:=pred(Y)
! While statementwhile X ! Y do !
! may be an arbitrary statement! Compound statement
begin ! 1; ! 2; … ; ! n end
WHILE Programs: Statements
X ! Y is the test
! is the body
i are arbitrarystatements
and n ! 0
A while program is none other
than a compound statement we
choose to identify as a program,
but which can also be used as a
compound statement in someother larger program
8/19/2019 While Programs
10/106
10/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
WHILE Programs: Example
!
How to write a while-program P that adds X to Y and leavethe resulting value in Z ?
Assign the value of X to Z
Add the value of Y to Z
There is no single step in our
programming language that will
carry it out
begin Z:=succ(X); Z:=pred(Z) endZ:=X
8/19/2019 While Programs
11/106
11/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
How to write a while-program P that adds X to Y and leavethe resulting value in Z ?
Add the value of Y to ZIt may be decomposed further using andauxiliary variable U and
Set U to 0
Add 1 to Z and add 1 to U as many
times as required to make U=Y
begin
U:=0;while U!Y do begin
Z:= succ(Z);U:= succ(U)
end
end
Z:=Z+Y
WHILE Programs: Example
8/19/2019 While Programs
12/106
12/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
How to write a while-program P that adds X to Y
and leave the resulting value in Z ?
begin
Z:=X
Z:=Z+Y
end
! Whenever we use the macro
statement Z:=X+U in awhile-program, whe should
u n d e r s t a n d t h a t i t
abbreviates the code
begin
Z:=succ(X); Z:=pred(Z)
begin U:=0;
while U !Y do
begin
Z:= succ(Z);U:= succ(U)
end
end
end
2
WHILE Programs: Example
8/19/2019 While Programs
13/106
Z:= X Y Z:=X*Y
Z:= X div Y Z:= X mod Y
Z:= X**Y Z:=f(X 1 , … , X m )
!!Z:= XZ:=X+Y
Z:=n (n>0)
!
Macro Statement: An abbreviation for a multi-instruction statement ,a short-hand notation for its macro definition
WHILE Programs: Macro-Statements
8/19/2019 While Programs
14/106
Result stored in X1
Macro +
Macro :=
begin X3:=0;
X4:=0;
while X3!X2 do
begin
X3:=succ(X3);
X4:=X4 + X1;
end
X1:=X4;
end
WHILE Programs: Macro-Statements
!
Provide with a while program for computing f(x,y) = x * y. ! Allowed macros for + and :=
‘x’ is stored in X1 and ‘y’ in X2
8/19/2019 While Programs
15/106
begin
X3:=0;
X4:=0;
while X3!
X2 dobegin
X3:=succ(X3);
X5:=0;
while X5!X1 do
begin
X5:=succ(X5);X4:=succ(X4);
end
end
X1:=succ(X4);
X1:=pred(X1);
end
Replace macro + by
basic operations
Replacemacro := bybasic operations
WHILE Programs: Macro-Statements
!
Provide with a while program for computing f(x,y) = x * y. ! Without macros.
8/19/2019 While Programs
16/106
beginX1:=succ(X1);
X3:=0;
X4:=0;
while X1!X4 do
beginX3:=succ(X3);
X1:=X1 X2;
end
X1:=pred(X3);
end
‘x’ is stored in X1 and ‘y’ in X2
Result stored in X1
!!
Macro for difference
WHILE Programs: Macro-Statements
!
Provide with a while program for computing f(x,y) = x div y. ! Using a macro for difference.
8/19/2019 While Programs
17/106
!
Provide with a while program for computing f(x,y) = x div y. ! Without macros.
Replace macro for
difference by basic
sentences
begin
X1:=succ(X1);
X3:=0;
X4:=0;while X1!X4 do
begin
X3:=succ(X3);
X5:=0;
while X5!X2 do
begin X1:=pred(X1);
X5:=succ(X5);
end
end
X1:=pred(X3);
end
WHILE Programs: Macro-Statements
8/19/2019 While Programs
18/106
!
Macro Test: Macro sentences defined inductively as follows ! Basic: X and Y are either natural numbers or variables, then
! X=Y, X
8/19/2019 While Programs
19/106
19/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
Proposition: A statement of the form
while T do !
where T is a test and ! is an arbitrary statement, is a macro sentence in
the language of while programs
Without loss of generality we may assume that the test T does not involve naturalnumbers
Given any test T, we can write an arithmetical expression ET in terms of the variablesused in T and the arithmetic operators succ, pred, + and such that
!!
!"#
=
otherwise0
trueisTif 1
T E
begin
U:=ET ;V:=0 ;while U!V do
begin ! ;
U:= ET
endend
WHILE Programs: Macro-Statements
8/19/2019 While Programs
20/106
20/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
Proposition: A statement of the form
while T do !
where T is a test and ! is an arbitrary statement, is a macro sentence in the
language of while programs
But….How to find E T for any arbitrary test T ?
HINT: Use the inductive definition of tests
Take tests of the form X < Y
Classify all other tests to be compositeT= X < Y
ET= (Y X) pred(Y X) !!!! !!
WHILE Programs: Macro-Statements
8/19/2019 While Programs
21/106
21/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
Proposition: A statement of the form
while T do !
where T is a test and ! is an arbitrary statement, is a macro sentence in the
language of while programs
Assuming we have found expressions ET1 and ET2 for test T1 and T2
T= T1 ^T2 ET= pred( ET1+ ET2 )
T= T1 T2
T= ~T1
ET= ( ET1+ ET2 ) pred( ET1+ ET2 ) !!
ET= 1 ET1 !!
WHILE Programs: Macro-Statements
8/19/2019 While Programs
22/106
22/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Example: Construct ET for T = (Z"Y) ^ (Z>X)
E(Z"Y)^(Z>X) = pred(EZ"Y + EZ>X) =
= pred((1-EZ
8/19/2019 While Programs
23/106
23/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Proposition: A statement of the formIf T then ! 1
If T then ! 1 else ! 2
Repeat ! until Twhere T is a test and ! 1 and ! 2 are arbitrary
statements, are all macro sentences in the language ofwhile programs
WHILE Programs: Macro-Statements
8/19/2019 While Programs
24/106
24/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Definition
A sentence ! is a k-variable statement, then the variables it uses are (asubset of) {X 1, X 2, … ,X k} variables
Definition
A state of computation for a k-variable while program is k-dimensionalvector over the natural numbers
State Vector: â=(a1, … ,ak )" Nk , where ai is the content of X i
Definition
Let P be a k-variable while program. A computation by P is a sequence,possible infinite, of the form
â0A1 â1 A2 â2 … ân-1 An ân …
Initial state vector Instructions
Size of sequence
WHILE Computable Functions
8/19/2019 While Programs
25/106
25/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Compute a computation sequence,given as initial state vector (4,2)
begin
X1:=0;
while X1!X2 do X1:= succ(X1)
end
â0=(4,2)
A1=X1:=0;
â1=(0,2)
A2
=X1"X2
â2=(0,2)
A3=X1=succ(X1)
â3=(1,2)
A4=X1"X2
â4=(1,2) A5 =X1=succ(X1)
â5 =(2,2)
A6=X1"X2 â6=(2,2)
Computation sequence. Example
8/19/2019 While Programs
26/106
26/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Let âi-1=(a1, … , ak ) be a non initial state vector
a) If Ai is a test, then âi= âi-1b) If Ai is a setting X n:=g(X m ), then:
âi =(a1 , … , an-1 , g(am ), an+1 , … , ak )
being g(.) either succ or pred or 0
begin
X1:=succ(0);
while X1!
X2 do X1:= pred(X1)end
â0=(0,0)
A1=X1:=succ(0);
â1=(1,0)
A2=X1!X2
â2
=(1,0)
A3=X1=pred(X1)
â3=(0,0)
A4=X1!X2
â4=(0,0)
Consistency Conditions
8/19/2019 While Programs
27/106
27/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Let P # begin 1 ; 2 ; … ; n end be
The first instruction of sequence is
a) If ! 1 is a setting, A1= ! 1b)
If ! 1 # while T do ! , A1=Tâ0A1 â1 A2 â2 … ân-1 An ân
begin
X1:=succ(0);while X1!X2 do X1:= pred(X1)
X2:=succ(X1);
end
â0=(0,0)
A1=X 1:=succ(0);
â1=(1,0)
A2=X1!X2
â2=(1,0) A3=X1=pred(X1)
â3=(0,0)
A4=X1!X2â4=(0,0)
Consistency Conditions
8/19/2019 While Programs
28/106
28/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Next instruction: Let Ai be an intermediate step in computation1. If Ai # T # Xn!X m associated to
! j # while T do !
a) If an! am then Ai+1 # 1st instruction within the body of the corresponding while
statement
b) If an= a
m then
i. If ! j is the last instruction of the body of a while sentence, Ai+1 # while Test
ii. otherwise Ai+1 # 1st instruction of ! j+1
â0A1 â1 A2 â2 … ân-1 An ân
â0=(0,0)
A1=X1:=succ(0);
â1=(1,0)
A2=X 1! X 2â2=(1,0)
A3=X1=pred(X1)
â3=(0,0)
A4=X1!X2â4=(0,0)
Consistency Conditions
begin
X1:=succ(0);
while X1!X2 do X1:= pred(X1)X2:=succ(X1);
end
8/19/2019 While Programs
29/106
29/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
â0A1 â1 A2 â2 … ân-1 An ân
â0=(0,0)
A1=X1:=succ(0);
â1=(1,0)
A2=X1!X2â2=(1,0)
A3=X 1=pred(X 1 )
â3=(0,0)
A4=X 1! X 2
â4=(0,0)
Next instruction: Let Ai be an intermediate step in computation1. If Ai # T # Xn!X m associated to
! j # while T do !
a) If an! am then Ai+1 # 1st instruction within the body of the corresponding while
statement
b) If an
= am
then
i. If ! j is the last instruction of the body of a while sentence, Ai+1 # while Test
ii. otherwise Ai+1 # 1st instruction of ! j+1
Consistency Conditions
begin
X1:=succ(0);
while X1!X2 do X1:= pred(X1)X2:=succ(X1);
end
8/19/2019 While Programs
30/106
30/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
â0A1 â1 A2 â2 … ân-1 An ân
â0=(0,0)
A1=X1:=succ(0);
â1=(1,0)
A2=X1!X2â2=(1,0)
A3=X1=pred(X1)
â3=(0,0)
A4=X 1! X 2
â4=(0,0)
Next instruction: Let Ai be an intermediate step in computation1. If Ai # T # Xn!X m associated to
! j # while T do !
a) If an! am then Ai+1 # 1st instruction within the body of the corresponding whilestatement
b) If an
= am
then
i. If ! j is the last instruction of the body of a while sentence, Ai+1 # while Test
ii. otherwise Ai+1 # 1st instruction of ! j+1
Consistency Conditions
begin
X1:=succ(0);
while X1!X2 do X1:= pred(X1)X2:=succ(X1);
end
8/19/2019 While Programs
31/106
31/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Next instruction: Let Ai be an intermediate step in computation1. If Ai # T # Xn!X m associated to
! j # while T do !
a) If an! am then Ai+1 # 1st instruction within the body of the corresponding whilestatement
b) If an
= am
then
i. If ! j is the last instruction of the body of a while sentence, Ai+1 # while Test
ii. otherwise Ai+1 # 1st instruction of j+1
â0A1 â1 A2 â2 … ân-1 An ân
â0=(0,0)
A1=X1:=succ(0);
â1=(1,0)
A2=X1!X2
â2=(1,0) A3=X1=pred(X1)
â3=(0,0)
A4=X 1! X 2
â4=(0,0)
A5=X 2=succ(X 1 )
Consistency Conditions
begin
X1:=succ(0);
while X1!X2 do X1:= pred(X1)X2:=succ(X1);
end
8/19/2019 While Programs
32/106
32/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Next instruction: Let Ai be an intermediate step in computation2. If Ai is a setting,
i. If ! j is the last instruction of the body of a while sentence,
Ai+1 # while Test
â0A1 â1 A2 â2 … ân-1 An ân
begin
X1:=succ(0);
while X1!X2 do X1:= pred(X1)X2:=succ(X1);
end
â0=(0,0)
A1=X1:=succ(0);
â1=(1,0)
A2=X1!X2â2=(1,0)
A3=X 1=pred(X 1 )
â3=(0,0) A4=X 1! X 2
â4=(0,0)
A5=X 2=succ(X 1 )
â0=(0,0)
A1=X1:=succ(0);
â1=(1,0)
A2=X1!X2â2=(1,0)
A3=X1=pred(X1)
â3=(0,0) A4=X 1! X 2
â4=(0,0)
A5=X 2=succ(X 1 )
Consistency Conditions
8/19/2019 While Programs
33/106
33/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Next instruction: Let Ai be an intermediate step in computation2. If Ai is an assigment,
i. If ! j is the last instruction of the body of a while sentence,
Ai+1 # while Test
ii. otherwise Ai+1 # 1st instruction of ! j+1
â0A1 â1 A2 â2 … ân-1 An ân
begin
X1:=succ(0);
while X1!X2 do X1:= pred(X1)X2:=succ(X1);
end
â0=(0,0) A1=X 1:=succ(0);
â1=(1,0)
A2=X1!X2â2=(1,0)
A3
=X 1
=pred(X 1
)
â3=(0,0)
A4=X 1! X 2
â4=(0,0)
A5=X 2=succ(X 1 )
â0=(0,0) A1=X 1:=succ(0);
â1=(1,0)
A2=X 1! X 2
â2=(1,0)
A3
=X 1
=pred(X 1
)
â3=(0,0)
A4=X 1! X 2
â4=(0,0)
A5=X 2=succ(X 1 )
Consistency Conditions
8/19/2019 While Programs
34/106
8/19/2019 While Programs
35/106
35/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Given P, compute its semantic function with arity 1.
begin
X3:=0;
while X1!X3 do
begin
X2:=pred(X2);
X1:=pred(X1);
endX1:=X2;
end
! j=1 !
As k"
j, P is executed using (x,0,0) as initial statevector.! After executing X1stores ?
P uses 3 variables # k=3%
(1)(x) = 0
Semantic Functions
8/19/2019 While Programs
36/106
36/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Given P, compute its semantic function with arity 3.
begin
X3:=0;
while X1!X3 do
begin
X2:=pred(X2);
X1:=pred(X1);
endX1:=X2;
endP uses 3 variables # k=3
Semantic Functions
! J=3 ! As k"j, P is executed using (x,y,z) as initial state
vector.!
After executing X1stores ?
%
(3)(x,y,z) = y-x
8/19/2019 While Programs
37/106
37/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Given P, compute its semantic function with arity 3.
begin
X3:=0;
while X1!X3 do
begin
X2:=pred(X2);
X1:=pred(X1);
endX1:=X2;
endP uses 3 variables # k=3
Semantic Functions
! J=5 ! As k
8/19/2019 While Programs
38/106
38/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
â0=(3,0,0,0,0)
X4:=X1+X2;
â1=(3,0,0,3,0)
X4>X5â2=(3,0,0,3,0)
X5:=succ(X5);
â3=(3,0,0,3,1)
X4:=pred(X4);
â3=(3,0,0,2,1)
X4>X5â4=(3,0,0,2,1)
X5:=succ(X5);
â5=(3,0,0,2,2)
X4:=pred(X4);
BeginX4:=X1+X2;While (X4>X5) do
BeginX5:=succ(X5);
X4:=pred(X4);End
X1:=X4;
While (X3&0) doBegin
X1:=succ(X1);X3:=pred(X3);
End
End
Assume j=1 !P(1)(a1)
â0=(4,0,0,0,0)
X4:=X1+X2;
â1=(4,0,0,4,0)
X4>X5â2=(4,0,0,4,0)
X5:=succ(X5);
â3=(4,0,0,4,1)
X4:=pred(X4);
â3=(4,0,0,3,1)
X4>X5â4=(4,0,0,3,1)
X5:=succ(X5);
â5=(4,0,0,3,2)
X4:=pred(X4);
%
(1)(x) = x/2
Semantic Functions
â6=(3,0,0,1,2)
X4>X5
â7 =(3,0,0,1,2)
X1:=X4;â8=(1,0,0,1,2)
â6=(4,0,0,2,2)
X4>X5
â7 =(4,0,0,2,2)
X1:=X4;â8=(2,0,0,2,2)
X3&0
â9=(2,0,0,2,2)
8/19/2019 While Programs
39/106
3
8/19/2019 While Programs
40/106
40/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
The j-ary semantic function, !P(j): Nj $ N, for a k variableprogram P is defined as follows.
Given an input vector (a1, …, aj), !P(j)(a1, …, aj) is evaluated
according to the following rules, with two cases arising:
1. k " j. Then !P(j)(a1, …, aj) is evaluated by applying P to theinitial state â0=(a1, …, aj,0, .. K-j .., 0)
2. k < j. Then !P(j)(a1, …, aj) is evaluated by applying P to the
initial state â0=(a1, …, ak).
In both cases, If and when P halts on this vector, the final value isstored on X1
In either case, if P fails to halt on the initial state vector, then thevalue of !P
(j)(a1, …, aj)= '
3
Semantic Functions
8/19/2019 While Programs
41/106
8/19/2019 While Programs
42/106
42/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Every algorithm or effective procedure is computable.
Church’s Thesis
8/19/2019 While Programs
43/106
43/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! While Programs.
! Turing Machines.
Models of Computation
8/19/2019 While Programs
44/106
Alan Turing
1912 - 1954
Alan Turing was one of the foundingfathers of CS.
! His computer model was premonitionof the electronic computer that cametwo decades later
! Was instrumental in cracking the NaziEnigma cryptosystem in WWII
!
Invented the “Turing Test” used in AI
Alan Turing
8/19/2019 While Programs
45/106
45/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
He was instrumental in cracking the Nazi Enigmacryptosystem in WWII.
! 1918 Arthur Scherbius built the Enigma" Advantage Enigma: cypher produced was very
difficult" Polish were good at cracking codes
" The French bought keys, couldn’t do anything with it
" Poland foresaw its invasion by Germany: gave allknowledge to England and France, destroyed itafterwards (1939)
" http://www.enigmaco.de/
A short story during the second world war
8/19/2019 While Programs
46/106
46/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! 1939 Turing was asked to help to crack the Enigma! Built with a team the Colussus, the first programmable
computer
!
Based on:" his own 1936 concept of the universal machine" the potential speed and reliability of electronic technology" the inefficiency in designing different machines for different
logical processes
! Cyphercode could be decrypted from 1943! All computers were destroyed, ordered by Churchill
A short story during the second world war
8/19/2019 While Programs
47/106
47/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Because of the construction of theColussus Turing thought it could bepossible to construct a computer with
the mind of a human being! “Turing was convinced that if a
computer could do all mathematicaloperations, it could also do anythinga person can do“
A short story during the second world war
8/19/2019 While Programs
48/106
! “Computing machinery andintelligence” (1950)
! Operating definition ofintelligence
! Loebner Prize! CAPTCHA
Turing Test
8/19/2019 While Programs
49/106
49/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
. . .
Finite State Control
A finite-state control equipped with
an external storage device whichcan be extended in both directions
May be a blank or may hold
any one symbol from as p e c i f i e d f i n i t e t a p e
alphabet
! Two-way, infinite tape, broken into cells, each containing one symbol.! Two-way, read/write tape head.! Finite control: a program containing the position of the read head, current symbol being scanned,
and the current state.! An input string is placed on the tape, padded to the left and right infinitely with blanks, read/write
head is positioned at the left end of input string.
!
In one move, depending on the current state and the current symbol being scanned, the TM 1)
changes state, 2) prints a symbol over the cell being scanned, and 3) moves its’ tape head one cell
left or right.
Turing Machine
8/19/2019 While Programs
50/106
50/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
First Instruction: Initial State. Tape head scans the first non blank symbolof the tape.
! Next Instruction:
Depending on the pair (State, symbol):
!
Write a symbol on the scanned square.
! Enter a new state of the finite-state control
! One of the options listed below:
– Shift the head left one square (L)
–
Shift the head right one square (R)–
Not shift it at all (N)
– Halt (H)
Turing Machine: Formal description
8/19/2019 While Programs
51/106
51/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
! Halting Test:
! The machine halts when there is no instructions.
! Result:! If it halts in a final state, the result is coded in the tape.
! If it halts in a non final state, the result is undefined
Turing Machine: Formal description
8/19/2019 While Programs
52/106
52/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Definition
A Turing Machine is specified by a quintuple (X, Q, T, i, F) where:
! Q is a finite set of states.
!
i(Q is the initial state.
! F ) Q is the halting state set.
! X denotes the set of symbols that can be written on tape, including the
blank symbol (B).
! T :Q x X :$ X x {L,R,H,N} x Q
Turing Machine: Formal description
8/19/2019 While Programs
53/106
53/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
An instantaneous description (ID) is a triple a1qa2, where :
a1= y1 … yn and a2= x1 … xm! q: the current state
! x1: The symbol the tape head is currently scanning
!
a2 = x2 … xm: Symbols from the tape head up to the rightmostnon-blank symbol
! a1 = y1 … ym: Symbols from the leftmost non-blank symbol upto the tape head
!
At the beginning of a computation a1= i x1 … xm
Instantaneous Description
8/19/2019 While Programs
54/106
54/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
A transition provides us with the description!
y1 … yn q x1 … xm
! It computes T(q, x1)
!
If T(q, x1)=(x’1, q’, D):! y1 … yn q x1 … xm ->y1 … yn x’1 q’ x2 … xm
! If T(q, x1)=(x’1, q’, I)!
y1 … yn q x1 … xm ->y1 … yn-1 q’yn x’1 x2 … xm
!
If T(q, x1)=(x’1, q’, N)! y1 … yn q x1 … xm ->y1 … yn q’x’1 x2 … xm
Turing Machine: Transitions
8/19/2019 While Programs
55/106
55/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
If T(q, x1)=(x’1, q’, H)
! y1 … yn q x1 … xm ->y1 … yn q’x’1 x2 … xm
! Special Cases:
!
With (x’1, q’, I): q x1 … xm -> q’B x’1 x2 … xm
! With (x’1, q’, I): y1 … yn q B -> y1 … q’yn x’1!
With (x’1, q’, D): y1 … yn q x1 -> y1 … yn x’1q’B
!
With (x’1, q
’, D): q x1 -> x
’1q’B
! With (x’1, q’, D): q B -> x’1q’B
Turing Machine: Transitions
8/19/2019 While Programs
56/106
56/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
!
Interpret TM as Computers of Number-Theoretic partialfunctions
! Input Codification: Unary Notation (X = {0,1})
!
Given n(N, it is represented by a block of (n+1)consecutive1’s.
! Given a vector (n1, …, nk), it will coded as
1 .. (n1+1) .. 101.. (n2+1) .. 10 … 01.. (nk+1) .. 1
Turing Machine: Semantics
8/19/2019 While Programs
57/106
57/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Semantic Function
Given a TM, M=(X, Q, T, i, F) the k-ary semantic function of M is
defined as:
%
M(k) : Nk $ N
! To compute %M
(k)(x1,…,xk), start M using the initial configuration.
! If and when M halts, count the total number of 1’s (consecutive or
non) on the tape, interpret this number in unary notation and take
this value to be the output value
Turing Machine: Semantics
8/19/2019 While Programs
58/106
58/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Definition
A function f: Nk $ N, is Turing computable if there exists a TM
M, such that:
%M(k)(x1,…,xk) = f(x1,…,xk) * (x1,…,xk) ( N
k
Turing Machine: Computation
8/19/2019 While Programs
59/106
59/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 1 1 1 0 1 1 0 0
First Step: Input Codification (Unary Notation)
Given n(N, it is represented by a block of (n+1) consecutive1’s.
Given a vector (n1, …, nk), it will be coded as
1 .. (n1+1) .. 101.. (n2+1) .. 10 … 01.. (nk+1) .. 1
INPUT VECTOR (x,y)
x y
X+Y
8/19/2019 While Programs
60/106
8/19/2019 While Programs
61/106
61/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 1 1 1 0 1 1 0 0
Third Step: Transition function, how does the machine work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q0, 1)=(0, q1, D)
Initial state
X+Y
8/19/2019 While Programs
62/106
62/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 1 1 0 0
T :Q x X :$ X x {L,R,N,H} x Q
T(q1, 1)=(1, q1, D)
X+Y
Third Step: Transition function, how does the machine work?
8/19/2019 While Programs
63/106
63/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 1 1 0 0
T(q1, 1)=(1, q1, D)
T :Q x X :$ X x {L,R,N,H} x Q
Third Step: Transition function, how does the machine work?
X+Y
8/19/2019 While Programs
64/106
64/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 1 1 0 0
T :Q x X :$ X x {L,R,N,H} x Q
T(q1, 0)=(0, q2, D)
Third Step: Transition function, how does the machine work?
X+Y
8/19/2019 While Programs
65/106
65/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 1 1 0 0
T :Q x X :$ X x {L,R,N,H} x Q
T(q2, 1)=(0, q2, H)
Third Step: Transition function, how does the machine work?
X+Y
8/19/2019 While Programs
66/106
66/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 0 0
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q2, 1)=(0, q2, H)
Final state
X+Y
8/19/2019 While Programs
67/106
67/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q0, 1)=(0, q1, D)
T(q1, 1)=(1, q1, D)
T(q1
, 0)=(0, q2
, D)
T(q2, 1)=(0, q2, H)
(q0, 1 , 0, q1, D)
(q1, 1 , 1, q1, D)
(q1
, 0 , 0, q2
, D)
(q2, 1 , 0, q2, H)
X+Y
8/19/2019 While Programs
68/106
68/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 1 1 1 0 1 1 0 0
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q0, 1)=(0, q1, D)
T(q1, 1)=(0, q1, H)
q0 initial state q1 final state
X+Y: Second try
8/19/2019 While Programs
69/106
69/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 1 1 1 0 1 1 0 0
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q0, 1)=(0, q1, D)
Initial state
X+Y: Third try
8/19/2019 While Programs
70/106
70/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 1 1 0 0
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q1, 1)=(1, q1, D)
X+Y
8/19/2019 While Programs
71/106
71/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 1 1 0 0
T(q1, 1)=(1, q1, D)
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
X+Y
X Y
8/19/2019 While Programs
72/106
72/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 1 1 0 0
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q1, 0)=(0, q0, D)
X+Y
8/19/2019 While Programs
73/106
X+Y
8/19/2019 While Programs
74/106
74/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 0 0
T(q1, 1)=(1, q1, D)
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
X+Y
X+Y
8/19/2019 While Programs
75/106
75/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 0 0
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q1, 0)=(0, q0, D)
X+Y
X+Y
8/19/2019 While Programs
76/106
76/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 0 0
Third Step: Transition function, how does the machine
work?
T :Q x X :$ X x {L,R,N,H} x Q
T(q0, 0)=(0, q0, H)
X+Y
X+Y
8/19/2019 While Programs
77/106
77/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
(q0, 1 , 0, q1, D)
(q1, 1 , 1, q1, D)
(q1, 0 , 0, q0, D)
(q0, 0 , 0, q0, H)
(q0, 1 , 0, q1, D)
(q1, 1 , 1, q1, D)
(q1, 0 , 0, q2, D)
(q2, 1 , 0, q2, H)
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q1, H)
Which one is the best?
X+Y
2
8/19/2019 While Programs
78/106
78/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 1 1 1 1 0 0 0 0
x
2x
T(q0, 1)=(0, q1, D)
Initial state
# Delete the 1 due to codification
2X
8/19/2019 While Programs
79/106
79/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
T(q1, 1)=(0, q2, D) # Mark the 1 to duplicate
0 0 1 1 1 0 0 0 0
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
2X
2X
8/19/2019 While Programs
80/106
80/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
T(q2, 1)=(1, q2, D) # Inside the codification
0 0 0 1 1 0 0 0 0
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)
2X
2X
8/19/2019 While Programs
81/106
81/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 0 1 1 0 0 0 0
T(q2, 1)=(1, q2, D) # Inside the codification
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)
2X
2X
8/19/2019 While Programs
82/106
82/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 0 1 1 0 0 0 0
T(q2, 0)=(0, q3, D) # End of codification, newsituation, new state
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
2X
2X
8/19/2019 While Programs
83/106
83/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 0 1 1 0 0 0 0
T(q3, 0)=(1, q4, I) # looking for a cell to write 1.1 is duplicated(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
new situation,new state
2X
2X
8/19/2019 While Programs
84/106
84/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 0 1 1 0 1 0 0
T(q4, 0)=(0, q5, I) # separator found(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q4, 0 , 0, q5, I)
2X
new situation,new state
2X
8/19/2019 While Programs
85/106
85/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 0 1 1 0 1 0 0
# inside the codification
2X
new situation,new state
T(q5, 1)=(1, q5, I)
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)(q3, 0 , 1, q4, I)
(q4, 0 , 0, q5, I)(q5, 1 , 1, q5, I)
2X
8/19/2019 While Programs
86/106
86/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 0 1 1 0 1 0 0
# inside the codification
2X
T(q5, 1)=(1, q5, I)
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)(q3, 0 , 1, q4, I)
(q4, 0 , 0, q5, I)(q5, 1 , 1, q5, I)
2X
8/19/2019 While Programs
87/106
87/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 0 1 1 0 1 0 0
# mark found
2X
new situation,
new state
T(q5, 0)=(1, q1, D)
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)(q3, 0 , 1, q4, I)
(q4, 0 , 0, q5, I)(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
8/19/2019 While Programs
88/106
2X
8/19/2019 While Programs
89/106
89/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 0 1 0 1 0 0
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)(q4, 0 , 0, q5, I)(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
2X
8/19/2019 While Programs
90/106
90/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 0 1 0 1 0 0
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)(q4, 0 , 0, q5, I)(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
2X
8/19/2019 While Programs
91/106
91/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 0 1 0 1 0 0
T(q3, 1)=(1, q3, D)
# looking for a blank
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3
, 1 , 1, q3
, D)(q4, 0 , 0, q5, I)
(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
8/19/2019 While Programs
92/106
2X
8/19/2019 While Programs
93/106
93/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 0 1 0 1 1 0
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)(q4, 1 , 1, q4, I)
(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
T(q4, 1)=(1, q4, I)
# looking for a blank
2X
2X
8/19/2019 While Programs
94/106
94/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 0 1 0 1 1 0
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)
(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
8/19/2019 While Programs
95/106
2X
8/19/2019 While Programs
96/106
96/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 0 1 0 1 1 0
(q0, 1 , 0, q1, D)
(q1
, 1 , 0, q2
, D)
(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
2X
8/19/2019 While Programs
97/106
97/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 1 0 1 1 0
2X
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)(q4, 1 , 1, q4, I)
(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
8/19/2019 While Programs
98/106
98/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 1 0
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)
(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
2X
8/19/2019 While Programs
99/106
99/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 1 0
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)
(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
2X
8/19/2019 While Programs
100/106
100/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 1 0
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)(q5, 1 , 1, q5, I)(q5, 0 , 1, q1, D)
2X
2X
8/19/2019 While Programs
101/106
101/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 1 0
(q0, 1 , 0, q1, D)(q
1
, 1 , 0, q2
, D)
(q2, 1 , 1, q2, D)(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
8/19/2019 While Programs
102/106
102/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 1 1
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
8/19/2019 While Programs
103/106
103/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 1 1
(q0, 1 , 0, q1, D)(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
8/19/2019 While Programs
104/106
104/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 1 1
(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)(q2, 1 , 1, q2, D)
(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)
(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
8/19/2019 While Programs
105/106
105/106
Computability. Grado en Ingeniería Informática del Software. Universidad de Oviedo 17/11/14
0 0 1 1 0 0 1 1 1(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)
2X
8/19/2019 While Programs
106/106
106/106
0 0 1 1 1 0 1 1 1(q0, 1 , 0, q1, D)
(q1, 1 , 0, q2, D)
(q2, 1 , 1, q2, D)(q2, 0 , 0, q3, D)
(q3, 0 , 1, q4, I)
(q3, 1 , 1, q3, D)
(q4, 0 , 0, q5, I)
(q4, 1 , 1, q4, I)(q1, 0 , 1, f, H)
(q5, 1 , 1, q5, I)
(q5, 0 , 1, q1, D)