• Aucun résultat trouvé

Spans of Delta Lenses

N/A
N/A
Protected

Academic year: 2022

Partager "Spans of Delta Lenses"

Copied!
15
0
0

Texte intégral

(1)

Spans of Delta Lenses

Michael Johnson

Departments of Mathematics and Computing, Macquarie University Robert Rosebrugh

Department of Mathematics and Computer Science Mount Allison University

Abstract

As part of an ongoing project to unify the treatment of symmetric lenses (of various kinds) as equivalence classes of spans of asymmetric lenses (of corresponding kinds) we relate the symmetric delta lenses of Diskin et al, with spans of asymmetric delta lenses. Because delta lenses are based on state spaces which are categories rather than sets there is further structure that needs to be accounted for and one of the main findings in this paper is that the required equivalence relation among spans is compatible with, but coarser than, the one expected. The main result is an isomorphism of categories between a category whose morphisms are equivalence classes of symmetric delta lenses (here called fb-lenses) and the category of spans of delta lenses modulo the new equivalence.

1 Introduction

In their 2011 POPL paper [4] Hoffmann, Pierce and Wagner defined and studied (set-based) symmetric lenses.

Since then, with the study of variants of asymmetric lenses (set-based or otherwise), there has been a need for more definitions of corresponding symmetric variants. This paper is part of an ongoing project by the authors to develop a unified theory of symmetric and asymmetric lenses of various kinds. The goal is to make it straightforward to define the symmetric version of any, possibly new, asymmetric lens variant (and conversely).

Once an asymmetric lens is defined the unified theory should provide the symmetric version (and vice-versa).

In [4] Hoffmann et al noted that there were two approaches that they could take to defining symmetric lenses.

One involved studying variousright andleft (corresponding to what other authors callforwards andbackwards) operations. The other would be based on spans of asymmetric lenses. In both cases an equivalence relation was needed to define composition of symmetric lenses, to ensure that that composition is associative, and to identify lenses which were equivalent in their updating actions although they might differ in “hidden” details such as theircomplements (see [4]) or the head (peak) of their spans. Hoffmann et al gave their definition of symmetric lens in terms of left and right update operations, noting that “in the span presentation there does not seem to be a natural and easy-to-use candidate for . . . equivalence”.

In [6] the present authors developed the foundations needed to work with spans of lenses of various kinds and proposed an equivalence for spans of well-behaved set-based asymmetric lenses (called here HPW-lenses) and also for several other set-based variants. Our goal was to find the finest equivalence among spans of HPW lenses that would satisfy the requirements of the preceding paragraph. Such an equivalence needed to include, and be coarser than, span equivalence (an isomorphism between the heads of the spans commuting with the

Copyrightc by the paper’s authors. Copying permitted for private and academic purposes.

In: A. Cunha, E. Kindler (eds.): Proceedings of the Fourth International Workshop on Bidirectional Transformations (Bx 2015), L’Aquila, Italy, July 24, 2015, published at http://ceur-ws.org

(2)

legs of the spans). Furthermore pre-composing the legs of a span of HPW lenses with a non-trivial HPW lens gives a new span which differs from the first only in the “hidden” details — the head would be different but the updating actions at the extremities would be the same — so such pairs of spans should also be equivalent. In [6]

we were able to show that the equivalence generated by such non-trivial HPW lenses (commuting with the legs of the spans) worked well, and that result was very satisfying because it demonstrated, as so much work in the theory of lenses does, that lenses and bidirectional transformations more generally are valuable generalisations of isomorphisms.

Of course, the work so far, being entirely set-based, is still far from a unified theory, so in this paper we turn to the category-based delta-lenses of Diskin, Xiong and Czarnecki [1] and study the symmetric version derived from spans of such lenses and compare it with the symmetric (forwards and backwards style) version that Diskin et al propose in [2].

The paper is structured as follows. In Sections 2 and 3 we review and develop the basic mathematical properties of delta-lenses (based on [1] and referred to here as d-lenses) and symmetric delta lenses (based on [2], and called here fb-lenses after their basic operations called “forwards” and “backwards”, thus avoiding clashing with the general use of “symmetric” for equivalence reduced spans of lenses). As in the work of Hoffmann et al, both fb-lenses and spans of d-lenses need to be studied modulo an equivalence relation and the two equivalence relations we propose are introduced in Section 4. In Section 5 we show that using the two equivalences does indeed yield a category of (equivalence classes of) fb-lenses and a category of (equivalence classes of) spans of d-lenses respectively (and of course, we need to show that the equivalence relations we have introduced are congruences in order to construct the categories). Finally in Section 6 we explore the relationship between the two categories and show that there is an equivalence of categories, indeed in this case an isomorphism of categories, between them.

Because of the usefulness of category-based lenses (in particular delta-lenses) in applications, the work pre- sented here lays important mathematical foundations. Furthermore the extra mathematical structure provided in the category-based variants has revealed a surprise — an equivalence generated by non-trivial lenses is not coarse enough to ensure that two spans of d-lenses with the same fb-behaviour are always identified. The diffi- culty that arises is illustrated in a short example and amounts to “twisting” the structures so that no single lens can commute with the lenses on the left side of the spans, and at the same time commute with the lenses on the right side of the spans. The solution, presented as one of the equivalences in Section 4, relaxes the requirement that the comparison be itself a lens, and asks that it properly respect the put operations on both sides (rather than having its own put operation commuting with both sides).

