Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi...

72
Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino http://www.di.unito.it/~stefano

Transcript of Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi...

Page 1: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Programming With Non-Recursive Maps

Last Update: Swansea, September, 2004

Stefano BerardiUniversità di Torino

http://www.di.unito.it/~stefano

Page 2: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Summary

1. A Dream

2. Dynamic Objects

3. Event Structures

4. Equality and Convergence over Dynamic Objects

5. A Model Of 02-maps

6. An example.

2

Page 3: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

References

This talk introduces the paper:

An Intuitionistic Model of 02-maps …

in preparation.

3

Page 4: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

1. A Dream

If only we had a magic Wand …

4

Page 5: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Just Dreaming ...

• A program would be easier to write using an oracle O for simply existential statements, i.e., using 0

2-maps.

• O is no recursive map, it is rather a kind of magic wand, solving any question x.f(x)=0, with f recursive map, in just one step.

• Our dream. To define a model simulating O and 0

2-maps in a recursive way, closely

enough to solve concrete problems.5

Page 6: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

The role of Intuitionistic Logic

• We define a model of 02-maps using

Intuitionistic Logic, in order to avoid any possibly circularity.

• Classical logic implicitely makes use of non-recursive maps.

• We want to avoid describing 02-maps in term of

themselves.

6

Page 7: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

An example of 02-map

• Denote by NN the set of integer codes for total recursive maps over integers.

• Using Classical Logic, we may prove there is a map F:(NN)N, picking, for any f:NN, some m = F(f) which is a minimum point for f:

xN. f(m) f(x)

7

Page 8: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

An example of 02-map

Here is m=F(f):

y=f(m)

x=m x

y

y=f(x)

8

Page 9: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

F is not recursive

There is no way of finding the minimum point m of f just by looking through finitely may values of f.

y=f(x)

m x

y

Area explored by a recursive F

9

Page 10: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

02-maps solve equations faster

• Fix any three f, g, h:NN.

• Suppose we want to solve in x the unequation system:

f(x) f(g(x))

f(x) f(h(x))

• x=F(f) is a solution: by the choice of x, we have f(x) f(y) for all y, in particular for y=g(x), h(x).

(1)

10

Page 11: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Did we really find a solution?

• Using the 02-map F, we solved the system rather

quickly, with x=F(f).

• The solution x=F(f), however, cannot be computed.

• Apparently, using non-recursive maps we only prove the existence of the solution.

11

Page 12: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Blind Search

• The only evident way to find the solution is blind search: to look for the first xN such that

f(x) f(g(x))

f(x) f(h(x))

• This is rather inefficient in general.

• It makes no use of the ideas of the proof.

(1)

12

Page 13: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Our Goal

We want to define approximations of 02-maps, in

order to use them to solve problems like the previous system.

13

Page 14: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

2. Dynamic Objects

Truth may change with time …

14

Page 15: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

An Oracle for Simply Existential Statements

• Our first step towards a model of 02-maps is:

• to define, for any recursive map f:NN, some approximation of an oracle O(f){True,False} for xN.f(x)=0.

• O is no recursive map.

• What do we know about xN.f(x)=0 in general?

15

Page 16: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

What do we know about xN.f(x)=0?

• We have, in general, an incomplete knowledge about xN.f(x)=0.

• Assume that, for some x1, ..., x

n, we checked if

f(x1)=0, ..., f(x

n)=0

• If the answer is sometimes yes, we do know:

xN.f(x)=0 is True.• If the answer is always no, all we do know is:

x{x1, ..., x

n}.f(x)=0 is false

16

Page 17: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

The idea: introducing a new object

• Since we cannot compute the truth value of xN.f(x)=0, we represent it by introducing a new object: the family of all incomplete computations of xN.f(x)=0.

• That is: the family of truth values of all

x{x1, ..., x

n}.f(x)=0

• for {x1, ..., x

n} finite set of integers.

17

Page 18: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

A notion of State

• We formalize the idea of incomplete computation of the truth value of xN.f(x)=0 by introducing a set T of computation states or “instants of time”.

