C AHIERS DE
TOPOLOGIE ET GÉOMÉTRIE DIFFÉRENTIELLE CATÉGORIQUES
B. H ILKEN
D. E. R YDEHEARD
Indexed categories for program development
Cahiers de topologie et géométrie différentielle catégoriques, tome 32, no2 (1991), p. 165-185
<http://www.numdam.org/item?id=CTGDC_1991__32_2_165_0>
© Andrée C. Ehresmann et les auteurs, 1991, tous droits réservés.
L’accès aux archives de la revue « Cahiers de topologie et géométrie différentielle catégoriques » implique l’accord avec les conditions générales d’utilisation (http://www.numdam.org/conditions). Toute utilisation commerciale ou impression systématique est constitutive d’une infraction pénale. Toute copie ou impression de ce fichier doit contenir la présente mention de copyright.
Article numérisé dans le cadre du programme Numérisation de documents anciens mathématiques
INDEXED CATEGORIES FOR
PROGRAM DEVELOPMENT
by B. HILKEN and D.E. RYDEHEARD
CAHIERS DE TOPOLOGIE ET GÉOMÉTRIE DIFFERENTIELLE
CA TÉGORIQUES
VOL. XXXII-2 (1991)
RESUME:
Dans cet article lescatdgories
index6esservent de cadre
alg6brique
et dem6talangage
pour lalogique
des programmes. Cettelogique incorpore
lesprogrammes dans un
langage
deprogrammation,
desconversions entre programmes, des
sp,6cifications
ducomportement des programmes dans un
langage sp6cifique,
et des preuves
explicites qu’un
programme est correct.Des m6thodes de
d6veloppement
de programmes sontinterpr6t6es
comme des constructions decatégories
index6es. Deux
exemples
sont donnés: les invariants de type et lesspecifications d’op6rations
et de leurimplémentation.
1. INTRODUCTION.
From the earliest
days
of electroniccomputers,
there have been attempts to establish the behaviour of computer programsthrough
mathematicalproof. Early examples
ofpub-
lished
proofs
are those of Goldstine and von Neumann[1947]
and of
Turing [1949],
who checks a factorial definition(see [Morris,
Jones84]).
Recentdevelopments
have concentratedon formal systems and
’methodologies’
forconstructing
prog-rams whose correctness is assured
through proof.
Proofs ofcorrectness involve the
following
components:O
Programs
written in aprogramming language -
alanguage
- which admits a notion of
computation
or evaluation..
Descriptions
of programbehaviour,
calledspecifica-
tions. These may be written in the same
language
as theprograms, a
language
related to theprogramming language
or a different
language altogether.
In the latter case we need a’program logic’ linking
programs andspecifi-
cations.
.
Proofs,
either informal in the usual mathematicalstyle
or formal
proofs expressed
in a suitablelanguage.
These components are
widely accepted
asunderpinning
a pre- cisedescription
of the process ofprogramming, although
thepracticality
ofusing
the fulldegree
offormality
is open toquestion.
In this paper, we propose a
single general
structurecontaining
programs,specifications
and formalproofs
as wellits other aspects of
programming
such as evaluation. The structure is based oncategories
and functors whichtogether
express the
relationship
between thesecomponents. Concepts
such as
functoriality, naturality
anduniversality
drawn from categorytheory
describe the way that the components inter-act. The structure itself is not new, indeed it is an
adap-
tation of Lawvere’s
[1969,70]
notion of ahyperdoctrine -
anindexed category
appropriate
for thedescription
oflogics.
The
novelty
of the paper lies in theapplication
of in-dexed
categories
to programdevelopment.
We introduce someof the basic ideas and constructions
linking
indexed categor- ies andprogramming.
The reader should be warned that theaccount in this paper is
incomplete
in that much remains tobe done to
give
a fulldescription
both of the categorytheory
involved and of itsapplication
to programdevelop-
ment. This is a
large project
of which this paper is anearly
account. The links we establish betweenprogramming
and
categories
are, in themain, fairly
obvious once the con-text has been made clear.
Despite this, interesting
ques- tions arise about the constructions oflogics
and thedesign
of programs.
Why
thiscategorical approach?
One reason is that cate-gory
theory
allows standardalgebraic techniques
to be usedin the
analysis
oflogics.
As anexample,
a standard con-struction in
algebra
is that of free extensionsgenerated by
lindeterminates’.
By
this means, we introduce adegree
ofabstraction, allowing
asingle expression
to cover a class ofground expressions.
This describes animportant
aspect of modular programdevelopment whereby
indetenminates for func- tions areintroduced, delaying
the definition of functions until furtherdevelopment
has takenplace.
Associated with thisdevelopment step
is a new programlogic
which arises asa free construction.
The
genericity
achievedby category theory
isimportant
as it allows a
description
ofprogramming
which isindepen-
dent of
particular programming languages
and programlogics.
There has been considerable interest
recently
ingeneric proof
construction systemsusing
the fact that the structureof
proofs
isindependent
of theparticular
set of inference rules used to generate them. Forexample, Edinburgh
LF[Harper
et al87]
and Isabelle[Paulson 86]
are two X-calculiwith sufficient type structure to allow the
encoding
of infe-rence rules. Proofs are
expressed
as X-terms over theserules. This is to be contrasted with the
description
oflog-
ics in category
theory
where thegenericity
arises from acommon format for the inference rules for the
logical
con-stants
(connectives
andquantifiers), namely
as thebijective correspondence
between arrowsdefining adjoints.
In systems based onX-calculi,
substitution is part of theunderlying algebra
ofexpressions
and allbinding operations, including quantification,
are described as X-abstraction. In indexedcategories,
substitution isexplicit
asfunctors,
andbinding operations
are introduced asadjoints.
The usual ‘side con-ditions’ on inference rules
restricting
the occurrence of free variables become type constraints.One intended result of this work is a software system to support the process of
programming, enabling
us to writespecifications
and programs andperform proofs.
Software for this purpose is sometimes called a’programming
support en- vironment’. InComputational Category Theory [Rydeheard,
Burstall
88],
we show how to expresscategorical
concepts as data types in aprogramming language,
andconstructions,
suchas those of limits and
colimits,
as programs. The structuresin this paper may be
implemented using
these ideas. The es-sence of this
implementation
lies in the construction ofclassifying (i.e. free,
in a suitablesense) hyperdoctrines.
Preliminary coding
has takenplace
in functionallanguages
such as ML
[Harper
et al86] and,
moreappropriately
with itstype
classes,
Haskell[Hudak,
Wadler et al88].
Various formal systems and
methodologies
have been pro-posed
for program -development.
Anexample
is VDM[Jones 86].
As a formal system VDM consists of a
logic,
a selection of data types and aprimitive
functionallanguage.
There is anassociated
’methodology’
of programdevelopment
in which de-velopment
steps areaccompanied by ’proof obligations’
whichexpress the
preservation
of correctness. VDM itself focuseson data
refinement, implementing
abstract typesby
suitablerepresentations.
In this paper, we follow some of the basic ideas of VDM-likesystems, though
we have yet togive
a pro- per account of data refinement. Othersystems
for program-ming
are based on typetheory.
Forexample,
inNuprl [Constable
et al85], programming
consists ofbuilding proofs (in
a constructivelogic)
followedby
an extraction of the constructive part of aproof
as a program which may be evalu- ated. Yet anotherapproach
to programdevelopment
is derivedfrom universal
algebra
andimplemented
in systems such as OBJ[Futatsugi, Goguen
et al85].
There is an abstractapproach
to this based upon a
categorical
modeltheory
(’institutions’) [Goguen,
Burstall84]. Abramsky [1987]
hasproposed
ageneral
framework for programlogics
and denota-tional semantics based upon
topological
spaces and Stone dua- lities. In essence- this paper proposes anotherdevelonment
system whose
meta-language
iscategory theory
and whichfocuses on
explicit proofs
and free constructions.There has been considerable interest in indexed
categories
in computer science asdescriptions
oftyped programming languages
in whichtype expression
are themselvesclassified
(by
what are often called‘kinds’). Examples
ofsuch
languages
are thosesupporting parametric polymorphism (2nd-order X-calculi) [Seely 87a], [Pitts 87] [Hyland,
Pitts89]
andlanguages
with program modules[Moggi 89a].
In thispaper, we revert to Lawvere’s
original application
of indexedcategories
to describepredicate logics.
Some notation and
terminology: Composition
is writtenapplicatively:
forf : a
-> b and g : b - c , thecomposite
isgf : a
-> c . We usejuxtaposition
or "o"for
composition
of(1-)arrows
and the horizontalcomposition
of
2-cells, reserving
"." for verticalcomposition
of2-cells. Notation for
categories:
Cat denotes the2-category
ofcategories,
Ccat the2-category
of cartesiancategories (those
with finiteproducts)
with functors andnatural transformations
preserving
the cartesian structureand BCCcat denotes the
2-category
of bicartesian closedcategories
withstructure-preserving
functors and naturaltransformations. The
primary objects
ofstudy
in this paperare indexed
categories
and indexed functors on a2-category base;
we shall call themsimply
indexedcategories
andindexed functors. Other structures,
however, involving
2-cells receive their full
2-prefixes (2-limits,
2-colimitsetc).
2. CATEGORICAL PROGRAM LOGIC
This section consists of a brief introduction to indexed
categories
and their extension to2-categories.
Weexplain
how indexed
categories
describelogics arising
in programdevelopment.
In Section 3 we describe some programdevelopment strategies
as constructions of indexedcategories.
We wish to
emphasize
that indexedcategories
are used todefine a
language,
rather than toclassify
known structuresor to define a class of models. The category
theory
that wepresent should be
thought
of as the abstractsyntax
of a programlogic.
Proofs will takeplace
in the term model(’classifying hyperdoctrine’).
We considerobjects
to betypes
(or,
in thelogic, predicates)
and arrows to be terms(or proofs).
We do not,therefore,
define the syntax of alanguage
and use categorytheory
toprovide
a semantics. A consequence of this is that we do not need lax structures.Laxity
arises whenequations
in a definition arereplaced by isomorphisms,
or moregenerally by
2-cells. The structureswe consider are built from the syntax of
programming languages
and programlogics
and are strict(equational).
However,
models of thelogic
mayrequire
theseequations
tobe relaxed to
isomorphisms.
The base
language (which
inapplications
may be aprogramming language)
is a2-category
T with finite2-products.
Weinterpret
this as follows:objects
of T aretuples
of types,products
in T are the concatenation oftuples
of types,arrows t : Y -> X of T are
tuples
of terms(programs)
. of types X with free variables of types
Y ,
2-cells a : t => s are
(sequences of)
conversions bet-ween terms,
taking
t to s . Conversionsobey
thelaws of a
2-category [Rydeheard,
Stell87].
For the purposes of this paper, a
primary example
of a2-category
isprovided by
atyped 03BB-calculus. Objects
in the2-category
aretuples
of types of thek-calculus.
Arrowst : Y - X in the
2-category
are a-conversion classes ofX-terms
of types X with free variables of types Y . The 2- cells aregenerated from 0 and n conversions,
defined as fol-lows. For each term t : Z x Y -> X there is a term
03BBt : Z -> XY ,
theX-abstraction
over Y .Moreover,
for eachterm
s : Z -> XY ,
there is a termapp(s) : Z x Y -> X .
Both of these
correspondences
are natural in Z .The 13 and 71
conversions
provide
2-cellsJ3t : app(03BB(t))
=> t and11s:
s =>03BB(app(s))
which are natural in t and s and form the co-unit and unit
respectively
of anadjunction.
This treatment of03BB,-calculi
withexplicit
conversion rules follows that ofSeely [1987],
rather than the standard treatment via cartesian closure
(see [Lambek,
Scott86]).
A
point
aboutproducts
incategories
andmultiple
vari-ables in a
language:
Theproducts
in T are strict rather than lax because their role is to admit termshaving
morethan one free variable rather than to represent
pairing
inthe
language.
Notice that we may allowexpressions
with mul-tiple
variables in alanguage
which does not haveexplicit pairs (e.g.
in somepresentations
of%-calculus).
If thelanguage
were also to havesurjective pairing,
theproduct
type x* Y would be
laxly isomorphic (adjoint
at the 2-level)
to theproduct
X x Y of the types X and Y asobjects
in T .We describe a
predicate logic
over the baselanguage
asan indexed category over
T ,
i.e. a functorp :
Top ->
Catwhere Cat is the
(2-)category
ofcategories.
Toincorporate explicit conversions,
we make T(the
basecategory)
a2-category
and p a 2-functoracting covariantly
on 2-cells. We
interpret
this indexedcategory
as follows:objects ¢
of thecategory p(X) (the fibre
overX)
arepredicates
with free variables of types Xarrows
f : 0 -> p
inp(X)
areproofs
of cpassuming ())
in the context of free variables X
functors pt :
p(X)
->p(Y) ,
where t : Y - X in T(using subscripts
for this functorapplication),
arethe substitution of the
(tuple of) term(s)
t for thefree variables in
predicates
andproofs
inp(X)
natural transformations
p(a) :
Pt -> pe , where a : t => S : Y -> X are, foreach 0
inp(X) ,
aproof
ofps(O) assuming pt(O) ,
i.e.properties
of terms arepreserved
underconversion.
This is a
description
oftyped logic
where types are used to control the occurrence of free variables withinexpressions.
Notice thatproofs
arecomponents
of the struc- ture, so that the concept of aproof
rather than the derived concept of entailment is madeprimary.
This is inkeeping
with the
application
to programdevelopment
where we want toconstruct and
manipulate
formalproofs. However,
we have notconsidered conversions between
proofs.
Tostudy
theproof theory
of the system,proof
conversions would be included as2-cells in the fibres.
The functor p acts
covariantly
on2-cells,
so we admitonly predicates
which arepreserved
under conversions. There is thus aninterplay
between behaviour describableby predic-
ates and
preservations
of behaviour under conversions. In alogic
with a suitableequality,
we can also reason contravar-iantly,
as we show in the nextsection,
so that conversionsare intensional
equalities. However,
we do notalways
wantan
equality
of this form in thelogic.
Consider a program-ming language
with a non-deterministic choice operator n . There are conversions 0 n 1 => 0 and 0 n 1 => 1 . The term0 n 1 should not have all the
properties
of 0(in particular,
that of
being equal
to0) ,
but it may haveproperties
commonto both 0 and 1 .
Propositional logic.
We have described the
predicate
structure without a pro-positional logic.
Toincorporate propositional logics
werestrict the fibres to a
sub-2-category L
of Cat. The cate-gories
in L contain sufficient structure tointerpret
thelogic,
and the functors and natural transformations in 2 pre-serve this
(distinguished)
structure. Forexample,
for anintuitionistic
logic
we choose 2 to be the category of bicar- tesian closedcategories, interpreting conjunction
A as bin-ary
product, disjunction
v asbinary coproduct,
true T asterminal
object,
false F as initialobject
andimplication
asexponential (see [Lambek,
Scott86]
fordetails).
Otherlog-
ics arise
by
a suitable choice of 2.The
indexing
functor p is to factorthrough
the inclu- sion of 2 in CatThis says that substitution preserves all
propositional
structure, for
example, pt(O^y)
=Pt(O)^pt(y) .
We now show that in a
logic
with suitablepropositional
structure and
equality predicate,
a conversionyields,
for any aproof
ofpt(O)
fromps(O) .
Proposition
1. Let p :Top ->L
Ccat be an indexed cate-gory.
If
=x is apredicate
inp(X
xX)
withreflexivity
and
substitutivity
axioms:in
where
Bx :X--4XxX
is thediagonal
arrow, thenfor
eacha : t => s : Y - X and each
cp
Ep(X)
there is an arrowfrom Ps(O)
topt(O).
Proof.
in
in ,
in
The
composition
of(*) , (t)
and(t) gives
an arrow ofthe
required
type.Quantifiers
andequality
We treat
quantifiers
andequality
in a standard way. 3 is leftadjoint
toprojection
and natural in theunquantified variable, giving
thebijective inference
rule:in in
and,
for the condition:Similarly,
V isright adjoint
toprojection
and natural inthe
unquantified
variable. If thelogic
hasconjunction
A ,we define
equality
so that(=X)
AP n1 (-)
is leftadjoint
tothe
diagonal.
Thisequality
satisfies the above axioms ofreflexivity
andsubstitutivity.
For details of theadjoint
formulation of
quantifiers
andpredicates,
see[Seely 83].
Some treatments of
hyperdoctrines
demand left andright adjoints
to all functors pt ,satisfying
the Beck condi- tions forpullbacks
in the base. Here we introduceadjoints
to
particular
classes of functors in order to defineparti-
cular
logical connectives,
andchange
the Beck condition:programming languages
do not havepullbacks
other than thosearising
from theproduct
structure, so we are left with thenaturality
condition(§).
Notice that
quantifiers
do not, ingeneral,
preserve thepropositional
structure so are not functors in 2 The con-structions below of new
logics
takeplace
within thecategory
-w so that a
prepositional
structure isimposed
on the con-structed
logic. However,
this does not work forquantifiers,
and in
general
the constructedlogics
do not havequantifiers (or equality)
even if theoriginal
does. We discuss a pos- sible solution to this in the conclusions.Interpretations
Indexed functors
(morphisms
between indexedcategories) provide
a notion of aninterpretation
of onelogic
inanother.
Definition 1. An indexed functor from p :
ToP -> L
to q :S°p
- z consists of a 2-functor J : T -> S which pre-serves finite
2-products,
and a 2-natural transformation 11:The 2-functor J : T -> S is a translation from
language
T to
language S , translating
types, terms and conversions.The components
qx : p(X) -> qJ(X)
of the 2-natural trans-formations q interpret predicates
in p over X aspredicates in q
overJ(X) . They
are functorsin L ,
so preserve thepropositional
structure. The action of this natural trans-formation on
proofs
ensures that theinterpretation
ofpredi-
cates is sound.
Indexed functors may be
composed
via functorcomposition
and a
composition
of natural transformations. Theresulting
category is a
2-category
with 2-cellsconsisting
of a 2-natural transformation a :J -> J’
and amodification v : n ->
(q o aop).ll’ (see [Gray 74]).
Kan extensions
provide
animportant
construction of indexed functors as follows: Let p :ToP
- z be anindexed
category
and J : T - S a 2-functor. We define anindexed
category
q :SOP
-> L and indexed functor(J,n) :
p - q as the left Kan extension of palong f’P.
The Kan extension exists if 2 has indexed colimits
(see [Kelly 82]).
Forlogics
which arefinitely presented,
thisis the case.
3. PROGRAM DEVELOPMENT.
In this section we introduce some program
development techniques
andcorresponding
constructions of programlogics
nc indexed categories For those not
familiar with program
development,
we illustrate the constructions withsimple examples.
The constructions of program
logics depend
upon’adding
indeterminate arrows’ to
categories
as follows:Definition 2. Let C be an
object
in a2-category 9 Cat ,
and let X and Y be
objects
of C . A categoryC[t :
X ->Y]
with functor J : C ->
C[t]
is the free extension of C with an(’indeterminate’)
arrow t : X -> Y if andonly
if J is the2-universal functor in g with an arrow t :
J(X)
-J(Y)
inC[t] .
In otherwords,
for any functor F : C -> D in E andarrow t :
F(X)
-F(Y)
inD ,
there is aunique
functorF*in
9 such that
commutes, and
F*(t)
= t .Moreover,
for any 2-natural trans- formation a :F,
->F2
between 2-functorsFt,F’2 :
C -> D in andarrows tl : FI(X)
-F1(Y)
andt2 : F2(X)
->F2(y)
suchthat ay o
tl
=t2
o ax , there is aunique
2-natural trans-formation a# : Ff -> F*2
in e such thataY* o t1 = t2 o a*X
andaJ=a.
This is an
example
of an indexed colimit. Street[1974, 76]
establishes results on the existence and construction of indexed colimits.Letting 9
be a2-category
of2-categories,
this defines the addition of indeterminate 1-arrows to 2-
categories.
Type
InvariantsTypes
in aprogramming language (objects
in a base cate-gory)
may not besufficiently discriminating
for use in spe-cifications,
so additionalproperties
of programs areimposed
as
predicates
over the types. Thesepredicates
are called’type
invariants’. The concept of ’invariance’ arises fromthe fact that
operations
over the type must preserve the pro-perties
of the type as described in the invariant.As a
simple example,
consider the concept of a date pre- sented as aday (the position
in ayear)
and a year(simpli- fying
theday-month-year
ormonth-day-year format).
Both theday
and the year are naturalnumbers,
so dates arepairs
ofnatural numbers. The restriction on the number of
days
ineach year, which
distinguishes
dates fromarbitrary pairs
ofnatural
numbers,
is notcaptured through
type constructorsbut is
expressed
as apredicate
over N x N , where N is the type of natural numbers:valid-date(d,y) -
ifleapyear(y)
then d 366 else d 365 whereleapyear
is thepredicate determining
whether a year isa
leap
year . The type Date of dates is then the type N x Ntogether
with thispredicate.
Now consider a function on
dates,
such as thatyielding
the next
day:
next-day(d,y) -
if
(leapyear(y)
n d =366)
v(-Jeapyear(y)
n d =365)
then
(l,y
+1)
else(d
+l,y)
This term not
only
takespairs
of natural numbers topairs
ofnatural
numbers,
but preserves the invariant. This meansthat there is a
proof f
of the sequentvalid-date(d,y) |- valid-date(next-day(d,y)) .
Working
withexplicit proofs,
it is thepair (next-day, 1)
that constitutes an arrow Date -> Date.
We now construct, as an indexed
category,
alogic
withtype invariants. The
starting point
is the idea of a compre- hension schema.Definition 3. An indexed
category
p :T’°p
-> L c Ccat satis- fies thecomprehension
schema for X E T if there is a functor{XI _} : p(X)
-TIX
and abijection
1
The current method of calculating leap years began with the Gregorian
calendar. This could be incorporated as an additional clause in the invariant, restricting years to be after 1582.
natural
in 0
Ep(X)
and t ET/X .
This is a variant of Lawvere’s
[1970] comprehension schema,
but does notdepend
on p,having
a leftadjoint.
The
following proposition
is based on the Grothendieck cons-truction of a fibration.
Proposition
2. Let p :7P
-> L Ccat be an indexed cate-gory. The indexed category
p’ : Top
-> L,defined
asfol- lows, satisfies
thecomprehension schema for
allobjects.
From p construct a category
T’ ,
which is the base cate-gory with invariants:
objects (X,O)
where X E Tand 0
ep(X) ,
type X underinvariant 0,
arrows
(t,f)
E(X,O)
->(Y,03C8)
where t : X -> Y inT , f : 0
->Pt(03C8)
inp(X) ,
t is a term,
f
is aproof
that it preserves the invar-iant,
2-cells a :
(tf)
=>(s,g)
where a : t => s ,g = p(a) ’If 0 f ,
t converts to s and the same conversion turns
f
into g ,products (X,cp) x (Y,’I’) = (X x Y, Px 1 (cp) A pn2(03C8)) ,
the invariant on the
product
holdsif
each invariant holds on thecorresponding
component.Define p’ : Top
-> L asfollows:
objects p’(X,O)
=p(X)[ax:
T ->O]
in L wherenX : p(X)
->p(X)[ax :
T ->O]
is thefree
extensionby
an axiom ax : T-> O saying that 0
holds over(X,O)
arrows
P’ (t,f) by universality of the free
extension:
2-cells
similarly, by
the universal propertyof
theindeterminate arrow on natural
transformations.
Note: There are two 2-functors:
The first translates
expressions
in the baselanguage
toexpressions
in thelanguage
with typeinvariants;
the second functor allows us toimplement,
in the baselanguage,
termswritten
using invariants, by omitting
the correctness infor- mation. The construction alsoprovides
the indexed functor(F,n) :
p ->p’ ,
a universalinterpretation
of p inp’ .
Proof. The
comprehension
schema forp’
is defined at(X,O) through
theuniversality
of the free extensionnx : p(X)
->p(X)[ax :
: T ->O] :
:Note that so the
bijection
takesin
to in
Quotient
types, as inNuprl [Constable
et al85],
may be handledsimilarly. Quotients
are defined as anequivalence
relation on each type,
differing
ingeneral
from the inherentequality
on terms of the types. A category is constructed withobjects
astriples (X,-,a)
where X ET , -
Ep(X
xX) and,
because allproofs
areexplicit,
oc is aproof
that -is an
equivalence
relation. Arrows in this category arearrows in T which preserve the
equivalence
relations and transform theequivalence proof
in the source to that in the target.Again
we may construct an indexed category over thisnew base. Partial
equivalence
relations enable us to combineboth
subtypes
andquotient
types.Specifications.
A
major
theme in programdevelopment
is the passage between abstractdescriptions
and morespecific
instances. In forma-lism,
abstraction arisesthrough
the addition of indetermin-ates
(variables)
so that asingle expression
witn inueterrmn-ates covers a class of
ground expressions (i.e.
those builtfrom
constants).
In modular programdevelopment,
we intro-duce names
(indeterminates)
and types foroperations, delay- ing
the definition of theoperation
until furtherdevelopment
has taken
place.
For correctness of programsinvolving
thisoperation,
we include aspecification
of its behaviour.Associated with this
development
step is a new programlogic
which we construct
freely using
a Kan extension.We
begin
with the idea of aspecification
of an opera- tion. Inprogramming, specifications
are oftenpresented
aspairs
of apre-condition
and apost-condition,
where the pre- condition describes the range of valid arguments and thepost-condition
relates the arguments and the result.Definition 4. A
specification
of typeX ,
Y is apair
ofpredicates
A term satisfies the
specification
if thereis a
proof
in
As an
example
of an operatorspecified
in terms of pre- andpost-conditions,
considerinteger
division.integer-divide(
pre
post
The
pre-condition gives
the range of validarguments,
whilst thepost-condition
is apredicate relating
thearguments n
and d to the result r . This is not aninteger
division al-gorithm,
butspecifies
therequired
behaviour. Analgorithm,
such as
’long division’,
isexpressed
as a term in the pro-gramming language
and willsatisfy
thespecification
in thesense of Definition 4. In
general,
notonly
will manyalgo-
rithms
satisfy
agiven specification,
but alsooperations
with different functional behaviour may
satisfy
the samespecification. Specifications
allow us togive
definitionsat a suitable level of
abstraction,
rather than be con- strained toalgorithmic
code as theonly
formal definition ofrequired
behaviour.We now describe the construction of the
logic
associatedwith a
specification
as a construction of an indexed cate-gory. In an indexed category, an indeterminate arrow may be added either to the base or to a
fibre,
or toboth;
each caseyields
a new indexedcategory.
Aspecification
introduces a new arrow in the baselanguage (the
name of theoperation being specified)
and a new arrow in afibre, extending
thefibre with a
proof
that theoperation
satisfies itsspecifi-
cation. The
universality
of this construction defines what is meantby
animplementation
of aspecification.
We definethe extension of the base
category (extension
of afibre,
inparentheses)
as follows.Definition 5.
Let L
Cat be a2-category and p : Top
->be an indexed category. For
objects X,Y
E T(object
X e Tand
objects 0, (p
in fibrep(X)) ,
an indexed categoryp’ : 71
-> L(indexed
categoryp’ : T°P -> L)
and indexedfunctor V =
(J,11) : p -> p’ (indexed
functorV =
(IT,n) :
p -p’)
is the free extension of p with arrow t : Y - X(with
arrowf : 0
-> (p overX)
if andonly
if V isthe 2-universal indexed functor with an arrow
t :
J(Y)
->J(X)
in T’(with
an arrowf : 0 -4
(p inp’(X))
In other
words,
for any indexedcategory
q :S°p
-> L, indexed functor(F,a) :
p -> q and arrow t :F(Y)
->F(X)
in S
(arrow f : aX(O)
->aX(cp)
inq(F(X)))
there is aunique
indexed functor(F" ,a’) : p’
-> q such thatcommutes and
F"(t)
= t(and a£(0 = fi . Moreover,
this isuniversal on 2-cells: For any
(e,v) : (F1,a1)
->(F2.a2)
with
F1, F2 : T -> S
and arrows t, :F1(y)
->F1(X
and in S such thatEx o t1= t2 o EY (arrows
in
q(F1(X» ,
andin
q(F2(X))
such thatthere is a
unique
such that and
(and
Each of these extensions may be
expressed
as an indexedcolimit,
constructions of which aregiven
in[Street 74,76].
The extension of the base can be described in terms of a Kan extension: To add arrow t : Y -> X to the base of p :
Top -> L ,
let J : T ->71t]
be a free extension of Tby
t . Construct the indexedcategory p’
as a left Kanextension of p
along f° :
Consider now a
specification
pre,post>
of typeX,Y
in indexed category p . We construct an indexed categoryp"
andinterpretation (indexed functor)
of p inp" by composition:
Extend the base of p with an arrow t : Y -> X to form indexed category
p’
and indexed functor(J,n) : p -> p’ ,
thenfreely adjoin
aproof
f : pre ->p’t,Y>(post)
overJ(Y)
top’
toform indexed category
p"
and indexed functor(IT,n’) : p’
-p" .
From theprogramming point
ofview,
the
universality
of this construction captures what is meantby
animplementation
of aspecification.
Animplementation
consists of a term t in a base
language
S . Ingeneral, S
may differ from the
underlying language
T of thespecifica-
tion. The term t satisfies the
specification
in that thereis a
proof f
of satisfaction. The term ttogether
with theproof f provide, through
theuniversality,
a soundinterpre-
tation of the
freely
constructed programlogic p" .
In astepwise development,
theimplementing
term may be an inde- terminatesatisfying
a strongerspecification,
so that thebase category S is itself constructed from a
specification.
CONCLUSIONS.
This is a rather