Logical Relations and Parametricity A Reynolds 2014 Electronic Notes in TH
Logical Relations and Parametricity A Reynolds 2014 Electronic Notes in TH
com
Edmund P. Robinson3
Queen Mary, University of London
Abstract
In his seminal paper on “Types, Abstraction and Parametric Polymorphism,” John Reynolds called for ho-
momorphisms to be generalized from functions to relations. He reasoned that such a generalization would
allow type-based “abstraction” (representation independence, information hiding, naturality or parametric-
ity) to be captured in a mathematical theory, while accounting for higher-order types. However, after 30
years of research, we do not yet know fully how to do such a generalization. In this article, we explain the
problems in doing so, summarize the work carried out so far, and call for a renewed attempt at addressing
the problem.
1 Introduction
Starting with the pioneering work of Emmy Noether, Emil Artin and van der Waer-
den in the 1930’s [51], homomorphisms have firmly established themselves as the
foundation for modern algebra. In due course, they led to the formulation of cat-
egory theory [10], whose central concept is that of “natural transformation,” em-
bodying the principle of uniformity with respect to homomorphisms.
1 Email: [email protected]
2 Email: [email protected]
3 Email: [email protected]
http://dx.doi.org/10.1016/j.entcs.2014.02.008
1571-0661/© 2014 Elsevier B.V. All rights reserved.
150 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
istic proof theory). See Statman [48] and the references cited there. The special
case of logical partial equivalence relations appeared even earlier in the work of
Turing and Gandy in characterizing “virtual types.” The essential purpose of logi-
cal relations in this context is to characterize properties satisfied by lambda terms,
or functions computed by lambda terms, so as to be consistent with the implicit
operations of the typed lambda calculus. When sufficiently abstracted, the essence
of the logical relations proof method can be squeezed out as the idea that the “→”
type constructor is a relator. Given relations R ⊆ X × X and S ⊆ Y × Y , there is
a corresponding lifting [R → S] ⊆ [X → Y ] × [X → Y ] for function types that is
consistent with operations of the typed lambda calculus, viz.,
Note that this form of a definition works for relations of any arity, not only binary
relations. In his seminal paper on lambda-definability [38], Plotkin demonstrates
that all functions definable in typed lambda calculus are invariant under all such
“logical” relations, and, moreover, functions invariant under a Kripke variant of
logical relations are precisely the lambda-definable ones.
A second, independent discovery of logical relations occurred in automata the-
ory [14,15]. We envision automata as having internal sets of states that are hidden
from the environment, while the observable behaviour is stated in terms of the
inputs and outputs of the automata. It was noticed in this context that homomor-
phisms between automata were inadequate to capture the equivalence of behaviour.
A form of structure-preserving relations was necessary. Such relations were called
“weak homomorphisms,” “covering relations” [9] or “simulation relations” [27]. In
due course, they developed into a mathematical theory of “information hiding”
or “data abstraction” in computer science, which is the underpinning conceptual
framework for the practice of object-oriented programming.
Reynolds integrated these two strands of thought and formulated a general prin-
ciple of relational parametricity that is applicable to a wide range of contexts for
capturing the notion of “information hiding” or “abstraction.” Unfortunately, we
believe that the magnitude of this achievement has not been sufficiently recognized.
As Reynolds attempted to give a set-theoretic semantics for impredicative polymor-
phic lambda calculus using parametricity, which was found to be impossible upon
subsequent investigation [43], the popular image that has developed in subsequent
years has tied parametricity to polymorphic lambda calculus. The fact that para-
metricity has broad applications throughout mathematics has gone unnoticed. In
fact, parametricity counters and challenges the foundations of 20th century math-
ematics for its reliance on homomorphisms. (See, for example, Freyd [12].) This
challenge has not yet been answered.
In this article, we attempt to re-explain relational parametricity from the first
principles, giving an indication of its broad applicability to mathematical concepts.
We make no mention of any “calculus” and pay no attention to impredicative type
systems. While these applications are interesting and important, they are not the
main point of parametricity in our view. Rather, parametricity re-invokes the same
152 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
intuitions that led to the notion of natural transformations and the definition of
categories in 1940’s and provides a different, novel answer. How to incorporate
this answer into the prevailing categorical foundations of mathematics is a question
that interests us. Through this exposition, we hope to spur further interest in this
question to carry forward Reynolds’s legacy.
Our presentation is targeted at readership from both Mathematics and Com-
puter Science. The aim is to explain the issues involved in addressing Reynolds’s
challenge, but we do not attempt to survey the entire literature on the sub-
ject. Other expository treatments of relational parametricity, by O’Hearn [11] and
Scott [47] may be perused for fuller surveys of the literature as well as alternative
view points.
2 Logical Relations
The way out of this impasse is to generalize homomorphisms from functions to
relations. — Reynolds [42, Sec. 1]
A “logical relation” for a particular form of a mathematical structure is a
structure-preserving relation just as a “homomorphism” is a structure-preserving
function. Such relations are also often called “compatible relations” in algebraic
literature because structure-preservation for relations is thought of as “compati-
bility” with structure. In this article, we will treat “structure preservation” and
“compatibility with structure” interchangeably.
Example 2.1 A group is an algebraic structure involving a set along with a binary
associative “multiplication” operation “·”, a unit 1 for multiplication and a multi-
plicative inverse x−1 for each element x. We write the underlying set of a group
A as |A|. The three operations of groups then have the types · : |A| × |A| → |A|,
1 : |A| and ( )−1 : |A| → |A|.
A (binary) logical relation of groups R : A ↔ A between groups 4 A and A is
a binary relation R ⊆ |A| × |A | such that:
Using the relation operators that are introduced later in this section, these formulas
amount to saying the operations of the two groups A and A are related as follows:
· [R × R → R] ·, 1A [R] 1A and ( )−1 [R → R] ( )−1 . A logical relation
With this definition, easy calculations give the following examples:
• The equality relation IA ⊆ |A| × |A| is a logical relation (the “identity” logical
relation IA : A ↔ A).
4 Even though we focus on binary relations for the ease of exposition, all the concepts of logical relations
discussed in this paper, except for that of ordered structures, generalize to relations of arbitrary arity. Note
that A ↔ A and A ↔ A are different types of logical relations. There is no implicit symmetry assumed.
C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180 153
where each Fk is a type expression built from (i) the sorts a1 , . . . , an , (ii) “known
types” such as boolean or integer, and (iii) type operators such as ×, + and →.
Given a signature a, Ω , an algebra A for the signature consists of
• an assignment Aa1 , . . . , Aan of sets for each sort, and
• an assignment Aωk of elements, for each ωk ∈ Ω, in the corresponding sets
Fk (Aa1 , . . . , Aan ).
This kind of algebra can be seen in e.g. [46], except that we allow known types
to appear directly in expressions, rather than regarding them as special sorts. We
also assume that we have function types, and therefore can equate an operation
with the corresponding value of function type. This allows us to deal only with
constants (many of which represent functions) and not operations.
From the type-theoretic point of view, the “sorts” are type variables and “known
types” are constant types. The entire signature a, Ω is then of a higher-order “sum
type”
Σa1 ,...,an (Πk∈I Fk (a1 , . . . , an )) (2)
where each of the type variables a1 , . . . , an ranges over all sets. For example, the
type of groups is Σa [a × a → a] × a × [a → a]. In this type-theoretic point of view,
an algebra is just an element of the type (2).
Given two algebras A and A for a signature a, Ω , a logical relation R : A ↔ A
is a family of binary relations Ra1 ⊆ Aa1 × Aa1 , . . . , Ran ⊆ Aan × Aan such that,
for each operation symbol ωk : Fk (a1 , . . . , an ) in Ω, its interpretations Aωk and
Aωk are related by Fk (R1 , . . . , Rn ). This definition is fashioned after Mitchell’s
treatment of logical relations for applicative structures [28,29], but specialized to
the “set-theoretic type frame.”
where IX ⊆ X × X is the identity relation for each set X. This is the part of the
theory of functors that deals with identities. By omitting requirements involving
composition, Reynolds was able to admit more type operators than categorical
functors can accommodate, chief among them the function type constructor →.
We will use the framework of reflexive graphs in Secs. 3 and 6 to formalize these
intuitions at the level of categories.
C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180 155
We begin with product, sum, function space, powerset and predicate types.
In the following, type-forming operations are applied to sequences A, B, C, . . . and
relations are between A and A , B and B (R ⊆ A × A , S ⊆ B × B , etc).
(i) Product: as usual, the cartesian product of two sets A and B is the set of
ordered pairs. The relation R × S ⊆ (A × B) × (A × B ) is defined by:
(a, b)[R × S](a , b ) ⇐⇒ a[R]a ∧ b[S]b .
(ii) Sum: we define the sum of two sets as the disjoint union of copies: A + B =
{0} × A + {1} × B. The relation R + S ⊆ (A + B) × (A + B ) is defined by:
(i, x)[R + S](j, y) ⇐⇒ (i = j = 0 ∧ x[R]y) ∨ (i = j = 1 ∧ x[S]y).
(iii) Function space: Let [A → B] be the set of (total) functions f : A → B. We
define the relation [R → S] ⊆ (A → B) × (A → B ) by f [R → S]f ⇐⇒
∀a, a . a[R]a ⇒ f (a)[S]f (a ).
(iv) Powerset: if PA is the set of all subsets of A, then we define the extension of
the powerset operator to relations by u[PR]u ⇐⇒ (∀a ∈ u. ∃a ∈ u . a[R]a )∧
(∀a ∈ u . ∃a ∈ u. a[R]a ). This definition corresponds to the Egli-Milner or-
dering for powerdomains [39].
(v) Predicates: The collection of predicates over a set A, which we denote by PA,
also has the set of all subsets of A as carrier. However, the relation action is
defined by u[PA]u ⇐⇒ (∀a, a . a[R]a ⇒ (a ∈ u ⇐⇒ a ∈ u )). Note that
corresponds to that of [A → 2].
the relation action of PA
Lemma 2.4 The above definitions satisfy the identity extension property.
(i) IA × IB = IA×B
(ii) IA + IB = IA+B
(iii) [IA → IB ] = I[A→B]
(iv) PIA = IPA
A = I
(v) PI PA
The left to right inclusion parts of these equations, e.g., [IA → IB ] ⊆ I[A→B] ,
amount to extensionality of higher type values. The right to left inclusions, e.g.,
I[A→B] ⊆ [IA → IB ], say that the relation actions are consistent with the observable
information of higher type values.
Nondeterministic functions. Operations in both mathematics and computer
science are often partial (not defined for all inputs) and sometimes nondeterministic
(different executions may produce different results). We therefore want to handle
f
the type of “nondeterministic functions”. We write x − → y to mean that y is a
possible result of applying the nondeterministic function f to input x, and the type
of nondeterministic functions as A ; B. It is convenient to reduce [A ; B] to
[A → PB]. The derived relation [R ; S] is then [R → PS]. Expressed directly in
156 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
f [R S] f ⇐⇒
f (x) = ∅ ∧ f (x ) = ∅ ∨ (5)
∀x, x . x [R] x =⇒
f (x) = ∅ ∧ f (x ) = ∅ ∧ f (x) [S] f (x )
Thus a logical relation of fields can relate 0 to only 0. Since 0 is the unit of the
additive group structure, this has the consequence that a logical relation of fields
is always a partial bijection. A homomorphism of fields, regarded as a total and
single-valued logical relation, is therefore necessarily injective. This is a well-known
fact in field theory, but logical relations provide an abstract reason for why it is so.
It is also worth noting that Reynolds’s leading example of type abstraction in [42]
involves Bessel’s and Decartes’s representations for the field of complex numbers.
The logical relation involved there is indeed a partial bijection.
Further examples
Algebraic structures such as monoids, semigroups, rings, semirings, etc. can be
treated in the same way as Examples 2.1 and 2.5. They are one-sorted structures
C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180 157
involving no “known types.” Next we look at actions, which bring out connections
with modules and vector spaces on the one hand, and algebraic automata theory
on the other. Automata theory happens to be one of the first areas in Computer
Science where logical relations were discovered.
A monoid is an algebraic structure M involving a set along with an associative
binary operation “·” and its unit 1. A logical relation of monoids R : M ↔ M is
a relation between the underlying sets such that the two multiplication operations
are related by R × R → R and the two units by R.
An action of monoid M on a set X, also called a module for M , is a monoid
homomorphism α : M → [X → X], where [X → X] is the collection of endomor-
phisms on X viewed as a monoid under composition. It is conventional to write
α(m)(x) as m·x, treating it as a form of “scalar multiplication” of type M ×X → X.
We use the notation M X to talk about the module as a structure. A logical relation
of M -actions R : M X ↔ M X is a relation R ⊆ X × X compatible with scalar
multiplication:
x R x =⇒ m · x R m · x (6)
If R = h is the graph of a function then h is a homomorphism of M -actions. Note
that, with reference to our universal algebraic description, an M -action is a structure
involving a “known type” M and a single sort a standing for the underlying set X,
i.e., has the type Σa M → [a → a]. This leads to the requirement that the action
maps must be related by IM → [R → R] as indicated in (6). Actions of rings or
semirings (modules) and those of fields (vector spaces) can be treated in a similar
way.
: set → set
P, P 1 , P
×, +, →, , ; : set × set → set
That means that they have an action on sets, such as PA or [A → B], as well as
an action on relations, such as PR and [R → S]. The type expressions Fk (a) in the
definition of algebraic structures are built from such relators as well as the constant
relators for “known types” ConstK : setn → set given by ConstK (A) = K and
ConstK (R) = IK .
Algebras for signatures a, Ω , along with their logical relations, give rise to
reflexive graphs in turn, denoted alg(a, Ω).
More generally, for any relator F : G → set, an F -algebra is a pair A = A, f
of a vertex A of G and an element f ∈ F (A). A logical relation of such algebras
R : A ↔ A is an abstract relation R in G such that f [F (R)] f in set. This gives
a reflexive graph alg(F ). Note that alg(a, Ω) is a special case of this where we use
G = setn (with a ranging over its vertices) and Ω is treated as a relator setn → set.
Using relations from rel(C), we can define logical relations for such algebras. Thus,
we obtain a reflexive graph algC (a, Ω) of algebras internal to C. Examples of such
algebras abound. For example, monoids and monoid actions internal to Ab are
well-known as rings and modules. Monoids and monoid actions internal to Poset
are called “pomonoids” (short for partially ordered monoids) and “M -posets.”
Reflexive graphs of the form rel(C) and algC (a, Ω) have additional categorical
structure which we discuss in Sec. 6.
Ordered structures
When we deal with ordered structures, we have the option of using the partial
order of the structure as the “identity edge” as noted by Reynolds [42, Sec. 5-6].
For example, the reflexive graph poset is similar to poset except that the identity
edge IA : A ↔ A is the partial order A . We still have relators such as × and →
(product and monotone function space) on poset because they preserve the new
“identity edges”: A × B = A×B and [A → B ] = [A→B] . We say that a
R in poset represents the “graph” of a monotone function f : A → B
relation
if x R y ⇐⇒ f (x) B y. We write this relation as f rather than f .
For algebras in poset , homomorphisms derived from logical relations will be “lax
homomorphisms.” Dually, those in poset will be “oplax homomorphisms.”
Reynolds’s concept of the “identity relations” is thus an abstract concept.
relation of automata
R : X, α, x0 ↔ X , α , x0 is a relation R ⊆ X × X
such that α IM → [R R] α and x0 R x0 . A homomorphism of automata
B(M) = { m ∈ M | m · x0 = ∅ }
(The existence of R∞ can be inferred using the Tarski’s fixed point theorem.) If
(x, x ) ∈ R∞ , then there must be some m ∈ M such that m · x = ∅ and m · x = ∅
or vice versa, i.e., x and x are not behaviorally equivalent states in their respective
machines. So, if M and M are behaviorally equivalent then (x0 , x0 ) ∈ R∞ , and
R∞ is the required logical relation.
Similar situation persists with other kinds of abstract machines. A Mealy ma-
chine of type M ⇒ O, where M and O are “known” monoids, is a set X equipped
with a monoid homomorphism α : M → [X → X × O]. The behaviour of a Mealy
machine with an initial state M = (X, α, x0 ) is defined as the input-output map-
ping B(M) = { (m, o) | ∃x. m · x0 = (x, o) }. Once again, homomorphisms represent
an incomplete reasoning principle for behavioral equivalence of Mealy machines
whereas logical relations represent a complete reasoning principle.
These observations suggest that isomorphisms, homomorphisms and logical re-
lations make up a spectrum of correspondences between mathematical structures,
with homomorphisms being a “halfway house.” When we deal with information
hiding, we face the symmetric concept of behavioral equivalence, which is unlikely
to be characterized by the asymmetric concept of homomorphism. Isomorphisms
seem appropriate when there is no information hiding involved and logical relations
seem appropriate when there is information hiding involved.
C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180 161
The existential operator “∃,” replacing the sum “Σ” in (2), captures the idea of
information hiding. Thus M -automata have the type ∃a ([M → [a a]] × a) and
Mealy machines have the type ∃a ([M → [a → a × O]] × a).
We call the elements of the type (7) abstract algebras. An abstract algebra is an
equivalence class of algebras for a, Ω under “behavioral equivalence.” Supported
by the evidence from automata theory, we take behavioral equivalence to be the
equivalence relation generated by the existence of logical relations. More precisely,
we say that
(i) two algebras are similar, A ∼ A , iff there exists a logical relation R : A ↔ A ,
and
(ii) two algebras are behaviorally equivalent, A ≈ A , iff there is sequence of algebras
A = A0 ∼ A1 ∼ · · · ∼ An = A , where the successive algebras are similar with
a logical relation between them.
Note that we do not require the similarity relation to be transitive, i.e., no require-
ment for logical relations to compose. Indeed, whenever function types or other
mixed variant type operators are involved, logical relations do not compose. We do
not see this as a loss. (There have been proposals for composable forms of logical
relations [37] but they are not uniformly defined.)
The notion of abstract types in programming languages and specification lan-
guages is the same as that of abstract algebras above. As a simple example, con-
sider an abstract type intset for finite sets of integers, equipped with the operations
e : intset, i : int × intset → intset, and m : int × intset → bool (for the empty
set, the insertion of an element into a set, and the membership test in a set). Two
simple ways to implement the abstract type are in terms of (unordered) lists (with
possible duplicate copies) and ordered lists. (Many other sophisticated implemen-
tations such as binary search trees and hash tables etc. can be found in text books
on data structures.) The two implementations would be behaviorally equivalent
if there is a logical relation between them. The natural candidate for the logical
relation is:
L R L ⇐⇒ |L| = |L | ∧ ordered(L )
where |L| denotes the set of elements of list L. To show that R is a logical relation,
one
must show that
the implementations
of the
operations are related: e R e,
i Iint × R → R i and m Iint × R → Ibool m . A fine method for proving the
correctness of a data structure implementation is to prove that it is behaviorally
equivalent to a naive implementation. Examples of such proofs may be found in
Reynolds’s Craft of Programming [41, Chapter 5] and de Roever and Englehardt[5].
162 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
5 Relational Parametricity
Parametric transformation is the concept parallel to natural transformation that
works with logical relations instead of morphisms. Just as natural transformations
are “maps of functors,” parametric transformations are “maps of relators.”
To keep this discussion concrete, we restrict attention to reflexive graphs of the
form rel(C) for categories C, with set = rel(Set) being the prototypical example.
We will refer to the category C as the “underlying category” of the reflexive graph.
A more satisfactory axiomatization of the structure is given in Sec. 6.
Given reflexive graphs G and H and two relators F, G : G → H, a parametric
◦
transformation η : F → G is a family of maps ηA : F (A) → G(A), indexed by
vertices A of G, such that, for all edges R : A ↔ A in G, we have
ηA F (R) → G(R) ηA (8)
which are not required to preserve composition. Hence parametricity applies when
naturality fails to apply. The following examples illustrate this fact.
◦ABC : [B → C] × [A → B] → [A → C]
where the type expressions on both the sides of → are treated as relators set3 → set
in the three type variables A, B, C. This is a parametric transformation (but the
version defined with maps is not natural in B). Given relations R : A ↔ A ,
S : B ↔ B and T : C ↔ C , we have:
g S → T g ∧ f R → S f =⇒ g ◦ f R → T g ◦ f
τX : N → [[X → X] → [X → X]]
∅, if f (x) = ∅
λf. λx.
x, otherwise
which evaluates f at x but discards the result, returning the original input x.
O’Hearn and Tennent [32, Sec. 6] show that this polymorphic type is isomorphic
N⊥ × Vnatop .
164 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
Arguments of this kind are familiar from the use of the Yoneda lemma for Hom-
sets. Relational parametricity allows us to internalize them and reason about inter-
nal homs (function spaces) in the same way. The generalization to relations seems
essential for dealing with internal homs. For example, note that, even though the
relation R : N ↔ X in the above example is the graph of a function, the relation
R → R is not the graph of a function.
To make the discussion concrete, we give a definition of ∀X F (X) in algebraic
settings, parallel to that of ∃X F (X) in Sec. 2. In doing this, we run into a cardinality
issue because the type variable X ranges over large collections such as “all sets,”
“all groups” etc. An element of ∀X F (X) is a family ϕ = {ϕX }X indexed by all
types of this form and, so, is too large to be a set. Our preferred solution to the
problem is to use Grothendieck universes, but we do not wish to belabor this point.
We use the notation ϕ ∈ ΠX F (X) to denote that ϕ is such a family.
If F : G → set is a relator then ∀X F (X) is the collection of families φ ∈
ΠX∈Gv F (X) subject to the parametricity requirement:
∀R : X ↔ X . ϕX F (R) ϕX (9)
In general, we might have type expressions that have other type variables. So, more
generally, if F : G × H → set is a relator then ∀X F (X, Y ) is a relator H → set that
sends vertices Y ∈ Hv to sets ∀X F (X, Y ) ⊆ ΠX F (X, Y ) and edges S : Y ↔ Y
to relations ∀X F (X, S) : ∀X F (X, Y ) ↔ ∀X F (X, Y ). These are determined by the
formulas:
ϕ ∈ ∀X F (X,Y ) ⇐⇒ ∀R : X ↔ X . ϕX F (R, IY ) ϕX
ϕ ∀X F (X, S) ϕ ⇐⇒ ∀R : X ↔ X . ϕX F (R, S) ϕX
The generalization of these concepts to reflexive graphs other than set appears in
Sec. 6.
type information about the ground types. This led to the thesis that the lambda-
definable elements should be invariant under all relations that carry out value sub-
stitutions of ground types (“permutations” in a general sense). Plotkin’s results
imply that selective information hiding is also captured by logical relations. An
element lambda-definable from a set of elements Σ, preserves all relations R that
are preserved by the elements of Σ. We see this notion at play, for instance, in
Church numerals of type ∀X [X → X] → [X → X]. Given an unknown type X
and values f : X → X and z : X, the definable elements of X are exactly those
that preserve all relations preserved by f and z. Thus, parametricity gives us an
extensional characterization of the intensional aspect of lambda-definability.
Parametric behaviour
B : ∀X ([M → [X X]] × X) → (M → 2)
and note that it is parametric in the state set X. Thus the “global” information
hiding for the state sets of automata is reducible to the “local” information hiding
of its designated behavior function.
Generalizing this, we can postulate the following equivalence of types:
∃X F (X) ∼
= ∀Y (∀X F (X) → Y ) → Y (10)
The type ∀X F (X) → Y on the right hand side is the type of a possible behaviour
function, which should be parametric in X. The type variable Y stands for the type
of the observable behaviour, e.g., M → 2 in the case of automata. The universal
quantifier ∀Y represents the idea that ∃X F (X) hides its representation type X from
all possible observable behaviour functions.
It is possible to prove the equivalence (10) as a theorem from our definitions of
∃X and ∀X quantifiers. However, Reynolds [42] turned the equivalence (10) around
and used it as the definition of ∃X in polymorphic lambda calculus. His calculus
only has the ∀X quantifier built-in and ∃X is a derived notion.
In the literature on logical relations [28,29,48], it is common to find a “funda-
mental theorem” or “basic lemma” to the effect that all terms of a syntactic calculus
preserve the defined logical relations. Reynolds’s insight means that this result can
be obtained in a syntax-independent way, by showing that all the primitives and
combinators involved in the calculus are parametric. The “fundamental theorem”
for logical relations is equivalent to the parametricity of the calculus. It would be
worthwhile reexamining the literature on logical relations from this perspective.
166 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
The identity functor I gives an identity edge IA for each object A as well as an
identity edge morphism If : IA → IB for each morphism f : A → B. Thus,
in a reflexive graph category, we accommodate homomorphisms as well as logical
relations side by side with an “equal status.” The reader familiar with double
categories [8,23] is invited to view reflexive graph categories as a weakening of
the structure of double categories, omitting the notion of composition for vertical
morphisms. In analogy with double categories, we also refer to edge morphisms
such as φ as “squares.”
Reflexive graph categories can be viewed as adding a category structure to re-
flexive graphs of Sec. 3. The underlying reflexive graph of a reflexive graph category
C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180 167
G, obtained by omitting all the morphisms of G, is denoted |G|. We also feel free to
treat |G| as a discrete reflexive graph category by implicitly adding identity arrows
for all vertices A and edges R. A functor F : |G| → H from a discrete category is
referred to as a “nonvariant” relational functor. It is essentially a relator because
it ignores all the morphisms of G. If F : |G| → H and F : |H| → K are nonvariant
relational functors, then there is a composite F F : |G| → K, and there is an “iden-
tity” nonvariant functor IdG : |G| → G. Hence, we can use the normal categorical
notation for nonvariant functors. If F : G → H is a relational functor, we use the
notation |F | : |G| → H to refer to its underlying nonvariant functor.
Reflexive graphs of the form rel(C) give rise to reflexive graph categories Rel(C).
The underlying category C of the reflexive graph serves as the vertex category of
Rel(C). Edges R : A ↔ A are subobjects R A × A and edge morphisms
φ : R → S that span f : A → B and f : A → B are the unique factors induced by
f × f : A × A → B × B .
φ
R >S
∨ ∨
(12)
∨ ∨
f ×f
A × A > B × B
In this situation, we also say that φ is above the pair of morphisms (f, f ) or that
φ is a lifting of the pair (f, f ) to Ge . The identity edge IA : A ↔ A is the diagonal
morphism δA : A A × A and the identity edge morphism If : IA → IB above
(f, f ) is nothing but f .
The reader is invited to contemplate the correspondence between the diagrams
(11) and (12), the first representing an abstract higher-dimensional view of relation-
preservation and the second representing a normal categorical view.
The definition of Rel(C) allows us to view every category with finite products
automatically as a reflexive graph category. From this point on, we change our
“call signs,” using names such as Set, Grp, Mod etc. to refer to the reflexive
graph categories obtained in this way.
The reflexive graph category Set, for example, has functions f : A → B as its
morphisms,
binary relations R ⊆ A × A as its edges, and relation preservation facts
f R → S f as its edge morphisms. Examples of relational functors include:
Note that, in any reflexive graph category of the form Rel(C), there is at most
one edge morphism of type R → S for any given R and S. A reflexive graph category
that has this property is said to be relational. Such a category has a hom-functor
Hom : G op × G → Set, whose vertex part sends pairs of objects (A, B) to the set
of morphisms Hom(A, B) and edge part sends pairs of edges (R, S) to relations
Hom(R, S) ⊆ Hom(A, B) × Hom(A , B ).
168 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
ηA
A F (A) > G(A)
∧ ∧ ∧
R F (R) ηR G(R)
∨ ∨ ∨
A F (A ) > G(A )
ηA
The identity edge IF : F ↔ F for a relational functor F is the family {F R}R and
the identity edge morphism Iη : IF → IG for a parametric natural transformation
.
η : F → G is the family {ηR }R . (In other words, the identity edge functor simply
selects the edge parts: IF = Fe and Iη = ηe .)
Since RGCat is a 2-category, we have the notions of adjunctions, monads and
comonads available for them. So, we can define the usual adjunctions
Δ× : G×G →G
+Δ : G →G×G
(− × A) [A → −] : G → G
When we calculate these for particular reflexive graph categories such as Set, we
obtain exactly the relation actions described in Sec. 2. A more detailed analysis of
such adjunctions in the context of fibrations is given in Sec. 7.
Fact 6.4 There is a “diagonal” relational functor Δ : H → HG that sends the
vertices of H to constant relational functors G → H and edges of H to constant
higher-order relations between constant functors.
For a vertex K of H, the constant relational functor Δv (K) : G → H sends every
vertex of G to K, every morphism to idK , every edge to the identity edge IK and
every edge morphism to IidK . For any edge S : K ↔ K in H, Δe (S) in (HG )e is
the constant family {S}R∈Ge that maps every edge of G to S.
Finally, we define the type quantifiers ∃ and ∀ as the left and right adjoints to
the diagonal functor:
∃ Δ ∀ : HG → H
To explicate the detail, given a relational functor F : G → H, the vertices ∀(F ) and
∃(F ), which are also denoted ∀X F (X) and ∃X F (X), are characterized as follows:
• ∀X F (X) comes equipped with a parametric natural transformation ν :
.
∀X F (X) → F that is universal, i.e., any other parametric natural transforma-
.
tion A → F for a vertex A of H uniquely factors through ν. We call this the
parametric limit of F .
• ∃X F (X) comes equipped with a parametric natural transformation μ :
.
F → ∃X F (X) that is universal, i.e., any other parametric natural transforma-
.
tion F → A for a vertex A of H uniquely factors through μ. We call this the
parametric colimit of F .
170 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
Diagrammatically:
ν μ
∀(F ) >F > ∃(F )
∧.... ..
..
.. ..
.. .
. τ σ
∨..
A >F >A
Note that these are the expected generalizations of the categorical concepts of
“limit” and “colimit” to reflexive graph categories. When we calculate the adjoints
for the case H = Set, we obtain the definitions given in Sec. 2 and Sec. 5.
It is also possible to define parametric ends and coends as the internalizations
of parametric dinatural transformations in a similar way.
6.1 Subsumption
of a commutative square:
f f
A >B A >B
∧ ∧
g h ⇐⇒ g h (13)
∨ f
∨ ∨
f
∨
A > B A > B
The reflexive graph category G is relational at least between graph relations. So, re-
lational squares on the right of the implication are unique when they exist. Further,
since IA = idA , we obtain the identity condition [24]:
(f, f ) : IA → IB ⇐⇒ f = f (14)
where the dotted lines represent the idea of being “above” an object or arrow. The
edge f ∗ S is called the reindexing of S along f and the edge morphism φ is called
the cartesian lifting of f at S.
Example 7.1 Reflexive graph categories of the form Rel(C) are fibred provided
the category C has pullbacks. Given a pair of arrows (f, f ) : (A, A ) → (B, B )
and an edge S B × B above (B, B ), the reindexing (f, f )∗ S is the pullback of
f × f : A × A → B × B and S B × B . For example, in the reflexive graph
C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180 173
In the Plotkin-Abadi logic for parametricity [36], the reindexed relation (f, f )∗ S
can be expressed as a “definable relation:” (x : A, x : A ) f (x) [S] f (x ).
Δ
/* Rel2
Δ Δ
Rel j / RelΔ k
⊥ ⊥
× ×
∂2
∂
& Δ /
Set o ⊥ Set2
×
( )×R
(π ,A )∗ )∗ R
( )×(π
Rel j / Rel( )×A ,A
/ Rel( )×A ( )×A
/, Rel
⊥ l ⊥ k ⊥
π ,A (π ,A )∗ R
→( ) A→( )
∂
∂
' v ( )×A
/ |
Set o ⊥ Set
A→( )
• The functor Δ : Rel → RelΔ is the fibre-wise diagonal functor sending R above
repre-
A to (R, R) above A. Its right adjoint is the fibre-wise product functor ×,
senting the conjunction or intersection of relations.
• The functor Δ : RelΔ → Rel2 sends (R, S) above A to (R, S) above (A, A). Its
right adjoint × is obtained by reindexing along the counit of the base adjunction,
viz., (π, π ). So, R × S = ((πAB )∗ R, (πAB
)∗ S).
• The right adjoint to Δ is then the composite of the two right adjoints:
S = (πAB )∗ R ×
R×
(πAB )∗ S
R
→S =
((πA→B,A )∗ R → (ev A,B )∗ S)
πA→B,A
As noted above, the fibration concept can be combined with that of reflexive graph
categories (which we abbreviate to “RG-categories”) by asking for the edges to be
fibred over tuples of vertices. More precisely, a fibred RG-category satisfies the
condition that the functor ∂ = ∂0 , ∂1 : Ge → Gv × Gv is a fibration. Explored in
[6,7], this structure allows us to import the “logical character” of fibrations to the
setting of RG-categories.
The reindexing operation of ∂ implies that there is a “pre-image” edge (f, f )∗ S
as shown in the square on the right:
φ f
(f, f )∗ S >S A >B
.. .. ∧ ∧
.. ..
.. .. (f,f )∗ S φ S
.. ..
. ∨ ∨
(f,f )
(A, A ) > (B, B ) A > B
f
List A ∼
= 1 + A × List A
that Iμ(T ) is the initial algebra μ(Te ) of the T functor at the level of edges. Recall-
ing that IT = Te in the functor category G G (Fact 6.3), our expectation amounts
to Iμ(T ) ∼
= μ(IT ), which is nothing but the identity extension property for the μ
operator.
The idea that structural induction is nothing but the identity extension prop-
erty of the μ operator was proposed by Hermida and Jacobs [19] in the setting of
fibrations.
Similarly, a coalgebra for a functor T : G → G is a pair X, α : X → T X .
There is a reflexive graph category CoAlg(T ) of such coalgebras. The final object
in the category is denoted ν(T ) or νX T (X). Properties of final coalgebras can be
proved using a coinduction principle, whose substance is again an identity extension
property: Iν(T ) ∼= ν(IT ).
In fact, both initial algebras and final coalgebras can be expressed in terms
of parametric limits and colimits using the formulas proposed by Plotkin and
Abadi [36]:
μX T (X) = ∀X (T (X) → X) → X
νX T (X) = ∃X (X → T (X)) × X
Here T (X) is a type expression that is functorial. The equations hold in many
parametric models of the (impredicative) polymorphic lambda calculus. Birkedal
and Mogelberg [3] give a categorical axiomatization of such models. What happens
beyond these models is not entirely clear. See Dunphy [6] for some results in this
direction. Characterizing the classes of models where these equations hold and
where they fail would form important steps in advancing our understanding of
parametricity.
9 Further work
Reynolds’s exhortation to generalize homomorphisms from functions to relations
comes to us as a “bolt from the blue.” Its implications will no doubt be far-reaching.
In this article, we have attempted to give some idea of how Reynolds’s ideas might
apply to mathematical considerations, for universal algebra and category theory.
This work is far from complete. We outline some possible directions for future
investigation.
Formulating a suitable categorical structure for representing logical relations and
relational parametricity tops our list of priorities. In our treatment, we presented
two possible approaches: reflexive graph categories, which model the action of type
constructors on abstract relations along with the identity extension postulate, and
fibrations, which explain in a syntax-independent manner, the origin of logical re-
lations formulae needed to obtain the relation actions. It appears to us that the
eventual theory of parametricity needs to integrate the two approaches. This might
involve understanding and isolating the stumbling blocks for the use of fibred func-
tors. As well as the contravariance needed for the function type constructor, see
Pitts [35, Sec. 4] for some of the issues in preserving cartesian liftings.
The category theorist would no doubt wonder about the notion of composition
178 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
for logical relations. The problem is that, in the first place, the function type con-
structor does not preserve the composition of relations, and, secondly, composition
brings back the variance issues of functors, which logical relations are meant to
avoid. Note that homomorphisms pre- and post-compose with logical relations,
although the resulting bimodule structures remains to be explored. It would also
be interesting to consider composite logical relations of higher arities [22]. On the
other hand, the structure of relations under composition leads to the consideration
of bicategories of relations, which might also be appropriate in some contexts. The
categorical analysis of relational modalities carried out in [18] considers this direc-
tion. The lifting of endofunctors in this context, with applications to coalgebraic
bisimulation in the spirit of Sec. 2 is addressed in [2] and the references therein.
Cross connections with other areas that employ relational correspondences need
to be made. We have in mind, for instance, the work in universal algebra dealing
with Galois connections between theories and relations, as well as the growing body
of work in computer science on coalgebraic bisimulations and modalities.
A logic for parametricity has been proposed in [36], where all the previously
known consequences of Reynolds’s identity extension postulate have been formally
derived. The soundness of such a system is established in [3] using fibrational
models. Dunphy [6] proposes a logic called System P for reasoning about fibred
reflexive graph categories appropriate for polymorphic lambda calculus. Such logics
can be useful for abstracting from some of the sophisticated categorical machinery
involved in the models.
References
[1] Abramsky, S. A. and T. P. Jensen, A relational approach to strictness analysis for higher-order
polymorphic functions, in: Eighteenth Ann. ACM Symp. on Princ. of Program. Lang., ACM, 1991,
pp. 49–54.
[2] Bı́lková, M., A. Kurz, D. Petrisan and J. Velebil, Relation lifting, with an application to the many-valued
cover modality, Logical Methods in Comp. Sci. 9 (2013), pp. 1–48.
[3] Birkedal, L. and R. E. Møgelberg, Categorical models of Abadi-Plotkin’s logic for parametricity, Math.
Struct. Comput. Sci. 15 (2005), pp. 709–772.
[4] Bodnarchuk, V. G., L. A. Kaluzhnin, N. N. Kotov and B. A. Romov, Galois theory for Post algebras,
I, Cybernetics 5 (1969), pp. 243–252.
[5] de Roever, W.-P. and K. Engelhardt, “Data Refinement: Model-Oriented Proof Methods and their
Comparison,” Cambridge Univ. Press, 1998.
[6] Dunphy, B. P., “Parametricity as a Notion of Uniformity in Reflexive Graphs,” Ph.D. thesis, University
of Illinois, Dep. of Mathematics (2002), available electronically from http://www.cs.bham.ac.uk/~udr.
[7] Dunphy, B. P. and U. S. Reddy, Parametric limits, in: Proc. 19th Ann. IEEE Symp. on Logic in Comp.
Sci., IEEE, 2004, pp. 242–253.
[8] Ehresmann, C., Catégories structurées, Ann. Sci. École Norm. Sup. 80 (1963), pp. 349–425.
[9] Eilenberg, S., “Automata, Languages, and Machines; Vol. B,” Academic Press, 1976.
[10] Eilenberg, S. and S. Mac Lane, General theory of natural equivalences, Trans. Amer. Math. Society 58
(1945), pp. 231–294.
[11] Fiore, M. P., A. Jung, E. Moggi, P. W. O’Hearn, J. Riecke, G. Rosolini and I. Stark, Domains and
denotational semantics: History, accomplishments and open problems, Bulletin of the European Assoc.
for Theoretical Computer Science 59 (1996), pp. 227–256.
C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180 179
[12] Freyd, P., Core algebra revisited, Theoretical Comput. Sci. 375 (2007), pp. 193–200.
[13] Geiger, D., Closed systems of functions and predicates, Pacific J. Math. 27 (1968), pp. 95–100.
[14] Ginzburg, A., “Algebraic Theory of Automata,” Academic Press, New York, 1968.
[15] Ginzburg, A. and M. Yoeli, Products of automata and the problem of covering, Trans. Amer. Math.
Soc 116 (1965), pp. 253–266.
[16] Hermida, C., Fibrations, logical predicates and indeterminantes, Ph.D. thesis and Technical Report
ECS-LFCS-93-277, University of Edinburgh (1993).
[17] Hermida, C., Some properties of fib as a fibred 2-category, J. Pure and Applied Algebra 134 (1999),
pp. 83–109.
[18] Hermida, C., A categorical outlook on relational modalities and simulations, Inf. Comput. 209 (2011),
pp. 1505–1517.
[19] Hermida, C. and B. Jacobs, Structural induction and coinduction in a fibrational setting, Inf. Comput.
145 (1998), pp. 107–152.
[20] Hoare, C. A. R., Proof of correctness of data representations, Acta Informatica 1 (1972), pp. 271–281.
[21] Jacobs, B., “Categorical Logic and Type Theory,” Studies in Logic and the Foundations of Mathematics
141, Elsevier, 1999.
[22] Jung, A. and J. Tiuryn, A new characterization of lambda definability, 1993 pp. 245–257.
[23] Kelly, G. M. and R. Street, Review of the elements of 2-categories, in: G. M. Kelly, editor, Proc. Sydney
Category Seminar, Lect. Notes Math. 420, Springer-Verlag, 1974 pp. 75–103.
[24] Kinoshita, Y., P. W. O’Hearn, A. J. Power, M. Takeyama and R. D. Tennent, An axiomatic approach to
binary logical relations with applications to data refinement, in: M. Abadi and T. Ito, editors, Theoret.
Aspects of Comp. Softw., LNCS 1281, Springer-Verlag, 1997 pp. 191–212.
[25] Mac Lane, S., “Categories for the Working Mathematician,” Springer-Verlag, 1991, second edition.
[26] Mac Lane, S. and G. Birkhoff, “Algebra,” Chelsea, New York, 1993, third edition.
[27] Milner, R., An algebraic definition of simulation between programs, in: Proc. Second Intern. Joint Conf.
on Artificial Intelligence, The British Computer Society, London, 1971, pp. 481–489.
[28] Mitchell, J. C., Type systems for programming languages, in: J. van Leeuwen, editor, Handbook of
Theoretical Computer Science, Volume B, North-Holland, Amsterdam, 1990 pp. 365–458.
[30] Mitchell, J. C. and G. D. Plotkin, Abstract types have existential types, ACM Trans. Program. Lang.
Syst. 10 (1988), pp. 470–502.
[31] Mitchell, J. C. and A. Scedrov, Notes on sconing and relators, in: Computer Science Logic ’92, Selected
Papers, LNCS 702, Springer-Verlag, 1993 pp. 352–378.
[32] O’Hearn, P. W. and R. D. Tennent, Parametricity and local variables, J. ACM 42 (1995), pp. 658–709,
(Reprinted as Chapter 16 of [33]).
[33] O’Hearn, P. W. and R. D. Tennent, “Algol-like Languages (Two volumes),” Birkhäuser, Boston, 1997.
[34] Parnas, D. L., Information distribution aspects of design methodology, in: IFIP Congress 71, North-
Holland, 1971, pp. 339–344.
[35] Pitts, A. M., Relational properties of domains, Inf. Comput. 15 (1996), p. 66.
[36] Plotkin, G. and M. Abadi, A logic for parametric polymorphism, 1993, pp. 361–375.
[37] Plotkin, G., J. Power, D. Sannella and R. Tennent, Lax logical relations, in: Intern. Colloq. Aut., Lang.
and Program., Springer-Verlag, 2000 pp. 85–102.
[38] Plotkin, G. D., Lambda definability in the full type hierarchy, in: J. R. Hindley and J. P. Seldin, editors,
To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, Academic Press,
1980 pp. 363–373.
[39] Plotkin, G. D., Domains (Pisa notes), Electronic manuscript, University of Edinburgh (1983), available
from http://homepages.inf.ed.ac.uk/gdp/publications/.
180 C. Hermida et al. / Electronic Notes in Theoretical Computer Science 303 (2014) 149–180
[40] Pöschel, R., Galois connections for operations and relations, in: K. Denecke, M. Erne and S. L.
Wismath, editors, Galois Connections and Applications, Kluwer, 2004 pp. 231–258.
[41] Reynolds, J. C., “The Craft of Programming,” Prentice-Hall International, London, 1981.
[42] Reynolds, J. C., Types, abstraction and parametric polymorphism, in: R. E. A. Mason, editor,
Information Processing ’83, North-Holland, Amsterdam, 1983 pp. 513–523.
[43] Reynolds, J. C., Polymorphism is not set-theoretic, in: G. Kahn, D. B. MacQueen and G. Plotkin,
editors, Semantics of Data Types, LNCS 173, Springer-Verlag, 1984 pp. 145–156.
[44] Robinson, E. and G. Rosolini, Reflexive graphs and parametric polymorphism, in: Proc. Ninth Ann.
IEEE Symp. on Logic in Comp. Sci., IEEE, 1994, pp. 364–371.
[45] Sangiorgi, D., On the origins of bisimulation and coinduction, ACM Trans. Program. Lang. Syst. 31
(2009), p. 15.
[46] Sannella, D. and A. Tarlecki, “Foundations of Algebraic Specification and Formal Software
Development,” Springer-Verlag, 2012.
[47] Scott, P. J., Some aspects of categories in computer science, in: M. Hazewinkel, editor, Handbook of
Algebra, Vol. 2, Elsevier, 2000 pp. 3–77.
[48] Statman, R., Logical relations and the typed lambda calculus, Inf. Control 65 (1985), pp. 85–97.
[49] Strachey, C., Fundamental concepts in programming languages, J. Higher-order Symbolic Comput. 13
(2000), pp. 11–49, (original lecture notes, Copenhagen, 1967).
[50] Streicher, T., Fibred categories à la Bénabou (1999), lecture Notes, available electronically from
http://www.mathematik.tu-darmstadt.de/~streicher/.
[51] van der Waerden, B. L., “Modern Algebra,” Unger, New York, 1949, second edition, (Translated from
German by Fred Blum, original version 1930-31).