• 検索結果がありません。

Memoryful Geometry of Interaction

N/A
N/A
Protected

Academic year: 2022

シェア "Memoryful Geometry of Interaction"

Copied!
10
0
0

読み込み中.... (全文を見る)

全文

(1)

Memoryful Geometry of Interaction

From Coalgebraic Components to Algebraic Effects

Naohiko Hoshino

RIMS, Kyoto University [email protected]

Koko Muroya Ichiro Hasuo

Dept. Computer Science, University of Tokyo [email protected] [email protected]

Abstract

Girard’sGeometry of Interaction (GoI)is interaction based seman- tics of linear logic proofs and, via suitable translations, of func- tional programs in general. Its mathematical cleanness identifies essential structures in computation; moreover its use as a compila- tion technique from programs to state machines—“GoI implemen- tation,” so to speak—has been worked out by Mackie, Ghica and others. In this paper, we develop Abramsky’s idea ofresumption based GoIsystematically into a generic framework that accounts for computational effects (nondeterminism, probability, exception, global states, interactive I/O, etc.). The framework is categorical:

Plotkin & Power’s algebraic operations provide an interface to computational effects; the framework is built on the categorical ax- iomatization of GoI by Abramsky, Haghverdi and Scott; and, by use of the coalgebraic formalization ofcomponent calculus, we de- scribe explicit construction of state machines as interpretations of functional programs. The resulting interpretation is shown to be sound with respect to equations between algebraic operations, as well as to Moggi’s equations for the computational lambda calcu- lus. We illustrate the construction by concrete examples.

Categories and Subject Descriptors D.3 [Formal Definitions and Theory]: Semantics; F.3 [Semantics of Programming Languages]:

Algebraic approaches to semantics General Terms Theory

Keywords Geometry of interaction, monad, algebraic effect

1. Introduction

Geometry of Interaction (GoI) is introduced by Girard [10] as semantics of proofs—i.e. programs, under the Curry-Howard correspondence—for the study of dynamics and invariants of the cut elimination process (i.e. program execution). Girard’s original presentation of GoI is in the language ofC-algebras; Mackie’s alternative presentation [25] as token machines initiated another important application of GoI, namely as acompilation technique.

There GoI provides translation of programs into state machines;

and the machines’ execution results are invariant under cut elimi- nation. Dynamics in such machines can be understood as a math-

Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

CSL-LICS 2014, July 14–18, 2014, Vienna, Austria.

Copyright c2014 ACM 978-1-4503-2886-9. . . $15.00.

http://dx.doi.org/10.1145/2603088.2603124

ematical counterpart of control flow in program execution, and in this way, GoI connects mathematics (denotational semantics), pro- gram evaluation (operational semantics) and state based computa- tion (low-level languages/implementations). Applications of GoI are widespread: implementation of (imperative) functional pro- gramming languages [8, 9, 25]; relationship to Krivine abstract machines [7] and to defunctionalization [30]; optimal graph reduc- tion for the lambda calculus [11]; and the design of a functional programming language for sublinear space [6].

Categorical GoI

This remarkable level of integration in GoI—of operational and denotational/structural semantics—is further exemplified by its categorical axiomatics (categorical GoI) developed by Abramsky, Haghverdi and Scott [2]. There a general construction is given from atraced monoidal category—together with additional constructs, altogether called aGoI situation—to acombinatory algebra. One can then apply therealizability construction (see e.g. [24]) that turns a combinatory algebra (an “untyped” model) into a categori- cal model of a typed calculus, from which one extracts realizers as concrete interpretations. The latter are sound by construction.

In a big picture, the current work is one of the attempts to instan- tiate this general methodology of categorical GoI to concrete situ- ations. Our starting point is the previous work [14] where we ex- tend the above workflow by a step prior to it. The extension comes from the following observation (a folklore result, see Lemma 4.3;

see also [18]): many traced monoidal categories arise as a Kleisli category of a monad with a suitable order structure. The resulting extended workflow is as follows.

(aSet-monadT whose Kleisli category isCppo-enriched)

Kleisli construction

7−→ (a traced monoidal category)

categorical GoI [2]

7−→ (a combinatory algebra)

realizability &

realizer extraction

7−→ (a GoI interpretation of a typed calculus) (1)

In [14] we pursued use of this extended general workflow that is parametrized byT: in order to interpret a calculus with a certain additional feature, we start with a monadTequipped with the same feature, and the generic constructions would yield a suitable GoI interpretation. In [14], specifically, we considered a calculus for quantum computation.

Effects and Resumption Based GoI

However, following this naive scenario turned out to be far from straightforward: in [14] we ended up using a complicated continu- ation monad that keeps track of all the measurement outcomes. In fact the same kind of difficulty is already with nondeterminism—

one of the most basic computational effects—as we exhibit now.

Here we shall speak on the intuitive level, using the game-theoretic

(2)

terms ofqueriesandanswersinstead of the categorical language for GoI.

Consider the call-by-value evaluation of the program

(λx:nat.x+x) (0t1) (2) where the subterm0t1returns0or1nondeterministically. Then the whole program is expected to return0or2. However, the usual GoI interpretation of (2) may return an unexpected value1, as the result of the following interaction.

1. We ask the value of the left occurrence ofxinx+x.

2. The subterm0t1answers0or1nondeterministically.

3. We ask the value of the right occurrence ofxinx+x.

4. The subterm0t1answers0or1nondeterministically.

5. We add the values of the leftxand the rightx.

The difficulty is as follows. After the first query 2), the nondeter- minism in the subterm0t1is resolved, with the subterm reduced to0or1. The second query 4) must stick to this choice; however, most instances of GoI—presented in terms ofC-algebra, token machines or categories—lack such an explicit “memory” mecha- nism. The lack of memories in GoI causes similar difficulties with other computational effects. Even more, it seems to be also the reason why additive connectives are far less trivial to interpret in GoI:additive slices—a common tool for additive connectives in GoI [23, 33]—indeed have a strong flavor of memories. In the pre- vious example (2) one may wonder if the call-by-value evaluation strategy is to blame. This is unlikely; see Remark 1.1.

The memory mechanism needed in the above example can be provided in the form of aMealy machine, or a(nondeterministic) transducer. The term0t1is now interpreted as

x0

q/0

:: oo

q/0 x0t1

q/1

//

x1

dd

q/1 (3)

where the machine can initially respond to a query q with0or 1; however, after that the machine sticks to the same choice by remembering the state by means of its internal state. For more examples of Mealy-like machines, see Section 7.

