• No results found

4 introduce equations valid in the equational theory of the implementing ADT, whereas rules 5-6 introduce equations valid in the inductive theory of the

implementation ADT.

Ruies 1- 4 introduce equations valid in the equational theory of the implementing ADT, whereas rules 5-6 introduce equations valid in the inductive theory of the

implementing ADT. Rules 1-5 Introduce equations which are derived from existing equations. We note that rule 5 is a restricted case of rule 6 and is most likely to be applicable when a does not contain any operators from the implemented ADT. We have not explicitly discussed how equations are shown to be valid in the inductive theory but clearly an induction rule based on the structure of ground terms is required as the usual rule:

for every ground substitution o, o(t)=o(u) g equational theory

t=u G inductive theory has infinitely many premises and is not therefore effective.

Given specifications A, C, a signature morphism a, and the abstraction mapping abs, we say that the specification C enriched according to these rules is well-spanned with respect to the representation when for each operator f: s.| .. s^ -> s in 2^, for all ground generator terms tji(Sj), (1<i<n), rep{f)(rep(t.j),..,rep{t^ )) is an instance of the l.h.s. of an equation. Clearly, a desirable implementation of A is an enrichment of C {constructed using only these rules) which is well-spanned with respect to the representation and the equations do not contain operator symbols from A. We note that when the representation mapping is not surjective, then the resulting specification is not well-spanned and thus the new operations may be only partially specified.

5.4 Access Nodes and Operators

We now consider the representation of a storage relation by a digraph. In order to choose (eventually) a representation of digraphs in a programming language, we designate a subset of the nodes of a digraph as access nodes. These are nodes which may be regarded as entry points into the digraphs; for each digraph which represents a storage relation, the labels of the access nodes are elements of the corresponding contents set.

The function of the access nodes is twofold; when we consider a storage relation as a digraph, then the set of access nodes should: 1) ensure that all the nodes in the digraph which need to be accessed are accessible (from the set of access nodes), and 2) define a potential space-time tradeoff. Namely, a node may be designated an access node if the inclusion of the node would enable operations on the digraph to be more (time) efficient; such nodes may already be accessible via the other access nodes. (Here, our notion of time efficiency is related to the number of edges traversed.)

Of course if the digraph is small enough, then the entire node set can be considered as access nodes. However, in most ADTs, the digraphs which represent the storage relations eventually become so large that this is no longer practicable; we must select the access nodes according to the above criteria.

So, we must be able to select the access nodes of a given digraph representation of a storage relation; moreover, we would like a general description, or specification, of the access nodes which does not depend on a particular digraph. (Although it is quite reasonable to expect that the selection depends on some of the properties which hold for all of the digraph representations of the storage relations of the object ADT.)

From our observational point of view, we are Interested in the labels of the access nodes; i.e. subsets of the domains of storage relations. The (labels of the) access nodes can be specified either by operations on digraphs (for example, an operation which returns the maximal node), or by operations on the derived sort elements from which the storage relation and digraphs are derived (for example, the operation fr o n t ) . We assume the latter form of specification: selectors In the object specification; we call the operators which name these operations access operators. Thus, we may refer to the access operators of a specification.

In the following sections, we consider the specification of the access operators according to the criteria described above. Because there are infinitely many operations which are applicable to a digraph, we cannot, in general, specify the access operators which will define a reasonable space-time trade-off. Instead, we give two different strategies for determining the access operators.

The first is a general, "automatic" strategy which does not depend on the object ADT ; however, because of this, it does not incorporate any aspects of efficiency analysis. The strategy uses a general result about the reachability of elements in the domain of the transitive closure of a storage relation. The second strategy depends on the object ADT; some aspects of efficiency analysis are incorporated by considering the Implementation of the object operations on the digraph representations of the storage relations. Because this strategy involves implementation, and hence some aspects of the inductive theories, some human intervention may be required.

5.5 Defining Access Operators: Method I

This method defines the access nodes of a digraph representation of a storage relation to be the least subset of nodes which ensures that the first criterion is fulfilled: all the nodes in the digraph are reachable from the access nodes. The method is a general one; that is, it does not depend on the particular object specification. Hence, for a given specification, the method may not return the least set which satisfies the first criterion. We show that for each storage relation =>^, all the elements In the domain of fit are reachable from the set of primitive elements returned by the application of the selectors to t, and the application of the compostition of the selectors with the rearrangers to t. The set of nodes thus defined is similar to the graph-theoretic notion of a root, or a point basis [Har 69], except that it is not required to be minimal.

Using this method, we define set of access operators of an ADT to be the set of selectors and compositions of selectors with rearrangers. In the following definition, we assume that f o g(x) f(g(x)).

Definition: Let (Z,E) be a keyless/implicitly keyed specification with selectors and rearrangers r . , T h e access operators of (Z,E) are the selectors Sj and the primitive sorted operators Sjj, defined as S|j =def o r|, for 1<i<n, 1<j<m.

For a given storage relation the (labels of the) access nodes of are the set of primitive elements {[s ( t ) ]| s e ({Sj} u {sy})}.

Lemma: Let (Z,E) be a keyless/impiicitly keyed specification, let t be a term of the derived sort, let (=>1)"^ be the transitive closure of =>|, and let A be the set of labels of the access nodes of =>^. For every element x in lit which is not in A, there is a path In the storage relation at t from an element in A to x. i.e.

(Vx e {z|}) (3y g A) y (=>^)+ x .

Proof: Let x be an element in lit which Is not the (label of) an access node. By the defn. of Ht, when x e lit and x g A, then there is a selector Qg and a class C in it such that Og(C)=x. By the defn. of it and because we do not consider elements of A in lit, there is a t’ in it and n eliminators a.j,...,a^, where n^1, such that is in C . Either [t] = [t'j, or there is a rearranger such that [t’]=[a^(t)]. By the defn. of b n .i(...a.|(t')...)]-> |C , [an.2(...a^(t')...)]->| [an_.,(...a.,(t')...)], and so on until [f]-> t [cr.| (t')]. By transitivity, we can show that [t’](“>|)'*'C. Also by transitivity, we can show that [Og(t')] (^^j)"*" cig(C). cTg(C)=x, and so by substitution, [Og(t')] (=> i)"*" x. By the definition of A, A = {[O g(t)],[O g(o/t))]}; if [t']=[t] then y is [cFg(t)] otherwise y is [ G s ( G r ( t ' ) ) ] . □

In some specifications, the access nodes will always be a point basis. For example, they will always be a point basis in

Q u e u e

and

S t a c k ,

but not in

Reversible__List__l

nor in

Circular^List^right

because in these specifications, the set of access nodes is not minimal. We conclude this section with some examples of access operators defined by this method.