• Aucun résultat trouvé

Primitive recursive categories and machines

N/A
N/A
Protected

Academic year: 2022

Partager "Primitive recursive categories and machines"

Copied!
8
0
0

Texte intégral

(1)

D IAGRAMMES

Y VES L AFONT

Primitive recursive categories and machines

Diagrammes, tome 22 (1989), p. 7-13

<http://www.numdam.org/item?id=DIA_1989__22__7_0>

© Université Paris 7, UER math., 1989, tous droits réservés.

L’accès aux archives de la revue « Diagrammes » implique l’accord avec les conditions gé- nérales d’utilisation (http://www.numdam.org/conditions). Toute utilisation commerciale ou impres- sion systématique est constitutive d’une infraction pénale. Toute copie ou impression de ce fi- chier doit contenir la présente mention de copyright.

Article numérisé dans le cadre du programme Numérisation de documents anciens mathématiques

http://www.numdam.org/

(2)

D I A G R A M M E S

A C T E S D E S J O U R N E E S E . L . I . T .

<UIMIV. P A R I S 7, 2 7 JUIIM-2 J U I L L E T 1 9 8 9 )

V O L U M E 2 2

Primitive Recursive Catégories and Machines

Yves Lafont C N R S

L a b o r a t o i r e d'Informatique de l'Ecole Normale Supérieure, 45 rue d'Ulm,

F 75230 Paris Cedex 05

R é s u m é

Nous étudions les relations entre des résultats catégoriques [Burroni] et des machines abstraites pour les algorithmes récursifs primitifs, dans la lignée de la Machine Catégorique Abstraite [CouCurMau] et de la Machine Linéaire Abstraite [Lafont88,Lafont88a].

A b s t r a c t

We investigate connections between categorical results of [Burroni], and ab- stract machines for primitive recursive algorithms, in the lineage of the Categori- cal Abstract Machine [CouCurMau] and the Linear Abstract Machine [Lafont88a].

r » ç u 1 « 2 1 / O S / 1 3eS»

(3)

1 P r i m i t i v e Recursive Functions

The primitive recursive functions are traditionally defined as the members of the smallest class of functions Nn - ^ N ( n E N ) containing some basic ones, and closed under substitution and primitive recursion:

• The projections I I1, . . . , IIn : Nn —> N are primitive recursive.

• If / i , . . . , /p : Nn- » N and g : Np—>N are primitive recursive, then the function h : Nn -> N such that

h(u) = g(fi(u),...Jp(u))

is also primitive recursive. Notation: h = g o ( / i , . . . , /p) (substitution).

• The constant zéro 0 : N° —* N and the successor function S : N —• N are primitive recursive.

• If / : Nn —+ N et g : N2 + n —• N are primitive recursive, then the function h : N1 + n -* N such that