The idea of using such memories (or states) in GoI is not new.

In [1, 2], an instance of categorical GoI is given by the category ofresumptions—roughly speaking, a resumption from a setAto Bis a “stateful computation” fromAtoB; more precisely it is a suitable equivalence class (e.g. modulo bisimilarity) of transducers fromAtoB. In [2] it is also characterized as an element of a final coalgebra.

Remark 1.1. Lack of memories in effectful situations causes dif- ficulties in GoI regardless of evaluation strategies. Consider the equation(tts)u = t uts u; we expect it to hold regardless of evaluation strategies. In the GoI interpretation of(tts)u, when ureceives a query from thetpart intts, we must make sure that the response goes back tot, not tos. It is not clear how to enforce this without using memories, as one would see trying to interpret the program in (any presentation of) GoI.

Contributions—from Coalgebraic Components to Algebraic Effects

Building on Abramsky’s idea ofresumption based GoI, the current paper aims at a generic framework that yields GoI interpretations—

or ratherGoI implementations, since they are given concretely as state based transducers like in (3)—of calculi with various compu- tational effects.

More specifically: we model an effect by a monad T fol- lowing Moggi [26]; and as an syntactic interface we use alge- braic operations like t for the powerset monad P, following

Plotkin & Power [28]. Concrete interpretations are given by (state based) transducers with the same effect T, much like the non- deterministic one in (3). Assuming thatT comes with a suitable Cppostructure—many effects qualify by the slight modification of adding partiality—we show that the categoryRes(T) of T- resumptionsis traced monoidal. Then the general workflow in (1), starting from its second step, yields a GoI interpretation of a cal- culus, with transducers as realizers. The resulting interpretation is sound with respect to the algebraic axioms (e.g. associativity oft) as well as Moggi’s equations for the computational lambda calculus.

This overall procedure—from a monadTand algebraic opera- tions to a GoI interpretation in the form ofT-transducers—we wish to callmemoryful GoI, emphasizing the role of memories (“mem- ories” here are the same as “internal states”; the choice is to dis- tinguish from the global “state” monad). A novelty is the use of memories (in the form of internal states of transducers) that allows us to describe interpretations of algebraic effects in a generic yet concrete manner.

We describe the construction of transducers concretely in terms ofcoalgebraic component calculus. Component calculi are heavily studied in software engineering (see e.g. [4]) as means of compos- ingsoftware components. A major concern there iscompositional- ity, much like in the study of process calculi (see e.g. [3]); and suc- cessful (co)algebraic techniques have been developed for the lat- ter [21, 32] as well as for the former [5]. We rely on the categorical formalization of component calculi in [5, 15] where components are coalgebras; categorical genericity is needed since our transduc- ers are parametrized by a monadT. In this way, the current work pursues “some convergence and unification”—suggested in the pa- per [1], from which we draw inspirations—of GoI and coalgebra, in program semantics.

Organization of This Paper In Section 2 we recall categorical GoI, and in Section 3 we summarize notations used in this paper.

In Section 4 we introduce component calculus on transducers; in Section 5 we quotient components by behavioral equivalence and define a traced symmetric monoidal category of sets and resump- tions. In Section 6, we sketch construction of categorical models of the computational lambda calculus based on categorical GoI with transducers; the resulting GoI interpretation is described in Sec- tion 7 with concrete examples. Due to space limitation, some proofs and argument in this paper are deferred to an extended version.

2. Categorical Geometry of Interaction

We recall a categorical formulation of GoI calledGoI situationin- troduced by Abramsky, Haghverdi and Scott and pin down the ob- stacle explained in the introduction in mathematical terms. A cru- cial notion in their categorical axiomatics is that oftraced symmet- ric monoidal category.

Definition 2.1. Atraced symmetric monoidal categoryis a sym- metric monoidal category(C,⊗,I)with a family of maps

trCA,B:C(A⊗C, B⊗C)→ C(A, B) subject to certain conditions (see [13, 20]).

Definition 2.2. LetC be a traced symmetric monoidal category.

A traced symmetric monoidal functor F: C → C is a strong symmetric monoidal functor such that

trF CF A,F B(m−1B,C◦F f◦mA,C) =F(trCA,B(f)) for allC-morphismsf:A⊗C →B⊗CwheremA,B:F A⊗ F B→F(A⊗B)is the coherence isomorphism ofF.

For example, the category (Rel,+,∅) of sets and relations forms a traced symmetric monoidal category: for aRel-morphism

(3)

f:A+C→B+C, we define the trace operatortrCA,B(f) :A→ Bby theexecution formula

