Professional Documents
Culture Documents
326
product constrained by equality of values between into PROLOGI [e.g. CM 811. Indeed one could
matching domains of the two relationa. The conjecture a paper titled, "Lists considered
notation in the relatlonal algebra used for the harmful". For storage of information for
PRTV was a Cartesian product associated with a commercial data processing lists are particularly
'selection' which indicated the columns to be inadequate. Relations as sets have no single
equated, for example ordering, and lists imposes one. Relations may be
Rl * R2 A=B complexly interconnected at the user level this
interconnection may be considered associative, but
A and B are role names, where A is a column of Rl, internally they need explicit connections not
and B a column of R2. The result is a relation of permitted in lists. The structure present in the
n + m columns (n = number of columns of Rl and m = problem must be capable of direct expression,
number of columns of R2. Two of these columns are extra structure to aid processing must be capable
identical - columns A and B, and clearly one of addition, extraneous structure which interferes
should be removed, but which one? In the PRTV with both must not be imposed. Thus a major
this was specified using a project operation, but motivation of this paper is to move away from
we felt there must be better ways of solving the lists while still remaining an applicative
role inheritance problem. language.
At the same time Stephen Todd was investigating A recent stimulating paper by Bob Kowalski [KOWA
how to ~~escape~~from the relational algebra into 831 notes the equivalence between predicates
PL/I, and one method he came up with replaced a (relations) and functions, and explores logic
relation by a PL/l procedure call. An equivalence PWgramning capabilities to match functional
between relations and procedures became evident, Programming. Here I go beyond that paper to
and we sought ways of reformulating the relational produce a full relational applicative language.
algebra so that the fact that a PL/I procedure was Perhaps this may in turn enrich logic programming.
invoked would be transparent.
Uniting relations with functional languages leads
The result was a l'generalised** relational algebra us to higher order relations, relations not in
(see example below) in which Codd 1st normal form. There has been a recent
matching role names in a Cartesian Waturall' move in this direction, as relational databases
join caused an equijoin on these columns. have been applied to engineering applications [eg.
the number of operations was reduced to LP 83, AR 841, and this paper completes this cycle
four. of development with an algebra of relations
This was published at a conference in 1975 [HHT appropriate to general hierarchical relations.
751 together with an analysis of the restrictions
cawed by the directional properties of
procedures. The paper was presented in a highly 3.0 A RELATIONAL APPLICATIVE LANGUAGE
analytical manner, and is not easy to read.
The basic languaf3e consists of relations,
An example of the generalised algebra is expressions involving these relations, and
Rl(X,Y,A,C)*R2(P,A,Q,X,F) definitional equations. Examples are shown in
which causes an equi-join on columns A and X in figures, to be motivated in the discussion below.
the two relations, yeilding a result
The basic syntax is.
relation-definition .= typed-relation 'w'
The resemblance of this to the predicate logic expression
formula typed-relation = relation-name relation-type
Pl(x,y,a,c) & W(p,a,l,x,f) relation-type = "(I' variable 'I 'I type I","
was initially coincidental, but it was soon variable I1 @Itype) ")'I
pointed out to us by Bob Kowalski. The expression I expression operator expression
correspondence has, of course, now been explored Imodadic-op expression
in depth [e.g. GM 781. Irelational-constant
Iuntyped-relation
At this time (1975) applicative languages were 111(11expression @*)"
beginning their regeneration led by, among others, operator = It*11 1 11+11
John Bachus [BACH781. It struck me then that monadic-op = II-11
there was a correspondence between the generalised relational-constant = relation-type 11[11tuple
join and functional application, but other things (",*' tuple} ")"
intervened. Then, recently, the appearance of two tuple = "(I1 value [*',I' value} ")"
books [HKND 80, DHT 821 has renewed my interest untyped-relation = relation-name '*(" variable
and the result is this paper. (ll,@* variable) ")I1
Applicative languages as they have developed today Notation. terminals have been included in quotes,
[as exemplified by the collection DHT 821 are braces v(** and 11)'1are metasymbols and have been
still very much moulded in the LISP tradition. included in quotation marks where they are
The critical limitation that this imposes is their required as terminal symbols.
dependence upon lists. For some applications
lists are an appropriate structure, but all too A relation is interpreted as a subset of the
frequently they are inappropriate, both as a means Cartesian product of the types. A type is a set.
of expressing the problem, and as a representation initially this is not particularly significant but
to aseist computation. Lists have evsn intruded later we will need to invoke a complete
327
type-lattice to make our 1-e general.
Position in the parameters list is significant, as precisely for this composition operation that the
in programming languages. The variables are used original generalised algebra was developed [HHT
for binding. A relation may be represented either 751.
extensionally, as an explicit set of "tuples" or
intensionally by some rule such as a relational
expression. The type of a relation is the list of
its parameters and their type, where the variables FIGURE 2
are not significant but position is. Relation Example of Relational Composition as Intersection
constants can be written as sets of tuples
conforming to the relation type immediately
preceding it. Alternative interpretations of MORK-RKADINGS(Pressure.real, Angle real)
relations are, as Predicates in Logic, and 5 (Pressure*real,angle real)
proceduut calls in programming languages. ((0.9,10),(1.3,10),(3.6,15),(4.2.25),(8.7,45)
328
alternatives to be combined as in ,,case,, and
"if . ..then...else., constructs. All three together positional significance of these in principle,
allow logic conditions. Figures 4 and 5 show all variables on the right-hand sids should
examples, expressed both in the functional appear. However, if some are omitted, this means
programming notation of Henderson [HKND 801 and in that they are projected out. Thus in Figures 4
the relational notation. and 5 the intermediate "value,, can be omitted, to
make the relational expression identical in
However, our composition operator is far more semantics to the functional Programming
powerful than traditional functional composition, expression.
for it allows functions to be used "backwards,,.
(Kowalski [KOWA~S] calls this ,,invertibility,,) As observed by Codd [CODD 721, projection involves
existential quantification, thereby giving the
relational algebra the power of the first order
predicate logic.
FIGURE 5 - Conditional Applicative Expressions
One could reasonably also allow extra columns on
the left hand side, interpretting these as
FUNCTIONS Cartesian products extending the relation defined
Sine R -> R by the right hand side of the definition.
Square-root R+->R
SIZE_oF_SET 1s t(2),(5))
One further operation is necessary. This IS the
,,projection,, of relational algebras. Rather than
To make this and other definitions of higher order
have a special operator for this, we will make it relations acceptable,
a property of the definitional equality ,,='. The we will have to consider
further the specification of "type,, in relations.
relation being defined and placed on the left-hand Up to this point we have assumed a base set of
side of ,,=,, lists its columns, thus determing the types like "real,,, ,,integer,,, ,,string,,, but now
*
329
must extend this to include relations themselves. digress from our main argument. The operation of
We have already defined the type of a relation as Figure 9 is the ,,GROUPBY,, operation of SQL [ABM
the list of the types of its columns, but that is 76) necessary for sub-totalling. Figure 9 shows
too restrictive for higher order relations like this use.
TOTAL shown in Figure 8 which must sum the values
of one column but does not care about the other
columns, if any. We will use a ,,...,, notation to
indicate optional columns, treating this FIGURE 9
informally while recognising that this should be Conversion from first-order to second-order
properly defined, perhaps as a lattice of types.
Figure 7 and 8 have used the notation we intend to
employ. The syntax is given
fullrelationtype = relationtype PURCHASE~DETAILS(supplier~string,item integer,
I ( variable type number integer,price.real)
11,..*;11-*~"
I "(...)" define
PURCHASES(supplier string,item integer,cost.real)
We will also allow columns to contain individual = PURCHASE~DBTAILS(supplier,item,number,price)
tuples, and denote their type in the same way as l (cost = number l price)
relations, but preceding the type description by a
prime PURCHASES-BY-SUPPLIER
tupletype 5: ,,,,, fullrelationtype (supplier string,order (item.integer,cost real))
= PURCHASES(supplier,item,cost)
The syntax for type is then
type = simpletype PURCHASES-SUMMARY (supplier string,total~cost~real)
I fullrelationtype = PURCHASES_BY_SUPPLIER(supplier,orders(item,cost))
I tupletype l TOTAL(orders.(...,cost,...),total-cost)
simpletype .*= identifier
We will pick out the components of a tuple using This simple operation for converting between
the usual dot notation orders of functions provides a very powerful file
typecomponent = tuplevariable ,,.,, conversion language, and could provide a
columnvariable theoretical basis for languages like EXPRESS [SHTG
771.
Higher order relations provide the ability to
FIGURE 8 - The Higher-order relation, TOTAL modify ,,programs,, in the sense that by suitable
relational expressions the transformations defined
by a relation can be changed. Note that this is
given different from the kind of changes featured by
TOTAL (relation (...,NUMBER real,.,.),total real) LISP which changes program text. Of course here
we could represent text by suitable relationships
define and do the sort of manipulations practiced in
ORDER~SUMMARY(supplier string,total-cost real) LISP, to write compilers and similar. However,
= TOTAL(orders (...,Cost,...),total-cost) that has not been my motivation, and my notation
*(supplier string,orders (item integer,cost real) has not been aimed at that.
((BLOGG_BROS,[(1,57.21),(32,1.06),(127,42.43))))
~RDER_SURWARY
IS ((BL~Gc-BROS, 100.70)) 5.0 RECURSIVEDEFINITIONS
Recursive definition of relations, inspired by the
Examples involving tuples as components only methods of functional programming, follows very
appear in section 4, Figures 11 and 12. readily. Figure 10 shows that overworked example,
the factorial function.
We can write relations as column values within
relation constants, as has been done in Figures 7
and 8. However we will need general mechanisms
for converting given relations into ,,equivalent,, FIGURE 10
higher order relations, and vice versa. Recursive Relational Definition of Factorial
For this we will extend the relational-definition
operation, so that the columns of a relation and fact(n) = if n==Othen 1 else n*fact(n-1)
its subrelation can be regrouped as shown in
Figure 9. The intermediate ,,PURCHASE,,relation is FACT(n integer,r integer)
not necessary, but has been included for clarity. = (n=G)*(x=l)
We will only use this operation in the form shown + (n>O)+(n*x=r)*(y+l=n)*FACT(y,x)
there, where a first order relation is converted
to a second relation with only one column of Note y+l=n is used to compute y=n-1.
relations. However a general operation could be
defined, though it will not be done here, since it
requires a very careful definition that would
330
Recursive definitions will be most useful in the the singleton relations and the elements contained
definitions of higher order relations, but before in them. The NON-SINGLETONrelation is defined as
we can do that, we need to be able to recurse on the relative complement of SINGLETON with the
the relations themselves, in the same way that elements projected out.
LISP and its derivatlves recurse on list
structures. We could choose to treat relations as
sequences and follow the practices of LISP, but
relations are sets and no ordering may be natural. FIGURE 12
The Split Function and another definition of TOTAL
What we need is some method of breaking a relation
into parts, and then these parts into parts and so
on recursively until atomic parts are encountered. given
We will see two alternative methods of approaching SPLIT(set (...),subsetl (...),subset2 (...))
this. SINGLETON(set (...),element I(...))
331
relations required, and their use, are shown in
FIGURE 13 - Sales analysis of Pig Market Figure 13.
332
One particular advantage of the relational view Prentice-Hall 1980.
was its neutrality on "dlrectlon@@. Relations can HHT 75 Hall P.A.V., Hitchcock P.J., and T&d
be used in any direction, functions engender a S.J.P. "An Algebra of Relations for
very strong direction from domaln to range which Machine Computationw. Second ACM
can help the user, but, perhaps, ln the end Symposium on Principles of Programming
conatraln him. In implementation, too, tbe Languages, Palo Alto, California, Jan.
neutrality of relations can be an advantage. 1975. Pages 225-232.
HITC 74 Hltchcock P. %ukiamental Operations on
The next step in this line of development of Relations" IBM UK Scientific Centre,
databases must be the incorporation of update and Report UKSC-0051 May 1974.
time. The usual approach of before and after HITC 76 Hltchcock P. "User Extensions to the
states inherent in most formal approaches to Peterlee Relational Test Vehicle", 2nd
computing [e.g. JONE 801 1s not judged adequate, VLDB Conference, Brussels 1976.
and something more along the life history approach HOT 76 Hall P.A.V., Cwlett J. and Todd S.J.P.
of Michael Jackson [JACK 831 is expected to be the "Relations and Entitiesw in Modelling in
fruitful approach. DataBase Management Systems, Editor GM.
NiJssen, IFIP/North Holland, 1976. Pages
201-220.
8.0 REFERENCES JACK 83 Jackson M.A. "System Developmentw
Prentice Hall 1983.
AB 84 Abitebout S. and Bldolt N., "Non Flrst JONE 80 Jones C.B. "Software Development. A
Normal Form Relations to Represent Rigorous Approach". Prentice Hall 1980.
Hierarchically Organised Data", Third ACM KOWA74 Kowalskl R.A. "Predicate logic as a
SIGACT-SIGMOD Symposium on Principles of wogr-iw language" in Information
Database Systems, April 1984. Processing 74, North Holland 1974. Pages
ABCE 76 Astrahan M.M., Blasgen M.W., Chamberlin 569-574.
D.D., Eswaren K.P., Gray J.N , Griffitha KOWA83 Kowalskl R.A. "Logic Programming" Invited
P.P., King W.F., Lorie R.A., McJones P.R., Paper for IFIP 83, to appear.
Mehl J.W., Putzolu G.R., Traiger I.L., LP 83 Lorie R., and Plouffe W. *'Complex Objects
Wade B.W., and Watson V. 'System R and Their Use in Design Transactions", in
Relational Approach to Database Engineering Applications, Database Week,
Management" ACM Transactions on Database ACM SIGMODAnnual Meeting, May 1983.
Systems, Vol. 1, no. 2, June 1976 page MACL 83 MacLeMan B.J. l'Overview of Relational
97-137. Programming" SIGPLAN Notices, Vol. 18 No.
BACK 78 Backus J.W. "Can programming be liberated 3 March 1983. Pages 36-45.
from the von Neumannstyle? A functzonal HCCR 80 McCracken D.D. ‘*A Guide to NOMAD for
style and its algebra of programs." CACM, Applications Development" Addison-Wesley
August 1978. 1980.
BF 79 Buneman O.P., Frankel R.E. "FQL - A SHIP 81 Shipman P.W. "The Functional Data Model
functional query language *I, In Proc. ACM and the Data Language DAPLFX" ACM
Sigmod, Int. Conf. Management of Data, Transactions on Database Systems, Vol. 6,
Boston May 30th - June 1, 1979, ACM, New No. 1, March 1981. Pages 140-173.
York 1979. Pages 52-57. SHTG 77 Shu N.C., House1 B.C., Taylor R.W., Ghosh
BFN 82 Buneman P., Frankel R.E., Nlkhil R. "An S.P., and Lum V.Y. "EXPRESS aData
Implementation Technique for Database Extraction, Processing, and REStructuring
Query Languages" ACM Trans. on Database Systems'* ACM Trans. on Database Systems,
Systems, Vol. 7 No 2 June 1982 pages Vo1.2, No.2 June 1977 Pages 136-171.
164-186. TODD 76 Todd S.J.P. "Peterlee Relation Test
CHEN 76 Chen P.P-S "The Entity-relationship model Vehicle a system overview" IBM Systems
Towards a unified view of data", ACM Trans Journal, Vol. 15, No.3 August 1976.
Database Systems. Vol. 1, No 1, March WILL 83 Williams J.H. "Note on the FP style of
1976, page 9-36. Functional Programmingw page 73-102 in DHT
CM 81 Clocksin W.F. and Melllsh C.S. 82.
**Programming in Prolog" Springer 1981.
CODD70 Codd E.F. "A Relational Model of Data for
Large Shared Data Banks" CACMVol. 13,
No.6, June 1970. Pages 377-387.
CODD72 Codd E.F. "Relational Completeness of
Data Base sublanguages*' In Data Base
Systems (Ed. R. Rustin) Prentice Hall,
1972. Pages 65-98.
DHT 82 Darlington J., Henderson P., Turner D.A.,
"Functional Programming and its
Application6 II Cambridge University Press,
1982.
GN 78 Gallaire H. and Minker J. "Logic and
Databases" Plenum Press 1978.
GRAD83 Gradwell D.J.L. llICL's Data Dictionary
System" In Database 83 Conference BCS
HEND 80 Henderson P. %lnctiona1 Programming,
Application and Implementation"
333