• T is any partial ordering.• Each tT is characterized by a set a(t) of actions,

taking place before t. In our case:

a(t)={x1, ..., x

n}

• Any “action” corresponds to some xN for which we checked whether f(x)=0.

18

Page 19: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

The truth value for xN.f(x)=0

• The “truth value” V of xN.f(x)=0 is a family:

{V(t)}tT

indexed over computation states, with

V(t) = truth value of (xa(t).f(x)=0).

• The statement (xa(t).f(x)=0) is the restriction of (xN.f(x)=0) to the finite set a(t)N associated to t.

19

Page 20: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

V(t0)=V(u

0)=V(v

0)=F

f(5)=7

f(4)=0

f(8)=2

f(2)=11

f(5)=7

f(9)=0

f(8)=2

f(6)=6

V(t3)=T

V(t2)=T

V(u3)=T

V(t1)=F

f(3)=1

V(u1)=F

V(v3)=F

V(v2)=F

t3

t2

t1

V(u2)=F v3v

2

v1

u2

u1

u3

t0=u

0=v

0

20

In each tT, we compute f(x) for some new x

T

Page 21: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

3. Event Structures

We record all we did …

21

Page 22: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

A notion of Event Structure

An Event Structure consists of:

1. An inhabited recursive partial ordering T of states.

2. a recursive set A of actions, which we may

execute in any state tT, and which may fail.

3. A recursive map a:T{finite subsets of A}

a(t) = set of all actions executed before state t

a is weakly increasing. 22

Page 23: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Covering AssumptionEvery action may be executed in any state: for any

tT, xA, there is some possibly future ut such that xa(u) (x is executed before u).

action x is executed here (it may fail)

t

u

T (states)

23

Page 24: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

An example of Event Structure

We consider actions of the form <d,i>: “send the datum d to the memory of name i”.

A (actions) = Data MemoryNames

T (states) = List(A)

a(t) (actions before t) = {<d,i> | <d,i>t}

Any tT describes a computation up to the state t. Most of the information in t is intended only as comment to the computation.

Page 25: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Positive Informations

• Assume <d,i>a(t): we sent datum d to the memory i before state t.• Then d is paired with i in all possible futures u of t (in all ut), because a is weakly increasing. • In Event Structure we represent only positive informations: erasing is not a primitive operation.•Erasing may be represented by using a fresh name for any new state of the memory i:

<i,0>, <i,1>, <i,2>, …

Page 26: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Erasing in Event Structures

•When memory i is in the state number n, its current content are only all d such that

< d, <i,n> > a(t)• When the state number changes, the current content d of memory i is lost forever.• Every action a = <d, <i,m>> referring to a state m different from the current state (with mn) “fails” (by this we mean: a is recorded, but d is never used).

Page 27: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Dynamic Objects

• Fix any recursive set X. • We call any recursive L:TX a

dynamic object over X• Dyn(X) = {dynamic objects over X}• Dyn(Bool) is the set of dynamic booleans.• The value of a dynamic object may change with

time, and it may depends on all data we sent to any memory.

27

Page 28: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Embedding X in Dyn(X)

• Static objects (objects whose value does not change with time) are particular dynamic objects.

• There is an embedding (.)°:XDyn(X), mapping each xX into the dynamic object x°Dyn(X), defined by

x°(t) = x for all tT

28

Page 29: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Morphisms over Dynamic Objects• Fix any recursive sets X, X’, Y. Any recursive application f : X, X’Y may be raised pointwise to a recursive application:

f° : Dyn(X), Dyn(X’) Dyn(Y)

defined by f°(L)(t) = f(L(t)), for all tT. For instance we set:

(L +° M)(t) = L(t) + M(t)

• We consider all maps of the form f° as morphisms over dynamic objects.

29

Page 30: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Morphisms over Dynamic Objects

• A morphism over dynamic objects should take the current value L(t) X of a dynamic object and return the current value f(L(t)) Y of another one• In general, however, f(L(t)) could be itself dynamic, that is, it could depend on time. • The same value L(t) could correspond to different values f(L(t)) for different t.• Thus, a morphism will be, in general, some map