h(0,u) = / ( u ) /i(Sar,w) = g(x,h(x,u),u) is also primitive recursive. Notation: /i = Rec(/, #) (primitive recursion).

This class is very big indeed: the reader can check that ail usual arithmetical functions are primitive recursive, for example:

plus(0,y) = y plus(Sx,y) = S(plus(x,î/)) times(0,2/) = 0 times(Sx,y) = plus(times(x, ?/), y)

fact(O) = SO fact(Sx) = times(fact(:r),S:c)

L e m m a 1 (encoding tuples) For ail n > 0, there are primitive recursive functions 7 : Nn - + N and 7T1,. ..,7rn : N -* N such that x* O 7 = IP for i = 1,.. . , n .

Define 7(2:1,^2,^3,...) = 2r i3X 25X 3. . . which is obviously primitive recursive.

Proving that the corresponding 7T1,... ,7rn : N —• N are also primitive recursive is a bit harder (see [Kleene]).

Primitive recursive functions are traditionally introduced to define the gênerai recursive functions, i.e. the ones that are computable, at least in theory. But we shall not consider them from this viewpoint.

2 Primitive Recursive Catégories

In the category of sets, and more generally in a topos, the object of natural num- bers N is characterised by the axiom of Lawvere:

(4)

1 —• N •— N is initial among the diagrams 1 —> A <— A (where 1 is the terminal object). In other words, for any such diagram, there is a unique lter(^, 0) : N —• A such that the following diagram commutes:

ter(v?,T/>)

However, this notion, which is a spécial case of Kan extension, is to weak to capture primitive recursion in catégories which are not Cartesian closed, and since primitive recursion has nothing to do with functionality (i.e. existence of exponen- tials), we need a stronger axiom:

A primitive recursive category is a category with finite products and a parametrised object of natural numbers 1 —• N <— N .

So for each object A, there is a unique () : X —*• 1, and for each diagram B t- A — C there is

diagram commutes:

B <— A —* C there is a unique (<Pjip) : A-+ B X C such that the following

BxC

We also require that for any diagram B —• A <— A x 5 , there is a unique Rec(<^>, ip) : N x B —• A such that the following diagram commutes:

N x B^ — N x B Rec(c^,i/;)

il>

( R e c ( ^ ^ ) , n2)

•AxB In particular B = 1 gives the axiom of Lawvere.

The structure of primitive recursive category with explicit choice of products and object of natural numbers is obviously (projectively) sketchable (although not alge- braic over graphs, see [CopLair]). Consequently, there is a free primitive recursive

(5)

category V, and a canonical functor T : V —» Set, since *Se£ is clearly a primitive re- cursive category. Using lemma 1, it is quite easy to see that the J-(<p) for <p : Nn—>N in V are precisely the primitive recursive functions.

Note that, by standard diagonalisation arguments, T is neither full (for exam- ple, Akermannn's function is not primitive recursive) nor faithful1 (some primitive recursive algorithms are extensionally equal although distinct in V).

3 Getting rid of Cartesian products

Although primitive recursive functions are explicitly defined in terms of projections and substitution, there are good reasons (see [Burroni]) to interpret this notion in catégories that are not necessarily Cartesian.

A Burroni category2 is just a category with an object of natural numbers B - £ MB <£ MB over each object B: for any diagram B -£ A 2- A, there is a unique lter(<p,-0) : MB

commutes:

A such that the following diagram

MB îfl.

Iter(y>,^) TL

MB

lter(y>,^) - A

A primitive recursive category is clearly a Burroni category with MB = N x B . The converse is false, since nothing forces a Burroni category to be Cartesian (consider for example a discrète category with two points), and even if it is, MA may hâve nothing to do with Ml X A (as it is the case in the dual category of Set). However, we hâve the quite surprising fact:

T h e o r e m 1 [Burroni] The free Burroni category B[X] over one object X admits fxnite products.

Since the objects of B[X] are of the form MnX for n 6 N , we guess that the terminal object is M°X = X and MPX X MqX = Arp+<*X. But of course, the main point of the proof is to construct ail required morphisms.

C o r o l l a r y 1 The category B[X] is équivalent to V.

1 There is an élégant proof of this in [Burroni], using Matijasevic's Theorem.

2This is called a Peano-Lawvere category in [Burroni].

10

(6)

There are indeed two canonical functors $ : B[X] -* V such that $ X = 1 and

\p - -p-+ B[X]. It is easy to see that # o $ is the identity functor on B[X], and $ o $ is naturally isomorphic to the identity on V.

Corollary 2 If G is the canonical functor B[X\—• Set such that QX = 1, fAe (7(v?) /or y? : MPX —• -/VX in 5[-ï] are precisely the primitive recursive functions.

Thèse results express that B[X] is the category of formai primitive recursive functions.

4 F r o m catégories to machines

Following Lambek's terminology, morphisms in the free catégories V and B[X] are syntacticly described as équivalence classes of categorical combinators. Thèse com- binators are truly programs written in a very low level language for a machine we shall describe precisely, at least in the case of B[X].

One major différence between V and B[X] is the structure of types (or objects).

In V, types are trees and data should be represented similarly:

X

/ \ / x Nv

/ \ \ / \ N N N S S

I I

S 0

0

0

In B[X], the corresponding type would be MMMX and the datum SSSOSOSSSSO, which can be implemented as a stack on a computer, whereas trees would require pointers, with usual problems of memory allocation and garbage collection.

Theorem 2 [Burroni] Every morphism X -> MX in B[X] is of the form Sn o 0 for some n G N . More generally, every morphism X —» MPX is of the form

S 0 . . . 0 S 0 O 0 . . . 0 S 0 . . . 0 S^oQ (standard tuple) ni times np times

for some (n\,..., np) in Np.

11

(7)

This resuit can be proved elegantly by applying the uni versai property of B[X]

to the gluing of B[X] and Set along the functor A »-> Hom(X, A). Alternatively, it is enough to check:

L e m m a 2 If <p : MPX —• MqX is a morphism in B[X], then for every standard p-tuple a, ipo a is a standard q-tuple.

This is proved by easy induction on (the length of) a combinator representing (p.

The proof of this lemma can be interpreted as an operational semantics for primitive recursive algorithme. Assume indeed that a standard tuple is implemented as a stack:

S S 0

S 0 Combinators are executed as foliows:

• Id : do nothing,

• (p o rp : exécute V7, then (py

• 0 : push 0 ,

• S : push S,

• lter(y>, VO : pop S until you reach 0 , pop 0 , exécute y?, and exécute ip as many times as you popped S.

On usual computers, the code is a séquence of instructions followed by Return.

Hence Id will be compiled into an empty séquence, <p o rp into a concaténation of two séquences, and 0 , S into primitive instructions. For lter(y, ^ ) , we need a loop instruction and a supplementary stack to store code addresses:

The Itérative Abstract Machine Before

code tuple stack code stack 0 ; c T C S;c T C lter(c',c");c T C

Loop(c',c") S/T C Loop(c',c") 0 / T C Return T c/C

After

code tuple stack code stack c 0 / T C c S / T C

Loop(c',c") T c/C Loop(c',c") T c"/C c' T C c T C

(8)

Lemma 2 can be reformulated as foliows:

Theorem 3 / / the machine starts with the code of a combinator <p : MPX —• MqX, a p-tuple a, and an empty code stack, it eventually stops on the instruction Return with a q-tuple r and an empty code stack. r is the resuit of applying the algorithm ip to a.

5 Conclusion

Our itérative machine is certainly not relevant for computer scientists since unary integers are notoriously inefficient. However, ail this material extends straightfor- wardly to finite Kan extensions, such as J3—• WB^ZWB (with two successor functions instead of one) corresponding to binary notation.

It is also interesting to consider the dual of B[X]t and more generally, finite right Kan extensions, because the corresponding machines look quite différent (lemma 2 is asymmetrical indeed): data are not tuples but automata. Perhaps we shall discuss this point in another paper. .

Anyhow this illustrâtes a new interprétation of category theory which has already been initiated in [CouCurMau] and extended in [LafontSS].

Références

[Burroni] A. Burroni, Récursivité graphique ( Ie partie): catégorie des fonctions ré- cursives primitives formelles, Cahiers de topologie et géométrie différentielle catégorique X X V I I - 1 (1986).

[CopLair] L. Coppey & C Lair, Algébricité, monadicité, esquissabilité et non- algébricité, Diagramme 13 (1985) 1-112.

[CouCurMau] G. Cousineau, P.L. Curien & M. Mauny, The Categorical Abstract Machine, J. P. Jouannaud, éd., Functional Programming Languages and Computer Architecture, LNCS 201 (Springer-Verlag, 19S5) 50-64.

[Goodstein] R.L. Goodstein, Constructive Formalism, Essays on the foundations of mathematics (University Collège, Leicester, 1951).

[Kleene] S.C. Kleene, Introduction to Meta-mathematics (North Hoiland, 1952).

[LafontSS] Y. Lafont, Logiques, Catégories et Machines, Thèse de doctorat (Univer- sité Paris VII, 1988).

[LafontSSa] Y. Lafont, The Linear Abstract Machine, Theoretical Computer Science 59 (1988) 157-180.

[Lambek] J. Lambek, Deductive Systems and catégories, Math. Systems Theory (1968).

Références

Documents relatifs

Unit´e de recherche INRIA Rennes, Irisa, Campus universitaire de Beaulieu, 35042 RENNES Cedex Unit´e de recherche INRIA Rhˆone-Alpes, 655, avenue de l’Europe, 38330 MONTBONNOT ST

used to study intensional properties of primitive recursive algorithms..

The proof of the main theorem needs a diÆcult combinatorial result (proposition.. 18) which has some interest

On donne pour ce langage des règles de traduction systématiques qui associent aux programmes des des- cripteurs de complexité représentant les coûts moyens sous forme de série

Non-recursive comb filter structure is shown in Figure 3. Compared to the CIC filter structure, 1) it is clear that during decimation process and decreasing

The last two examples are new to this paper: in section 3.4, we present call-by-value trees and show how to compile them into abstract B¨ohm trees, and in section 3.5 we show how to

• Local environments are faster: we analyze local environments in their most well-known incarnation, Krivine Abstract Ma- chine (KAM), pointing out simple and yet unusual

If a strategy → is reasonable then its length is a reasonable cost model, despite size- explosion: the idea is that the λ -calculus is kept as an abstract model, easy to define