mathematics for informatics

45
Mathematics for Informatics Carlos Areces and Patrick Blackburn [email protected] [email protected] http://www.loria.fr/ ~ areces http://www.loria.fr/ ~ blacbur INRIA Lorraine Nancy, France 2007/2008

Upload: vuhanh

Post on 31-Dec-2016

224 views

Category:

Documents


3 download

TRANSCRIPT

Mathematics for Informatics

Carlos Areces and Patrick [email protected] [email protected]

http://www.loria.fr/~areces http://www.loria.fr/~blacbur

INRIA LorraineNancy, France

2007/2008

CompositionLet f : Nk → N and g1, . . . , gk : Nn → N. h : Nn → N isobtained from f and g1, . . . , gk by composition if

h(x1, . . . , xn) = f (g1(x1, . . . , xn), . . . , gk(x1, . . . , xn))

TheoremIf h is obtained from the (partially) computables functionsf , g1, . . . , gk by composition then h is (partially) computable.

Proof.The following program computes h:

Z1 ← g1(X1, . . . ,Xn)...

Zk ← gk(X1, . . . ,Xn)

Y ← f (Z1, . . . ,Zk)

If f , g1, . . . , gk are total then h is total.

2

CompositionLet f : Nk → N and g1, . . . , gk : Nn → N. h : Nn → N isobtained from f and g1, . . . , gk by composition if

h(x1, . . . , xn) = f (g1(x1, . . . , xn), . . . , gk(x1, . . . , xn))

TheoremIf h is obtained from the (partially) computables functionsf , g1, . . . , gk by composition then h is (partially) computable.

Proof.The following program computes h:

Z1 ← g1(X1, . . . ,Xn)...

Zk ← gk(X1, . . . ,Xn)

Y ← f (Z1, . . . ,Zk)

If f , g1, . . . , gk are total then h is total.

2

CompositionLet f : Nk → N and g1, . . . , gk : Nn → N. h : Nn → N isobtained from f and g1, . . . , gk by composition if

h(x1, . . . , xn) = f (g1(x1, . . . , xn), . . . , gk(x1, . . . , xn))

TheoremIf h is obtained from the (partially) computables functionsf , g1, . . . , gk by composition then h is (partially) computable.

Proof.The following program computes h:

Z1 ← g1(X1, . . . ,Xn)...

Zk ← gk(X1, . . . ,Xn)

Y ← f (Z1, . . . ,Zk)

If f , g1, . . . , gk are total then h is total.2

Recursion for h : N→ Nh : N→ N is obtained from g : N2 → N by primitive recursion if

h(0) = k

h(t + 1) = g(t, h(t))

TheoremIf h is obtained from g by primitive recursion and g is computablethen h is computable.

Proof.The following program computes h:

Y ← k (is a macro, it’s easy to do)

[A] IF X = 0 GOTO E (another macro, IF with =)

Y ← g(Z ,Y )

Z ← Z + 1

X ← X − 1

GOTO A

If f , g1, . . . , gk are total then h is total.

3

Recursion for h : N→ Nh : N→ N is obtained from g : N2 → N by primitive recursion if

h(0) = k

h(t + 1) = g(t, h(t))

TheoremIf h is obtained from g by primitive recursion and g is computablethen h is computable.

Proof.The following program computes h:

Y ← k (is a macro, it’s easy to do)

[A] IF X = 0 GOTO E (another macro, IF with =)

Y ← g(Z ,Y )

Z ← Z + 1

X ← X − 1

GOTO A

If f , g1, . . . , gk are total then h is total.

3

Recursion for h : N→ Nh : N→ N is obtained from g : N2 → N by primitive recursion if

h(0) = k

h(t + 1) = g(t, h(t))

TheoremIf h is obtained from g by primitive recursion and g is computablethen h is computable.

Proof.The following program computes h:

Y ← k (is a macro, it’s easy to do)

[A] IF X = 0 GOTO E (another macro, IF with =)

Y ← g(Z ,Y )

Z ← Z + 1

X ← X − 1

GOTO A

If f , g1, . . . , gk are total then h is total. 3

Recursion for h : Nn+1 → N

h : Nn+1 → N is obtained from g : Nn+2 → N and f : Nn → N byprimitive recursion if

h(x1, . . . , xn, 0) = f (x1, . . . , xn)

h(x1, . . . , xn, t + 1) = g(t, h(x1, . . . , xn, t), x1, . . . , xn)

TheoremIf h is obtained from f and g by primitive recursion and f and gare computable then h is computable.