L, t f(L(t))(t)30

Page 31: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Morphisms over Dynamic Objects

Fix any recursive sets X, Y. We call an application

: Dyn(X)Dyn(Y)

a morphism if (L)(t) depends only over the current value L(t) of L, and on tT:

( L )(t) = ( L(t)° )(t) for all tT

31

Page 32: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Raising a map to a morphism

• For all recursive X, Y, every recursive f:XDyn(Y) may be raised to a unique morphism

f* :Dyn(X) Dyn(Y)• Set, for all tT, and all LDyn(X):

f*(L)(t) = f(L(t))(t) Y• f*(L) is called a synchronous application:

the output f(.)(t) and the input L(t)

have the same clock tT

32

Page 33: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

L(t0)

L(t1)

L(t2)

X Y

f*

f*

f*

33

f(L(t1))(t1)

f(L(t2))(t2)

f(L(t0))(t0)

Page 34: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

4. Convergence and Equality for Dynamic Objects

We interpret parallel computations in Event Structures.

34

Page 35: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Some terminology for Parallel Computations

• Computation states. They include local states of processes, and the state of a common memory.

• Computation. An asyncronous parallel execution for a finite set of processes.

• Agents. Processes modifying the common memory.

• Clusters of Agents . Finite sets of agent, whose composition may change with time.

35

Page 36: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Interpreting Computation States

• Any tT describes a possible state of a computation.

• Any weakly increasing succession :NT represents a possible history of a computation.

36

Page 37: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Interpreting ComputationsA computation is any weakly increasing total recursive succession :NT of states.

(0)

(1)

(2)

(3) T (states)

37

Page 38: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Execution of an Agent

• An agent outputs actions, possibly at very long intervals of time.

• Any action may take very long time to be executed.

• We allow actions to be executed in any order.

• Many other actions, from different agents, may be executed at the same time: there is no priority between agent.

38

Page 39: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Interpreting Agents

• A agent is a way of choosing the next state in a computation.

• A agent is any total recursive map

A : TA

• taking an state t, and returning some action A(t)A to execute from t.

• If is any computation, we define the set of actions of by nN a(n))

39

Page 40: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Computations executing an Agent

We say that a computation :NT executes a agent A, or :A for short, iff for infinitely many iN:

A((i)) {actions of }

That is: for infinitely many times, the action output by A at some step of are executed in some step in

(maybe much later)

If :F, and is subsuccession of , we set by definition :F.

40

Page 41: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Computations executing an AgentIf a computation executes a agent A, then A “steers” : for infinitely many times, the next position in is partly determined by the action output by A.

(0)

(1)Constraint:a((2)) A((1))

(3)

(2)

T (states)

41

Page 42: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Computations executing many AgentsMany agents A, B, C, … may “steer” infinitely many times the same computation :

(0)

(1)

Constraints:a((2)) A((1)), B( (1))

(4)

(2)

(3)

Constraint:a((4)) C((3))

T (states)

42

Page 43: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Interpreting Clusters of Agents

• A cluster is a set of agents variable in time, represented by a total recursive map

F : T{finite sets of agents}

• taking an state tT, and returning the finite set of agents which are part of the cluster in the state t.

• The agent A corresponds to the cluster constantly equal to {A}.

43

Page 44: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Computation executing a ClusterWe say that executes a cluster F, or :F, iff for all agents A there are infinitely many iN such that

if AFi)then A i) {actions of }

In infinitely many steps of ,

provided A is currently inF,

the action output by A takes place

(maybe much later) in If :F, and is subsuccession of a , we set by definition :F.

44

Page 45: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Two Sets of of Computations

• Let :NT be any computation, L, M:TX any dynamic objects.

• L is the set of computations :NT such that

L(n) = L(n+1) : X, for some nN

• (L=M) is the set of computations :NT such that

L(n) = M(n) : X, for some nN

45

Page 46: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Forcing

We say that a cluster F forces a set P of computations, and we write

