Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi...
-
Upload
asher-martin -
Category
Documents
-
view
214 -
download
0
Transcript of Programming With Non-Recursive Maps Last Update: Swansea, September, 2004 Stefano Berardi...
Programming With Non-Recursive Maps
Last Update: Swansea, September, 2004
Stefano BerardiUniversità di Torino
http://www.di.unito.it/~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
References
This talk introduces the paper:
An Intuitionistic Model of 02-maps …
in preparation.
3
1. A Dream
If only we had a magic Wand …
4
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
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
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
An example of 02-map
Here is m=F(f):
y=f(m)
x=m x
y
y=f(x)
8
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
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
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
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
Our Goal
We want to define approximations of 02-maps, in
order to use them to solve problems like the previous system.
13
2. Dynamic Objects
Truth may change with time …
14
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
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
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
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
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
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
3. Event Structures
We record all we did …
21
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
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
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.
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>, …
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).
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
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
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
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
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
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
L(t0)
L(t1)
L(t2)
X Y
f*
f*
f*
33
f(L(t1))(t1)
f(L(t2))(t2)
f(L(t0))(t0)
4. Convergence and Equality for Dynamic Objects
We interpret parallel computations in Event Structures.
34
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
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
Interpreting ComputationsA computation is any weakly increasing total recursive succession :NT of states.
(0)
(1)
(2)
(3) T (states)
37
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
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
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
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
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
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
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
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
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
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
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
…
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.
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
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
5. An Intuitionistic Model Of 0
2-maps
Just a bit of Category Theory …
52
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
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
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
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
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.
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
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
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
6. An Example: Solving System (1)
Is it a game or is it real?
61
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
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
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
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
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
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
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
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
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
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
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