4

Recursion for h : Nn+1 → N

h : Nn+1 → N is obtained from g : Nn+2 → N and f : Nn → N byprimitive recursion if

h(x1, . . . , xn, 0) = f (x1, . . . , xn)

h(x1, . . . , xn, t + 1) = g(t, h(x1, . . . , xn, t), x1, . . . , xn)

TheoremIf h is obtained from f and g by primitive recursion and f and gare computable then h is computable.

4

Another way to characterized computable functions?Let’s combine computable functions with the schemes of

I compositionI primitive recursion

to obtain new computable functions.

I We defined computable functions as the total functions wherecan be programmed in the simple imperative functiosn S.

I Let’s now think in a simple functional language (i.e., with avery restricted recursion)

I Can we define computable functions though the schemes ofcomposition and primitive recursion instead or using S ?

I in other words, can we characterize computable functions usinga simple functional language?

We need initial functions. Let’s try withI s(x) = x + 1I n(x) = 0I proyections: un

i (x1, . . . , xn) = xi for i ∈ {1, . . . , n}

5

Another way to characterized computable functions?Let’s combine computable functions with the schemes of

I compositionI primitive recursion

to obtain new computable functions.

I We defined computable functions as the total functions wherecan be programmed in the simple imperative functiosn S.

I Let’s now think in a simple functional language (i.e., with avery restricted recursion)

I Can we define computable functions though the schemes ofcomposition and primitive recursion instead or using S ?

I in other words, can we characterize computable functions usinga simple functional language?

We need initial functions. Let’s try withI s(x) = x + 1I n(x) = 0I proyections: un

i (x1, . . . , xn) = xi for i ∈ {1, . . . , n}

5

Another way to characterized computable functions?Let’s combine computable functions with the schemes of

I compositionI primitive recursion

to obtain new computable functions.

I We defined computable functions as the total functions wherecan be programmed in the simple imperative functiosn S.

I Let’s now think in a simple functional language (i.e., with avery restricted recursion)

I Can we define computable functions though the schemes ofcomposition and primitive recursion instead or using S ?

I in other words, can we characterize computable functions usinga simple functional language?

We need initial functions. Let’s try withI s(x) = x + 1I n(x) = 0I proyections: un

i (x1, . . . , xn) = xi for i ∈ {1, . . . , n}

5

Another way to characterized computable functions?Let’s combine computable functions with the schemes of

I compositionI primitive recursion

to obtain new computable functions.

I We defined computable functions as the total functions wherecan be programmed in the simple imperative functiosn S.

I Let’s now think in a simple functional language (i.e., with avery restricted recursion)

I Can we define computable functions though the schemes ofcomposition and primitive recursion instead or using S ?

I in other words, can we characterize computable functions usinga simple functional language?

We need initial functions. Let’s try withI s(x) = x + 1I n(x) = 0I proyections: un

i (x1, . . . , xn) = xi for i ∈ {1, . . . , n}5

PRC ClassesA class C of total functions is PRC (primitive recursive closed) if

1. the initial functions are in C2. if a function f is obtained from other functions already in C

using composition and primitive recursion, then f is also in C.

Theoremthe class of computable functions is a PRC class.

Proof.We already saw 2. Let’s see 1:

I s(x) = x + 1 can be computed with the program

Y ← X + 1

I n(x) = 0 is computed with the empty program

I uni (x1, . . . , xn) = xi is computed with the program

Y ← Xi

6

PRC ClassesA class C of total functions is PRC (primitive recursive closed) if

1. the initial functions are in C2. if a function f is obtained from other functions already in C

using composition and primitive recursion, then f is also in C.

Theoremthe class of computable functions is a PRC class.

Proof.We already saw 2. Let’s see 1:

I s(x) = x + 1 can be computed with the program

Y ← X + 1

I n(x) = 0 is computed with the empty program

I uni (x1, . . . , xn) = xi is computed with the program

Y ← Xi

6

PRC ClassesA class C of total functions is PRC (primitive recursive closed) if

1. the initial functions are in C2. if a function f is obtained from other functions already in C

using composition and primitive recursion, then f is also in C.

Theoremthe class of computable functions is a PRC class.

Proof.We already saw 2.

Let’s see 1:

I s(x) = x + 1 can be computed with the program

Y ← X + 1

I n(x) = 0 is computed with the empty program

I uni (x1, . . . , xn) = xi is computed with the program

Y ← Xi

6

PRC ClassesA class C of total functions is PRC (primitive recursive closed) if