F : P

iff :F implies P (if all computations executing F have the property P).

46

Page 47: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Convergence and Equality for Dynamic Objects

Let L, M:TX be any dynamic objects.

L is convergent iff F : L for some F

L,M are equivalent iff F : (L=M) for some F

We think of a convergent dynamic object as a process “learning” a value.

Let P: TBool be any dynamic boolean.

P is true iff F:(P=True°) for some F

47

Page 48: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

A “steers” forcing L

Assume A:L

48

Constraint:a((6)) A((5))

Constraint:a((2)) A((1))

(0)(1)

(2)

(3)(4)L((4))=13

(5)L((5))=13

(6)L((6))=13

Page 49: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

About Convergence

Assume F forces L to converge. Classically, we may prove that if :F, then L is stationary.

However:

• On two different computations following F, L may converge to different values.

• On some computation not following F, L may diverge.

Page 50: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

L(0)=7

L(2)=3

L(1)=2

L(3)=3

L(2)=4

L(1)=4

L(1)=1

L(2)=9

: F L is convergent

: F L is convergent

50

does notfollows F:L can diverge

Page 51: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Termination for clusters

• The clusters F and ° are both dynamic objects over Pfin(A).

• A cluster F is call terminating iff

F : (F = °)

(if we execute F, eventually F becomes empty)

• If F is terminating, and follows F, then F((i))= for some iN.

51

Page 52: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

5. An Intuitionistic Model Of 0

2-maps

Just a bit of Category Theory …

52

Page 53: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

The Category Eff

• Eff is the Category of Countable Effective Sets.

• Objects of Eff are:

Partial Equivalent Relations over N

• Morphisms of Eff are:

Recursive Maps compatible with such Relations

53

Page 54: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

The extension LX of X

• For all XEff, we call LX the set of convergent dynamic objects, quotiented up to equivalence.

• L is a Subcategory of Eff, whose morphisms are the morphism over dynamic objects preserving:

1. convergence of a dynamic object

2. equivalence of two dynamic objects.

54

Page 55: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

LX is an Universal Construction

Theorem (LX is an Universal Construction). (.)°:XLX is a universal morphism for the Category Eff w.r.t. the Category L.

55

Page 56: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Lifting a map to LXLY

• Since (.)°:XLX is a universal morphism, we may lift every total recursive map f:XY to some map f°:LXLY, defined by:

f° = (f (.)°)*

• or, alternatively, by:

f°(L)(t) = f(L(t)) for all tT• Lemma (Density). If f(x)=g(x) is true for all

xX, then f°(L)=g°(L) is true for all LLX.56

Page 57: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

LN is a model of 02-maps

Theorem (LN is a model 02-maps).

1. Morphisms over LN are the smallest class:

• including oracles for 01-statements,

• Including any (lifting of) total recursive map over N

• closed under minimalization.

2. LN may be defined using only terminating clusters.

Page 58: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

LX is a Conservative Extension of X

• For all total recursive f, g:XY, any equation f(x)=g(x) over xX may be raised to some equation f°(L)=g°(L) over LLX.

Theorem (Conservativity). If F : f°(L)=g°(L) for some LLX, then f(x)=g(x) for some xX.

• Conservativity allow to use LX in order to solve concrete problems about X.

58

Page 59: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Solving equations in X

• In order to find some solution xX to f(x)=g(x), it is enough to find some convergent dynamic solution LLX of f°(L)=g°(L), then turn L into a solution xX of f(x)=g(x).

• x may be effectively computed out of L and the cluster F forcing f°(L)=g°(L).

• F is the constructive content of a classical proof of f°(L)=g°(L).

59

Page 60: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Solving equations in X: a Rule of Thumb

• Assume F : f°(L)=g°(L).

• We may assume F terminating.

1. Pick any following F.

2. Look for the first i such that F((i))= (there is some because F is terminating).

3. Now x=L((i)) is a solution of f(x)=g(x).

60

Page 61: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

6. An Example: Solving System (1)

Is it a game or is it real?

61