2 Asymmetric delta lenses

For any categoryC, we write|C|for the set (discrete category) of objects ofC andC2 for the category whose objects are arrows of C. For a functor G : S //V, denote the “comma” category, whose objects are pairs consisting of an object S ofSand an arrowα:GS //V, by (G,1V) . We recall the definition of a delta lens (or d-lens) [1, 5]:

Definition 1 A (very well-behaved) delta lens (d-lens) from S to V is a pair (G, P) where G : S //V is a functor (the “Get”) and P:|(G,1V)| //|S2|is a function (the “Put”) and the data satisfy:

(i) d-PutInc: the domain of P(S, α:GS //V)isS (ii) d-PutId: P(S,1GS:GS //GS) = 1S

(iii) d-PutGet: GP(S, α:GS //V) =α

(iv) d-PutPut: P(S, βα:GS //V //V0) =P(S0, β:GS0 //V0)P(S, α:GS //V) whereS0 is the codomain of P(S, α:GS //V)

For examples of d-lenses, we refer the reader to [1]. Meanwhile, we offer a few sentences here to help orient the reader to the notations used. Both the categoriesSandVrepresent state spaces. Objects ofSare states and an arrowS //S0 ofSrepresents a specific transition from the stateS which is its domain to the stateS0 which is its codomain. Such specified transitions are often called “deltas”. Similarly forV. A functorG:S //Vmaps states ofSto states ofV—S is sent toGS. Furthermore, being a functor it maps deltasS //S0 inSto deltas GS //GS0inV. The objects of (G,1V) are important because, being a pair (S, α:GS //V), they encapsulate

(3)

both an object of Sand a delta starting at GS. Such a pair is the basic input for a Put operation. The Put operationP itself, in the case of a d-lens, is just a function (not a functor) and it takes such an “anchored delta”

(S, α:GS //V) inVto a delta inSwhich, by d-PutInc, starts atS. The axioms d-PutId and d-PutPut ensure that the P operation respects composition, including identities. Finally, the axiom d-PutGet ensures that, as expected, the Put operation results in a delta inSwhich is carried by Gto α, the given input delta.

In [5], we proved that d-lenses compose, that a c-lens as defined there is a special case of d-lens and that their composition is as for d-lenses, and finally that d-lenses are strictly more general than c-lenses. We also proved that d-lenses are certain algebras for a semi-monad.

Furthermore, in [6] we developed the technique to compose spans of lenses in general. For d-lenses, this specializes to Definition 3. We first need a small but important proposition, and we formally remind the reader about our notations for spans and cospans.

Aspan is a pair of morphisms, with common domain:

X Y

S X

u

S

Y

v

?

??

??

Despite the symmetry, such a span is often described as a “span from X to Y”, and is distinguished from the same two arrows viewed as a span from Y to X. The illustrated span above is often denoted for brevity’s sake u:Xoo S //Y :vand, whenX,SandY are understood or easily derived, we sometimes just refer to it as the spanu, v. The objectS is sometimes called thehead orpeak of the span and the arrowsuandv are called the legs of the span. The objectsX andY are, naturally enough, called thefeet of the span. Cospans are described and notated in the same way but the arrowsuand vare reversed. Finally, if, as sometimes is necessary, a span is drawn upside down, the common domain is still called the head despite being drawn below the feet.

When working with spans it is often necessary to calculate pullbacks. For simplicity of presentation we will usually assume that the pullback has been chosen so that its objects and morphisms are pairs of objects from the categories from which it has been constructed (so, for example, in the diagram below, objects ofTare pairs of objects (S, W) from the categoriesSandWrespectively, with the property thatG(S) =H(W), and similarly for morphisms ofT).

Proposition 2 Let G : S //Voo W : H be a cospan of functors. Suppose that P : |(G,1V)| //|S2| is a function which, withG, makes the pair(G, P)a d-lens. Then, in the pullback square incat:

S W

T S

H0

yysssssssT

W

G0

%%K

KK KK K

S

GKKKKK%%V KK

S WW

VyyssssHss

the functorG0 together withP0:|(G0,1W)| //|T2|defined byP0((S, W), β:G0(S, W) //W0) = (P(S, H(β)), β) : (S, W) //(S0, W0)define a d-lens fromT toW.

Proof. Note first that P0 makes sense since H(β) is a morphism HG0(S, W) //H(W0) but HG0(S, W) = GH0(S, W) =GSso it is in fact a morphismGS //H(W0). Furthermore we denote the codomain ofP(S, H(β)) by S0 so that G(S0) = H(W0) and thus (S0, W0) is an object of T. The d-PutInc, d-PutId and d-PutGet conditions on (G0, P0) are satisfied by construction. The d-PutPut condition follows immediately from d-PutPut for (G, P).

This means we can talk about the “pullback” of a d-lens along an arbitrary functor, in particular along the Get of another d-lens. This is similar to the situations described in [6]. The inverted commas around “pullback”

are deliberate because the constructed d-lens may not be an actual pullback in the category of d-lenses (the category whose objects are categories and whose arrowsS //Vare d-lenses from StoV).

(4)

Definition 3 Suppose that in

S S0

T S

H

yysssssssT

S0

K

%%K

KK KK K

S

GKKRKKKK%%Y

SK SS00 YyyssssFssL S

X

GL

yysssssss S0

Z

FR

%%K

KK KK KK

the functors GL, GR, FL, andFR are the Gets of d-lenses with corresponding Puts PL, PR, QL, andQR, andT is the pullback ofGR andFL. For the “pullback” d-lenses with GetsH andK, denote the Puts byPH andPK. Then the span composite of the span of d-lenses (GL, PL), (GR, PR) from X to Y with the span of d-lenses (FL, QL),(FR, QR)from YtoZ, denoted

((GL, PL),(GR, PR))◦((FL, QL),(FR, QR))

is the span of d-lenses from XtoZ specified as follows. The Gets are GLH andFRK. The Puts are those for the composite d-lenses (GL, PL)(H, PH)and(FR, QR)(K, PK).

In a sense, the composite just defined corresponds to the ordinary composite of spans in a category with pullbacks. In the category of categories, the ordinary span composition of the span GL, GR and with the span FL, FRis the spanGLH, FRK. As usual for such composites, the operation is not associative without introducing an equivalence relation and we do so later in this paper.

3 Symmetric delta lenses

A symmetric delta lens (called an “fb-lens” below) is between categories, say X and Y. It consists of a set of synchronizing “corrs”, so named because the make explicit intended correspondences between objects of X and objects of Y, together with “propagation” operations. In the forward direction, given objects X and Y synchronized by a corr r and an arrowx with domainX, the propagation returns an arrowy with domainY and a corr synchronizing the codomains ofxandy. This is made precise in the following definition and is based on definitions in [2] and [3]. We denote the domain and codomain of an arrowxbyd0(x), d1(x).

Definition 4 LetX andYbe categories. An fb-lensfromX toYisM = (δX, δY,f,b) :X←→Yspecified as follows. The data δX, δY are a span of sets

δX:|X|oo RXY //|Y|:δY

An elementr of RXY is called a corr. Forr inRXY, if δX(r) =X, δY(r) =Y the corr is denoted r:X ↔Y. The data f andbare operations called forwardand backward propagation:

f:Arr(X)×|X|RXY //Arr(Y)×|Y|RXY

b:Arr(Y)×|Y|RXY //Arr(X)×|X|RXY

where the pullbacks (also known as fibered products) mean that iff(x, r) = (y, r0), we haved0(x) =δX(r), d1(y) = δY(r0)and similarly forb. We also require thatd0(y) =δY(r)andδX(r0) =d1(x), and the similar equations for b.

Furthermore, we require that both propagations respect both the identities and composition in X and Y, so that we have:

r:X↔Y implies f(idX, r) = (idY, r) and b(idY, r) = (idX, r) and

f(x, r) = (y, r0)andf(x0, r0) = (y0, r00) imply f(x0x, r) = (y0y, r00) and

b(y, r) = (x, r0)andb(y0, r0) = (x0, r00) imply b(y0y, r) = (x0x, r00)

(5)

Iff(x, r) = (y, r0) andb(y0, r) = (x0, r00), we display instances of the propagation operations as:

X0 oo Y0

r0_ _//

_ _ X X0

x

X oo r //YY Y0

y

f //

X0 oo Y0

r00_ _//

_ _ X X0

x0

X oo r //YY Y0

y0

oo b

For examples of fb-lenses we refer the reader to [2].

Definition 5 Let M = (δRX, δRY,fR,bR) and M0 = (δYS, δSZ,fS,bS) be two fb-lenses. We define the composite fb-lensM0M = (δX, δZ,f,b)as follows. Let TXZ be the pullback of categories in

RXY SYZ

TXZ

RXY δ1

yysssss

TXZ

SYZ δ2

%%K

KK KK RXY

|Y|

δKYRKKKK%%

RXY SSYZYZ

|Y|yysssδssYS

Let δXXRδ1:TXZ //Xand δZSZδ2. The operations for M0M are defined as follows. Denote fR(x, r) = (y, rf),fS(y, s) = (z, sf)andbS(z, s0) = (y, sb),bR(y, r0) = (x, rb). Then

f(x,(r, s)) = (z,(rf, sf))andb(z,(r0, s0)) = (x,(rb, sb)) The diagram

X0 oo r Y0

f_ _//

_ _ X X0

x

X oo r //YY Y0

y

fR//

Y0 oo s Z0

f_ _//

_ _ Y

YY0oo s //ZZ Z0

z

fS //

shows that the arities are correct forfin the forward direction. That is, we have f:Arr(X)×|X|TXZ //Arr(Z)×|Z|TXZ

and similarly

b:Arr(Z)×|Z|TXZ //Arr(X)×|X|TXZ

It is easy to show that thef andbjust defined respect composition and identities inXandZand we record:

Proposition 6 The compositeM0M just defined is an fb-lens fromX toZ.

We note that because it is defined using a pullback, this construction of the composite of a pair of fb-lenses is not associative, and when we later define a category of fb-lenses the arrows will be equivalence classes of fb-lenses.

Next we define two constructions relating spans of d-lenses with fb-lenses.

We first consider a span of d-lenses. Let L = (GL, PL) where GL : S //V and K = (GK, PK) where GK :S //Wbe (a span of) d-lenses.

Construct the fb-lens ML,K= (δV, δW,f,b) as follows:

– the corrs areRV,W=|S|withδVS=GLS andδWS=GKS;

– forward propagationfforv:V //V0 andS:V↔W is defined byf(v, S) = (w, S0) wherew=GK(PL(S, v)) andS0 is the codomain of PL(S, v);

– backward propagationbis defined analogously.

Lemma 7 ML,K is an fb-lens.

(6)

Proof. Identity and compositionality for ML,K follow from functoriality of the Gets for L and K and the d-PutId andd-PutPut equations in Definition 1.

In the other direction, suppose thatM = (δV, δW,f,b) is an fb-lens fromVtoWwith δV:|V|oo R //|W|:δW

We now construct a span of d-lenses LM : Voo S //W :KM from V to W. The first step is to define the headSof the span. The set of objects ofSis the setR of corrs of M. The morphisms ofSare defined as follows: For objectsrand r0,S(r, r0) ={(v, w)|d0v=δV(r), d1v=δV(r0), d0w=δW(r), d1v=δW(r0)}(where we write, as usual,S(r, r0) for the set of arrows ofSfromrtor0). Thus an arrow may be thought of as a formal square:

V0 oo W0

r0 //

V V0

v

V oo r //WW W0

w

Composition is inherited from composition in V and W at boundaries, or more precisely, for (v, w)∈ S(r, r0) and (v0, w0)∈S(r0, r00) we define:

(v0, w0)(v, w) = (v0v, w0w)

in S(r, r00). The identities are pairs of identities. It is easy to see thatSis a category.

Next we define the d-lensLM to be the pair (GL, PL) where we define GL :S //Von objects by δV, and on arrows by projection, that is GL(v, w) =v. The Put forLM,PL :|(GL,1V)| //|S2|, is defined on objects (r, v :GL(r) //V0) of the category (GL,1V) by PL(r, v) = (v, π0f(v, r)) which is indeed an arrow ofSfrom r to π1f(v, r). (As is usual practice, we writeπ0andπ1 for the projection from any pair onto its first and second factors respectively.) We define KM = (GK, PK) similarly.

Lemma 8 LM = (GL, PL)andKM = (GK, PK)is a span of d-lenses.

Proof. GL andGK are evidently functorial. We need to show that PL andPK satisfy (i)-(iv) of Definition 1.

These follow immediately from the properties of of the fb-lensM.

The two constructions above are related. One composite of the constructions is actually the identity.

Proposition 9 For any fb-lensM, with the notation of the constructions above M =MLM,KM

Proof. By inspection, the corrs andδ’s ofMLM,KM are those ofM. Further, it is easy to see that, for example, the forward propagation ofMLM,KM is identical to that ofM.

However, the other composite of the constructions above, namely the span of d-lenses LML.K, KML.K is not equal to the original span L, K (because the arrows of the originalShave been replaced by the formal squares described above). We have yet to consider the appropriate equivalence for spans of d-lenses, and we do so now.

We will see thatLML.K, KML.K is indeed equivalent toL, K.

4 Two equivalence relations

Our first equivalence relation is on spans of d-lenses fromXto Y.

Suppose that

Xoo (GL,PL) S (GR,PR) //Y and Xoo (G

0L,PL0)

S0 (G

0R,PR0)

//Y

are such spans.

The functor Φ :S //S0 is said to satisfy conditions (E) if:

(1)G0LΦ =GL andG0RΦ =GR

(7)

(2) Φ is surjective on objects

(3) whenever ΦS=S0, we have bothPL0(S0, G0LS0 α //X) = ΦPL(S, GLS α //X) and PR0(S0, G0RS0 β //Y) = ΦPR(S, GRS β //Y).

By (1) any such Φ is a “2-cell” in spans of categories between the two X to Y spans GL, GR and G0L, G0R. Moreover, Φ is required both to be surjective on objects and also to satisfy (3), a condition which expresses a compatibility with the Puts. Notice that the identity functor onSsatisfies conditions (E).

Definition 10 Let ≡Sp be the equivalence relation on spans of d-lenses from X to Y which is generated by functorsΦ satisfying (E).

To simplify describing≡Sp we now prove some properties of functors satisfying conditions (E).

Lemma 11 A composite of d-lens span morphisms satisfying (E) also satisfies (E).

Proof. Suppose that we have spans of d-lenses (GL, PL),(GR, PR) and (G0L, PL0),(G0R, PR0) as above, and a third such span is:

Xoo (G

00L,PL00)

S00 (G

00R,PR00)

//Y

Suppose Φ :S //S0 and Φ0:S0 //S00satisfy (E). Properties (1) and (2) for Φ0Φ are immediate. We show thePL0 part of property (3) for Φ0Φ. Suppose Φ0ΦS=S00and considerPL00(S00, G00LS0 α //X). By (E) for Φ and Φ0, since Φ0(Φ(S)) =S00, we havePL00(S00, G00LS00 α //X) = Φ0PL0(Φ(S), andG0LΦ(S) α //X) = Φ0ΦPL(S, GLS α //X) as required.

Suppose that Φ satisfies (E). When ΦS=S0 it follows thatGLS=G0LΦS =G0LS0, which we will use below.

Note that if Φ were the Get of a d-lens (although it need not be) then it would be surjective on arrows by the d-PutGet equation, but not necessarily surjective on hom sets.

Lemma 12 Suppose once again that(GL, PL),(GR, PR),(G0L, PL0),(G0R, PR0)and(G00L, PL00),(G00R, PR00)are spans of d-lenses as above. LetΦ :S //S0oo S00: Φ0 be the functors in a cospan of span morphisms satisfying (E).

Let

S S00

T S

Ψ

yysssssssT

S00

Ψ0

%%K

KK KK K

S

S0

ΦKKKKK%%

KK

S SS0000 S0 yyssssΦss0 be a pullback in cat. Then there is a span of d-lenses Xoo (G

T L,PLT)

T (G

T R,PRT)

//Y defined byGTL=GLΨand

PLT((S, S00), GTL(S, S00) α //X) = (S PL(S,α) //W, S00 P

L00(S00,α)

//W00)

and similarly for (GTR, PRT). Moreover,ΨandΨ0 satisfy (E).

Proof. The first point is that (GTL, PLT) and (GTR, PRT) actually are d-lenses. We need to know that PLT is well-defined. Since (S, S00) is an object of the pullback T, we know that Φ(S) = Φ0(S00) = S0, say. We want PLT((S, S00), GTL(S, S00) α //X) to be an arrow of T, so we need to show that Φ(S PL(S,α) //W) is equal to Φ0(S00 P

L00(S00,α)

//W00). However both are equal toP0L(S0, α) since both Φ and Φ0satisfy (E). Thus furthermore, (W, W00) is an object ofTand using this ford-PutPut each of the required d-lens equations is easy to establish.

Next, we show that Ψ and Ψ0 satisfy (E). First of all, the Gets commute by definition. Moreover, both Ψ and Ψ0 are surjective on objects because Φ and Φ0 are so.

(8)

It remains to check property (3) for Ψ and Ψ0. We need to show that whenever Ψ(S, S00) =S, we have PL(S, GLS α //U) = Ψ(PLT((S, S00), GTL(S, S00) α //U))

and this follows immediately from the definitions of Ψ andPLT. (Notice that for S= Ψ(S, S00) we haveGLS = G0LΦS=G0LΦ0(S00) =G00L(S00) and thusPL00(S00, G00LS00 α //U) is well-defined.) Similarly Ψ0 satisfies (3).

Corollary 13 Zig-zags of span morphisms satisfying (E) reduce to spans of span morphisms satisfying (E).

A zig-zag is any string of arrows (ignoring the direction of the indidual arrows so that neighbouring arrows might be connected head to head or tail to tail as well as tail to head). It follows that any proof that two spans of d-lenses are≡Spequivalent can be reduced to a single span Ψ,Ψ0 of span morphisms satisfying (E).

The second equivalence relation we introduce is on the set of fb-lenses fromXtoY. Recall that Diskin et al [3] defined symmetric delta lenses (our fb-lenses), but they did not consider composing them. Like Hoffman et al [4] they would find that they need to consider equivalence classes of their symmetric delta lenses in order for the appropriate composition to be associative. Also like Hoffman et al, there is a need for an equivalence among their lenses to eliminate artificial differences. In fact, defining an equivalence to restore associativity is easy.

Choosing the correct equivalence to eliminate the artificial differences is more delicate. And what do we mean by

“atificial differences”? Symmetric lenses of various kinds include hidden data — the complements of Hoffmann et al and the corrs of Diskin et al are examples. The hidden data is important for checking and maintaining consistency, but different arrangements of hidden data with the same overall effect should not be counted as different symmetric lenses.

We now introduce such a relation on the set of fb-lenses fromXtoY.

Definition 14 Let L = (δX, δY,f,b) and L0 = (δ0X, δ0Y,f0,b0) be two fb-lenses (from X to Y) with corrs RXY, R0XY. We sayL≡fbL0 iff there is a relationσfrom RXY toR0XY with the following properties:

1. σis compatible with the δ’s, i.e. rσr0 impliesδXr=δ0Xr0 and δYr=δY0 r0

2. σis total in both directions, i.e. for all rinRXY, there isr0 inR0XY with rσr0 and conversely.

3. for all r, r0,x an arrow of X, if rσr0 and δXr is the domain of x then the first components of f(x, r) and f0(x, r0)are equal and the second components areσrelated, i.e.π0f(x, r) =π0f0(x, r0)andπ1f(x, r)σπ1f0(x, r0) 4. the corresponding condition for b, i.e. for allr, r0,yan arrow ofY, ifrσr0 andδXris the domain ofxthen

π0b(y, r) =π0b0(y, r0)andπ1b(y, r)σπ1b0(y, r0) Lemma 15 The relation≡fb is an equivalence relation.

Proof. For reflexivity take σ to be the identity relation; for symmetry take the opposite relation for σ; for transitivity, the composite relation is easily seen to satisfy conditions 1. to 4.

Lemma 16 ForL, L0 as in the definition above, consider a surjectionϕ:RXY //R0XY compatible with theδ’s and satisfying the following conditions:

• for corrs r, r0, and an arrow x of X, if ϕ(r) =r0 and δXr is the domain of x then the first components of f(x, r) and f0(x, r0) are equal and the second components are ϕ related, i.e. π0f(x, r) = π0f0(x, r0) and ϕ(π1f(x, r)) =π1f0(x, r0)

• the corresponding condition forb, i.e. for all r, r0,y an arrow ofY, if ϕ(r) =r0 andδXr is the domain of xthenπ0b(y, r) =π0b0(y, r0)andϕ(π1b(y, r)) =π1b0(y, r0)

The collection of such surjections (viewed as relations) generates the equivalence relation ≡fb.

(9)

Proof. To see that≡fbis generated by such surjections, consider the span tabulating the relationσin ≡fbviz.

RXYoo σ //R0XY.

Notice that each leg is a surjection satisfying the conditions of the lemma. Conversely, any zig-zag of such surjections defines a relation which is easily seen to satisfy the conditions of Definition 14.

Remark 17 Although≡fbis generated by zig-zags of certain surjections, we have just seen that any such zig-zag can be reduced to a single span of such surjections between sets of corrs.

Proposition 18 Suppose that M ≡fb M0 are fb-lenses from X to Y equivalent by a generator for ≡fb, i.e. a surjectionϕ:RXY //RXY0 . Then(LM, KM)≡Sp(LM0, KM0)as spans of d-lenses fromXtoY.

Proof. We first define Φ :S //S0on objects byϕ. Notice that Φ is surjective on objects sinceϕis a surjection.

To define Φ on arrows ofS, consider an arrow

X0 oo Y0

r0 //

X X0

x

X oo r //YY Y0

y

ofS. Its image under Φ is defined to be the arrow

X0 oo Y0

ϕ(r0) //

X X0

x

X oo ϕ(r) //YY Y0

y

which is an arrow ofS0 sinceϕis compatible with theδs. This Φ is evidently functorial and commutes with the Gets. It remains to show that Φ satisfies condition (3) of (E), that is, whenever Φ(r) =r0,PL0(r0, G0Lr0 x //X0) = ΦPL(r, GLr x //X0) (with the similar equation holding forPK0 ).

Now, whenr0 = Φ(r), we have

PL0(r0, x) = (x, π0f0(x, r0))

= (x, π0f(x, r)) see Lemma 16

= Φ(x, π0f(x, r)) definition of Φ

= ΦPL(r, x) as required. Similarly forPK0 .

Proposition 19 Suppose that (L, K)≡Sp (L0, K0)as spans of d-lenses fromX toY are made equivalent by a generator for≡Sp, i.e. a functorΦ :S //S0 satisfying conditions (E). ThenML,KfbML0,K0 as fb-lenses from X toY.

Proof. Letϕbe the object function of Φ. Since Φ commutes with the Gets,ϕis compatible with theδ’s.

We need to show thatϕsatisfies the conditions in Lemma 16. Suppose Φ(S) =S0 andGL(S) is the domain ofx. Then

π0f(x, S) = GKPL(x, S)

= G0KΦPL(x, S)

= G0KPL0(x, S0)

= π0f0(x, S0)

(10)

and

ϕπ1f(x, S) = ϕd1PL(x, S)

= d1ΦPL(x, S)

= d1PL0(x, S0)

= π1f0(x, S0) as required. Similarly for the equations involvingb.

5 Two categories of lenses

The collections of lenses so far discussed do not form categories since their composition is not associative. We are going to use the equivalence relations of the previous section to resolve this, but first we show that the equivalence relations respect the composites defined above, that is they are “congruences”.

Proposition 20 Suppose that M = (δX, δY,fR,bR), M0 = (δ0X, δ0Y,fR0,bR0) and N = (δYS, δZ,fS,bS) are fb- lenses (see the diagram below in which RXY, R0XY and SYZ are the corresponding corrs). Further, suppose ϕ:RXY //RXY0 is a generator of≡fb. ThusM ≡fbM0. Then N M ≡fbN M0.

Proof. The compositeN M has as corrs the pullbackTXZas in Definition 5, and similarly N M0 has corrsTXZ0 .

|X| |Y|

RXY

|X|

δX



RXY

|Y|

δY

?

??

??

??

?

|X|

R0XY

__

δ?X0??????

|X| ||YY||

R0XY

??

δY0



SYZ

|Y| δ

S

oo Y SYZ δZ //|Z|

TXZ

RXY δ1

oo

TXZ0 R0XY

δ01

oo

TXZ

SYZ δ2

?

??

??

??

?

TXZ0

SYZ δ02

??







 RXY

R0XY

ϕ

In order to show that N M ≡fb N M0, we construct ϕ0 : TXZ //TXZ0 . This is straightforward using the universal property of the pullbackTXZ0 , sinceδY0 ϕδ1YSδ2.

To finish, we need to check thatϕ0 satisfies the four requirements of Definition 14.

Compatibility withδs is easy when we note thatϕδ110ϕ0 andδ20ϕ02.

The function ϕ0 is a total relation in both directions since it is surjective. To see that ϕ0 is surjective, note that any element of TXZ0 can be thought of as a pair (r0, s) compatible overY, and sinceϕis surjective, there exists anrin RXY, necessarily compatible with s, such thatϕ0(r, s) = (ϕ(r), s) = (r0, s).

Letf be the forward propagation of the compositeN M, as defined in Definition 5, and letf0 be the forward propagation of the composite N M0. Suppose r0 =ϕ(r) and thus (r0, s) =ϕ0(r, s). We need to show that the first components of f(x,(r, s)) and f0(x,(r0, s)) are equal and that ϕ0 takes the second component off(x,(r, s)) to the second component off0(x,(r0, s)).

The first component of f(x,(r, s)) is π0fS0fR(x, r), s), while the first component of f0(x,(r0, s)) is π0fS0fR0(x, r0), s), and these are equal sinceϕis a generator of≡fbimpliesπ0fR(x, r) =π0fR0(x, ϕ(r)).

The second component of f(x,(r, s)) is (π1fR(x, r), π1fS0fR(x, r), s)), while the second component of f0(x,(r0, s)) is (π1fR0(x, r0), π1fS0fR0(x, r0), s)), and ϕ0 of the first equals the second since, as before, π0fR(x, r) =π0fR0(x, ϕ(r)).

The same arguments work for bandb0.

Proposition 21 Suppose that M = (δX, δRY,fR,bR), N = (δY, δZ,fS,bS) and N0 = (δ0Y, δZ0,fS0,bS0) are fb- lenses (see the diagram below in which RXY, SYZ and SYZ0 are the corresponding corrs). Further, suppose ϕ:SYZ //SYZ0 is a generator of≡fb. ThusN ≡fbN0. Then N M ≡fbN0M.

(11)

Proof. The compositeN M has as corrs the pullbackTXZas in Definition 5, and similarly N0M has corrsTXZ0 .

|Y| |Z|

SYZ

|Y|

δY



SYZ

|Z|

δZ

?

??

??

??

?

|Y|

SYZ0

__

δ?Y0??????

|Y| ||ZZ||

SYZ0

??

δ0Z

 RXY δ |Y|

R Y //

RXY

|X|oo δX

TXZ SYZ δ2

//

TXZ0 SYZ0

δ20 //

TXZ

RXY δ1



TXZ0 RXY

δ10

__???

?????

SYZ

SYZ0

ϕ

The proof follows the same argument as in the previous proposition.

Theorem 22 Equivalence classes for≡fb are the arrows of a category, denoted fbDLens.

Proof. We first note that Propositions 20 and 21 ensure that composition is well-defined independently of choice of representative. There is an identity fb-lens with obvious structure which acts as an identity for the composition. It remains only to note that associativity follows by standard re-bracketing of iterated pullbacks.

The re-bracketing function is theϕfor an≡fb equivalence.

Proposition 23 Suppose that (GL, PL), (GR, PR), (G0L, PL0), (G0R, PR0), (FL, QL), and (FR, QR) are d-lenses whose Gets are shown in the diagram below. Further, supposeΦ :S //S0 is a functor satisfying properties (E).

Thus the span(GL, PL),(GR, PR)is≡Sp to the span(G0L, PL0),(G0R, PR0). Then the two possible span composites are equivalent, that is

((GL, PL),(GR, PR))◦((FL, QL),(FR, QR))≡Sp((G0L, PL0),(G0R, PR0))◦((FL, QL),(FR, QR)).

Proof. The top composite span of d-lenses in the diagram below has head T, the pullback ofGR andFL (see Definition 3), similarlyT0 is the head of the bottom span composite.

X Y

S

X

GL



S

Y

GR

?

??

??

??

?

X

S0

__

G??0L??????

X YY

S0

??

G0R



R

Yoo FL R FR //Z T

Soo H

T0 S0

H0

oo

T

R

K

?

??

??

??

?

T0

R

K0

??







 S

S0

Φ

In order to show the claimed equivalence, we construct a functor Φ0 :T //T0. Since G0RΦH =FLK, Φ0 is defined by applying the universal property of the pullbackT0.

Since T and T0 are pullbacks of functors, their objects can be taken to be pairs of objects from S and R, respectively S0 and R. Similarly, their arrows can be taken to be pairs. Also H and K, respectively H0 and K0 can be taken to be projections. We can now explicitly describe the action of Φ0 on an arrow of T as Φ0(t0, t1) = (Φt0, t1).

As in Definition 3, we denote the Puts of the lenses whose Gets are H andK by PH andPK. Similarly for H0 andK0. Denote the composite lens (GL, PL)(H, PH) by (G, P) and similarly (G0, P0) = (G0L, PL0)(H0, PH0).

We need to show that Φ0 satisfies the conditions (E). By its construction Φ0 commutes with the Gets, and is surjective on objects.

It remains to show that whenever Φ(S, R) = (S0, R0) (which implies that R=R0 and Φ(S) =S0) we have P0((S0, R0), G0LH0(S0, R0) α //X0) = Φ0P((S, R), GLH(S, R) α //X0)

(12)

and

Q0((S0, R0), FRK0(S0, R0) γ //Z0) = Φ0Q((S, R), FRK(S, R) γ //Z0)

We begin by proving the first equation immediately above. We know that whenever Φ(S) = S0, PL0(S0, G0L(S0) α //X0) = ΦPL(S, GL(S) α //X0). We calculate

P0((S0, R0), G0LH0(S0, R0) α //X0) = P0((S0, R0), G0L(S0) α //X0)

= PH0((S0, R0), PL0(S0, G0L(S0) α //X0))

= (PL0(S0, G0L(S0) α //X0), QL(R0, G0RPL0(S0, G0L(S0) α //X0)))

= (ΦPL(S, GL(S) α //X0), QL(R, G0RΦPL(S, GL(S) α //X0)))

= Φ0(PL(S, GL(S) α //X0), QL(R, GRPL(S, GL(S) α //X0)))

= Φ0(PH((S, R), PL(S, GL(S) α //X0)))

= Φ0P((S, R), GLH(S, R) α //X0)

The first step is merely that H0 is a projection; the second is the definition ofP0 as the Put of the composite lens whose Get is G0LH0; the third is the definition of PH0 (see Proposition 2); the fourth uses R0 = R and the hypothesis stated just before the equations; the fifth follows since Φ commutes with GR and G0R and the definition of Φ0; the sixth is the definition ofPH (see Proposition 2); the last is the definition ofP as the Put of the composite lens whose Get isGLH.

To establish the second equation, suppose Φ0(S, R) = (S0, R0), whenceR=R0and Φ(S) =S0, and so because Φ satisfies conditions (E), we have

PR0(S0, G0R(S0) β //Y0) = ΦPR(S, GR(S) β //Y0)

and since GR(S) = G0RΦ(S) = G0R(S0), the right hand side can be written as ΦPR(S, G0R(S0) β //Y0). We calculate

Q0((S0, R0), FRK0(S0, R0) γ //Z0) = PK0((S0, R0), QR(R0, FR(R0) γ //Z0))

= (PR0(S0, FLQR(R0, FR(R0) γ //Z0)), QR(R0, FR(R0) γ //Z0)) Before continuing the calculation, we simplify by definingβ by (G0R(S0) β //Y0) =FLQR(R0, FR(R0) γ //Z0) = FLQR(R, FR(R) γ //Z0) after noting thatG0R(S0) is the domain ofFLQR(R0, FR(R0)γZ0) since theT0 pullback square commutes. Now, continuing the calculation above:

= (PR0(S0, G0R(S0) β //Y0, QR(R0, FR(R0) γ //Z0)))

= (ΦPR(S, GR(S) β //Y0, QR(R0, FR(R0) γ //Z0)))

= (ΦPR(S, G0R(S0) β //Y0, QR(R, FR(R) γ //Z0)))

= Φ0(PR(S, FLQR(R, FR(R) γ //Z0), QR(R, FR(R) γ //Z0)))

= Φ0PK((S, R), QR(R, FR(R) γ //Z0), QR(R, FR(R) γ //Z0))

= Φ0Q((S, R), FRK(S, R) γ //Z0)

The first step uses thatK0 is a projection and the definition ofQ0 as the Put of the composite lens whose Get is FR0K0 ; the second is the definition ofPK0 (see Proposition 2); the third is the definition ofβ above; the fourth uses the hypothesis stated before the equations; the fifth uses R =R0 and the note just before the equations;

the sixth uses the definitions of Φ0 andβ; the seventh is the definition ofPK (see Proposition 2); the last is the definition of Qas the Put of the composite lens whose Get isFRK.

Like Propositions 20 and 21, there is a reflected version of Proposition 23, showing that equivalent spans of d-lenses when composed on the left with another span of d-lenses are equivalent.

Références

Documents relatifs

It analyses how the copyright regime (a subsystem of the legal system) evolved over time, by scrutinizing the interdependencies between copyright law and the other

In this paper, we first validate CSEM simulations and then introduce the numerical implementations and comparison results for four deep events and two shallow events and a suite

Our main conclusion is that when testing accuracy recognition of the target embedded in (place) images, the eccentricity-dependent model – without contrast normalization and

When a pointed ∞-category satisfies the property that F p is an equivalence for every finite set K and every diagram p : K −→ C we say that C is semiadditive.. In the world of

In addition, the symmetric lenses in the image of that functor have particularly simple structure: as spans of asymmetric lenses, their left legs are the long studied and

In this paper we introduce a class of asymmetric amendment lenses called spg-lenses (stable put- get lenses) which is more general than well-behaved amendment lenses, but is

The figures in the first column are obtained from QBE simulations with the Fermi’s golden rule laser transition, the figures in the second column are obtained from QBE simulations

Durant le deuxième chapitre et dans le but de manipuler l’image de phase interférométrique, nous avons examiné une étude pour la faisabilité de traitement