trCA,B(f) =fAB∪ [

n≥0

fCB◦fCCn ◦fAC

wherefXY:X →Y is the restriction offto a relation between XandY.

Definition 2.3. AGoI situationis a list(C, U, F, φ, ψ, u, v)con- sisting of a traced symmetric monoidal category (C,⊗,I), a C- objectUand a traced symmetric monoidal functorF:C → Cwith retractionsφ:U⊗UCU:ψandu:F UCU:vtogether with the following retractions

n: ICU :n0 eA:ACF A:e0A dA:F F ACF A:d0A cA:F A⊗F ACF A:c0A wA: ICF A:wA0 such thateA,dA,cAandwAare natural inA.

The retraction(φ, ψ)and(n, n0)provides GoI interpretation of the multiplicative fragment of linear logic, and the traced symmetric monoidal functor F with the remaining retractions provide GoI interpretation of the exponential fragment of linear logic. In [2], a GoI situation is shown to yield alinear combinatory algebra; via the Girard translation, we obtain anSK-algebrathat is a model of intuitionistic logic.

Proposition 2.4. Let(C, U, F, φ, ψ, u, v)be a GoI situation. The setC(U, U)with the binary applicationa•bonC(U, U)given by

a•b= trUU,U((U⊗(u◦F b◦v))◦ψ◦a◦φ) forms anSK-algebra: there existS, K∈ C(U, U)such that

S•a•b•c=a•c•(b•c), K•a•b=a where we assume that the binary application is left associative.

On the categorical level, the obstacle in the introduction stems from the fact that the trace operatortronReldoes not preserve the union of relations:

trCA,B(f∪g) = trCA,B(f)∪trCA,B(g)∪gCB◦fAC∪ · · · (4) Failure of preservation of the trace results in failure of the equation:

(a∪b)•c6= (a•c)∪(b•c) (5) in the SK-algebra(Rel(U, U),•)constructed from a GoI situation (Rel, U, F, φ, ψ, u, v). The unexpected value returned by the pro- gram (2) appears in the extra summands in (4).

Remark 2.5. In the original definition of GoI situation in [2], the retractions(e, e0), (d, d0), (c, c0) and(w, w0)are required to be monoidal natural transformations. In this paper, we only require the injection side of retractions to be natural since this is enough to prove Proposition 2.4. This relaxation is needed in our concrete examples. We also note that since we do not requiree, d, candwto be monoidal, the retraction pairs(e, e0),(d, d0),(c, c0)and(w, w0) do not give rise to pointwise natural transformations. Pointwise naturality is required in [2] to construct weak linear category.

3. Notations

We summarize several notations used in this paper. LetSetbe the category of sets and maps (i.e. functions). We write

A−−−−→inlA,B A+B←−−−−inrA,B B, A+A−−→γA A for the injections and the codiagonal map. We write

A×B−−−→σA,B B×A, A×B+A×C−δ−−−−A,B,C→A×(B+C)

for the canonical bijections. We write>A:A→1and⊥A:∅ → Afor the unique maps. For setsIandA, we writeAIfor theI-fold product ofA.

Let(T, η, µ)be a monad onSet. In order to distinguish maps from morphisms in the Kleisli categorySetT, we writef:A→T

Bwhenfis aSetT-morphism fromAtoB. SinceT is a monad onSet, we have tensorial strengths

T A×B−st−−−A,B→T(A×B), A×T B st

0

−−−−A,B→T(A×B).

For SetT-morphisms f: A →T B and g:B →T C, a map h:A→Band a setD, we defineSetT-morphismsg◦Tf,f⊗D, D⊗fandhby

g◦Tf=µC◦T g◦f:A→T C,

f⊗D= stB,D◦(f×D) :A×D→TB×D, D⊗f= st0D,B◦(D×f) :D×A→TD×B,

hB◦h:A→TB.

The first construction is the composition of Kleisli morphisms. The second and the third constructions are thepremonoidal productsin SetT. See [29] for premonoidal category, although further famil- iarity will not be needed. ForSetT-morphismsf:A→T Band g:C→T Dsuch that

(f⊗D)◦T(A⊗g) = (B⊗g)◦T(f⊗C),

we writef ⊗gfor(f ⊗D)◦T (A⊗g); this happens whenT is acommutativemonad. The last construction(−)is the Kleisli inclusion fromSet to SetT, which lifts the (finite) coproducts (∅,+,inl,inr) ofSet to (finite) coproducts(∅,+,inl,inr) of SetT.

For legibility, we omit some obvious isomorphisms in the re- mainder of this paper. For example, we writeηA for a map from 1×AtoT(1×A)obtained by composingηAwith obvious iso- morphisms.

4. Transducers and a Component Calculus

4.1 Transducer

Transducers are “functions with internal states.”

Definition 4.1. Let T be a monad on Set. For sets A and B, aT-transducer fromA toB is a pair (X, c)consisting of a set X together with a SetT-morphism c:X ×A →T X ×B.

Apointed T-transducer is a triple (X, c, x) consisting of a T- transducer (X, c) and a map x: 1 → X. We often drop the word ‘pointed’ in ‘pointedT-transducer.’ When(X, c, x)is aT- transducer fromAtoB, we write(X, c, x) :A_B.

A T-transducer(X, c, x)is a machine consisting of a set of (internal) statesX, an initial state xand a transition rulec. For example, whenT is the identity functor, an equationc(y, a) = (y0, a0)means that if an input isaand the current internal state of the machine isy, then the machine outputsa0and the next internal state isy0. The monadT enables us to consider variouseffectsof transition rules: whenTis the powerset monad, transition rules are nondeterministic.

Requirement 4.2. Throughout the paper we require that the sym- metric monoidal category(SetT,+,∅)has a trace operatortrthat satisfies the following restricted uniformity [12]: for allh:C → D, f: A+C →T B +C and g: A+D →T B +D, if (B+h)◦Tf=g◦T(A+h), thentrCA,B(f) = trDA,B(g).

It is typical inparticle styleGoI [2] that the underlying traced symmetric monoidal category of a GoI situation is a Kleisli cate- gory with a trace operator that is uniform in the above restricted sense. The next lemma is useful for checking Requirement 4.2. We

(4)

writeCppofor the category of pointed complete posets (cpo) and continuous maps. We considerCppo-enrichment with respect to the symmetric monoidal structure given by the finite products. A Cppo-enriched cocartesian categoryCis aCppo-enriched cate- gory whose underlying category has finite coproducts such that the coproductf+g:A+B→C+Dis continuous onfandg.

Lemma 4.3. If the Kleisli categorySetTis aCppo-enriched co- cartesian category such that the bottom morphisms⊥A,B:A→T

Bsatisfy the following conditions:

f◦TA,B=⊥A,B0for allf:B→TB0

A,BTg=⊥A0,Bfor allg:A0→A then(SetT,+,∅)satisfies Requirement 4.2.

In the following examples, we can use Lemma 4.3 to check Re- quirement 4.2: we combine partiality with the standard definitions of monads so that the Kleisli categories are enriched overCppo.

Example 4.4. We give leading examples of monads that satisfy Requirement 4.2.

TheliftmonadLA= 1 +A.

The(full) powersetmonadPA = 2Aand thecountable pow- ersetmonadPωA={a⊆A|ais countable}.

Theprobabilistic subdistributionmonad DA=

d:A→[0,1]|P

a∈Ada≤1 where[0,1]is the unit interval.

Aglobal statemonadSA= (1 +A×VL)VLwhereV andL are (countable) sets.

AwritermonadT A= 1 +M×AwhereMis a monoid.

AnexceptionmonadEA= 1 +E+AwhereEis a set.

AcontinuationmonadT A=RA ⇒RwhereRis a pointed cpo andRA⇒Ris the set of continuous maps from theA-fold product ofRtoR.

AnI/OmonadT A=νD.(O×D+DI+A)whereOand Iare (countable) sets.

In the last example, we regard a set as a cpo with the discrete order, andDis the pointed cpo obtained by adding a bottom element to a cpoD. For an endo-functorFonCppo, the fixed pointνD. F D denotes a finalF-coalgebra inCppo.

4.2 A Component Calculus

We shall extend some constructions onSetT to constructions on T-transducers, namely the sequential compositionf◦Tg, the traced symmetric monoidal structure(SetT,+,∅,tr)and algebraic oper- ations onT. These extensions will organizeT-transducers into a

“traced symmetric monoidal category,” on which we will define a

“GoI situation.” Here the quotation marks (“so to speak”) are be- cause the equational axioms of traced symmetric monoidal cate- gory and GoI situation hold only up-to suitable equivalences be- tweenT-transducers. In Section 5, we will (properly) introduce a traced symmetric monoidal category and a GoI situation as quo- tients of the “traced symmetric monoidal category” and the “GoI situation” in this section.

4.2.1 Identity and Composition

For a setA, we define an “identity” onAto be the obvious one-state T-transducer

(1, ηA,id1) :A_A.

Generalizing the above “identity,” we have a constructionJ from aSetT-morphismf:A →T B to aT-transducerJ f:A _ B defined by(1, f,id1). For a mapg:A → B, we define a T- transducerJ0g:A _B as the composition ofJand the Kleisli inclusion, namely(1, g,id1).

ForT-transducers(X, c, x) :A_B and(Y, d, y) :B _C, we define a “composition”

(Y, d, y)◦(X, c, x) :A_C

to be(X×Y, e, x×y)whereeis aSetT-morphism fromX× Y ×AtoX×Y ×Cgiven by

(X⊗d)◦T(X⊗σB,Y )◦T(c⊗Y)◦T(X⊗σY,A ).

This is the sequential composition of machines:

(Y, d, y)◦(X, c, x) =

(Y,d,y)

(X,c,x) A B C

We note that this is an intuitive representation of the composition and is inept for rigorous reasoning. For example, the composition ofT-transducers fails to be associative in the strict sense.

4.2.2 Monoidal Product We define a “monoidal product”

(X, c, x)(Y, d, y) :A+C_B+D

ofT-transducers(X, c, x) :A_Band(Y, d, y) :C _Dto be (X×Y, e, x×y)where

e:X×Y ×(A+C)→TX×Y ×(B+D) is a uniqueSetT-morphism such that

e◦T(X⊗Y ⊗inlA,C) = (σY,X ⊗inlB,D)

T(Y ⊗c)◦TX,Y ⊗A), e◦T(X⊗Y ⊗inrA,C) = (X⊗Y ⊗inrB,D)◦T(X⊗d).

