Parametric Sheaves for modelling Store Locality Hongseok Yang
Uday S. Reddy
[email protected]
[email protected]
Department of Computer Science School of Computer Science University of Illinois at Urbana-Champaign University of Birmingham July 14, 2000
Abstract
In this paper, we bring together two important ideas in the semantics of Algol-like imperative programming languages. One is that program phrases act on xed sets of storage locations. The second is that the information of local variables is hidden from client programs. This involves combining sheaf theory and parametricity to produce new classes of sheaves. We de ne the semantics of an Algol-like language using such sheaves and discuss the reasoning principles validated by the semantics.
1 Introduction A programmer working in an imperative programming language understands intuitively that every program phrase acts on a xed collection of storage locations and, it will continue to act on the same set of locations even if invoked in a larger store with extra locations. Capturing this form of locality in a semantic model is the subject of this paper. As an application of locality idea, consider a predicate of \independence." For program phrases M and N , M ? N is to mean that M and N act on disjoint sets of locations. The idea then is that one can intermix the computations of M and N freely, and there would be no unwanted interference. Using our intuitive understanding of the independence predicate, we can formulate a \decomposition" axiom: M ? N1 ^ M ? N2 =) M ? (N1 ; N2 ) In words, if locations accessed by M are disjoint from those accessed by N1 and those accessed by N2 , then they should be disjoint from the locations accessed by the pair (N1 ; N2 ). Unfortunately, most semantic models found in the literature do not validate this reasoning principle. Hence, they fail to capture storage locality. 1
The independence predicate was rst postulated by Reynolds [26] in formulating his system of Syntactic Control of Interference. The semantics of this system was studied by O'Hearn [13, 14], who successfully modelled the independence predicate by using pullback-preserving functors on location worlds. A similar model was used by Pitts and Stark [24], who also noted that the pullback-preserving functors form sheaves in the Shanuel topos. The supportbased model of [12] is also related. Since most other models of Algol-like languages use functors [27, 21, 32, 18], this would seem like a small further step. But the categories of worlds used in these other models do not have pullbacks. It is still an open question whether these models have an interpretation for the independence predicate (with the decomposition axiom). The next major step in the semantics of Algol-like languages is the realization that the \information hiding" features implicit in local variables can be modelled using relational parametricity [19, 16]. In Reddy [25], these ideas were applied to semantics of object-oriented programs. Reddy also formulated a programming logic using the independence predicate mentioned above, but the eort to give a semantics foundered because the existing tools were not adequate to model the combination of parametricity and the independence predicate. In this paper, we formulate a semantic model that combines parametricity and the independence predicate by extending sheaf theory for re exive graphs of categories. (The latter form the framework for modelling parametricity.) Sheaves, familiar from topology and geometry [11], capture the kind of locality property involved in imperative computations over locations. In fact, the original models of [14, 24] are sheaf models. The challenge for us is to extend theory of sheaves to cover parametricity aspects. We believe that the ideal setting for modelling parametricity is to move from categories to re exive graphs of categories [19]. Having made such a move, we face the question: what is a presheaf in the world of re exive graphs. A standard answer might be re exive graph-functors of type Cop ! Rel, where Rel is the re exive graph structure on Set with binary relations as edges and relationpreserving pairs of functions as edge morphisms. Certainly, this re exive graph is pervasive in parametricity theory [29, 19], and seems to play a role similar to that of Set in category theory. However, the category of such functors, RelC , does not form a topos. So, we work in SpanC , where Span is the re exive graph with spans in Set as edges. Since Rel embeds into Span, this seems to be a good choice. But, Span is cumbersome to work with and our de nitions end up with excessive detail and lack conviction. We close the circle by showing that our de nitions match up with the standard de nitions of sheaves internal to the topos SpanC . op
op
op
Related Work
After Reynolds' series of seminal papers on higher-order imperative languages such as Idealized Algol (in short, IA) and Syntactic Control of Interference (in short, SCI) [27, 26, 28], there have been several works to de ne the semantics of IA and SCI based on the presheaf category [21, 13, 14, 32, 18, 15, 12]. In 2
[19, 16], the relational parametricity has been used to obtain more abstract model which captures data abstractions and the model is extended in [25] to handle classes and objects. Atomic sheaves on the category of nite sets and injections (equivalently, pullback-preserving functors) are used to give a model of SCI in [14] and that of nu-calculus in [31, 24]. Such atomic sheaves also become the theoretical basis of the approach for handling binders in abstract syntax in [4]. The parametricity theory itself arose from an eort to get a model of polymorphic lambda calculus and to formalize logical relations in a categorical setting [29, 10, 30]. A structure known as re exive graph has been used in the theory. The category of sheaves has been used to give a semantics of a type theory or a rst order logic in [9, 11, 22]. Goguen proposed a framework based on sheaves for de ning semantics of concurrent object oriented languages [5]. Fiore and Simpson de ned Grothendieck logical relations using ideas from sheaf theory to show lambda de nability results [3]. In [6], Hilken extended the meaning of sheaves in order to obtain a model for intuitionistic modal logic. He de ned \relational" sheaves for a \relational" topological space, which are essentially sheaves with respect to somewhat unusual Grothendieck topology on the category of open sets with one more condition: they are separated with respect to the usual Grothendieck topology. His de nition as well as his motivation is very dierent from our work: neither subsumes the other and it is not clear that either of the de nitions can be used to solve the main motivating problem in the other's approach.
2 Preliminaries 2.1 Sheaves
A presheaf is a Set-valued functor. Intuitively, a presheaf denotes sets parameterized over a category. For example, interpretations of Algol types, like COMM and EXP, denote presheaves that are parameterized by \store shapes." COMM(X ) denotes commands for modifying stores of shape X . EXP(X ) denotes expressions that read stores of shape X . Sheaves are again sets parameterized by a category but satisfying a property that is \local" in an abstract sense. A standard motivating example is the property of topological continuity [11]. Intuitively, continuity is a local property in that a function on a space O is continuous just if it is continuous on each Oi belonging to one family of open sets fOi gi2I that cover O. Let S be the category of all subspaces of a space S , with inclusions as morphisms. Consider the set CONT(O) of all continuous real-valued functions on O. We make two observations: First, whenever O0 O is a subspace of O, we have a restriction operation CONT(O) ! CONT(O0 ). This just says that CONT : Sop ! Set is a presheaf. Second, if fOi gi2I is an open cover of O, and fi 2 CONT(Oi ) is a family of continuous functions that agree on all common elements of the Oi , 3
then there is a unique f 2 CONT(O) such that each fi is a restriction of f . This says that CONT is a sheaf. However, note that the idea of sheaf depends on the notion of \open covers" which is not a part of the speci cation of the category S. To model the covers, we assume that we are given a function J that assigns to each space O a set of covers of O (i.e., families of subspaces of O satisfying certain axioms). The pair (S; J ) is called a site and CONT is a sheaf over this site. Coming to Algol semantics, regard store shapes as nite sets of locations. Form a category W of these store shapes with reverse inclusions as morphisms. We can treat parameterized sets COMM(X ) in the same fashion as CONT(O) above. First, whenever there is an inclusion X ,! X 0 (so that X 0 is thought of as a \subspace" of X ), there is an operation COMM(X ) ! COMM(X 0 ) that restates a command on X as one on X 0 . (It is better to think of this operation as an \expansion" rather than a \restriction."). Second, if fXi gi2I is a family T of store shapes such that i2I Xi = X , and ci 2 COMM(Xi ) is a family of commands that is consistent in an appropriate sense (see below), then there is a unique command c 2 COMM(X ) whose expansions are the various ci . This amounts to saying that COMM is a sheaf on a site (W; J ). The notion of consistent family involved in both CONT and COMM can be characterized in a categorical fashion. To say that a family of elements fxi 2 Xi gi2I is consistent is to say that for any cone of the form
Y
Xi * ... HHH HHj Xj
the elements xi of the Xi 's involved in the cone restrict/expand to the same element in Y . Further, we can obtain economy of expression by including all such Y 's in the cover fXi gi2I to start with. Then, consistency would just amount to preservation under restriction/expansion operations. Formally, a sieve on an object K is a collections of morphisms S leading to K that is right-closed under composition:
8f : X ! K 2 S; 8g : Y ! X: f g 2 S A site is a pair (C; J ) where C is a category and J assigns to each object X of C, a collection of sieves on X (which are then called covers of X ) satisfying the conditions of a Grothendieck topology [11]. If F : Cop ! Set is a presheaf and S is a sieve on an object X of C, a matching family over S for F is a family of elements fxf 2 F (dom(f ))gf 2S such that xf g = F (g)(xf ). Given such a family, an element x 2 F (X ) is called its amalgamation if xf = F (f )(x) for each f 2 S . A sheaf over the site (C; J ) is a presheaf such that every matching family
for a covering sieve has a unique amalgamation. The category of sheaves over (C; J ) with natural transformations as morphisms is denoted Sh(C; J ). A sheaf 4
category Sh(C; J ) is always cartesian closed. So we can interpret typed lambda calculus-based programming languages in it. It also forms a topos, which allows us to model programming logics as well. The thesis is that all Algol types are local in this abstract sense and, hence, they are sheaves for an appropriate Grothendieck topology on the category of store shapes.
2.2 Parametricity and Re exive Graphs
Relational parametricity, as formulated by Reynolds [29] for the set-theoretic case, involves statements of the form:
8x0 ; x1 : x0 R x1 =) f0(x0 ) S f1 (x1 ) where R : A0 $ A1 and S : B0 $ B1 are binary relations and f0 : A0 ! B0 and f1 : A1 ! B1 are functions. Intuitively, the idea is that f0 and f1 map R-related values to S -related values. We use the diagrammatic notation
A0 R
6 ?
A1
f0
- B0 6 S
f1
- B?1
(1)
to denote such a relationship between f0 and f1 . These kinds of statements play the same role as commutative squares in category theory and form the basis of the uniformity concept captured by relational parametricity. O'Hearn and Tennent [19] used re exive graphs of categories to lift this picture to an abstract level, so that it could be applied to the semantics of Idealized Algol. (See also [8, 23, 30] for other applications.) Looking at the diagram (1) above, we notice two kinds of objects and morphisms: fi Bi vertices and vertex morphisms: Ai ; Bi and Ai !
A0 edges and edge morphisms: R; S and R 6 ? A1
- B0 ?S f1 - B6 1 f0
These can be organized into two categories Cv and Ce together with two functors
@0 ; @1 : Ce ! Cv that pick out the source and target of edges/edge morphisms in the vertical direction. In addition to these, we require a functor
I : C v ! Ce 5
which assigns to each vertex V a canonical edge IV (the \identity edge") and similarly for each vertex morphism. The identity edges are used to capture the \identity extension" property of type constructors. All said and done, we have the following de nition:
De nition
1. A re exive graph of categories is a quintuple C = (Cv ; Ce ; @0 ; @1 ; I) where Cv and Ce are categories and the remaining components are functors such that: @i C = Id Cv !I Ce ! v Cv
2. A re exive graph-functor (RG-functor) F : C ! D is a pair F = (Fv : Cv ! Dv ; Fe : Ce ! De ) preserving the structure of re exive graphs: @i Fe = Fv @i and I Fv = Fe I (The second condition is referred to as the identity extension property.) 3. Given two RG-functors F; G : C ! D, a parametric natural transformation : F ! G is a pair = (v : Fv ! Gv ; e : Fe ! Ge ) preserving the structure of re exive graphs: @i e = v @i and Iv = e I When the collection of parametric natural transformations F ! G is a set, it is denoted by Par[F; G]. (We omit the subscripts v and e whenever the context makes it clear which is meant.) As remarked in [19], these de nitions are nothing but those of indexed categories, indexed functors and indexed natural transformations for a particular situation. The term \parametric" in the part 3 of the de nition signi es our notion of parametricity at the abstract level. The canonical example of re exive graphs, denoted Rel, captures Reynolds' parametricity theory [29]. The vertex category Relv is Set. The edge category Rele has binary relations R : A $ B as objects and relation-preserving pairs of functions (f0 ; f1 ) : R ! S as morphisms. The functors @0 and @1 are the evident ones. The functor I sends a set A to the diagonal relation on A and a function f : A ! B to (f; f ): IA ! IB . Note that products C1 C2 and duals Cop of re exive graphs are easily de ned pointwise (separately for the vertex and edge parts). Examples of RG-functors include the product and exponent functors: : Rel Rel ! Rel and ) : Relop Rel ! Rel: The edge parts of these RG-functors are the usual \logical relation" constructions R S and R ) S : (x0 ; y0 ) (R S ) (x1 ; y1 ) () x0 R x1 ^ y0 S y1 : f0 [R ) S ] f1 () 8x0 ; x1 : x0 R x1 ) f0 (x0 ) S f1 (x1 ): 6
Examples of parametric natural transformations include fstA;B : A B ! A A;B : (A ) B ) A ! B
whose vertex parts are standard. For the edge parts, we have fstR;S = (fstA ;B ; fstA ;B ) R;S = (A ;B ; A ;B ) 0
0
1
0
0
1
1
1
The existence of these edge parts captures the parametricity condition of Reynolds. A second example of re exive graphs, which will play a signi cant role in this paper, is denoted Span. The vertex category is again Set. The edge category has spans in Set as objects. The edge morphisms are span-morphisms, i.e., triples of functions (f0 ; fw ; f1 ) making the following diagram commute:
R
- B0 3 S0 -S QQ Qs S1 QQ - B1 f f0
A0
R03
fw QQ QQ R1 Qs A
1
1
The functors @0 and @1 send a span to its two tips respectively, and a span morphisms (f0 ; fw ; f1) to f0 and f1 respectively. The functor I sends a set A to the \identity span": idA A A idA? A ?!
and a function f to (f; f; f ). Spans are rather similar to relations, with the main dierence being that we also get to encode \witnesses" for relating elements. Note that every relation can be regarded as a span A0 R ! A1 by using projections of R A0 A1 as arrows. Thus, Span may be thought of as a \constructive" variant of Rel. There is a functor wit : Spane ! Set
that sends a span A0 R R R! A1 to the witness set R and a span morphism (f0 ; fw ; f1 ) to fw . We often use the notation Fw = wit Fe (for RG-functor F : C ! Span) w = wit e (for parametric natural transformation : F ! G) for the functors and natural transformations that pick out the witness components of spans. 0
1
7
Both Rel and Span are cartesian closed re exive graphs (in an appropriate sense). An important dierence between them is that Rel is a \relational" re exive graph, i.e., given edges R and S , for any pair of vertex morphisms (f0 ; f1 ) there is at most one edge morphism ' : R ! S such that @0 (') = f0 and @1 (') = f1 . This means that the edge morphisms R ! S de ne a relation between vertex hom-sets. On the other hand, in Span, edge morphisms (f0 ; fw ; f1 ) have additional \witness" information in fw . So, Span is not relational. Other structures used for modelling parametricity, such as the categories REL(K; B; F ) of Ma and Reynolds [10], and the category of pers with saturated relations of Bainbridge at al. [1] can also be described as re exive graphs. The following property is satis ed by Rel, Span and most re exive graphs of interest:
De nition A re exive graph C is said to satisfy the identity condition if the functor I is full.[8] Note that the functor I is already faithful for any re exive graph. So, for a re exive graph with identity condition, we have the isomorphism HomCe [IA ; IB ] = HomCv [A; B ].
3 RG-Presheaves
In the world of categories a presheaf is taken to be a functor of type Cop ! Set. The category of presheaves SetC forms a topos. Sheaves are then de ned to be presheaves with special properties. To duplicate these constructions in the world of re exive graphs, we rst need a canonical re exive graph that plays the same role as Set does in the case of categories. One immediate candidate for the canonical re exive graph is Rel, whose edges are binary relations between sets. Unfortunately, RelG is not in general a topos. So, this immediate choice has a shortcoming. In particular, this means that the Lawvere-Tierney notion of sheaves is not available to RelG . A second candidate for the canonical re exive graph is Span, whose edges are spans over Set. It turns out that SpanG is always a topos and, therefore, serves our purpose. In this section, we examine the topos structure of this category. op
op
op
op
De nition Given a re exive graph with identity condition G, an RG-presheaf over G is an RG-functor Gop ! Span. The category of RG-presheaves with parametric natural transformations as morphisms is denoted SpanG . op
From now on, we assume that the re exive graph G is small , i.e., both Gv and Ge are small categories. If G is a small re exive graph satisfying the identity condition, there is a Yoneda embedding of Gv in SpanG , via a \hom-functor." op
8
De ne the RG-bifunctor: Hom : Gop G ! Span
as follows. The vertex part is, expectedly, Homv [U; V ] = homGv [U; V ]:
For the edge part, let P : U0 $ U1 and R : V0 $ V1 be edges of G. Then Home [P; R] is the span @ Hom [U ; V ] Homv [U0 ; V0 ] @? homGe [P; R] ?! v 1 1 1
0
If ' : P 0 ! P and : R ! R0 are edge morphisms with @0 (') = f0 , @1 (') = f1 , @0 ( ) = g0 , @1 ( ) = g1, then Home ['; ] is the span-morphism Homv [f0 ; g0] Homv [U00 ; V00 ] Homv [U0 ; V0 ]
@03
@03
homGe ['; ] 0 homGe [P; R] homGe [P ; R0 ] QQ QQ Q QQ @1 Qs @1 Qs Q - Hom [U 0 ; V 0 ] Hom [U ; V ] v 1 1
v 1 1 Hom [f ; g ] v 1 1
It is apparent that Hom preserves @0 and @1 : Homv (@i @i ) = @i Home . The identity extension property Home (I I) = I Homv follows from the identity condition on G.1 For a xed vertex V of G, we can specialize the hom-functor to an RGpresheaf Hom[?; V ]: Gop ! Span de ned by Homv [?; V ] = homGv [?; V ] and Home [?; V ] = Home [?; IV ] For any vertex morphism f : V ! V 0 in G, we have a parametric natural transformation Hom[?; f ]: Hom[?; V ] ! Hom[?; V 0 ] de ned by: Homv [U; f ] = f ? and Home [P; f ] = If ?
This gives a Yoneda embedding of Gv in SpanG which sends a vertex V to Hom[?; V ] and a vertex morphism f to Hom[?; f ]. There is also a functor H from the edge category Ge to SpanG , for which a Yoneda lemma for edges holds, i.e., given an RG-functor F in SpanG , Par[H(?); F ] is isomorphic to Fw in the presheaf category SetGe . But this is nontrivial and does not follow the general categorical pattern used above. 1 Strictly speaking, Hom e (I I) = I Homv but not Home (I I) = I Homv . The equality can be obtained by modifying Hom using isomorphisms between Home [IV ; IV ] and IHomv (V ) for all vertices V . Whenever we present RG-functors to Span, we leave such an op
op
op
op
appropriate modi cation of the RG-functors to the reader.
9
Since we will not explicitly need this functor for the results of this paper other than the proof of externalization in Section 4.1, we relegate it to the Appendix A and refer the interested reader to the discussion there. However we will need the following functor in the ensuing discussion, which is obtained by xing the second argument of the Home bifunctor at R: Home [?; R]: Gop e ! Spane
Lemma 1 If G is a small re exive graph with identity condition, the corresponding RG-presheaf category SpanG is cartesian closed. The details are as in [19] but generalized to nonrelational re exive graphs. Products and a terminal object are given pointwise: (F G)(?) = F (?) G(?) and 1(?) = 1 (for spans and span-morphisms, the products F (R) G(R) and F (') G(') are given pointwise.) Exponents are as follows: (F ) G)(V ) is the set of parametric natural transformations Par[Hom[?; V ] F; G]. (F ) G)(R), for an edge R : V0 $ V1 , is a span whose witness set consists of all triples (0 ; ; 1 ) where i 2 (F ) G)(Vi ) and : Home [?; R] Fe ! Ge such that 1. @i = (i )v @i , and 2. for every edge morphism of the form ' : IU ! R (for some vertex U ) and composable edge morphism : P ! IU , op
?
?
P (' ; ?) = (0 )e P (I@ (') ; ?) = (1 )e P (I@ (') ; ?) 1
0
The arrows of the span send (0 ; ; 1 ) to 0 and 1 respectively. (F ) G)(f ), for a vertex morphism f , is Par[Hom[?; f ] F; G], which sends to (Hom[?; f ] idF ), (F ) G)('), for an edge morphism ' : R0 ! R with @0 (') = f0 and @1 (') = f1 , sends (0 ; ; 1 ) to ((F ) G)(f0 )(0 ); (Home [?; '] idFe ); (F ) G)(f1 )(1 )) The second condition in the de nition of (F ) G)(R) is somewhat surprising. No such condition is involved for the exponents in RelG studied in [19]. More accurately, the condition is automatically satis ed in RelG because relations have unique witnesses for related pairs of elements. On the other hand, spans may have multiple witnesses in general. The condition is needed to ensure that F ) G has the identity extension property. op
op
10
Theorem 2 If G is a small re exive Ggraph with identity condition, the corresponding RG-presheaf category Span is a topos. Since we have already argued that SpanG is a CCC, all that is left is to de ne the subobject classi er : Gop ! Span (which must be an RGop
op
functor). We de ne it using two kinds of sieves, called vertex-sieves and edgesieves respectively.
De nition If G is a re exive graph with identity condition and V is a vertex in G, a vertex-sieve on V is a pair S = (Sv ; Sw ) where Sv is a sieve on V in Gv and Sw is a sieve on IV in Ge such that they are closed under the structure of the re exive graph: 8' 2 Sw : @0 ('); @1 (') 2 Sv and 8f 2 Sv : If 2 Sw A vertex-sieve can be regarded as an RG-subfunctor S ,! Hom[?; V ]. Then S (U ) = ff 2 Sv j f : U ! V g and S (R : V0 $ V1 ) = S (V0 ) @ f' 2 Sw j @ S (V ). ' : R ! IV g ! 1 0
1
De nition If G is a re exive graph with identity condition and R : V0 $ V1 is an edge in G, an edge-sieve on R is a triple = (S0 ; w ; S1 ) where S0 and S1 are vertex-sieves on V0 and V1 respectively, and w is a sieve on R in Ge such that 1. for every ' 2 w , @0 (') 2 S0 and @1 (') 2 S1 and 2. for every morphism of the form : IU ! R with @0 ( ) = f0 and @1 ( ) = f1 , we have2 If ((S0 )w ) = If ((S1)w ) = (w ) 0
1
Using these de nitions, we can show that the subobject classi er of SpanG is as follows: (V ) = the set of vertex-sieves on V 2 For any category C, a morphism f : C D induces a mapping of sieves on D to sieves op
on C , denoted f : f (S ) = g f g S . f
j
2
!
g
11
(f ) = f (R) = the span with the set of edge-sieves on R as the witness set and
projections sending each (S0 ; ; S1 ) to S0 and S1 , respectively. (') = ( (@0 (')); ' ; (@1 ('))) The parametric natural transformation T : 1 ! , denoting the constant-true predicate, is de ned by TV = (tV ; tIV ) TR = (TV ; tR ; TV ) where tX denotes the maximal sieve on X (in a category). To get some intuition for these de nitions, we consider the notion of a matching family (which will be used to de ne sheaves in the next section). 1
0
De nition Let G be a re exive graph with identity condition and F : Gop ! Span an RG-functor. If S = (Sv ; Sw ) is a vertex-sieve on a vertex V , a matching family over S for F is a pair of families (fxf 2 F (dom(f ))gf 2Sv ; fs' 2 Fw (dom('))g'2Se ) such that3 xf g = xf g; s' = s' ; and for all ' : R ! IV in Se with F (R) = (F (U0 ) Fw (R) ! F (U1 )), 0
1
0 (s' ) = x@ (') and 1 (s' ) = x@ (') . 0
1
More abstractly, a matching family is parametric natural transformation (x; s): S ! F with S regarded as an RG-functor. This de nition shows the role played by edge-parts of sieves. The matching families must be consistent in that they must respect all the relationships denoted by the edges included in the sieve. There is similarly a notion of matching families for edge-sieves.
De nition Let G be re exive graph with identity condition and F : Gop ! Span an RG-functor. If = (S0 ; w ; S1) is an edge-sieve on an edge R : V0 $ V1 of G, a matching family over for F is a triple ((x; s); w; (y; t)) where (x; s) and (y; t) are matching families over S0 and S1 respectively, and w = fw' 2 Fw (dom('))g'2w satisfying the following conditions: 1. w'' = w' '0 3 For any RG-functor F : Gop Span, we write x f for F (f )(x) and w ' for Fw (')(w). 0
!
12
2. for all ' 2 P ! R in w , with F (P ) = (F (V0 ) Fw (P ) ! F (V1 )), 0 (w' ) = x@ (') and 1 (w' ) = x@ (') 0
0
1
1
' R in w 3. for every edge morphism of the form P ! IU ! w' = sI@ ' = tI@ ' 0( )
1( )
Relational Presheaves
Having given the de nitions for the general case, we consider a special case of RG-presheaves which are encountered in Algol semantics. Note that we have a re exive graph embedding J : Rel ,! Span which sends a relation R : A0 $ A1 to the span A0 R ! A1 with projections as arrows. We call an RGpresheaf F : Gop ! Span relational if it factors through this embedding upto isomorphism, i.e., F = JF 0 for an RG-functor F 0 : Gop ! Rel. So, we can regard Fw (R), for any edge R : V0 $ V1 of G, as simply a relation F (V0 ) $ F (V1 ). The subcategory of relational RG-presheaves in SpanG is cartesian closed. However, it does not have a subobject classi er. We show the notion of matching families for relational RG-presheaves because it is considerably simpler than the general case. If F is a relational RG-presheaf, a matching family over a vertex-sieve S for F is a family fxf 2 F (dom(f ))gf 2Sv such that 1. for all f : U ! V in Sv and all vertex morphisms g : U 0 ! U , xf g = xf g 2. for all ' : R ! IV in Se , x@ (') [Fw (R)] x@ (') . We do not need a separate family of witnesses because the witnesses are unique whenever they exist. For an edge sieve = (S0 ; w ; S1 ), a matching family is merely a pair of matching families (x; y) for S0 and S1 such that, for all ' : P ! R in w , x@ (') [Fw (P )] y@ (') . op
0
1
0
1
4 RG-Sheaves Sheaves can be de ned internal to any topos using a Lawvere-Tierney topology [11]. Since SpanG is a topos, we automatically have sheaves internal to it. We call them RG-sheaves. Such an internal characterization is very abstract and hard to use in applications. In this section, we give an external characterization of RG-sheaves similar to the de nition of sheaves in Section 2.1. We also show that it coincides with the internal characterization. As in Section 2.1, we rst need a Grothendieck topology J that assigns a collection of sieves to each vertex and edge of a re exive graph G. op
13
De nition Let G be a small re exive graph with identity condition. A Grothendieck topology on G is a pair J = (Jv ; Jw ) where Jv assigns to each vertex of G, a collection of vertex-sieves on V (called the \covers" of V ); and Jw assigns to each edge R : V0 $ V1 of G a collection of edge-sieves on R (called the \covers" of R) such that the following conditions are satis ed: 1. Closed under re exive graph structure: { For each (S0; w ; S1) 2 J (R), S0 2 J (V0 ) and S1 2 J (V1 ). { For each S 2 J (V ), (S; Sw ; S ) 2 J (IV ). 2. Maximality: TV 2 J (V ) and TR 2 J (R). 3. Stability: { If S 2 J (V ), then (f )(S ) 2 J (V 0) for any f 0 : V 0 ! V . { If 2 J (R), then w (')() 2 J (R0 ) for any ' : R0 ! R. 4. Transitivity: { If S 2 J (V ) and S 0 is any vertex-sieve on V such that (f )(S 0) 2 J (U ) for all f : U ! V in Sv and w (')(S 0 ; Sw0 ; S 0 ) 2 J (P ) for all ' : P ! IV in Sw , then S 0 2 J (V ). { If 2 J (R) and 0 = (S00 ; 0w ; S10 ) on R : V0 $ V1 such that S00 2 J (V0 ), S10 2 J (V1 ) and w (')(0 ) 2 J (P ) for all ' : P ! R in w , then 0 2 J (R). We call the pair (G; J ) an RG-site. The idea of covers, as mentioned in Section 2.1 is to identify certain sieves that are intended to force unique amalgamations. A Grothendieck topology is meant to pick out such covers. A simple example of a Grothendieck topology is called the atomic topology. (This will play a role in Algol semantics of Section 5.) Denoting it by the symbol A, we have: Av (V ) = the set of all vertex-sieves (Sv ; Sw ) such that Sv and Sw are nonempty. Aw (R) = the set of all edge-sieves (S0 ; w ; S1 ) such that S0 2 Av (V0 ), S1 2 Av (V1 ) and w is nonempty. When for any two edge morphisms ' : R0 ! R and : R00 ! R in G, there exist edge morphisms '0 : P ! R0 and 0 : P ! R00 such that ' '0 = 0 , A satis es all the axioms to be a Grothendieck topology on G. Matching families for vertex- and edge-sieves have already been de ned in Section 3. So, we have the main de nition: 14
De nition An RG-sheaf over an RG-site (G; J ) is an RG-presheaf F : Gop ! Span such that for every vertex-sieve S 2 J (V ) and matching family (x; s) over S , there is a unique amalgamation: an element x 2 F (V ) such that xf = x f for all f 2 Sv and s' = x ' for all ' 2 Sw ; and for every covering edge-sieve 2 J (R : V0 $ V1 ) and matching family ((x; s); w; (y; t)) over , there is a unique amalgamation: an element w 2 Fw (R), where F (R) = F (V0 ) Fw (R) ! F (V1 ), such that 0 (w) and 1 (w) are the amalgamations of (x; s) and (y; t) respectively and w' = w ' for all ' 2 w . 0
1
It is instructive to consider the special case of relational RG-sheaves. Lemma 3 Let F : Gop ! Span be a relational RG-presheaf. Then, it is an RG-sheaf i for every S 2 J (V ) and matching family x over S , there is a unique amalgamation: an element x 2 F (V ) such that xf = x f for all f 2 Sv . for every 2 J (R : V0 $ V1 ) and matching family (x; y) over , the amalgamations x of x and y of y satisfy x [Fw (R)] y. In the next section, we will nd several examples of relational RG-sheaves over atomic RG-sites. It follows from the general results discussed in Section 4.1 that: Theorem 4 An RG-sheaf category Sh(G; J ) is a topos (and, hence, cartesian closed.).
4.1 RG-Sheaves are Sheaves
The de nition of RG-sheaves above involves excessive detail and it is hard to convince oneself that the de nitions are right. In this section, we show that RGsheaves are precisely the sheaves in the topos SpanG using Lawvere-Tierney topologies. A Grothendieck topology J = (Jv ; Jw ) can be easily turned into an RGfunctor. By equipping each Jw (R) with projections that send (S0 ; w ; S1 ) to S0 and S1 respectively, we obtain a functor Je : Gop e ! Spane . (The morphism part comes from the stability condition.) The pair J = (Jv ; Je ) does form an RG-functor. Since the sets involved in J are all sets of sieves, it is clear that J ,! is an RG-subfunctor.4 The characteristic morphism of the subobject, j : ! , 4 Given two RG-presheaves F and G, F is an RG-subfunctor of G if F and F v w are subop
functors of Gv and Gw respectively.
15
is a Lawvere-Tierney topology on SpanG . Conversely, the kernel of every Lawvere-Tierney topology on SpanG is a Grothendieck topology (regarded as an RG-functor). Lemma 5 There is one-to-one correspondence between Grothendieck topologies on a small re exive graph G with identity condition and Lawvere-Tierney topologies on SpanG . Theorem 6 (Externalization) For any RG-site (G; J ), an RG-functor F : Gop ! Span is an RG-sheaf i it is a sheaf for j = char(J ). The whole structure of the proof for the theorem is similar to that for the corresponding theorem in the presheaf category case, shown in [11]. A straightforward extension of the proof in [11] shows only-if direction in SpanG , but showing if-direction requires a somewhat new idea. We mainly focus on that direction. Recall that F is a sheaf for j i for all dense monomorphisms : G ! H and a morphism , can be uniquely extended along , i.e., there exists a unique 0 such that = 0 . Dense monomorphisms in SpanG can be characterized in a manner very similar to the presheaf category case, which explains the reason that only-if direction can be shown easily by just extending the proof in the presheaf category. We have a characterization of monos in SpanG : Lemma 7 A parametric natural transformation : F ! G is monic in SpanG i for any vertex V and edge R, (v )V and (w )R are injections. For any monic parametric natural transformation, by the above lemma, we can assume that (v )V and (w )R are inclusions. The dense monomorphism has the following characterization: Lemma 8 A monomorphism : F ,! G in SpanG is dense for a LawvereTierney topology j i 1. for any vertex V in Gv and x 2 G(V ), (ff : W ! V j x f 2 F (W )g; f' : R ! IV j x ' 2 Fw (R)g) is in J (V ); and 2. for any edge R : V0 $ V1 in Ge , w 2 Gw (R), x 2 G(V0 ) and y 2 G(V1 ) such that w is a witness for (x; y), op
op
op
op
op
op
op
op
?
(ff : V 0 ! V0 j x f 2 F (V 0 )g; f' : R0 ! IV j x ' 2 Fw (R0 ))g); f' : R0 ! R j w ' 2 Fw (R0 ))g; (ff : V 0 ! V1 j y f 2 F (V 0 )g; f' : R0 ! IV j y ' 2 Fw (R0 ))g) is in J (R) The following lemma informally says that for any matching family for vertexand edge-sieves, the existence of unique amalgamation can be equivalently expressed by the existence of an unique extension along a dense monomorphism, which implies if-direction of our main theorem. First, we deal with vertex-sieves: 0
1
16
Lemma 9 Let (G; J ) be an RG-site.
1. A covering S on a vertex V induces a RG-subfunctor G of Hom[?; V ], whose inclusion is dense. More precisely, G is de ned by Gv (U ) = Hom[U; V ] \ Sv Gw (R : V0 $ V1 )) = Hom[R; IV ] \ Sw 2. A matching (x; s) of F over S has one-to-one correspondence with the parametric natural transformation from G to F given by (v )U (f ) = xf for all f 2 Gv (U ) and (w )R (') = w' for all ' 2 Gw (R). 3. A matching family (x; s) of F has a unique amalgamation i the corresponding parametric natural transformation can be uniquely extended along the inclusion from G to Hom[?; V ]. In the case of edge-sieves on an edge R : V0 $ V1 , we need a more complicated RG-functor H(R), whose exact de nition is shown in Appendix A. We only mention that H(R)v (V ) is de ned a quotient of a disjoint union of homGv [V; V0 ] and homGv [V; V1 ] by an appropriate equivalence relation and H(R)w (P ) a quotient of a disjoint union of homGe [P; IV ], homGe [P; IV ] and homGe [P; R] by an appropriate equivalence relation. In fact, the very existence of such an RG-functor Hom[?; R] is the most interesting part of this whole proof. Lemma 10 Let (G; J ) be an RG-site. 1. A covering on an edge R induces a RG-subfunctor G of H(R), whose inclusion is dense. More precisely, G is de ned by Gv (U ) = f[f ] j [f ] 2 H(R)v (U ) ^ (f 2 (S0 )v _ f 2 (S1 )v )g Gw (P : U0 $ U1 )) = f['] j ['] 2 H(R)w (P ) ^ (' 2 (S0 )w _ ' 2 (S1 )w _ ' 2 w )g 2. A matching ((x; s); w; (y; t)) of F over has one-to-one correspondence with the parametric natural transformation from G to F given by (v )U ([f ]) = yxf ifif ff 22 ((SS0 ))v and 1v 8f