Communication Algebras Michal Walicki
Magne Haveraaen
Sigurd Meldal
Universitetet i Bergen Institutt for Informatikk HiB, 5020 Bergen, Norway fmichal, magne,
[email protected]
Abstract
We introduce a semantic framework which generalises algebraic speci cations by equipping algebras with descriptions of . The semantic objects are not merely algebras, but algebras with associated data dependencies. The latter provide separate means for modeling computational concerns along with the functional speci cations usually captured by an algebra. The formalization of evaluation strategies allows the formal manipulation of how the operations of an algebra are to be evaluated. This formalization introduces (1) increased portability among dierent hardware platforms, as well as (2) allowing a potential increase in execution eciency, since a chosen evaluation strategy may be tailored to a particular platform. We present the development process where algebraic speci cations are equipped with data dependencies, the latter are then re ned and, nally, mapped to actual hardware architectures. evaluation strategies
1 Introduction The creed of algebraic speci cation is abstraction: one models programs as algebras, thus abstracting from the operational details and focusing on the abstract functionality of the system. A single such speci cation may be implemented on dierent platforms. The implementation design, as well as the particular platform on which it is realised, need not be the primary issues. It is one of the central tenets of the algebraic speci cation that the designer may initially model his system at a high level of abstraction without involving himself into low level implementation details, only introducing implementation concerns as appropriate, much later in the development process. At some point during the development process the choice of the set of constructors, the computation strategy, the target language, and, perhaps, the hardware platform begin to play a more important role. In particular, because of its intentional abstraction from the operational aspects, the standard algebraic approach to speci cation has diculties when faced with the possibilities of parallel implementations. It is at this point that our intend method comes into successful play. We propose a framework of communication algebras adressing the issue of how to incorporate computation-related aspects within the framework of classical algebraic semantics. Though occasionally tempting, we would like to avoid rebuilding the theory from scratch { we want to take advantage of the existing theoretical and tool-oriented results of algebraic speci cations. Our aim is only to extend the classical framework with constructs which in an algebraic way addresses the choice of computational strategies. This is achieved by associating additional structures, data dependency graphs, with standard algebras. The data depency graphs carry information about evaluation strategies for the operations of the algebras. We have to warn the reader that our data dependencies are not exactly what is meant by that in the literature, especially on imperative programs, e.g. [MW83, FOW87, KK90]. We proceed from the algebraic, that is, functional descriptions and dependencies relate functional The author gratefully
acknowledges the nancial support received from the Norwegian Research Council (NFR).
1
terms and not program statements. In particular, a variable is only a (sub)term denoting speci c value { it is not an actual program variable of a program capable of storing various values at dierent points of computation. We address mainly the semantic issues of this approach, without entering into a discussion of possible speci cation formalisms . Thus we will assume that data dependencies are given along with algebras, and study their interaction. Since data dependencies are standard algebraic objects we expect that they can easily be described in a standard algebraic fashion. (We intentionally refrain from including an analysis of control dependencies { unlike data dependencies, they seem to be inherent features of actual programs rather than of abstract data types.) In some cases data dependencies may be recovered directly from an algebraic speci cation and section 3 describes a way to do it. By allowing computational structures into the semantics of a speci cation we provide the means not only for development of programs, but for the development of ecient programs. We will show that data dependencies provide such a means, enabling one to assess the time/space resources required and to pursue optimization strategies such as syntactic and semantic memoisation. Above all, the computational structures carry the information necessary to achieve parallel implementations; the identi cation of dependencies between various parts of a computation enables us to determine its possible parallel distributions. In addition to algebras and data dependencies, we will introduce a representation of (parallel) machine architectures and show how mappings from dependencies to architectures may be utilized to yield parallel implementation. The framework enables us then to port the implementations of communication algebras along the morphisms between various hardware architectures. It should be emphasized, however, that we are not concerned with a general theory of concurrency. In this context, we view concurrency merely as a means of increasing eciency of the implementation. Section 2 introduces the basic notions of communication algebras and their implementations and illustrates them on a simple example. Section 3 addresses the issue of constructing dependencies for a given algebra A given a speci cation satis ed by A. It illustrates the ideas of a programming language Sapphire developed at the University of Bergen for which communication algebras provide the semantic framework. Section 4 discusses a series of speci c issues which have not been treated in sucient detail by the general framework of section 2, indicating some of its weaknesses. Section 5 summarises the results and indicates some directions for future work. The paper focuses on the description of the concepts; its technical content is limited to a few results. It gives an improved version of the results from [WHM96]. The more technical aspects assume some elementary knowledge of the category theory (e.g., [BW90], [RB88]) with particular emphasis on brations.
2 The Framework of Communication Algebras This section introduces gradually the framework of communication algebras. We de ne rst some basic notions in 2.1, then data dependencies in 2.2, communication algebras in 2.3, and their implementation in 2.4. Subsection 2.5 summarizes these pieces presenting the view of the development process using communication algebras.
2.1 Signatures, Algebras and Graphs
We use the standard notion of a signature as a pair hS ; Fi of sort and operation symbols. In subsection 4.2 we will use the category Sig with signatures as objects and injective signature morphisms. For a signature , Alg() will denote a category of -algebras. It is \a category" because we do not make any assumptions as to what the algebras are, except that they are objects where one can interpret the -terms. One may think of standard -algebras with -homomorphisms de ned in the usual way. But one may as well think of the category of multilagebras with various multihomomorphisms, power algebras, uni ed algebras, etc. We will de ne various notions relatively 2
to an arbitrary full subcategory A Alg().1
De nition 2.1 Gr is the category of irre exive directed acyclic graphs where2: 1. objects are DAGs { algebras over the signature ? = hI ; : I I ! Booli satisfying: x y ) y = x (or equivalently x = x) ; G F 2. a Gr-morphism g : G ! F is a mapping I G ! I F such that i j ) g(i) g(j ). i j indicates an edge between nodes i and j . For a relation R, R denotes its transitive (but
not re exive) closure. For aesthetic reasons, we will allow the graph with the empty carrier, , which is the initial object in Gr. We will consider \graph" a synonym for \DAG" since DAGs are the only graphs we A will talk about. Also, we will usually not distinguish between a graph A and its relation . A A denotes the transitive closure, i.e., the graph hI A ; () i. In particular, a graph A will be said to A be well-founded when the relation is. We may occasionally use the following terms: A graph is sequential if is a total ordering of the nodes. =n I with 1 < n < ! A partitioning of a graph is a partitioning of the set of nodes I = Skk=1 k such that each Ik is sequential. An st-indexed (\space-time") graph has nodes indexed by hs; ti 2 S IN, such that: 1. 8s; t : hs; ti hs; t + 1i ; 2. 8s; s0; t; t0 : hs; ti hs0 ; t0 i ) t0 = t + 1 ; 3. 9k 2 IN : 8s; s0 ; t : hs; ti hs0 ; t + 1i , hs; t + ki hs0 ; t + k + 1i. The st-indexed graphs are singled out because they will be used as the space-time representation of hardware architectures [MW83]. The s component identi es a processor and the t component a time-point during a computation. Edges represent possible communications. The rst condition says that each processor performs a sequential computation with the possibility of maintaining its local data from one step of the computation to the next one. The second condition requires all elementary communications to happen in a single time-step. The last condition says that the communication topology is xed throughout the whole computation, i.e., the graph is actually a repetition of the pattern of the k-steps communications. We will make extensive use of a dierent notion of a morphism between graphs F and G which amounts to embedding of F into the path closure of G, mapping F -nodes to G-nodes and F -edges to G-paths. A path i + j in a graph is a sequence of nodes k1 ; :::; kz with z > 1; i = k1 ; j = kz such that for 1 n < z : kn kn+1 . + denotes all the paths generated by and, for a given graph G, G its path closure is a multigraph G+ = hI G ; ()+ i. Obviously, in general, G == G+ .
De nition 2.2 Gr+ is the category where:
1. objects Obj (Gr+ ) = Obj (Gr) ; F G 2. a morphism m : F ! G is a mapping m : I F ! I G such that i j ) m(i)()+ m(j ); 3. the composition of morphisms is de ned pointwise in the obvious way: G for f : F ! G; g : G ! H , f g(i) = g(f (i)) and if f (i j ) = f (i)()+ f (j ), then f g(i G + j ) is obtained by the iterated application of g to all the edges in the path f (i)( ) f (j ).3
Example 2.3 An example of a morphism f : D ! W in Gr+ is given in the gure 1.
1 Using the dierent font for categories, we hope that the use of the subset symbol also for subcategory won't create any confusion. 2 We assume xed sort Bool with two elements. 3 Composition is written in the diagrammatic order: a b means \ rst a, then b".
3
4 FF
FF F x3 xx x x 2 FF FF F c
O
;
O
c
1
D
GG
O
O
;
LLL L 3 r r rr r r 2 rLLL LLL L f
O
c
O
8
;
O
c
4 LLL
w Gw Gw G www G GGG w Gw G ww ww G GG w Gw Gw G www G c
O
O
f
;
O
f :D
W
/
1
W+
Figure 1: A morphism in Gr+ . We note the following characterisation: Proposition 2.4 Let e : A ! B 2 Mor(Gr+). e is mono , e is injective on the nodes.
2
Proof. )) If e is mono, then for any T and two arrows T fg A , f e = g e ) f = g. In particular, for any node i 2 I T : e(f (i)) = e(g(i)) ) f (i) = g(i). Taking T as a one-node graph and considering all f; g : T ! A, implies that e must be injective on the nodes. () Suppose e is injective on the nodes and f e = g e. For each node i 2 I T we then have e(f (i)) = e(g(i)) ) f (i) = g(i). To verify that f = g, we have to check that also for each edge k in T , f (k) = g(k). If not, then there exists a node j 2 I A which is on the path f (k) but not g(k) (or other way around). Since e is injective on the nodes, e(j ) cannot be on the path e(g(k)), that is, e(g(k)) == e(f (k)),4 contrary to the assumption f e = g e. /
/
2
2.2 Data Dependencies
As remarked in introduction, our data dependencies relate functional terms and not program statements. Thus, for instance, term f (s(x); 2) may depend on s(x) but x is just a variable which, in any instance, has some speci c value. The variable x never depends on itself, as it might do if it was a program variable occurring in a statement x := x + 1. For a signature , a data dependency is a graph with nodes labeled by ground -terms T . The only requirement we put on the morphisms is that they respect the sorting of labels.
De nition 2.5 DD() is the category of data dependencies where (? is as in de nition 2.1): 1. an object is a data dependency { an algebra A over the signature ? = ? [flab : I ! T g such that the reduct Aj? is an object in Gr; 2. a DD()-morphism m : C ! D is a Gr+ -morphism between the underlying graphs Gr(C ) ! Gr(D), such that 8i 2 I C : Sort(labD (m(i))) = Sort(labC (i)).5 In the sequel, we will let D denote an arbitrary subcategory of DD(). Gr : DD() ! Gr+ is the
obvious forgetful functor which, for a given data dependency D, returns its underlying graph. We call such a graph the shape of D.
4 Injectivity on the nodes implies injectivity on the edges (and paths), but the opposite implication does not hold. 5 For a signature = hS ; Fi, the function Sort : T ! S returns the sort of the argument term. ;X
4
The relation i j is ment to indicate that the computation at node j depends on the computation at node i. If lab(i) = s and lab(j ) = t this means that the result of the evaluation of t at j depends on the result of the evaluation of s at i. The dependency morphism C ! D expresses the fact that D can simulate C { dependencies of C are re ected in D, not necessarily as direct edges but possibly as paths, and they may be enriched with new dependencies. Remark. Gr-embedding of A into B is a special case of a DD()-morphism A ! B . One might expect that a surjective (on the nodes) Gr-morphism B ! A would yield a simpler notion of simulation. However, it would require our graphs to be re exive (this is not a big problem) and, more importantly, would exclude many cases where B is a richer structure than A. For instance, there is no surjective Gr-morphism from
B=
vvv HHH
z
onto A =
/
/
. But we would like to say that B does re ect the dependencies of A
(and introduces some more) { and so there is a DD()-morphism A ! B . 2 $
Example 2.6 To give a avor of our aims, consider a speci cation of the Fibonacci function: Fib is S : IN F : : : : the usual de nitions of IN F : IN ! IN A: F (0) = 1 F (1) = 1 F (n + 2) = F (n) + F (n + 1)
Ignoring for the moment details (to be discussed later), we may easily recognize the dependency given by the tree of recursive calls R in gure 2. Certainly, de nition 2.5 allows us to map this tree, for instance, onto a linear order (respecting the ordering in the tree and avoiding loops). In the following subsection we will couple dependencies with algebras and thus specify the means of avoiding uniteresting morphisms admitted, in principle, by de nition 2.5. In the gure 2 we have indicated two dependecy morphisms: d0 corresponding to syntactic memoisation (identifying the nodes with identical labels), and d00 corresponding to semantic memoisation (identifying F (0) with F (1)) given the above speci cation.6 Here, we may consider the dependency D as a re nement ;
w ww ;
;
F (1)
F (2)4
w ww
Z
F (3)4
44 44 44 4
Z
F (4) G
w ww
c
44 44 44 4
F (1)
F (0)
F (4) G
GG GG GG GG G
F (1)
F (2)4
w ww ;
O
Z
44 44 44 4
c
F (4) G
GG
F (3)
d0
w ww F (2) G GG ;
/
O
O
c
F (1)
F (0)
GG
O
d00
c
F (3)
w ww F (2) G GG /
;
O
c
F (1)
F (0)
D0
R
D
Figure 2: The recursive tree dependency R, together with the \actual" dependencies for computation of Fibonnaci, D0 and D, and the dependency morphisms d = d00 d0 . (improvement) of R. Notice that D is sequential under the ordering F (n) < F (m) for n < m. Nevertheless, the partitioning of D indicated by the vertical arrows implies serious savings of storage space, even if the computations along both lines are heavily synchronised and far from independent. 2 6 In subsection 4.3.1, we suggest a more speci c notion of a dependency morphism compatible with a given class of algebras of which d00 is an example.
5
Remark. As a matter of fact, there is also a dependency morphims g : D ! R which embeds D into the leftmost part of R+. This illustrates the fact that re nement of data dependencies is not necessarily an \improvement" in the narrow sense of memoisation { it rather re ects the relation of one dependency being able to perform the computations of which another one is capable. 2
2.3 Communication Algebras
A -communication algebra is a algebra with an associated -dependency. The latter provides a clue for how various operations of the algebra are to be computed. In general, for A Alg(), D DD(), an (A; D)-communication algebra is an A-algebra with an associated D-dependency. C~ ; evC i where De nition 2.7 An (A; D) communication algebra C is a triple hC; 1. C 2 Obj (A) ; 2. C~ 2 Obj (D) ; 3. evC : I C~ ! C is an evaluation function such that labC~ (i) = t ) evC (i) = tC . The ev function is uniquely determined by C and the labelling of C~ , so we will usually write a C~ i. When (A; D) does not matter or is clear from the context, communication algebra as a pair hC; we will say C-algebra (instead of (A; D) algebra). Dependencies may (and will) be interpreted as the requirements on the communications between dierent space-time points on an actual architecture. Consequently, we will refer to the dependency part C~ of an algebra C as its communication part. De nition 2.8 An (A; D) homomorphism h : C ! D is a pair hh ; ~hi such that: 1. h : C ! D 2 Mor(A) ; 2. ~h : D~ ! C~ 2 Mor(D), and 3. h(evc (~h(i))) = evD (i), for all i 2 I D~ .7 '&!~ evC %$"# C
C
/
O
~h '&!~ evD D
C
h D%$"#
h D
/
Figure 3: A homomorphism between two communication algebras. Like for C-algebras, when (A; D) does not matter, or is clear from the context, we will speak about C-homomorphisms. CAlg(A; D) is the category with (A; D) algebras as objects and (A; D) homomorpisms as morphisms (and obvious pointwise composition). When talking about the entire category CAlg(Alg(); DD()), we will instead write CAlg(). The functor Dep : CAlg(A; D) ! Dop projects C-algebras onto their communication part, i.e., Dep(A) = A~ and Dep(h) = ~h.8 Revisiting the example 2.6 and dependency morphisms from gure 2, it is obvious that given, for instance, the standard algebra of natural numbers N with function F , we may form C-algebras hN; Ri, hN; D0 i and hN; Di with the respective morphisms, e.g. hidN ; di : hN; Di ! hN; Ri. On the other hand, a dependency morphism which sends, for instance, a node labeled with F (2) to a node labeled with F (4) will not yield a C-morphism unless some additional (and here, surprising) identi cations take place in the algebra part N . 7 The diagram 3 commutes, but not in a category (at least none we have de ned explicitly), and so we write the composition of functions explicitly as a(b(i)). 8 Of course, each (A; D) has its own functor Dep(A D) . But we may as well view each such a functor as a restriction of DepCAlg() to the respective source subcategory. ;
6
2.4 Machines and Implementations
We introduce the model of machine architectures and their mappings (simulations) in 2.4.1, and then de ne implementation of a communication algebra on a given architecture 2.4.2.
2.4.1 Machine architectures
In order to relate the dependencies to hardware architectures we will consider the latter as spacetime unfoldings of the actual inter-processor communication structure [MW83]. Thus, a (static) architecture is simply an st-indexed DAG, where each node represents a unique time-point at a given processor and edges represent the possible single-step communications. This perspective may be extended to cover dynamically changing architectures as well (it would merely require more general graphs than the st-indexed ones) but for the moment we restrict our attention to the static case. A morphism between two architectures expresses the possibility of using one architecture, Z , to simulate another, W , i.e., that each communication of which W is capable can be simulated by a chain of communications in Z . This is captured by the existence of an embedding of W into the path closure of Z , that is, a Gr+ -monomorphism W ! Z . Consequently, we de ne: De nition 2.9 The category of machine architectures is MAr = Gr+. Thus, similarly to the dependency morphisms, an architecture morphisms W ! Z tells us that, and how, Z can simulate communications of W . Example 2.10 An n-dimensional vector W has n processors connected so that each processor, except for W1 and Wn , has two-ways communication channels to its left and right neighbour: W1 W2 Wn . A space-time unfolding for a 2-dimensional vector is illustrated in gure 4.a). The vertical arrows (Wi ; k) (Wi ; k + 1) are added to represent the fact that each processor can carry its local data from one computation step to the next. A ring Z with 3 processors where, in each step, processor Z1 can communicate to Z2 , Z2 to Z3 , and Z3 to Z1 is given in gure 4.b). This architecture may simulate the 2-dimensional vector W by the morphism m indicated in gure 4.c). 2 JJ
JJ tt JJ ttt Jt t J tt JJJ JJ tt t J tt JJ t JJ t JJ ttt JJt J tt tt JJJ t JJ t t t e
O
O
9
O
e
W1
9
O
/
o
a)
TTTTtT
t TTT tttt t t T T tt tt TT TTTTt T t T TTTtTttt t t tt tt TT TTTTt T t t TTTt ttt t t T T t T t t T TTTTt TTTT ttt t t t t T T t t t t TT j
:
O
O
O
O
W2
Z1
O
j
:
:
O
O
j
:
:
O
O
j
@A O
:
O
/
:
:
O
O
Z2
BC
b)
/
Z3
SSSS
SSSS vvv vvSSS vv v vv SSS SSSS vv vS S S v v S v v v vv i
O
O
;
O
i
;
O
m:W !Z +
c)
Figure 4: Space-time representations of a) 2-dimensional vector W , b) 3-processor ring Z , and c) a simulation m of W by Z . We might have given a more restrictive de nition of MAr. For instance, the unfoldings of actual processor-architectures will be st-indexed graphs which are simply repeating patterns of one-step communications. Also, simulation morphisms might be restricted to Gr+ -monomorphisms. Nevertheless, we choose this more generous de nition because it will result in a more uniform treatment { it will allow us to consider also shapes of data dependencies as objects, and implementations as morphisms of the same category MAr. 7
2.4.2 Implementation
The composition of functors Dep Grop : CAlg(A; D) ! Dop ! MArop applied to an algebra returns the underlying graph of its communication part (which is an object of the category MAr = Gr+ ). C~ i on a given architecture W amounts to a simulation of the Implementation of an algebra hC; (shape of the) communication structure given by Gr(C~ ) on W . That is De nition 2.11 An implementation of a communication algebra C on an architecture W is an MAr-morphism m : (Dep Grop )(C ) ! W . An implementation, so to speak, maps the dependency relation to the communication structure of a hardware architecture. Example 2.12 The dependency D~ (with the shape D from gure 2) is mapped onto twoprocessors vector W as it was illustrated in example 2.3, gure 1. Figure 5 is just a repetition of this earlier example: a) is the data dependency D~ with the shape Gr(D), b) is a two-processors vector W and c) is an implementation f of D on W . HH
F (4) K O
e
KKK K
ss sss 9
F (3)
KKK K
D~
O
O
F (2) K e
HHvvv vvHHH v v HH v HHvv vvHH vv H HH v HHvv vvHH vv H d
O
O
F (1)
:
O
d
:
O
d
W1
:
O
/
o
a)
4 O
F (4) K
KKK K
e
O
3
ss sss 9
2
F (2) K e
1
KKK K
W2
fD!W
b)
c)
F (3) O
F (1)
Figure 5: a) The data dependency D~ , b) space-time representation of a 2-dimensional vector W , and c) an Gr+ -embedding f : Gr(D) ! W + .
2
Combining such implementation morphisms with the simulation morphisms between various architectures, leads to the possibility of porting the implementations. Example 2.13 The mapping f from gure 5.c) is an implementation of a communication algebra D~ i (where D is a Fib -algebra satisfying Fib) on the vector W . Then, the mapping m D = hD; ( gure 4.c) gives an implementation of D on the ring Z . The obvious results are shown in gure 6.
2
Since an implementation m is a mapping of Gr(A~ ) into W + , it will be sometimes written explicitly as mA!W and called an implementation morphism or just an implementation. Unfortunately, an implementation morphism is not a morphism between implementations. The latter is de ned as follows: De nition 2.14 A morphism between two (A; D) implementations, m : fA!W ! gB!Z , is a pair hhm; m ~ i; m+ i, where: 1. hm; m ~ i : A ! B 2 Mor(CAlg(A; D)) ; + 2. m : Z ! W 2 Mor(MAr), and 3. Gr(m ~ ) f = g m+ . 8
F (4)D
DD DD DD
a
O
F (4)D
F (3)
F (3)
zz zz z zz
a
zz zz z zz
O
=
=
F (2)D a
DD DD DD
O
DD DD DD
F (1)
F (1)
D~
n F (3) nn nn n n nnn F (2) WWWWW WWWWW WW F (1) + (f m)(D!Z )
O
DD DD DD
7
O
k
fD!W
a)
WWWWW WW
k
O
F (2)D a
F (4) WWWWW
b)
c)
Figure 6: a) Data dependency, b) its implementation on a 2-dimensional vector W , and c) implementation b) ported to the ring Z
'&!A
%$ A~"#
evA o
f
fA!W
W /
O
O
m m ~ '&!B evB ~%$"# B g
m
m+
o
/
gB!Z
Z
Figure 7: A homomorphism between two implementations. Simplifying a bit, we may depict the situation as in gure 7. The diagram of gure 7 is a convenient abbreviation ignoring the application of Gr. The commutativity of its rightmost square is actually the requirement of the commutativity (in Gr+ ) of the rightmost square in the diagram from gure 8. A~
Gr /
O
m ~ B~
f Gr(A~ )
W /
O
O
Gr(m ~) Gr /
Gr(B~ ) g /
m+ Z
Figure 8: We let Imp(A; D) be the category with objects being implementations of (A; D) algebras from de nition 2.11, with morphisms de ned in de nition 2.14 and pointwise composition.9 The forgetful functor MAr : Imp(A; D) ! MArop is the obvious projection of implementations onto their architecture part.10
2.5 The Development Process
The framework is motivated by the view of the development of (possibly parallel) implementations by means of communication algebras. We envision the process starting with the usual re nement of
9 This works because the commutativity of the square in gure 8 { i.e., for each edge e in Gr(B~ ), the paths obtained in W by m+ (g(e)) and by f (Gr(m ~ )(e)) are identical { implies commutativity for each path in Gr(B~ ). Hence composition with another such commuting square, given by Gr(~n) : Gr(C~ ) ! Gr(B~ ), n+ : Y ! Z , and h : Gr(B~ ) ! Y , will yield a commuting square (Gr(~n) Gr(m ~ )) f = h (n+ m+ ). 10 Again, we may view each MAr(A;D) as a restriction of MArCAlg() to CAlg(A; D).
9
algebraic speci cations (an algebra A in gure 9). At some point, when the speci cation becomes suciently concrete, one introduces the dependencies, i.e., constructs a communication algebra B~ i. Dependencies can then be re ned along with a further re nement of the algebra itself or, hB; perhaphs, keeping the algebra xed. Remark. Since there is no surjectivity requirement on ev, the communication part C~ need not contain the full information about all operations of the algebra C . (In the extreme case, the shape of C~ might
be the empty graph.) There are several reasons for the lack of such a requirement. Firstly, it allows us to consider a standard algebra C as a communication algebra with an empty communication part. More importantly, it allows us to model the development process in which more and more operations of the algebra are gradually equipped with more detailed computational information. Finally, we may imagine a speci cation of C-algebras as a kind of algebraic speci cation with hidden functions: only the visible operations are of interest to the implementation, and the resulting C-algebra need only provide the dependency structure for these operations. 2
When all the required operations of the algebra have been associated with the satisfactory de C~ i, one may choose an architecture on which to implement the obtained commupendencies, hC; nication algebra, fC!W . Once this is done, there remains only the question of portability, that is, of moving the implementation to dierent architectures. One may tend to imagine that a transition from one level (category) to the next means that the structure resulting from the development at the previous level is complete and remains xed for the rest of the process. Thus, having reached the algebra B we begin to introduce and re ne dependencies while B remains unchanged (and so, C is actually B ). Similarly, having designed C~ i and implementing it on W , we may move to another architecture Z but hC; C~ i will be hC; ~ ~ kept xed (i.e., hD; Di = hC; C i). Although this is probably the most natural scenario, gure 9 illustrates the process in its full generality, where all the aspects may change at all levels. Imp(A; D) A
D
Dop
D~
MArop
Z
CAlg(A; D)
C
/ /
evD
O
/
g
C~
O
evB
/
f
B /
evC
O
/
/
A
/
/ /
A
B~
W
/
/
Figure 9: The development process Although the technical results below (and in section 4) are rather straight-forward and hardly surprising, they provide a sound justi cation for the above methodology as well as a clue as to how it may be applied. They yield a pleasing conceptual structure in which algebras can be thought of as indexed by various dependencies, and communication algebras by machine architectures. More importantly, they give us the possibility of modularising the implementation process and reusing its results: The (simulation) mappings between architectures MAr may be de ned and stored independently of the actual programs implemented on them. Suppose that we have implemented a communication algebra C on an architecture W , fC!W . If MAr is a bration with an explicitly de ned cleavage cl, then all we need to do to port C to another architecture Z is to nd (that is, choose from the library) an MAr morphism W ! Z . The cleavage then yields an algebra D together with an implementation gD!Z which is an implementation of fC!W . As a matter of fact, the triviality of the proof (that MAr is a bration) coincides with the desired fact that D = C . Lemma 2.15 For any (A; D), MAr : Imp(A; D) ! MArop is a split bration. Proof. We use the notation from the diagram to the right which illustrates the bration situation in the present context (dashed arrows indicate the directions in the op categories): 10
7654 B O
JJ
7 J 0123 B~ , 777 JJJJ
bB!Z@ f
Imp(A; D)
cC!Z
,, 77f JJgJ JJ ,, 777 77654 JJJJJ7654 ,, D D ,, , idD b ,,, 0123 0123 ~ D~ ,, D ,, d ,, dh+ ,
@@ @@ @@g @@ @@ @
h
/
$
/
dD!W
MAr
MArop
O
O
+
Z _ _ h_ _ _ W
Z h+ W
/
o
For an MArop -morphism h+ : Z 99 K W and implementation d = dD!W , the cleavage is de ned as
+i mcl(h+; d) def = h : c ! d where ch == dhid Dh+; h: Gr (D~ ) ! Z +
(1)
It is trivially a morphism in Mor(Imp(A; D)) since idD~ c = d h+ . Let g : b ! d be hhg;~gi; h+ i (i.e., such that MAr(g) = h+ ). The unique f : b ! c with MAr(f ) = idZ making f h = g is then hhg;~gi; idZ i. f 2 Mor(Imp(A; D)) because ~g b = d h+ = c idZ , where the rst equality holds since g 2 Mor(Imp(A; D)). Composition of cleavages yields a cleavage: for h+ : W ! Z , g+ : Z ! V and d 2 MAr?1 (W ) we have mcl(h+ ; d) = hidD ; h+ i, mcl(g+; d h+ ) = hidD ; g+ i, so mcl(h+ ; d) mcl(g+; d h+ ) = hidD ; h+ g+i = mcl(h+ g+ ; d): Hence MAr is a bration. It is split: we have (idW ) (d) = d, so the natural transformation idMAr?1 (W ) (idW ) is identity. Since composition of cleavages gives a cleavage, we have that (g+ ) (h+ ) = (h+ g+) .
2
The ber over a given architecture represents naturally all communication algebras which can be implemented on this architecture, together with the associated implementation morphisms. Example 2.16 The collection of all our examples so far illustrates exactly this idea of development. We have designed a dependency R~ which was then re ned to D~ . The latter was implemented on W ( gure 5) and ported to Z ( gure 6). Provided that the mappings m and f were available from a library, all the work we had to do was to design the mapping d. 2 idD d ~ D~ D~ R o
o
f m
f
Z m W
o
Figure 10: The summary of the example
3 Constructing Graphs and Labelings So far we have considered relationships between various aspects { functional speci cation (algebra), evaluation (communication part) and implementation { given independently from each other. In this section we show how, given an algebra satisfying some speci cation, one can derive an ecient data dependency and a labelling function. First, in 3.1, we introduce a general way of de ning data dependencies for a given signature and a set of nodes, by de ning a context free language 11
for every node of the graph. This grammar induces the edges between and the labelings of the given set of nodes. The next subsection 3.2 illustrates the use of this general idea with particular B~ i, have a speci c speci cations of recursive functions. In terms of gure 9, we are at the point hB; ~ algebra B and construct the communication part B for it.
3.1 From signature to data dependency
Recall that a data dependency D, De nition 2.5, for a given signature consists of a set of nodes I D , a set of directed arcs given by D , and a labeling function labD from nodes to terms T . De nition 3.1 A context free grammar G is represented by a 4-tuple hT; N; ?!; si, where T is the set of terminal symbols, N is the set of non-terminal symbols, N \ T = ;, ?! N (N [ T ) is the set of production rules, and s 2 N is the start symbol. The productions de ne a relation ) (N [ T ) (N [ T ), called derivations, on strings: given L ?! R, then rLt ) rRt where rLt and rRt are strings in (N [ T ). The language de ned by G is L(G) = fq 2 T j s ) qg, where ) is the transitive, re exive closure of ) . Here (N [ T ) and T are the strings of symbols and the strings of terminal symbols, respectively. Given a signature = hS ; Fi and a set (of nodes) V , we construct a grammar G;V (v) for every v 2 V as follows. The set of terminals T = F is the set of function symbols in . For every node v 2 V we introduce a new, distinct non-terminal Nv , i.e., N = fNv j v 2 V g such that Nv = Nu implies v = u. To de ne the productions, we extend to N (and F to FN ) by assigning all symbols Nv 2 N some (not necessarily distinct) sort sv from S and treating the Nv as new constants of the respective sorts. Conversion of a signature to a grammar involves, typically, reversing a function pro le f : S1 : : : Sn ! S to a production S ?! f (S1 ; : : : ; Sn ). The rules ?!G;V of our grammars are constructed analogously except that, instead of sort symbols we use the constant symbols Nv of the respective sorts. Thus, the productions have the form Nv ?!G;V t where t 2 TN and, for every node v 2 V , its language L(G;V (v)) will only contain type correct terms11 . Letting, nally, for every v 2 V the start symbol of its grammar G;V (v) be Nv , we obtain the grammar (2) G;V (v) = hF ; N; ?!G;V ; Nv i de ning a node-speci c language L(G;V (v)) of terms T for every node v 2 V . Denote the G;V collection of such node-speci c grammars by G;V . De ne such that for all u; v 2 V we have G;V
u v , Nv ?!G;V rNu t
(3)
for some r; t such that rNu t 2 TN . This gives us a graph structure on V , and we can de ne a \compatible" labeling function by requiring that
8v 2 V : labG;V (v) 2 L(G;V (v))
(4)
The following fact states the obvious conditions on G;V ensuring that (2) and (3) imply uniqueness of the labeling satisfying (4). Proposition 3.2 If a collection of node-speci c grammars G;V (for some signature and a set V ) is such that 1. for every non-terminal Nv there is exactly one rule Nv ?!G;V t, and G;V
2. the resulting graph ?G;V = hV; i is well founded, then G;V determines a unique data dependency. 11 We can now de ne a grammar G with a new non-terminal s as start symbol and a rule s ?! N for all N 2 N , i.e., G = hF ; N [ fsg; ?! ;V [ fhs; N i j N 2 N g; si. Then L(G) = T , but we will rather de ne distinct grammars for each node. v
G
v
v
12
v
Proof. 2. implies that ?G;V is acyclic. That, for every v 2 V , L(G(v)) is a one-element set follows easily: by 1. we have exactly one Nv ?!G;V t for each v, and, since ?G;V is well founded,
each path from t will uniquely lead to a terminal node. Thus the unique data dependency is G;V DG;V = hV; ; labG;V i where labG;V (v) = q, where q is the unique string in L(G;V (v)). 2 G;V
Another obvious fact following from the assumptions of claim 3.2 is that if u v then labG;V (u) is a subterm of labG;V (v).
3.2 Dependencies for recursive functions
The above construction can be used for the special, yet quite frequent and useful, speci cations of functions which we call CR (for \constructive recursive" [Hav93]). They are de ned by recursive equations of special form. Here we will focus our attention on the speci c form of (generalised) recurrence relations. Let SP = h; Ai be a speci cation and S1 :::Sn ; S be sorts from . A generalised -term recurrence R 62 of type S1 ::: Sn ! S is given by a set of equations of the form (5) R(0 (x)) = 0 (x) ( x; R(1 (x)); R(2 (x)); : : : ; R(z (x)) ) where x is a (sequence of) variable(s), for each 0 k z : k (x) is a sequence of terms t1;k (x):::tn;k (x) of appropriate sorts, i.e., ti;k (x) 2 T (x)Si , and 0 (x) (x; y1 :::yn ) 2 T (x; y1 :::yn )S with all yi of sort S . R may be given by a set of such equations, i.e., dierent equations for dierent (sequences of) term(s) 0 (x). From now on we assume that we have chosen a speci c algebra A and want to construct a dependency structure for it. As the index set (of nodes) we take the cartesian product V = S1A ::: SnA of the respective carriers in A. For any assignment : x ! A, let i 2 V refer to the interpretation of i (x) under . (I.e., i = i A ((x)) = tA1;i ((x)) ::: tAn;i ((x)).) We may now de ne the set of productions ?!G;A from the recurrence (5) by collecting
(6) N0 ?!G;A A0 (0 ; N1 ; N2 ; : : : ; Nz ) for all assignments . Gathering the productions G;A (v) for every v 2 V , we obtain a collection of node-speci c grammars G;A as in (2). The recurrence R from (5) is well-de ned in A, i.e., determines a function from V to S A , if and only if this collection of the node-speci c grammars G;A satis es the conditions of Proposition 3.2. This obviously subsumes primitive recursion for which we have = hN; Fi, the only model A
being that of the naturals such that F are the basic primitive recursive operations on naturals. Speci cally, = hfN g; fs : N ! N; z : N gi, with N A = IN, sA = s the successor function, and z A = 0. Given recursive equation schema for an R with n + 1 variables
R(0; y1 ; : : : ; yn ) = g(y1 ; : : : ; yn ) R(s(i); y1 ; : : : ; yn ) = h(i; y1; : : : ; yn ; R(i; y1; : : : ; yn )); where g and h are primitive recursive operations, we get V = INn+1 , nodes y = hy0 ; y1 ; : : : ; yn i, and the productions for any xed values of y1 :::yn :12
Nh0;y1;:::;yni ?! g(y1 ; : : : ; yn ) Nhi+1;y1 ;:::;yni ?! h(i; y1; : : : ; yn ; Nhi;y1 ;:::;yn i ) 12 Notice that, although we are taking as the set of nodes IN +1 , here we would obtain essentially n + 1 linear graphs (which are isomorphic as graphs, mutually unconnected). The recursion goes only on the rst argument and y1 : : : y function merely as parameters. Thus the only computationally relevant information resides in the rst parameter. We do not address here the more speci c questions as to how to retrive and utilize this kind of information. n
n
13
Fibonacci again
As a trivial example, take again the Fibonnacci function from example 2.6.. We have the signature = hfN g; fs : N ! N; : N N ! N; z : N gi, with R : N ! N . Taking A to be the natural numbers, we get V = IN, sA = s the successor function, A = +, and z A = 0. Applying the above schemata, we obtain the productions for the collection of the node-speci c grammars Fib
N0 ?! 1 N1 ?! 1 Ni+2 ?! (Ni+1 Ni ) The resulting graph and labeling (with parantheses added for readability) are shown in gure 11. Notice the advantage of using this method { we do not obtain the usual tree of recursive calls but a much more ecient graph ?Fib. (1+1)+((1+1)+1) V
4 NNN
VVVV V (1+1)+1 g g gg g g g g 1+1 WgWWWW WWWWW WW 1
NNN 3 ppp p p 2 PpPP PPP f
O
O
7
k
3
O
O
g
k
O
O
1
0
1
?Fib
labFib
Figure 11: The graph and labeling resulting from the collection of node-speci c grammars Fib.
3.3 Parallelisation - Fast Fourier Transform
To illustrate the appliction to actual parallelisation of programs, we review the technique of fast Fourier Transform, FFT, due to [CT65]. We do not focus here on the development process, but merely recast an existing solution of the problem in our formalism: we explain brie y the background, apply a designed data dependency and map it onto a hypercube. In the last paragraph we show how this solution can be obtained directly from the de ning equations using the technique from 3.1-3.2. The numerical problem P can be summarised as follows: In many areas, computing of the n-order polynomials p(x) = ni=0 pi xi , 0 n, for certain argument values x = x1 ; : : : ; xk is important. These areas include, for instance, signal processing, where evaluation of the polynomials for the complex roots of unity plays a central role. An n'th complex root of unity is a number ! such that !n = 1. For every n 1 there are n distinct complex roots, denoted !nj , and satisfying
!n0 = 1 j !n+1 = !nj !n1 !nj = !nj mod n
(The second equation is trivial for j = 0.) Useful facts about these roots are that (!2jn )2 = !22nj = !nj and !2jn+n = ?!2jn. The roots may be computed by !nj = e2i=n = cos(2j=n) + sin(2j=n)i, where i = !41 is the imaginary unit, i.e., i2 = ?1. Cooley and Tukey [CT65] discovered a very ecient fast Fourier transform for computing an n-order polynomial for all n'th complex roots of unity. Let us consider this method for the case where n = 2M , i.e., the one-dimensional binary version. Then p(x) = pe (x2 ) + x po (x2 ), where 14
P n?1 P n?1 pe (x) = 2i=0 p2i xi and po (x) = 2i=0 p2i+1 xi . Taking into account the special properties
of the roots of unity, we get
p(!2jm ) = pe (!2jm?1 ) + !2jm po (!2jm?1 ) pe (!2jm?1 ) = pe;e (!2jm?2 ) + !2jm?1 pe;o(!2jm?2 ) po (!2jm?1 ) = po;e (!2jm?2 ) + !2jm?1 po;o(!2jm?2 )
This can be formulated as a recurrence equation p(!2jM ) = F (j; M ) F (j; m + 1) = F (s0 (j; m + 1); m) + !2jm+1 F (s1 (j; m + 1); m) (7) F (j; 0) = pj ; where s0 (j; m) = j ? (j mod 2m ) + (j mod 2m?1) sets the m'th bit of j to 0 and s1 (j; m) = j ? (j mod 2m ) + 2m + (j mod 2m?1 ) sets the m'th bit of j to 1. Bits are the 0's and 1's in the binary representation of a number, and are counted with the least signi cant bit as number 1. The stencil of the recurrence F { the butter y graph { is illustrated in gure 12 for M = 3.
m
WWWWWWWWWWWWWWWWWWgWgWgWWgWgWgWgWgWgWggggggggggggggg
3
WWWWg WgWg Wg WgWgWWg Wg gg g Wg W g Wg gW Wg gW gWg W Wgg gW gWg Wg W WgW WWWWW g gWW gW gW ggg gW gWgWgW W g g g g g W g W g W W W W WW g g g g W W W g g g g OgOgOg gOOgOgoo gggoo ggWgW OOOWW OOOWoWo WoWo OOOooo OOOooo OOOooo OOOooo oooOOoOoOoOooOOOOO oooOOoOoOoOooOOOOO o o o o @o@ o @@ @o@ o @@ ~ ~ @~ @ @@ @@~~ ~ ~ ~~ @@ @ ~@@@ ~~ ~~@@ ~~ @ ~ ~ ~ ~ ~ ~ ~ ~ @
O
2 O
1 O
0
0
1
2
j
/
Figure 12: The butter y pattern of the recurrence F . Columns correspond to the j and rows to the m arguments with the leftmost column and bottom row numbered 0. Thus, for instance, the value of F (2; 1) resides at the row 2 column 1 (marked with the circle instead of bullet on the drawing). Increasing M by one, i.e., taking n = 2M +1 , amounts to putting two butter ies of height M side by side and connecting uppermost nodes (in the M 'th row) of the one butter y to the respective nodes of the other in the row M +1. Now, gure 13 shows the topology of hypercubes of dimension M = 3 and 4. Each of the 2M processors has M bidirectional communication channels. A hypercube of dimension M + 1 is obtained from two hypercubes of dimension M by connecting each node of one hypercube to corresponding node of the other. The gure 4.1 shows the embedding of the butter y dependency
WWWWW oo WW o WWWWW WW ooo
WWWW oWoWoWWWWW WoWoWo WWWWW o oWoWWWWWW oWoWo
WWWW oWoWoWWWWW WoWoWo
Figure 13: Connections for hypercubes of dimension 3 (solid), and 4 (solid and dotted). of height 3 from gure 12 into the space-time representation of the hypercube of dimension 3 15
from gure 13 (due to the \exceeded TeX capacity", the gure has been divided into two parts 14 and 14.b on page 17.) Using the regularity in building a butter y and a hypercube of a higher dimension, an analogous embedding is obtained for a butter y of arbitrary height M into a hypercube of dimension M . BB BB |
BB BB |
BB B| || BB |||BBB ||| B B | | |B |B || BBB||| BBB | BB || ||BB 1| | 1 11
11
11
11
1 1
1
11
111
1 1
BB B| || BB |||BBB ||| B B| | B |B | || BBB||| BBB | B BB | | | | B 1| | 1 11
11
11
11
11
1
11
111
1 1
Figure 14: The rows 0-2 of the butter y implemented on a hypercube.
Construction of dependency for FFT
Applying the strategy from 3.1-3.2, we obtain the same dependency structure directly from the de nition. The equations (7) de ne a recurrence relation in two arguments. Working again with the algebra of natural numbers, we take as the set of nodes V the cartesian product fhi; j i 2 IN IN j 0 i < 2M ; 0 j M g. The grammar resulting from the (last two) equations of (7) is then:
Nhj;0i ?! pj Nhj;m+1i ?! Nhs0 (j;m+1);mi !2jm+1 Nhs1 (j;m+1);mi
with the coecients pj of the polynomial treated as input since the roots of unity are xed once M is known. The resulting shape of the data dependency is precisely the one given in gure 12. Again, observe how this method leads directly to an \appropriate" graph instead of generating the full tree of recursive calls.
4 Variations and Remarks The framework of communication algebras introduced in section 2 is only a very general setting. A series of issues, concerning both re nment of the general concepts and their application in a concrete context, has not been addressed and demands further research. In this section we make just a few observations concerning such aspects as well as possible extensions. We begin by listing some additional properties of the category of communication algebras not mentioned earlier.
4.1 Some general facts about CAlg(A D). ;
1. Double category.
The following proposition allows us to view CAlg(A; D) as a double category with horizontal and vertical arrows, respectively, of the form h~h; idi and hid; h i. That is, the horizontal part is essentially D and the vertical part A. The nice implication of this is that we can work relatively independently with the algebra- and the communication-part of the objects in CAlg(A; D). Proposition 4.1 Each morphism h : C ! D in CAlg(A; D) can be factored so that 1. h = hh ; idC~ i hidD ; ~hi, 16
WWWWWWWWWWWWWWWWWWWWWWgWgWgWgWWggWWgWgWgWggggg ggggggg ggggggg
WWWWW gWgWgWgWgW gWgWgWgWgW gWgWgWgWgW ggggg W g Wg W g W g W gW g gW gW gggggggggWgWgWgWggWggWgWgWWgWWgWgWggWggWgWgWWgWWgWgWgWgWWWWWWWWWWWWW g g g g WW gW WWW WWW WWW gggg gggg gggg ggg
Figure 14.b:Embedding of the rows 2-3 of the butter y into a hypercube. 2. h = hidC ; ~hi hh ; idD~ i. Proof. The following diagram details the rst case: ~h '&~%$ '&~%$
D
C 33 o
evD evC 333 3 !C"#3 333 h !D"# 3 33 33idC~ 333 ~ h 33 3 '& %$ h 333 C~ idD 33 ev 3 Y
/
E
!D"# The intermediary C-algebra is as shown in the gure with ev = evC h . This makes hh ; idC~ i C~ ; evC i ! hD; C~ ; evi. Also, since h is a C-homomorphism, we have for a C-homomorphism hC; ~ D C D ~ ~ all i 2 I : h(ev (h(i))) = ev (i), h evC h = evD , idD (ev(~h(i))) = evD (i), i.e., hidD ; ~hi is a C; ~ evi ! hD; D; ~ evD i. C-homomorphism hD; D; ~ ~h evC i. 2 The second case is entirely analogous with the intermediary algebra being hC;
2. Adjunction.
Another general fact is the following: Proposition 4.2 If A has an initial object TA, then the functor F : Dop ! CAlg(A; D) de ned by F (C~ ) = hTA ; C~ i and F (~h) = hidTA ; ~hi is left adjoint to Dep, F a Dep, with identity as unit. Thus, if Dop has an initial object, so does CAlg(A; D). However, in general, this won't be the case since interesting subcategories of DD() do not have terminal objects (Dop do not have initial objects). In particular is initial in Gr+ and in DD(), but there is no terminal objects there. (If ZA is terminal in A, then hZA ; i is terminal in CAlg(A; DD()).) We do not focus on the notion of initiality and the relevance of empty communication part is probably limited to the fact that it allows us to treat usual algebras as communication algebras with an empty dependency.
3. Re nement.
De nition 2.8 has following implications for the notion of re nement. If an (A; D)-morphism h : C ! D is taken as a model of the re nement notion for communication algebras, we obtain the standard re nement of algebras h : C ! D . Re nement of dependencies, however, is the contravariant Gr+ - mapping ~h : Gr(D~ ) ! Gr(C~ ). That is, all the dependencies from D~ have to
be preserved, but they may be \streched" and augmented with new dependencies, as the example in gure 15 illustrates. We let ~h(a) = a, ~h(b) = d, and ~h(f ) = f . The commutativity requirement, h (evC (~h(i))) = evD (i), restricts the legal combinations of ~h and h . In particular, the labels in C~ may dier from those in D~ like with ~h(b) = d, only if d evaluates in C to a value x representing bD , i.e., such that h(x) = bD . 17
C~ : vv f EE v c FF v v v
evC
;
b
O
O
b
;
/
:
b
a
b
:
O
~h
+
C
d
C h
evD
D~ : vv f EE v a b
h
D
D
/
:
b
b
:
Figure 15: An example of re nement of communication algebras. Also, re nement \does not care" about what is computed in C at the nodes which are not in the image of ~h(D~ ). There may be new nodes and dependencies, also on nodes labelled by terms not occurring in the labelling of D~ (like c f in C~ ). In particular, if we admit a communication algebra with an empty dependency part (i.e., empty carriers in the category D), a standard algebra i. Then A may be considered a communication algebra with empty communication part, A = hA; any algebra B with non-empty communication part will be a re nement of A provided there is a homomorphism h : B ! A. As an example of possible drawback, consider an algebra D with the sorts S; S1 ; S2 , and the dependency s f (s) for two terms of sort S . Furthermore, let the sort S be the Cartesian product of the two other sorts S = S1 S2 , with the obvious projections i : S ! Si and pairing function h ; i : S1 S2 ! S . Let D satisfy the natural equalities for these functions and, in addition, let D j= s = hs1 ; s2 i, and D j= f (s) = hf1 (s1 ); f2 (s2 )i. This allows us to design the re nement of the dependency structure illustrated in gure 16 which together with the identity on D yields a C-homomorphism hidD ; ~hi. idD
D
/
O
D O
ev
hf1 (s1 );f2 (sQ2 )i QQQ nn n Q n n
f (s) O
h
6
f1 (s1 )
ev
6
f2 (s2 )
h
O
O
o
O
~h
O
s1 RRR i
RRR 1 RRR i
s kk 2
s
k kkk kkk 2 5
5
O
s
Figure 16: Another example of re nement of communication algebras. One may say that it is counterintuitive { the dependency s f (s) in D~ is re ned to both paths (through s1 and s2 ). Our morphism, however, sends the former only on one of them. This might indicate the need for a more speci c de nition of dependency morphism. For the time being we have settled for the one which seems simple enough { in this case it is better to have a morphism like the one above rather than not having any. Most alternatives seem to prevent one from designing a morphism at least in some cases where one would expect (like to have) one.
4.2 Communication Algebras over Dierent Signatures
So far we have only considered C-algebras over one given signature. Thus, the development process illustrated in gure 9 is not quite realistic since it is rather certain that such a process will involve 18
change of signatures. In this subsection we extend the standard way of attening the categories of algebras indexed by signatures to the C-algebras and their implementations. Thus we obtain the means of re ning the picture of the development process from gure 9 by also admitting transitions between C-algebras over dierent signatures. As announced in subsection 2.1, we let Sig be the category of signatures with injective signature morphisms.13 De nition 4.3 Let : 0 ! 2 Mor(Sig) and D 2 DD(). The -reduct of D, Dj 2 DD(0 ), is de ned in two steps as follows: X D 1. let X be D with restricted re-labelling : I X = I D , = and labX (i) = ft : (t) = labD (i)g ; 2. Dj is then given by I Dj = I D n fi : labX (i) = g, labDj (i) = t 2 labX (i), and
(
D i j , i Xj or X 9 i k1 k z j : 1 n z ) labX (kn ) = D j
In the rst step, we remove all the labels from D which are not in the image of , and re-label the remaining ones to their pre-image. In the second we convert paths with unlabelled intermediary nodes into edges between the labelled end-points. For A 2 Alg() and : 0 ! 2 Mor(Sig), we let Aj denote the usual reduct. We then have the extension of the standard result: Lemma 4.4 : 0 ! 2 Mor(Sig) induces the functor j : CAlg() ! CAlg(0): Proof. For an A 2 CAlg(), de ne Aj = hAj ; A~ j i. For a morphism h : A ! B 2 Mor(CAlg()), hj = hh j ; ~hj i where h j is the image of h under the usual reduct functor for algebras, while ~hj is the restriction of ~h to B~ j under changed labelling: each node i of B~ j is sent to the node ~h(i)j , and edge e of B~ j onto the edge (path) ~h(e)j in A~ j . This is a well de ned DD(0 )-morphism: commutativity ~h evA h = evB implies the corresponding commutativity in the reduct, since the latter operations are restrictions of their pre-images. 2 Thus j : Sigop ! CAT sending to CAlg() and to j is an indexed category. By the standard application of the Grothendieck construction we may de ne the attened category CAlg with 1) objects h; Ai where A 2 Obj (CAlg()), 2) morphisms of the form h; f i : h0 ; Ai ! h; B i, where 2 Mor(Sig) and f : A ! B j 2 Mor(CAlg(0 )), and 3) composition h; f ih; gi = h ; f gj i. Quite an analogous construction yields an indexed category j : Sigop ! CAT which sends to Imp(). For : 0 ! , the induced functor j : Imp(0 ) ! Imp(), sends an implementation fA!W 2 Imp() onto (f j )Aj !W 2 Imp(0 ), where f j is the restriction of f to A~ j . The result of the attening is the category Imp. We do not dwell on this notion, because we consider the category Imp() as more central { porting implementations does not typically involve changes of signature.
4.3 More speci c dependency morphisms
The class CAlg(), although a legitimate entity in our setting, is of little interest. The reason is that the arbitrary dependency morphisms in DD() make the connection between the algebraand the communication-part of the objects in CAlg() rather loose and inde nite. We mention two possible restrictions.
13 We restrict ourselves to the injective signature morphisms for one main reason: de ning a reduct functor over data dependencies for non-injective morphisms implies several choices which seem slightly arbitrary. We therefore prefer to postpone such a decision until we have more experience and reasons to choose one alternative rather than another.
19
4.3.1 C-Algebras with Compatible D-morphisms
Let A be a xed class of -algebras. It is natural to think of it as a model class of some (equational) speci cation. One may postulate that such a choice of A should restrict the relevant dependency morphisms. In particular, if A j== s = t, the D-morphisms should not be allowed to map nodes labelled by s to ones labelled by t (nor vice versa), since such mappings are not compatible with the algebras in A. Thus, compatibility of a DD() morphism ~h : C~ ! D~ wrt. an algebra A means that ~h does not eect a re-labelling which is inconsistent with valuation in A. More precisely: De nition 4.5 Let ~h : C~ ! D~ 2 Mor(DD()) and A 2 A Alg(). 1. ~h is A-compatible i 8i 2 I C~ : (labD~ (~h(i)))A = (labC~ (i))A ; 2. ~h is A-compatible i it is A-compatible for all A 2 Obj (A) ; 3. DD(A) is a wide subcategory of DD() with A-compatible morphisms.
Alternatively, ~h is A-compatible i for each A 2 Obj (A), hidA ; ~hi is a C-homomorphism hA; D~ i ! hA; C~ i. We have the obvious Proposition 4.6 Suppose that A has an initial object TA, and let ~h : C~ ! D~ 2 Mor(DD()). ~h is A-compatible , ~h is TA -compatible. Proof. ()) is obvious. For (() assume ~h is TA-compatible. This means that the lower triangle of the following diagram commutes, where ev assigns the values in the algebra to the nodes according to their labels.
A 333 3 a 333 evA TA 33evA EE 33 EE 3 zzzz EE 33 zzzev EE 3 ev E zz E
O
Y