The “monoidal product”is the parallel composition of machines:

(X, c, x)(Y, d, y) =

(X,c,x) (Y,d,y)

. TheT-transducers(X, c, x) and (Y, d, y) behave independently following their own internal states.

4.2.3 Trace

For aT-transducer(X, c, x) :A+C _B+C, we define aT- transducerTrCA,B(X, c, x) :A_Bto be

X,trX×CX×A,X×B((δX,B,C )−1Tc◦TδX,A,C), x .

Hereδ is the bijection in Section 3 and tris the trace operator ofSetT. The operator Tr is a “trace operator” with respect to the “symmetric monoidal structure”(,∅). Checking that trace axioms are indeed “satisfied” is laborious but doable; see [15]. The

“trace operator” introduces feedback:

(X,c,x)

B C

C

A A C

B TrC

7−→A,B (X,c,x)

The internal states enable us to memorize history of feedbacking.

LetLbe the lifting monad given in Example 4.4. Then the internal states of anL-transducer

({0,1,· · ·, n}, c,0) :{0}+{0}_{0}+{0}

given by

c(i,inl{0}+{0}(0)) = (

(0,inr{0}+{0}(0)) (i < n) (0,inl{0}+{0}(0)) (i=n)

c(i,inr{0}+{0}(0)) =

((i+ 1,inr{0}+{0}(0)) (i < n) (0,inl{0}+{0}(0)) (i=n)

(5)

memorizes number of feedback loops.

4.2.4 GoI Situation

LetNbe the set of natural numbers. We define maps

κn: 1→N, $n,X:XN→XN×X, fN:AN→BN to be the constant mapκn(∗) =n, the permutation that picks the n-th element, and theN-fold product of a mapf:A→B.

For a setA, we define a setF Ato beN×A, and for aT- transducer(X, c, x) :A_B, we define aT-transducer

F(X, c, x) :F A_F B to be(XN, c0, xN)whose transition map

c0:XN×N×A→T XN×N×B is a uniqueSetT-morphism such that

c0(−, n,−) :XN×A→T XN×N×B=

(($n,X)−1⊗κn⊗B)◦T(XN⊗c)◦T($n,X ⊗A) for all natural numbersn. The constructionF, which corresponds to the linear exponential comonad of linear logic, introduces a parallel composition of countably infinite copies:

F(X, c, x) =

(X,c,x) A B

(X,c,x) A B

(X,c,x) A B

···

. Each(X, c, x)inF(X, c, x)behaves independently.

We choose bijectionsφ:N+N∼=N:ψandu:FN∼=N:vin Set, which induce the following “retractions”

J0φ:N+N∼=N:J0ψ, J0u:FN∼=N:J0v.

The list (N, F, J0φ, J0ψ, J0u, J0v) forms a “GoI situation.” In fact, we have the following “retractions”

J0N :∅CN:J(trNN,∅N))

J01×A) :ACF A:J0(>N×A) (dereliction) J0(u×A) :F F A∼=F A:J0(v×A) (digging)

J0F A:∅CF A:J(trF AF A,∅F A)) (weakening) J0(φ×A) :F A+F A∼=F A:J0(ψ×A) (contraction) where we omit several obvious “isomorphisms.”

We illustrate how these “retractions” act onT-transducers. We note that a pair ofT-transducers

(Y, d, y) :A0_^A: (Y0, d0, y0) induces a translation ofT-transducers:

(X, c, x) :A_A 7−→

(Y0, d0, y0)◦(X, c, x)◦(Y, d, y) :A0_A0. For aT-transducer(X, c, x) :A_A, dereliction pulls out the first (X, c, x)inF(X, c, x), and digging sortsF(X, c, x)into a bunch of bunches of(X, c, x)’s:

· · ·

digging dereliction 7−→

7−→ ,

. .. . .. . ..

. Weakening discardsF(X, c, x)completely, and contraction sorts F(X, c, x)into a pair ofF(X, c, x)’s:

. ..

. .. . .. . ..

contraction weakening 7−→

7−→ ∅

, .

The construction of GoI situation is essentially equivalent to those in [2]. For operational description of GoI situation, see [16].

ForT-transducers(X, c, x),(Y, d, y) :N_N, we define aT- transducer(X, c, x)•(Y, d, y) :N_Nto be