1. the initial functions are in C2. if a function f is obtained from other functions already in C

using composition and primitive recursion, then f is also in C.

Theoremthe class of computable functions is a PRC class.

Proof.We already saw 2. Let’s see 1:

I s(x) = x + 1 can be computed with the program

Y ← X + 1

I n(x) = 0 is computed with the empty program

I uni (x1, . . . , xn) = xi is computed with the program

Y ← Xi

6

PRC ClassesA class C of total functions is PRC (primitive recursive closed) if

1. the initial functions are in C2. if a function f is obtained from other functions already in C

using composition and primitive recursion, then f is also in C.

Theoremthe class of computable functions is a PRC class.

Proof.We already saw 2. Let’s see 1:

I s(x) = x + 1 can be computed with the program

Y ← X + 1

I n(x) = 0 is computed with the empty program

I uni (x1, . . . , xn) = xi is computed with the program

Y ← Xi

6

PRC ClassesA class C of total functions is PRC (primitive recursive closed) if

1. the initial functions are in C2. if a function f is obtained from other functions already in C

using composition and primitive recursion, then f is also in C.

Theoremthe class of computable functions is a PRC class.

Proof.We already saw 2. Let’s see 1:

I s(x) = x + 1 can be computed with the program

Y ← X + 1

I n(x) = 0 is computed with the empty program

I uni (x1, . . . , xn) = xi is computed with the program

Y ← Xi

6

Primitive Recursive FunctionsA function is primitive recursive (p.r.) if it can be obtained frominitial functions by means of a finite number of applications ofcomposition and primitive recursion.

Theorema function is p.r. iff it belongs to any PRC.

Proof.

(⇐) The class of p.r. functions is a PRC class. Hence, if f is inany PRC class, in particular f is p.r.

(⇒) Let f be p.r. and let C be a PRC class. As f is p.r., there is alist

f1, f2, . . . , fnsuch that

I f = fnI fi is initial (hence it is in C) or it is obtained by composition or

primitive recursion from functions fj , j < i (hence it is also inC).

But then, all the functions in the list are in C.

7

Primitive Recursive FunctionsA function is primitive recursive (p.r.) if it can be obtained frominitial functions by means of a finite number of applications ofcomposition and primitive recursion.

Theorema function is p.r. iff it belongs to any PRC.

Proof.

(⇐) The class of p.r. functions is a PRC class. Hence, if f is inany PRC class, in particular f is p.r.

(⇒) Let f be p.r. and let C be a PRC class. As f is p.r., there is alist

f1, f2, . . . , fnsuch that

I f = fnI fi is initial (hence it is in C) or it is obtained by composition or

primitive recursion from functions fj , j < i (hence it is also inC).

But then, all the functions in the list are in C.

7

Primitive Recursive FunctionsA function is primitive recursive (p.r.) if it can be obtained frominitial functions by means of a finite number of applications ofcomposition and primitive recursion.

Theorema function is p.r. iff it belongs to any PRC.

Proof.

(⇐) The class of p.r. functions is a PRC class. Hence, if f is inany PRC class, in particular f is p.r.

(⇒) Let f be p.r. and let C be a PRC class. As f is p.r., there is alist

f1, f2, . . . , fnsuch that

I f = fnI fi is initial (hence it is in C) or it is obtained by composition or

primitive recursion from functions fj , j < i (hence it is also inC).

But then, all the functions in the list are in C. 7

Computable Functions = Primitive Recursive Functions?

Ok then, the class of p.r. functions is the smallest PRC class.

Corollary

Every p.r. function is computable.

Proof.We already proved that the class of computable functions is PRC.By the previous tehorem, if f is p.r., then f is in the class ofcomputable functions.

Of course, no every partially computable function is p.r. becauseevery p.r. function is total. But. . .

Is every computable function p.r.?

8

Computable Functions = Primitive Recursive Functions?

Ok then, the class of p.r. functions is the smallest PRC class.

Corollary

Every p.r. function is computable.

Proof.We already proved that the class of computable functions is PRC.By the previous tehorem, if f is p.r., then f is in the class ofcomputable functions.

Of course, no every partially computable function is p.r. becauseevery p.r. function is total. But. . .

Is every computable function p.r.?

8

Computable Functions = Primitive Recursive Functions?

Ok then, the class of p.r. functions is the smallest PRC class.

Corollary

Every p.r. function is computable.

Proof.We already proved that the class of computable functions is PRC.By the previous tehorem, if f is p.r., then f is in the class ofcomputable functions.