Page 62: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Solvingf°(x) f°(g°(x)) f°(x) f°(h°(x))

• (1)° is the corresponding of (1) in LN.

• Classically, and in N, a solution of (1) is any minimum point xN of f on N.

• Intuitionistically, and in LN, a solution of (1)° is any minimum point MLN of f°on LN.

• Any solution of (1)° in LN may be effectively turned into some solution of (1) in N.

(1)°

62

Page 63: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Minimum point as dynamical object

• Fix f:NN total recursive.

• There is some MLN such that f°(M)f°(L) for all LLN.

• We may define M:TN, on all tT, by

M(t) = first minimum point of f over a(t){0}

• M is convergent if restricted to any computation, because it changes value at most f(0) times.

63

Page 64: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Minimum point as dynamical objectM(t) is, in fact, the minimum point of f over the

finite set of integers we explored up to the state tT.

a(t){0}M(t)

y=f(x)

x

y

64

Page 65: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Minimum point as dynamical object

• A agent forcing

( f°(M) f°(x°) ) = True° • for xN is Add(x):TA, defined for all tT by:

Add(x)(t) = if f(M(t)) f(x) then else {x}• In any computation which follows Add(x), we

have f(M((i))) f(x) true, from some iN on. • From the same i on we have Add(x)((i)) = :

Add(x) is terminating65

Page 66: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Minimum point as dynamical object

• (f°(M) f°(L)) is true for all LLN.

• We may check that a agent forcing (f°(M) f°(L)) to be true is obtained by lifting Add:

Add*(L) : TA

66

Page 67: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

An integer solution of system (1)

• x=ML(N) solves

f°(x)f°(g°(x))

f°(x)f°(h°(x))• By the previous page, a cluster forcing (1) is

F = { Add*(g°(M)), Add*(h°(M)) }• We may check that F is terminating.• We may effectively turn M into a solution

x=mN of (1). How is computed m?

(1)°

67

Page 68: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

The agent Add*(g°(M))

• Just by definition unfolding:

Add*(g°(M))(t) = (by definition of *)

Add(g°(M)(t))(t) = (by definition of °)

Add(g(M(t)))(t) = (by definition of Add)

if f(M(t)) f(g(M(t))) then else {g(M(t))}

• Add*(g°(M)) adds g(M(t)) to a(t), if the dynamic boolean f(M(t)) f(g(M(t))) is false.

68

Page 69: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

The agent Add*(h°(M))

• Same as before:

Add*(h°(M))(t) =

if f(M(t)) f(h(M(t))) then else {h(M(t))}

• Add*(h°(M)) adds h(M(t)) to a(t), if the dynamic boolean f(M(t)) f(h(M(t))) is false.

69

Page 70: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

The cluster F• Pick any computation which follows

F = {Add*(g°(M)), Add*(h°(M))• At each step iN, if for x=M((i)) either

f(x) f(g(x)) or f(x) f(h(x)) • are false, we form a((i+1)) by adding either

g(x) or h(x) to a((i)) .• Otherwise we add nothing, F((i))= becomes

empty, and x=M((i)) is a solution of (1).

70

Page 71: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

An algorithm solving system (1)

• The intuitionistic proof of solvability of system (1) in LN implicitely contains a non-deterministic algorithm finding a solution of (1) in N:

1. Start from x:=0.

2. Set x:=g(x) or x:=h(x) if, respectively, f(x) > f(g(x)) or f(x) > f(h(x)).

3. Continue until f(x) f(g(x)) f(x) f(h(x))

71

Page 72: Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi Università di Torino stefano.

Conclusions

• If we have to find some x1, …, xnN such that P(x1, …, xn), for some total recursive property P, it is enough to find some L1, …, LnLN and a cluster F forcing P°(L1, …, Ln)=True°.

• If F is terminating, to solve P(x1, …, xn)=True we pick any computation following F. We look for the first i such that F((i))=. Eventually, we set x1=L1((i)), …, xn=Ln((i)).

• This method is no blind search. In fact it makes no reference to P, only to F.

72