TrNN,N((N(J0u◦F(Y, d, y)◦J0v))◦J0ψ◦(X, c, x)◦J0φ).

Since(N, F, J0φ, J0ψ, J0u, J0v)is a “GoI situation,” the set of T-transducers with the binary application(−)•(−)forms an “SK- algebra” by Proposition 2.4. The binary application consists of parallel composition plus hiding:

(X, c, x)•(Y, d, y) = (X,c,x) J0ψ

J0φ

F(Y,d,y) J0u

J0v

.

Hiding means that we can not observe interaction betweenJ0u◦ F(Y, d, y)◦J0vandJ0ψ◦(X, c, x)◦J0φfrom outside.

Remark 4.5. Since we work in untyped setting (at the transducer level), it is straightforward to extend our results to model polymor- phic calculi. For modeling computational lambda calculi without polymorphism, you can choose typed approach, which will sim- plify our framework.

4.2.5 Algebraic Operation

We extend algebraic operations on the monadT to operations on T-transducers. We first recall the definition of algebraic operation, which is a mathematical interface to computational effects.

Definition 4.6 ([28]). Let T be a strong monad on a cartesian closed category(C,1,×,⇒)with countable products, and letIbe a countable set. AnI-ary algebraic operation onT is a family of C-morphisms

A,B: (A⇒T B)I →(A⇒T B)}A,B∈C

such that

αA0,B0◦cpI◦∆ = cp◦((B⇒T B0)×αA,B×(A0⇒A)) where

cp : (B⇒T B0)×(A⇒T B)×(A0⇒A)→(A0⇒T B0) is the (Kleisli) composition, and

∆ : (B⇒T B0)×(A⇒T B)I×(A0⇒A)→

((B⇒T B0)×(A⇒T B)×(A0⇒A))I is theC-morphism that is diagonal in the first argument and the third argument. We writeary(α)forI.

We defineAlgOpTto be the category of algebraic operations onT: an object is a countable set, and a morphism fromItoI0is a family ofC-morphisms

A,B: (A⇒T B)I→(A⇒T B)I0}A,B∈C

such that the family{πj A,B◦αA,B}A,B∈Cis anI-ary algebraic operation for allj ∈ I0whereπj A,B is thej-th projection from (A⇒T B)I0toA⇒T B. The categoryAlgOpThas countable products given by the disjoint sum.

Example 4.7. We give examples of algebraic operations.

A binary algebraic operation⊕onPgiven by (f⊕A,Bg)(a) =f(a)∪g(a)

where we use an infix notation. We will use the operation⊕to interpret thetconstruct in the introduction.

(6)

A binary algebraic operation⊕ponDgiven by (f⊕pA,Bg)(a) =p·f(a) + (1−p)·g(a) wherepis a real number in the unit interval[0,1].

A state monadSX= (1 +X×VL)VLfor a countable set of locationsLand a countable set ofvaluesV has the following algebraic operations

