Theory of Computation
Composition, Primitive Recursion, Primitive Recursively Closed (PRC) Function Classes,
Primitive Recursive Functions
Vladimir Kulyukin
www.vkedco.blogspot.com
Outline● Composition● Primitive Recursion● Primitive Recursively Closed (PRC) Function Classes● Primitive Recursive Functions
Primitives & Scientific Theory● A scientific theory starts with primitives and proceeds to combine those
primitives into increasingly complex structures ● We will proceed in the same fashion: we will combine computable functions in
such a way that the output of one becomes the input of another● Such function combination is called composition● This is the basis of functional programming: programs return values consumed
by other programs that, in turn, return new values consumed by still other programs, etc.
● Another way to obtain new functions from old functions is to compose old functions with themselves or with other old functions mechanically a specific number of times: this is called primitive recursion
Composition
Composition
n.compositio
by ,..., and from obtained is Then
,,...,,...,,...,,...,
Let
. variables of functions be ,...,Let
. variables offunction a be Let
1
1111
1
k
nknn
k
ggfh
xxgxxgfxxh
ngg
kf
Theorem 1.1 (Ch. 3)
If h is obtained from the (partially) computable functions f, g1, …, gk by composition, then h is (partially) computable.
Proof 1.1
. is so ,computable are ,,..., If
. is so,computablepartially are ,,..., If
),...,(
),...,(
...
),...,(
1
1
1
1
111
hfgg
hfgg
ZZfY
XXgZ
XXgZ
k
k
k
nkk
n
Theorem’s Implications
● This simple theorem has an important implication for software reuse
● Essentially, it states that incremental software development is provably possible: we can develop new functions by composing the functions that have already been developed
● Software libraries can be developed from other libraries
Using Composition in Function Computability Proofs
Example 1
.computable is 2 that Show xxh
Example 1
coding. no requires and veconstructi is proof that thisNote
1.1). Theorem(by computable
is ))(),(()(Then .computable is
),( and computable is )( that know We
xxxgxgfxh
yxyxfxxg
Example 2
.computable is 4 that Show 2xxh
Example 2
coding. no requires and veconstructi is proof thisAgain,
1.1). Theorem(by computable is
22))(),(()(Then .computable
is 2)( and computable is ),( that know We
xxxgxgfxh
xxgyxyxf
Primitive Recursion
Motivation● Now we know how to take some functions and compose a
larger function from them that will compute a new value out of their output values
● What is lacking? We have to compose the functions manually● A method would be useful that to takes a function and
compose it with itself any given number of times mechanically● Enter Recursion!
Primitive Recursion: Definition 01
).( by from obtained is Then
))(,()1(
)0(
:follows as from obtained be Let
function. a be ),(Let number. fixed some is Suppose
recursionrecursionprimitivegh
thtgth
kh
g h
totalyxgk
Working with Definition 01: Example 01
times.ofnumber given a
itself with composed is end, in the that Note
,0,1,20,0,1,2
1,1,22,2123
,0,10,0,11,1112
,00,0101
0
g
kggghggg
hgghghh
kgghgghghh
kghghh
kh
Working with Definition 01: Example 02
kggggg
hgggghggg
hgghghh
kgggg
hgggghggg
hgghghh
,0,1,2,3,4
1,1,2,3,42,2,3,4
3,3,44,4145
,0,1,2,3
0,0,1,2,31,1,2,3
2,2,33,3134
Theorem 2.1 (Ch. 3)
.computable is Then .computable
be Let 01. DefinitionRecursion toaccording
recursion primitiveby from obtained be Let
h
g
gh
Proof 2.1: Lemma 1
. of any valuefor macro thehave that weassumecan weThus,
lines
1
...
1
1
: computes that program an is Below
.computable is )(function constant Any :1 Lemma
kkY
k
YY
YY
YY
xfL
kxf
Proof 2.1: Lemma 2
macro. a as 0 V have weThus,
.0 if 1
;0 if 0 computes program This
0 Y [A1]
E1 GOTO
1 Y
A1 GOTO 0 X1 IF
:program hisConsider t exists. macro predicate 0 V :2 Lemma
x
xxP
L
Proof 2.1
1 GOTO
111
111
),1(Y
1 GOTO 0X1 IF ]1[
0 1 Z
Y
:program following heConsider t
A
XX
ZZ
YZg
EA
k
This program computes h(x)
Notes on Proof 2.1
● Suppose X1 = 0. Then Y = k. In other words, h(0) = k, as in the definition
● Suppose X1 = 1. Y is assigned the value of g(0, k). In other words, h(0+1) = g(0, h(0)) = g(0, k)
● Suppose X1 = 2. Y is assigned the value of g(0, k). Then Y is assigned the value of g(1, Y) = g(1, g(0, k)). In other words, h(1+1) = g(1, h(1)) = g(1, g(0, k))
● In general, if X1 = j, Y will take the successive values of h(0), h(1), h(2), …, h(j).
Primitive Recursion: Definition 02
. by and from obtained be tosaid is Then
).,...,),,,...,(,()1,,...,(
),...,()0,,...,(
:follows as and
from obtained variables1 offunction a be Let ly.respective
, variables2 and of functions are and that Suppose
111
11
recursionprimitivegfh
xxtxxhtgtxxh
xxfxxh
gf
nh
nntotalgf
nnn
nn
Working with Definition 02: Example 01
nnn
nnn
nnn
nn
nnn
nn
xxxxxxfgg
xxxxxxhgg
xxxxhgxxh
xxxxfg
xxxxhgxxh
xxfxxh
,...,,,...,,,...,,0,1
,...,,,...,,0,,...,,0,1
,...,,1,,...,,12,,...,
,...,,,...,,0
,...,,0,,...,,01,,...,
,...,0,,...,
111
111
111
11
111
11
Theorem 2.2 (Ch. 3)
.computable is Then .computable be and let and
recursion primitiveby and from obtained be Let
hgf
gfh
Proof 2.2
.,,,..., computes program This
1A GOTO
1
11Z1 Z
),...,,Y,1Z(Y
1E GOTO 0 IF ]1A[
0 1 Z
),...,(Y
:program hisConsider t
1
11
1
1
1
Nttxxh
XX
XXg
X
XXf
n
nn
n
n
n
Proof 2.2
● Why does this program work? Suppose Xn+1 = j. Then Y takes the successive values of h(0), h(1), … ,h(j): Y = f(x1, x2, … ,xn); Y = g(0, h(x1, x2, … ,xn, 0), x1, x2, … ,xn); Y = g(1, h(x1, x2, … ,xn, 1), x1, x2, … ,xn); Y = g(2, h(x1, x2, … ,xn, 2), x1, x2, … ,xn); … Y = g(j-1, h(x1, x2, … ,xn, j-1), x1, x2, … ,xn).
A Perspective on Primitive Recursion
● Primitive recursion is another method that, like composition, allows us to construct new functions from existing functions by composing the existing functions with themselves mechanically
● Does it capture the notion of computability completely?● The answer is – no, because there are computable
functions that cannot be defined via composition or primitive recursion
Key Difference Between Computability and Algorithmics
Big Question
Is there to be, in any way, a bound on the length of a computation? More specifically, should we require that the length of a particular computation be always less than a value which is “easily calculable” from the input and from the set of instructions P? To put it more informally, should we require that, given any input and given any P, we have some idea, “ahead of time,” of how long the computation will take?
Hartley Rogers, Jr. “Theory of Recursive Functions and EffectiveComputability”
A Classical Answer
We thus require that a computation terminate after some finite number of steps; we do not insist on an a priori ability to estimate this number.
Hartley Rogers, Jr. “Theory of
Recursive Functions and Effective
Computability”
A Fundamental Consequence
● The absence of any requirement to know the number of steps a computation may take ahead of time is a distinctive feature of computability theory (aka theory of recursive functions or recursion theory)
● It is this feature that distinguishes computability from algorithmics, because the latter seeks to know the number of steps a computation may take ahead of time whenever possible
Primitive Recursively Closed Classes of Functions
Primitives & Operations in Formal Systems● Any formal system (e.g. Euclidian geometry, number theory, etc.) must state its
primitives, i.e. elements that cannot be decomposed any further● A theory also defines operations that can manipulate primitives into more complex
objects● Examples:
In Euclidean geometry, points are primitives, they can be combined into segments, segments define polygons
In arithmetic, numbers are primitives that can be manipulated with addition, sub-traction, multiplication, etc.
In programming, assembly operations are primitives that can be combined into larger programs
Theory of Primitive Recursive Functions
● Theory of primitive recursive functions also has its primitives: they are called initial functions
● They are called primitives because they are undefinable (unbreakable into further primitives)
● It is of these primitives that we can effectively construct more complicated functions through two operations: composition and primitive recursion
Initial Functions
nixxxu
xn
xxs
inni
1,),...,( :function projection The 3.
0)(:function null The 2.
1)( :functionsuccessor The 1.
1
Primitive Recursively Closed (PRC)
● We can now apply the notion of mathematical closure to classes of functions
● A class of total functions C is a primitive recursively closed (PRC) class if The initial functions are in C Any function obtained from the functions already in C by
composition or primitive recursion is also in C
Theorem 3.1 (Ch. 3)
The class of computable functions is PRC.
Proof 3.1There are two parts to this proof:
1. We show that the initial functions are computable so that the first condition of the PRC definition
2. We can use theorems 1.1 (Ch. 3), 2.1 (Ch. 3), and 2.2 (Ch. 3) to show that any function that is obtained from the initial functions through composition, primitive recursion, or any combination thereof is also computable: in other words, composition, primitive recursion, and any combination thereof preserves computability
Proof 3.1: Part 1
i
nni
XY
xxu
xn
XY
xxs
:Program-L
),...,(:Function Initial
:Program-L
0)(:Function Initial
11 :Program-L
1)( :Function Initial
1
Proof 3.1: Part 2
● Theorem 1.1 (Ch. 3) ensures that any function obtained by composition of computable functions is computable
● Theorems 2.1 (Ch. 3) and 2.2 (Ch. 3) ensure that any function obtained by recursion from another computable function is also computable
● Therefore, any finite sequence of compositions and recursions applied to computable functions leads to a computable function (this can be formalized with an inductive proof)
Primitive Recursive Functions
Definition: Primitive Recursive Function
A function is called primitive recursive if it can be obtained from the initial functions (successor, null constant, and projection) by a finite number of applications of composition or primitive recursion
Terminology Note 01
● We should distinguish the definitions of primitive recursion and primitive recursive function
● Primitive Recursion defines a method (operation) through which functions are constructed from existing functions
● Primitive Recursive Function defines function that has a specific property (it can be constructed by a finite number of applications of composition and primitive recursion to the three initial functions)
Terminology Note 02
● Primitive Recursive Closed (PRC) applies to classes of functions that satisfy specific properties (see the definition of the PRC class)
● Primitive recursive applies to individual functions that have a specific property (see the definition of primitive recursive function)
Simple Insight
● The definition of primitive recursive function has a constructive interpretation
● If f is a primitive recursive function, there is a list of functions f1, …, fn, where fn = f and every function fi in the list is either an initial function or is obtained from the preceding functions in the list by composition or primitive recursion
Corollary 3.2 (Ch. 3)
The class of primitive recursive functions is PRC.
Proof 3.2
● The three initial functions are trivially primitive recursive (because they obtained from themselves by zero applications of composition and recursion)
● Any function obtained from the initial functions by a finite number of applications of composition and/or primitive recursion is primitive recursive, by definition
● So the class of primitive recursive functions is PRC
Theorem 3.3 (Ch. 3)
A function is primitive recursive if and only if it belongs to every PRC class.
Proof 3.3
We need to show:1. If a function is primitive recursive, it belongs to every
PRC class2. If a function belongs to every PRC class, it is primi-
tive recursive
Proof 3.3 (Part 1)1. Assume that a function f is primitive recursive and let C be some
PRC class2. f is either an initial function or is obtained from the initial
functions by a finite number of applications of composition and primitive recursion
3. If f is an initial function, it is in every PRC class, by definition, so f is in C
4. If f is obtained from the initial functions by a finite number of applications of composition and primitive recursion. In other words, there is a list of functions f1, f2, …, fn, such that f = fn and each fi in the list is either initial function or is obtained from the initial functions by a finite number of compositions and recursions. Thus, since C is PRC, every f in the list, including f, is also in C
Proof 3.3 (Part 2)
1. Assume that a function f belongs to every PRC class2. The class of primitive recursive functions is PRC3. Therefore, f must be in the class of primitive recursive
functions, which makes it primitive recursive
Corollary 3.4 (Ch. 3)
Every primitive recursive function is computable.
Proof 3.4
1. Assume that f is primitive recursive
2. By corollary Theorem 3.3 (Ch. 3), f is in every PRC class
3. By Theorem 3.1 (Ch. 3), the class of computable functions is PRC
4. Therefore, f is in the class of computable functions and, therefore, is computable
Question
How can we show that a function is primitive recursive?
Answer
There are two strategies:
1. Obtain the function from the initial functions through composi-tion and/or primitive recursion (first principles reasoning that works on fairly simple functions)
2. Use the knowledge that some functions are already primitive recursive in combination with composition or primitive recur-sion (this is a more generic method that requires more insight but less work)
Reading Suggestions
● Chapters 2 & 3, Computability, Complexity, & Languages by Davis, Weyuker, Sigal
Top Related