Of course, no every partially computable function is p.r. becauseevery p.r. function is total. But. . .

Is every computable function p.r.?

8

Example of a p.r. functionAddition add(x , y) = x + y is p.r.Let’s think how do we write it in a functional language

add :: nat -> natadd x y = x + y

But let’s not use the + function; just +1

add :: nat -> natadd x 0 = xadd x (y+1) = (add x y) + 1

We can rewrite this as

add(x , 0) = u11(x)

add(x , y + 1) = g(y , add(x , y), x)

whereg(x1, x2, x3) = s(u3

2(x1, x2, x3))

9

Example of a p.r. functionAddition add(x , y) = x + y is p.r.Let’s think how do we write it in a functional language

add :: nat -> natadd x y = x + y

But let’s not use the + function; just +1

add :: nat -> natadd x 0 = xadd x (y+1) = (add x y) + 1

We can rewrite this as

add(x , 0) = u11(x)

add(x , y + 1) = g(y , add(x , y), x)

whereg(x1, x2, x3) = s(u3

2(x1, x2, x3))

9

Example of a p.r. functionAddition add(x , y) = x + y is p.r.Let’s think how do we write it in a functional language

add :: nat -> natadd x y = x + y

But let’s not use the + function; just +1

add :: nat -> natadd x 0 = xadd x (y+1) = (add x y) + 1

We can rewrite this as

add(x , 0) = u11(x)

add(x , y + 1) = g(y , add(x , y), x)

whereg(x1, x2, x3) = s(u3

2(x1, x2, x3))

9

Example of a p.r. functionAddition add(x , y) = x + y is p.r.Let’s think how do we write it in a functional language

add :: nat -> natadd x y = x + y

But let’s not use the + function; just +1

add :: nat -> natadd x 0 = xadd x (y+1) = (add x y) + 1

We can rewrite this as

add(x , 0) = u11(x)

add(x , y + 1) = g(y , add(x , y), x)

whereg(x1, x2, x3) = s(u3

2(x1, x2, x3))

9

Other p.r. functions

I x · yI x!

I xy

I x−̇y =