lookup`,A,B:SetS(A, B)V →SetS(A, B), updatev,`,A,B:SetS(A, B)→SetS(A, B) for each`∈Landv∈V given by

((lookup`,A,B(f))(a))(s) = (fs(`)(a))(s), ((updatev,`,A,B(f))(a))(s) = (f a)(s[v/`]) where the states[v/`]∈VLis given bys[v/`](`0) =s(`0)for

`6=`0ands[v/`](`) =v.

For other examples of algebraic operations, see [28].

For a monadTonSet, anI-ary algebraic operationαonTand a family ofT-transducers{(Xi, ci, xi) :A_B}i∈I, we define

αA,B{(Xi, ci, xi)}i∈I:A_B

to be aT-transducer(1 +Y, d,inl1,Y)consisting of a coproduct Y = `

i∈IXi inji

←−− Xi and a uniqueSetT-morphismd from (1 +Y)×Ato(1 +Y)×Bsatisfying

d◦T(inl1,Y ⊗A) =αA,(1+Y)×B{c0i}i∈I

d◦T((inr1,YTinji)⊗A) = ((inr1,YTinji)⊗B)◦Tci

wherec0iis aSetT-morphism fromAto(1 +Y)×B given by (inr1,Y ⊗B)◦T(inji ⊗B)◦TciT(xi⊗A).

Intuitively, the constructionαA,B introduces branching at the (fresh) initial state. AT-transducerαA,B{(Xi, ci, xi)}i∈Imemo- rizes the first branching information using its internal states, and af- ter the first branching, the behavior ofαA,B{(Xi, ci, xi)}i∈Iin the i-th branching follows thei-thT-transducer(Xi, ci, xi)for each i∈I. For example, the nondeterministic Mealy machine in (3) is the same as the followingP-transducer

({x0}, c0, x0)⊕{q},{0,1}({x1}, c1, x1) :{q} → {0,1}

where({xi}, ci, xi) :{q} _ {0,1}areP-transducers given by ci(xi, q) = (xi, i)fori= 0,1.

5. Behavioral Equivalence

We have presented “GoI situation” on the “traced symmetric monoidal category” of sets and T-transducers. Precisely speak- ing, they are not so in a strict sense: in order to satisfy the equa- tional axioms of traced symmetric monoidal category and GoI situation,T-transducers must be suitably quotiented. For exam- ple,(X, c, x)◦(1, ηA,id1)is not equal to(X, c, x), and we need to identify them. In this paper, we usebehavioral equivalence, a notion common in coalgebra [19]. Intuitively, two (pointed) T- transducers are behaviorally equivalent if the initial states are con- nected by a zigzag of homomorphisms.

Definition 5.1. Let(X, c, x)and(Y, d, y)beT-transducers from A to B. Ahomomorphism from (X, c, x) to (Y, d, y) is a map h:X→Y such that(h⊗B)◦Tc=d◦T(h⊗A)andh◦x=y.

Definition 5.2. ForT-transducers(X, c, x)and(Y, d, y)fromA toB, we say that(X, c, x)isbehaviorally equivalent to(Y, d, y) if there is a T-transducer (Z, e, z) :A _ B and homomor- phisms from(X, c, x)to(Z, e, z)and from(Y, d, y)to(Z, e, z).

When (X, c, x)is behaviorally equivalent to (Y, d, y), we write (X, c, x)'TA,B(Y, d, y).

A zigzag of homomorphisms can be reduced to acospanused in the previous definition, since the category ofT-transducers (identified as coalgebras) has pushouts. See [19].

Up to the behavioral equivalence, we can drop the quota- tion marks in Section 4.2. It is easy to check that constructions

◦,,Tr, F,•and αare compatible with the behavioral equiva- lence. Below we abuse notations: we use,Tr, F and•for oper- ators onT-transducers as well as those on equivalence classes of T-transducers.

We define a categoryRes(T)by

Objects are sets.

Morphisms fromAtoB are'TA,B-equivalence classes ofT- transducers fromAtoB.

For aT-transducer (X, c, x) :A _ B, we write[(X, c, x)]for theRes(T)-morphism fromAtoBrepresented by(X, c, x). The identity onAis[(1, ηA,id1)], and the composition of aRes(T)- morphism [(X, c, x)] from A to B and a Res(T)-morphism [(Y, d, y)]fromBtoCis[(Y, d, y)◦(X, c, x)].

The category Res(T) with (,∅,Tr)is a traced symmetric monoidal category. The coherence isomorphisms of the symmetric monoidal category(Set,+,∅)induce coherence isomorphisms of (Res(T),,∅). The following list

(Res(T),N, F,[J0φ],[J0ψ],[J0u],[J0v]) is a GoI situation, and(Res(T)(N,N),•)is an SK-algebra.

Theorem 5.3. Letαbe anI-ary algebraic operation onT. The operatorαis natural, andTr is distributive overαmodulo the behavioral equivalence:

For eachT-transducer(X, c, x) :B _ B0, for each family ofT-transducers{(Yi, di, yi) :A_B}i∈Iand for each map h:A0→A, it holds that

(X, c, x)◦αA,B{(Yi, di, yi)}i∈I◦J0h

'TA0,B0 αA0,B0{(X, c, x)◦(Yi, di, yi)◦J0h}i∈I.

For each family ofT-transducers{(Xi, ci, xi)}i∈IfromA+C toB+C, it holds that

TrCA,BA+C,B+C{(Xi, ci, xi)}i∈I)

'TA,BαA,B{TrCA,B(Xi, ci, xi)}i∈I. (6) Let α be an I-ary algebraic operation on T. The following behavioral equivalence is a consequence of Theorem 5.3:

αN,N{(Xi, ci, xi)}i∈I•(Y, d, y)

'TN,NαN,N{(Xi, ci, xi)•(Y, d, y)}i∈I (7) where{(Xi, ci, xi)}i∈Iand(Y, d, y)areT-transducers fromNto N. In fact, we have

αN,N{(Xi, ci, xi)}i∈I•(Y, d, y)

= TrNN,N((Z, e, z)◦J0ψ◦αN,N{(Xi, ci, xi)}i∈I◦J0φ) 'TN,NTrNN,NN,N{(Z, e, z)◦J0ψ◦(Xi, ci, xi)◦J0φ}i∈I) 'TN,NαN,N{TrNN,N((Z, e, z)◦J0ψ◦(Xi, ci, xi)◦J0φ)}i∈I

N,N{(Xi, ci, xi)•(Y, d, y)}i∈I

where we write(Z, e, z)forN(J0u◦F(Y, d, y)◦J0v). The first equivalence follows from naturality ofα, and the second equiv- alence follows from distributivity ofTr over α. The behavioral equivalences (6) and (7) are the equivalences that we wish to hold as we observed at the end of Section 2.

(7)

6. Realizability and Categorical Models

In the next section, we exemplify GoI interpretation of algebraic effects. The purpose of this section is to sketch how to derive them:

we use realizability technique. For details of arguments and proofs in this section are deferred to an extended version.

From the SK-algebra (Res(T)(N,N),•), we can utilize the realizability construction and constructs a cartesian closed category Per(T) consisting of partial equivalence relations on the SK- algebraRes(T)(N,N)and realizable maps. See [17] for a precise definition of the category of partial equivalence relations. Since the category Per(T) has countable products, we can consider algebraic operations with countable arities on monads onPer(T).

The next theorem is our main theorem, from which soundness of GoI interpretation that we are going to give follows.

Theorem 6.1. The cartesian closed categoryPer(T)has a strong monadΦand an identity-on-object countable-product-preserving faithful functor(−):AlgOpT →AlgOpΦ.

We only give a definition ofΦRforRinPer(T). Lethbe a map fromNtoNgiven by

φ◦(φ+N)◦(N+ς)◦(ψ+N)◦ς◦(φ+N)◦(N+ς)◦(ψ+N)◦ψ whereς:N+N→N+Nis the swapping. We derivedhusing combinatory completeness: the maphrepresents a termλx. λk. k x of the untyped linear lambda calculus [31]. We say that an objectR inPer(T)isclosedwhen(αN,N{ai}i∈ary(α), αN,N{a0i}i∈ary(α)) is inRfor each {(ai, a0i) ∈ R}i∈ary(α) and for each algebraic operationαonT. We defineΦRby

ΦR=\

{S∈Per(T)|R0⊆SandSis closed}

whereR0={([J0h]•a,[J0h]•a0)|(a, a0)∈R}.

By Theorem 6.1, the Kleisli categoryPer(T)Φ is a categor- ical model of the computational lambda calculus, i.e., there is a canonical interpretation of the computational lambda calculus in Per(T)Φ. The interpretation, which we callcategorical interpre- tation, is sound with respect to the standard equational theory of the computational lambda calculus [26]. We can interpret algebraic effects using algebraic operations onΦinduced by algebraic opera- tions onT via(−). For example, when we need nondeterminism, we can start from the powerset monad; when we need global states, we can start from a global state monad.

We sketch extraction of GoI interpretation—i.e. extraction of concreteT-transducers as realizers—from the categorical interpre- tation of the computational lambda calculus extended with alge- braic effects and a base typenat. For simplicity, we only consider closed terms.

1. We choose a monadT onSetthat satisfies Requirement 4.2.

2. We interpret the computational lambda calculus in the Kleisli categoryPer(T)Φas in [26, 28] where we interpret algebraic effects by algebraic operations on Φ derived from algebraic operations on T via(−), and we interpretnatby a natural number object ofPer(T).

3. The categorical interpretation of a closed termtof a typeτbi- jectively corresponds to an equivalence class of a partial equiv- alence relationΦJτKwhereJτKis the categorical interpretation of the typeτ. We choose aRes(T)-morphism onNthat repre- sents the equivalence class, and then, we extract aT-transducer LtM:N_Nthat represents theRes(T)-morphism onN. We call theT-transducerLtMGoI interpretationof a termt.

We extracted GoI interpretation so that the next theorem holds.

Theorem 6.2(Soundness). For closed termstandsof typeτ,

Ift≈s, then([LtM],[LsM])∈ΦJτK.

Ift≈sandτis the base typenat, thenLtM'TN,NLsM. where[LtM]is theRes(T)-morphism represented byLtM, and we writet ≈ s when the equation holds in the extension of the computational lambda calculus. For example, we have

v(3t5)≈v 3tv 5, 3t5t3≈3t5≈5t3 for any valuevwhen the extension of the computational lambda calculus has nondeterminism.

7. GoI Interpretation of Algebraic Effects

7.1 Memoryless GoI Interpretation

For comparison, we first present (memoryless) GoI interpretation of the following programs:

(λxy:nat.x+y)5 3 (λx:nat.x+x)3.

We writegforφ◦inlN,N,dforφ◦inrN,Nlike [23] andhn, mifor u(n, m). Fori∈N, we define a mapki:N→Nby

kihm, ni=hm, ii,

and we define mapssum,cpy:N+N+N→N+N+Nby sum(inj1(n)) = inj2(n)

sum(inj2(n)) = inj3hn,0i sum(inj3hhn, mi, li) = inj1hn, m+li

cpy(inj1hn, mi) = inj3hgn, mi cpy(inj2hn, mi) = inj3hdn, mi cpy(inj3hgn, mi) = inj1hn, mi cpy(inj3hdn, mi) = inj2hn, mi

whereinji:N→N+N+Nis thei-th injection. The mapcpyis from contraction in the GoI situation.

In (memoryless) GoI interpretation, we interpret a closed term as a partial map fromNtoN. The following diagrams present GoI interpretation of programs:

LnM=kn:N*N,

L(λxy:nat.x+y)5 3M= sum k3 k5 :N*N,

L(λx:nat.x+x)3M= sum cpy k3 :N*N.

If we inputhn, mi toL(λxy : nat.x+y)5 3M, then we get an outputhn,8ias a result of the following interactive computation betweensum,k3andk5.

1.sumreceives an inputhn, mifrom the leftmost port and out- putshn, mifrom the middle port to ask a value ofx.

2.k5answershn,5itosum.

3.sumreceives an inputhn,5ifrom the middle port and outputs hhn,5i,0ifrom the rightmost port to ask a value ofy.

4.k3answershhn,5i,3itosum.

5.sumoutputshn,8ifrom the leftmost port.

As a whole, GoI interpretation is sound with respect toβ-equality:

L(λxy : nat.x+y)5 3Mis equal tok8. Similarly, we can check that the GoI interpretationL(λx:nat.x+x)3Mis equal tok6. The interactive computation illustrates howsumandcpywork:sum computes sum, andcpycopies data.

(8)

7.2 Memoryful GoI Interpretation of Global State

GoI interpretation of the computational lambda calculus (i.e. call- by-value calculus) in Section 7.2 and Section 7.3 follows from the general scheme that we developed in this paper. In this section, we present GoI interpretation of the computational lambda calculus ex- tended with global states. We have a countably infinite setLocof location names, and each location stores a natural number. Exis- tence of global states enables us to fetch a natural number stored at a location`∈Locand update a value stored at a location`:

!`:nat, `:= 3 :unit.

We extract GoI interpretation of global states from the categorical interpretation inPer(S)ΦwhereΦis the monad in Theorem 6.1 for T = S given bySA = (1 +A×NLoc)NLoc. This is a global state monad in Example 4.4 where V = N and L = Loc. In this section and the next section, we often confuse a map f:N → N with a T-transducer J0f:N _ N and a SetT- morphismg:N→T Nwith aT-transducerJ g:N_N. GoI Interpretation of core fragment For a type judgment

Γ`t:τ (Γ =x11,· · ·, xnn), we inductively define anS-transducer

LΓ`t:τM:N⊗(n+1)_N⊗(n+1)

whereN⊗(n+1)is the(n+1)-fold tensor product ofN, i.e.,(n+1)- fold direct sum ofN. First, we give GoI interpretation of constants, variables, the term application and the lambda abstraction. We interpret natural numbers, summation and variables as follows:

h kn

w w

w0 w0

···

···

LΓ`n:natM=

h sum

w

w0 w

w0

···

···

LΓ,x:nat,y:nat`x+y:natM=

LΓ`t+s:natM=LΓ`(λxy:nat.x+y)t s:natM

w w0

w w0

w w0

w w0

h ···

···

···

i−1

···

···

···

Lx11,· · ·,xnn`xiiM=

wherew0:N→S∅andw:∅ →SNare uniqueSetS-morphisms, andh:N+N→N+Nisψ◦h◦φ. Herehis from Section 6, and wandw0are from weakening of the GoI situation in Section 4.2.4.

The combinatorhcorresponds to the unit of the monadΦ.

ForΓ`t:τ ⇒σandΓ`s:τ, we defineLΓ`t s:σMby

φ ψ

φ

ψ e

e0 φ ψ

c

c0 c

c0

LΓ`t:τ⇒σM LΓ`s:τM

···

···

···

···

LΓ`t s:σM=

where we writee foru◦(κ1×N),e0 for(>N ×N)◦v, cfor u◦(φ×N)◦(v+v)andc0for(u+u)◦(ψ×N)◦v. Here we omit some obvious bijections likeN×(N+N) ∼=N×N+N×N. TheseS-transducers are from dereliction and contraction of the GoI situation given in Section 4.2.4. We note that the component cpyconsists ofcandc0.

ForΓ,x:τ`t:σ, we defineLΓ`λx:τ.t:τ⇒σMby

d

d0

d

d0 h

φ

ψ

···

···

···

···

LΓ,x:τ`t:σM

LΓ`λx:τ.t:τ⇒σM=

whered and d0 are S-transducers fromN to N given by d = u◦(u×N)◦F v◦vandd0=u◦F u◦(v×N)◦v. They are from digging of the GoI situation in Section 4.2.4. The dashed line box is an application of the “strong monoidal”Fgiven in Section 4.2.4 followed by composition of the following isomorphism

F(N⊗ · · · ⊗N)−→= FN⊗ · · · ⊗FNu⊗···⊗u−→ N⊗ · · · ⊗N.

GoI interpretation of algebraic effects LetPer(T)-objects L andN be countably infinite coproducts of terminal object1. The algebraic operations in Example 4.7 induce algebraic operations onΦ, which induce the followingPer(S)Φ-morphisms

drf :L→ΦN asg :L×N→Φ1

calledgeneric effectsin [28]. Interpretation of dereferencing!`and assignment`:=nare derived fromdrfandasgrespectively. For simplicity, we give GoI interpretation of!`and`:=nfor a fixed location`and a fixed valuen.

We interpret− `!`:natby anS-transducer drf`= ({x`, x1, x2,· · · }, c, x`) :N_N

where theSetS-morphismcon{x`, x1, x2,· · · } ×Nis given by (c(x`, n))(s) = (xs(`),Ls(`)M(n), s),

(c(xm, n))(s) = (xm,LmM(n), s).

Initially, theS-transducerdrf`looks up the global statesand be- haves as anS-transducerLs(`)M. At the same time, theS-transducer drf`stores the values(`)locally using its internal state. Thereafter, drf`looks up its internal state: if an internal state isxn, thendrf`

behaves followingLnMwithout referring to global states.

We interpret− ``:=n:unitby anS-transducer asg`,n= ({xrun, xdone}, c0, xrun) :N_N

where theSetS-morphismc0on{xrun, xdone} ×Nis given by (c0(xrun, m))(s) = (xdone,L1M(m), s[n/`]) (c0(xdone, m))(s) = (xdone,L1M(m), s).

Initially,({xrun, xdone}, c0, xrun)updates a global state, and there- after,({xrun, xdone}, c0, xrun)does nothing. We note thatL1M in the right hand side can be any GoI interpretation of a constant.

For example, the GoI interpretation of the following program Q= (λx:nat.x+ (`:=3);x) (!`) :nat

(9)

wheret;sis an abbreviation of(λx:unit.s)tis

LQM=

φ

φ

ψ ψ

ψ ψ

ψ

φ

φ φ

φ ψ

φ

drf` h sum h cpy asg`,3 w0

ψ w

. Here we simplified the canonically derived GoI interpretation. For example, sinceφis the inverse ofψ, we can apply the following reduction to GoI interpretation:

φ ψ 7−→ .

These diagrams represent the identity onN+N, and the reduction does not affect the execution result of GoI interpretation. Correct- ness of the simplification can be checked by the realizability inter- pretation. Automatic simplification is future work.

For an inputddhn, miand a global statessuch thats(`) = 2, theS-transducer behaves as follows:

1.drf`refers to the global statesand memorizes the values(`) = 2by means of its internal state.

2.asg`,3assigns3to`changing its internal state toxdone. 3.sumasks a value of the right occurrence ofxinx+x.

4.cpypasses the query fromsumtodrf`.

5.drf`answers2to the query following its internal state. In this step,drf`does not refer to the global states[3/`].

6.cpypasses the answer fromdrf`tosum.

7.sumasks a value of the left occurrence ofxinx+x.

8.cpypasses the query fromsumtodrf`.

9.drf`answers2to the query following its internal state. In this step,drf`does not refer to the global states[3/`].

10.cpypasses the answer fromdrf`tosum.

11.sumoutputs4 = 2 + 2.

We note that without internal states,drf` can not but refer to a global state at 5) and 9), which results in a wrong output. We only sketched computation process for lack of space. For example, we omit some access toasg`,3.

As a whole, theS-transducer

L(λx:nat.x+ (`:=3);x) (!`)M:N_N is behaviorally equivalent to anS-transducer

({x`, x1, x2,· · · }, d, x`) :N_N where theSetS-morphism

d:{x`, x1, x2,· · · } ×N→ {x`, x1, x2,· · · } ×N is given by

(d(x`, n))(s) = (xs(`),Ls(`) +s(`)M(n), s[3/`]), (d(xm, n))(s) = (xm,Lm+mM(n), s).

We can observe that the GoI interpretation of the following program (λx:nat.(`:=3); (x+x)) (!`) :nat

is also behaviorally equivalent to({x`, x1, x2,· · · }, d, x`).

Remark 7.1. Some readers may notice symmetries in diagrams in this paper: the top half of diagrams are mirror images of the bottom half of diagrams. This phenomenon stems fromInt-construction in the GoI workflow [2, 20] and is also observed in [22].

7.3 Memoryful GoI Interpretation of Nondeterminism In this section, we consider nondeterminism. We can extract GoI interpretation for nondeterminism from the categorical interpreta- tion inPer(P)ΦwhereΦis the monad in Theorem 6.1 forT=P.

We interpret the computational lambda calculus as in Section 7.2.

Interpretation of the nondeterministic choice operatortis derived from the algebraic operation⊕onΦ.

We give two examples of GoI interpretation. The first one is GoI interpretation of the nondeterministic choice3t5. The GoI interpretationL− ` 3t5 : natM:N _ Nis a P-transducer L3M⊕N,NL5M= ({x3t5, x3, x5}, c, x3t5)given by

c(x3t5, n) ={(x3,L3M(n)),(x5,L5M(n))}

c(x3, n) ={(x3,L3M(n))}

c(x5, n) ={(x5,L5M(n))}.

TheP-transducer L3M⊕N,NL5M behaves like the nondeterministic Mealy machine (3): initially, theP-transducerL3M⊕N,NL5Mnonde- terministically choosesL3MorL5M; thereafterL3M⊕N,NL5Msticks to the same choice referring to its internal state.

We next consider the following program:

P= (λx:nat.x+x) (3t5) :nat.

We have the following equations:

P= ((λx:nat.x+x)3)t((λx:nat.x+x)5)

= (3+3)t(5+5) =6t10.

GoI interpretation of the programPis

LPM=

ψ φ

h sum cpy

ψ

φ L3MN,NL5M

. Here we also simplified canonically derived GoI interpretation.

TheP-transducerLPMbehaves as follows:

1. We inputddhn, mi.

2.L3M⊕N,NL5M receives an input gddhn, mi, and the internal state nondeterministically changes tox3 or x5. Here we as- sume thatL3M⊕N,NL5M choosesx3. Then L3M⊕N,NL5M outputs dgddhn, mi.

3.sumreceiveshn, mifrom the leftmost input port and outputs hn, mifrom the middle port to ask a value of the right occur- rence ofxinx+x.

4.cpyreceives an inputhn, mifrom the leftmost port and outputs hgn, mifrom the rightmost port to getx.

5.L3M⊕N,NL5Mreceivesddhgn, mi. Since the internal state isx3, it answersddhgn,3i

6.cpy receives hgn,3i from the rightmost port and answers hn,3itosumvia the leftmost port.

7.sumreceiveshn,3ifrom the middle port and asks a value of the left occurrence ofxinx+xby outputtinghhn,3i,0ifrom the rightmost port.

参照

関連したドキュメント