CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14
description
Transcript of CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14
![Page 1: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/1.jpg)
1
CD5560
FABER
Formal Languages, Automata and Models of Computation
Lecture 14
Mälardalen University
2006
![Page 2: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/2.jpg)
2
Rices sats
Om är en mängd av Turing-accepterbara språk som innehåller något men inte alla sådana språk, så kan ingen TM avgöra för ett godtyckligt Turing-accepterbart språk L om L tillhör eller ej.
(Varje icke-trivial egenskap av Turing-accepterbara språk är oavgörbar.)
![Page 3: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/3.jpg)
3
Avgörbart? Motivera!
a) ”Är L(M) oändlig?” Givet att M är en godtycklig DFA.
b) ”Är L(M) oändlig?” Givet att M är en godtycklig TM.
Svar
a) AVGÖRBART! Man behöver bara kontrollera om M innehåller någon slinga på väg till acceptans, vilket kan göras i ändligt många steg. Se Sallings bok uppgift 7.2.
b) OAVGÖRBART! Följer av Rices sats, om man väljer som mängden av alla oändliga Turingaccepterbara språk, eftersom denna mängd är icketrivial.
Exempel
![Page 4: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/4.jpg)
4
Recursion
In computer programming, recursion is related to performing computations in a loop.
![Page 5: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/5.jpg)
5
Recursion in Problem Modelling
Reducing the complexity by• breaking up computational sequences
into its simplest forms. • synthesizing components into more
complex objects by replicating simple component sequences over and over again.
![Page 6: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/6.jpg)
6
"A reduction is a way of converting one problem into another problem in such a way that a solution to the second problem can be used to solve the first problem."
Michael Sipser, Introduction to the Theory of Computation
![Page 7: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/7.jpg)
7
Recursion can be seen as concept of well-defined self-reference.
We use recursion frequently. Consider, for example, the following hypothetical “definition of a Jew”. I found it on web, as a joke.
“Somebody is a Jew if she is Abraham's wife Sarah, or if his or her mother is a Jew.”
(My digression: I wonder what about Abraham?)
![Page 8: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/8.jpg)
8
So if I want to know if I am a Jew, I look at this definition. I'm not Sarah, so I need to know whether my mother is a Jew.
How do I know about my mother? I look at the definition again. She isn't Sarah either, so I ask about her mother.
I keep going back through the generations - recursively.
![Page 9: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/9.jpg)
9
Self-referential definitions can be dangerous if we're not careful to avoid circularity.
The definition ''A rose is a rose'‘* just doesn't cut it.
This is why our definition of recursion includes the word well-defined.
*Know Gertrude Stein? '' A rose is a rose is a rose''
![Page 10: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/10.jpg)
10
We can write pseudocode to determine whether somebody is an immigrant:
FUNCTION isAnImmigrant(person): IF person immigrated herself, THEN:
return true ELSE:
return isAnImmigrant(person's parent) END IF
This is a recursive function, since it uses itself to compute its own value.
[According to some authors (Rudbeckius) Adam and Eve were Swedish.]
Yet another recursive definition: an immigrant…
![Page 11: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/11.jpg)
11
Functions
From math classes, we have seen many ways of defining and combining numerical functions.– Inverse f-1
– Composition f ◦ g– Derivatives f´(x), f´´(x), …– Iteration f1(x), f2(x), f3(x), f4(x), …
– …
![Page 12: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/12.jpg)
12
Functions
Look at what happens when we use only some of these.
– How can we define standard interesting functions?
– How do these relate to e.g. TM computations? We have seen TMs as functions. They are cumbersome!
As alternative, look at a more intuitive definition of functions.
![Page 13: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/13.jpg)
13
Notation
For brevity, limit to functions on natural numbers
N = {0,1,2,…}
Notation will also use n-tuples of numbers(m1, …, mn)
![Page 14: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/14.jpg)
14
Natural Numbers
Start with standard recursive definition of natural numbers (remember Peano?):
A natural number is either• 0, or• successor(n), where n is a natural number.
![Page 15: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/15.jpg)
15
What is a recurrence?
A recurrence is a well-defined mathematical function written in terms of itself.
It is a mathematical function defined recursively.
![Page 16: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/16.jpg)
16
Fibonacci sequence
1, 1, 2, 3, 5, 8, 13, 21, 34, 55,... The first two numbers of the sequence
are both 1, while each succeeding number is the sum of the two numbers before it.
(We arrived at 55 as the tenth number, since it is the sum of 21 and 34, the eighth and ninth numbers.)
![Page 17: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/17.jpg)
17
F is called a recurrence, since it is defined in terms of itself evaluated at other values.
F(0) = 1 F(1) = 1 (base cases)F(n) = F(n - 1) + F(n - 2)
![Page 18: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/18.jpg)
18
A recursive process is one in which objects are defined in terms of other objects of the same type.
Using some sort of recurrence relation*, the entire class of objects can then be built up from a few initial values and a small number of rules.
Recursion & Recurrence
(*Recurrence is a mathematical function defined recursively.)
![Page 19: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/19.jpg)
19
Computable Function
Any computable function can be programmed using while-loops (i.e., "while something is true, do something else").
For-loops (which have a fixed iteration limit) are a special case of while-loops.
Computable functions could also be coded using a combination of for- and while-loops.
![Page 20: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/20.jpg)
20
Total Function
A function defined for all possible input values.
Primitive Recursive FunctionA function which can be implemented using only for-
loops.
![Page 21: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/21.jpg)
21
103
An example function
1)( 2 nnfDomain Range
10)3( f
![Page 22: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/22.jpg)
22
We need a way to define functions.
We need a set of basic functions.
![Page 23: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/23.jpg)
23
Zero function: 0)( xzero
Successor function: 1)( xxsucc
Projection functions: 1211 ),( xxxp
2212 ),( xxxp
Basic Primitive Recursive Functions
![Page 24: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/24.jpg)
24
Building functions
Composition
)),(),,((),( 21 yxgyxghyxf
![Page 25: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/25.jpg)
25
Composition, GenerallyGiven
g1 : Nk N . . . gm : Nk N
f : Nm N
h(n1,…,nk) = f(g1(n1,…,nk), …, gm(n1,…,nk))
h = f ◦ (g1,…,gm) Alternate notation.
Create h : Nk N
![Page 26: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/26.jpg)
26
Primitive Recursion “Template”
)),(),,(()1,( 2 yxfyxghyxf
)()0,( 1 xgxf
N.B. For primitive recursive functions recursion in only one argument.
![Page 27: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/27.jpg)
27
Any function built fromthe basic primitive recursive functionsis called Primitive Recursive Function.
![Page 28: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/28.jpg)
28
0)( xzero
)())(( xzeroxsucczero
Basic Primitive Zero function (a constant function)
0)0()1()2()3( zerozerozerozero
Example
![Page 29: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/29.jpg)
29
Basic Primitive Identity function
...
xxidentityxx
210)(210
))(())((0)0(
xidentsuccxsuccidentityidentity
Recursive definition
![Page 30: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/30.jpg)
30
Basic Primitive Successor function
...
1321)(210
xxsuccxx
![Page 31: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/31.jpg)
31
))(()( xzerosuccxone
Using Basic Primitive Zero function and a Successor function we can construct Constant functions
etc..
))(()( xonesuccxtwo
))(()( xtwosuccxthree
![Page 32: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/32.jpg)
323
)2())1((
)))0((())))((((
)))((())(()(
succsuccsucc
succsuccsuccxzerosuccsuccsucc
xonesuccsuccxtwosuccxthree
Example
![Page 33: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/33.jpg)
33
A Primitive Recursive Function ),( yxadd
xxadd )0,( (projection)
)),(()1,( yxaddsuccyxadd (successor function)
![Page 34: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/34.jpg)
34
5 )4(
))3(( )))0,3(((
))1,3(()2,3(
succsuccsucc
addsuccsuccaddsuccadd
Example
![Page 35: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/35.jpg)
35
5 14
1)13( 1)1)0,3((
1))1,3(()2,3(
addaddadd
Example
![Page 36: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/36.jpg)
36
Basic Primitive Predecessor function
...
1100)(210
xxpredxx
![Page 37: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/37.jpg)
37
Predecessor
xxsuccpredpred
))((0)0(
1)( xxpred
)())((0)0(
xGxsuccpredpred
Predecessor is a primitive recursive function with no direct self-reference.
x) identity(G(x) templaterecursive primitive
![Page 38: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/38.jpg)
38
Subtraction
)),(())(,()0,(
xysubpredxsuccysubyysub
xyxysub ),(
)1)()1(( xyxy
![Page 39: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/39.jpg)
39
1 )2(
))3(( )))0,3(((
))1,3(()2,3(
predpredpred
subpredpredsubpredsub
Example
![Page 40: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/40.jpg)
40
0)0,( xmult
)),(,()1,( yxmultxaddyxmult
),( yxmultA Primitive Recursive Function
))()1(( xxyyx
![Page 41: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/41.jpg)
41
xxxadd
xxaddxaddxxaddxaddxadd
xaddxaddxaddxaddxmultxaddxaddxaddxadd
xmultxaddxaddxaddxmultxaddxadd
xmultxaddxmult
4)3,(
))2,(,())),(,(,(
))))0,(,(,(,()))))0,(,(,(,(,(
))))1,(,(,(,()))2,(,(,(
))3,(,()4,(
Example
![Page 42: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/42.jpg)
42
1),0( xexp
)),,((),1( yyxexpmultyxexp
),( yxexpA Primitive Recursive Function
)( 1 yyy xx
![Page 43: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/43.jpg)
43
Example
4
)),()),,((
)),),,((()),),),,1((((
)),),),),,0((((()),),),,1((((
)),),,2((()),,3((),4(
yyyyy
yyyymultyyyymultmult
yyyymultmultmultyyyymultmultmultmult
yyyyyexpmultmultmultmultyyyyexpmultmultmult
yyyexpmultmultyyexpmultyexp
![Page 44: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/44.jpg)
44
Primitive Recursion: Logic
A predicate (Boolean function) with output in the set {0,1} which is interpreted as {yes, no}, can be used to define standard functions.– Logical connectives , ,, , …– Numeric comparisons =, < ,, …– Bounded existential quantification in, f(i)– Bounded universal quantification in, f(i)– Bounded minimization min i in, f(i)
where result = 0 if f(i) never true within bounds.
![Page 45: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/45.jpg)
45
Recursive Predicates and?zero ?_ zeronon
1110))?(?(?_0001)),(()?(3210
xzerozerozerononxxonesubxzero
x
![Page 46: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/46.jpg)
46
),( yxand ),( yxor ),( yxless )(xnon returns
1
0
00 yx 00 yx
00 yx00 yx
yx
yx
0x
0x
More Recursive Predicates
))),(?((),())),(?((),())),(?((),(
yxsubzerononyxlessyxaddzerononyxoryxmultzerononyxand
![Page 47: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/47.jpg)
47
)),((),(_ yxequalnonyxequalnon
))),(()),,(((),( xylessnonyxlessnonandyxequal
More Recursive Predicates...
![Page 48: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/48.jpg)
48
Example
Recursive predicates can combine into powerful functions.
What does this compute?
Tests primality.
???(n) = in, jn, ((i=1 j=n) (j=1 i=n) ijn)
![Page 49: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/49.jpg)
49
prime(n) = n2 i<n, (i1 mod(n,i) > 0)
mod(m,n) = if n>0 then (min i im, div(m,n)n+i=m) else 0
div(m,n) = if n>0 then (min i im, (i+1)n>m) else 0
ExampleAnother version of prime(n)
![Page 50: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/50.jpg)
50
Function
00
),,(
xifyxifz
zyxif
if
![Page 51: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/51.jpg)
51
yzyxsuccifzzyif
),),((),,0(
)(),),(()(),,0(
yGzyxsuccifzBzyif
identityG Bwith
our construction
primitive recursive template
)),(),,(()1,( 2 yxfyxghyxf
)()0,( 1 xgxf
![Page 52: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/52.jpg)
52
Division example: x/4
rdqx quotient remainderx
0
1
2
3
4
5
6
7
8
0400
1401
2402
3403
0414
1415
2416
3417
0428
0
0
0
0
1
1
1
1
2
0
1
2
3
0
1
2
3
0
quotientq remainderr 4d
![Page 53: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/53.jpg)
53
Division as Primitive Recursion
))),,((,
),,((),(
ddxsubremainx
dxlessifdxremain
)))),,(((,0
),,((),(
ddxsubquotsucc
dxlessifdxquot
![Page 54: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/54.jpg)
54
Division example: x/4
))),,((,
),,((),(
ddxsubremainx
dxlessifdxremain
rdqx quotient remainderx
0
1
2
3
4
5
6
7
8
0400
1401
2402
3403
0414
1415
2416
3417
0428
0
0
0
0
1
1
1
1
2
0
1
2
3
0
1
2
3
0
quotientq
remainderr
4d
)))),,(((,0
),,((),(
ddxsubquotsucc
dxlessifdxquot
![Page 55: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/55.jpg)
55
Division as Primitive Recursion
)0)),,(((
),)),,(((()),((0),0(
dxsubremainsuccddxremainsucclessifdxsuccremain
dremain
)),()),),((?(()),((0),0(
dxquotdxsuccremainzeroadddxsuccquotdquot
![Page 56: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/56.jpg)
56
)),(?(),( dxremainzerodxdivisible
Recursive Predicate divisible
![Page 57: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/57.jpg)
57
)),((),(_ yxequalnonyxequalnon
Recursive Predicate
)),(?(),( dxremindzerodxdivisible
![Page 58: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/58.jpg)
58
Theorem The set of primitive recursive functions is countable.
Proof Each primitive recursive function can be encoded as a string.
Enumerate all strings in proper order. Check if a string is a function.
![Page 59: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/59.jpg)
59
There is a function that is not primitive recursive.
ProofEnumerate the primitive recursive functions
,,, 321 fff
Theorem
![Page 60: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/60.jpg)
60
Define function
1)()( ifig i
g differs from every ifg is not primitive recursive
END OF PROOF
![Page 61: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/61.jpg)
61
A specific function that is notprimitive recursive:
Ackermann’s function:
)),(,1()1,()1,1()0,(
1),0(
yxAxAyxAxAxA
yyA
Grows very fast, faster than any primitive recursive function
![Page 62: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/62.jpg)
62
The Ackermann function is the simplest example of a well defined total function which is computable but not primitive recursive, providing a counterexample to the belief in the early 1900s that every computable function was also primitive recursive.
![Page 63: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/63.jpg)
63
Recursive Functions
0),(such that smallest )),(( yxgyyxgy
Ackermann’s function is a
Recursive Function
![Page 64: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/64.jpg)
64
Primitive recursive functions
Recursive Functions
![Page 65: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/65.jpg)
65
Primitive Recursion: Extended Example
Needs following building blocks:– constants– addition– multiplication– exponentiation– subtraction
A polynomial function:
f(x,y) = 3x7+ xy – 7y2.
![Page 66: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/66.jpg)
66
Additionadd(m,n) = m+n
add(0,n) =add(m+1,n) =
nsucc(add(m,n))
Multiplication:mult(m,n) = mn
mult(0,n) =mult(m+1,n) =
0add(mult(m,n),n)
![Page 67: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/67.jpg)
67
Exponentiation:exp(m,n) = nm
exp(0,n) =exp(m+1,n) =
1mult(exp(m,n),n)
= one(n)
Subtraction sub(m,n) = m-n
sub(0,n) =sub(m+1,n) =
0 = zero(n)succ(sub(m,n))
![Page 68: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/68.jpg)
68
Primitive Recursion: Extended Example
f(x,y) = (3x7+ xy) - 7y2
f = sub◦ (add ◦ (f1,f2), f3)
f1(x,y) = mult(3,exp(7,x)) f1 = mult ◦ (three, exp ◦ (seven))
f2(x,y) = mult(x,y) f2 = mult
f3(x,y) = mult(7,exp(2,y)) f3 = mult ◦ (seven, exp ◦ (two))
f(x,y) = sub(add(f1(x,y),f2(x,y)),f3(x,y))
![Page 69: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/69.jpg)
69
Primitive Recursion
All primitive recursive functions are total.I.e., they are defined for all values.
Primitive recursion lack some interesting functions.“True” subtraction – when using natural numbers.“True” division – undefined when divisor is 0.Trigonometric functions – undefined for some values.…
![Page 70: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/70.jpg)
70
Partial Recursive
A function is partial recursive it can be defined by the previous constructions.
A function is recursive it is partial recursive and total.
![Page 71: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/71.jpg)
71
Division:div(m,n) = m n
div(m,n) = min i, sub(succ(m),add(mult(i,n),n)) = 0
div(m,n) = minimum i such thati mnin m-(n-1)in+n m+1(m+1) – (in+n) 0(m+1) (in+n) = 0
Example
![Page 72: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/72.jpg)
72
Relations Among Function Classes
Functions TMs– Define TMs in terms of the
function formers.– Straightforward, but long.
TMs Functions– Define functions where
subcomputations encode TM behavior.
– Simple encoding scheme.– Straightforward, but very
messy.
partial recursive= recognizable
recursive= decidable
primitiverecursive
![Page 73: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/73.jpg)
73
otherwise 0,)(
even isn if,1neven
))(,1()1(1)0(
kevensubkeveneven
More Examples of Primitive Recursion
A recursive function is a function that calls itself (by using its own name within its function body).
Even
![Page 74: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/74.jpg)
74
))1(),(()1(1)0(
xxfactmultxfactfact
Factorials
))1)1(! nnn
![Page 75: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/75.jpg)
75
),(),)),(((()),((),0(),0(),()?(
),()(
yxisSquareyxsuccsquareequaloryxsuccisSquareyequalyisSquarexxisSquarexsquare
xxmultxsquare
)),(,()),(,(),),,(((),()0,()?(
yymultxequalysuccxhxyymultlessifyxhxhxsquare
Is a number a square?
Forward recursion (-recursion)
![Page 76: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/76.jpg)
76
number. naturalany of square anot is 50))5,0(
))5,0(.......................................................................))5,1(..........................................................................))5,2(..........................................................................
))))5,3(),5,4(((),5,5((()5,4(),5,5((()5,5(
)5,5()5?(
isSquare
isSquareetcisSquareetcisSquareetc
isSquaresquareequalorsquareequalorisSquaresquareequalorisSquare
isSquaresquare
![Page 77: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/77.jpg)
77
etc
multequalhmultlessifhhsquare
...))0,0(,5(),1,5(),5),0,0((()0,5(
)0,5()5?(
![Page 78: CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 14](https://reader036.fdocuments.us/reader036/viewer/2022081604/56814a9a550346895db7aa30/html5/thumbnails/78.jpg)
78
Midterm Exam 3Restriction-Free Languages
Place: the LAMBDA examination hall Time: on Tuesday 2004-05-30, 10:15-12:00
It is OPEN BOOK. (This means you are allowed to bring in one book
of your choice.)It will cover Turing Machines/Restriction-free
Languages).
You will have the two hours to do the test.