{x − y if x ≥ y

0 otherwise

I α(x) =

{1 if x = 0

0 otherwise

I and many others. Are they all the computable functions?

10

Other p.r. functions

I x · yI x!

I xy

I x−̇y =

{x − y if x ≥ y

0 otherwise

I α(x) =

{1 if x = 0

0 otherwise

I and many others. Are they all the computable functions?

10

Primitive recursive predicates

Predicates are just functions that take values in {0, 1}.I 1 is interpreted as true.

I 0 is interpreted as false.

p.r. predicates are those which are represented by p.r. functions in{0, 1}.

For example, the predicate x ≤ y is p.r. because it can be definedas

α(x−̇y)

11

Primitive recursive predicates

Predicates are just functions that take values in {0, 1}.I 1 is interpreted as true.

I 0 is interpreted as false.

p.r. predicates are those which are represented by p.r. functions in{0, 1}.

For example, the predicate x ≤ y is p.r. because it can be definedas

α(x−̇y)

11

Logical operators

TheoremLet C be a PRC class. If p and q are predicates in C then ¬p,p ∧ q and p ∨ q are in C.

Proof.

I ¬p can be defined as α(p)

I p ∧ q can be defined as p · qI p ∨ q can be defined as ¬(¬p ∧ ¬q)

Corollary

If p and q are p.r. predicates, then also ¬p, p ∨ q and p ∧ q arep.r. predicates.

Corollary

If p and q are computable predicates, then also ¬p, p ∨ q y p ∧ qare computable predicates.

12

Logical operators

TheoremLet C be a PRC class. If p and q are predicates in C then ¬p,p ∧ q and p ∨ q are in C.

Proof.

I ¬p can be defined as α(p)

I p ∧ q can be defined as p · qI p ∨ q can be defined as ¬(¬p ∧ ¬q)

Corollary

If p and q are p.r. predicates, then also ¬p, p ∨ q and p ∧ q arep.r. predicates.

Corollary

If p and q are computable predicates, then also ¬p, p ∨ q y p ∧ qare computable predicates.

12

Logical operators

TheoremLet C be a PRC class. If p and q are predicates in C then ¬p,p ∧ q and p ∨ q are in C.

Proof.

I ¬p can be defined as α(p)

I p ∧ q can be defined as p · qI p ∨ q can be defined as ¬(¬p ∧ ¬q)

Corollary

If p and q are p.r. predicates, then also ¬p, p ∨ q and p ∧ q arep.r. predicates.

Corollary

If p and q are computable predicates, then also ¬p, p ∨ q y p ∧ qare computable predicates.

12

Logical operators

TheoremLet C be a PRC class. If p and q are predicates in C then ¬p,p ∧ q and p ∨ q are in C.

Proof.

I ¬p can be defined as α(p)

I p ∧ q can be defined as p · qI p ∨ q can be defined as ¬(¬p ∧ ¬q)

Corollary

If p and q are p.r. predicates, then also ¬p, p ∨ q and p ∧ q arep.r. predicates.

Corollary

If p and q are computable predicates, then also ¬p, p ∨ q y p ∧ qare computable predicates.

12

Definition by cases (2)

TheoremLet C be a PRC class. Let h, g : Nn → N be functions in C and letp : Nn → {0, 1} be a predicate in C. Then the function

f (x1, . . . , xn) =

{g(x1, . . . , xn) if p(x1, . . . , xn)

h(x1, . . . , xn) otherwise

is in C.

Proof.f (x1, . . . , xn) =g(x1, . . . , xn) · p(x1, . . . , xn) + h(x1, . . . , xn) · α(p(x1, . . . , xn))

13

Definition by cases (m + 1)

TheoremLet C be a PRC class. Let g1, . . . , gm, h : Nn → N be functions inC and let p1, . . . , pm : Nn → {0, 1} be predicates in C. Then thefunction

f (x1, . . . , xn) =

g1(x1, . . . , xn) if p1(x1, . . . , xn)

...

gm(x1, . . . , xn) if pm(x1, . . . , xn)

h(x1, . . . , xn) otherwise

is in C.

14

Primitive recursion

I we have not yet answer the question: p.r. = computable?

I and we can still not answer it

Observe that the recursion scheme

h(x1, . . . , xn, 0) = f (x1, . . . , xn)

h(x1, . . . , xn, t + 1) = g(t, h(x1, . . . , xn, t), x1, . . . , xn)

is very simple:

I recursion is always done in the last parameter

I the variant function of h(x1, . . . , xn, xn+1) is xn+1

15

Primitive recursion

I we have not yet answer the question: p.r. = computable?

I and we can still not answer it

Observe that the recursion scheme

h(x1, . . . , xn, 0) = f (x1, . . . , xn)

h(x1, . . . , xn, t + 1) = g(t, h(x1, . . . , xn, t), x1, . . . , xn)

is very simple:

I recursion is always done in the last parameter

I the variant function of h(x1, . . . , xn, xn+1) is xn+1

15

Primitive recursion

I we have not yet answer the question: p.r. = computable?

I and we can still not answer it

Observe that the recursion scheme

h(x1, . . . , xn, 0) = f (x1, . . . , xn)

h(x1, . . . , xn, t + 1) = g(t, h(x1, . . . , xn, t), x1, . . . , xn)

is very simple:

I recursion is always done in the last parameter

I the variant function of h(x1, . . . , xn, xn+1) is xn+1

15

For-programsIf we go back to the imperative language known as Pascal, the p.r.functions are the onces that can be written using for-loops:

I the only type of looks are of the formfor i=1 to x {

S(i)}

I it is not the kind of cicles we have in S (which are ratherwhile loops)

We know that:

I S can simulate whileI for loops can be simulated using whileI any for-program can be rewritten in S

Questions:

I Any S program can be rewritten as a for-program?I Is primitive recursion as expressive as general recursion in a

functional language?I computable = primitive recursive?

16

For-programsIf we go back to the imperative language known as Pascal, the p.r.functions are the onces that can be written using for-loops:

I the only type of looks are of the formfor i=1 to x {

S(i)}

I it is not the kind of cicles we have in S (which are ratherwhile loops)

We know that:

I S can simulate whileI for loops can be simulated using whileI any for-program can be rewritten in S

Questions:

I Any S program can be rewritten as a for-program?I Is primitive recursion as expressive as general recursion in a

functional language?I computable = primitive recursive?

16

For-programsIf we go back to the imperative language known as Pascal, the p.r.functions are the onces that can be written using for-loops:

I the only type of looks are of the formfor i=1 to x {

S(i)}

I it is not the kind of cicles we have in S (which are ratherwhile loops)

We know that:

I S can simulate whileI for loops can be simulated using whileI any for-program can be rewritten in S

Questions:

I Any S program can be rewritten as a for-program?I Is primitive recursion as expressive as general recursion in a

functional language?I computable = primitive recursive?

16