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

記憶つき相互作用の幾何における 再帰と妥当性

N/A
N/A
Protected

Academic year: 2022

シェア "記憶つき相互作用の幾何における 再帰と妥当性"

Copied!
46
0
0

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

全文

(1)

記憶つき相互作用の幾何における 再帰と妥当性

Recursion and Adequacy in

Memoryful Geometry of Interaction

室屋 晃子

(

蓮尾研

)

(2)

memoryful GoI with recursion

概要

memoryful GoI

[Hoshino, M. & Hasuo ’14]

GoI

[Girard ’89]

コンパイラ / 高位合成 [Mackie ’95] [Ghica ’07]

暗黙的計算量理論 [Dal Lago ’06]

(3)

Geometry of Interaction (

相互作用の幾何

)

表示的

(

要素還元的

)

意味論

線形論理に対して

[Girard ’89]

関数型プログラムに対して

操作的な性質

計算の経過を表現

背景: GoI

(4)

Geometry of Interaction (

相互作用の幾何

)

表示的

(

要素還元的

)

意味論

線形論理に対して

[Girard ’89]

関数型プログラムに対して

操作的な性質

背景: GoI

トークンマシン意味論

(5)

背景:トークンマシン意味論

関数型プログラム

トークンマシン

(6)

背景:トークンマシン意味論

関数型プログラム

トークンマシン

(7)

背景:トークンマシン意味論

関数型プログラム

トークンマシン

(8)

背景:トークンマシン意味論

q

関数型プログラム

トークンマシン

(9)

背景:トークンマシン意味論

1

関数型プログラム

トークンマシン

(10)

背景:トークンマシン意味論

1

関数型プログラム

トークンマシン

(11)

背景:トークンマシン意味論

コンパイル技術への応用 [Mackie ’95] [Ghica ’01]

暗黙的計算量理論への応用 [Dal Lago ’06]

圏論による定式化 [Abramsky et al. ’02]

関数型プログラム

トークンマシン

(12)

memoryful GoI with recursion

概要

memoryful GoI

[Hoshino, M. & Hasuo ’14]

GoI

[Girard ’89]

コンパイラ / 高位合成 [Mackie ’95] [Ghica ’07]

暗黙的計算量理論 [Dal Lago ’06]

(13)

関数型プログラム + 計算副作用

メモリつきトークンマシン

背景: memoryful GoI [Hoshino, M. & Hasuo ’14]

( x. x + x) (3 t

0.1

5)

(14)

関数型プログラム + 計算副作用

メモリつきトークンマシン

背景: memoryful GoI [Hoshino, M. & Hasuo ’14]

( x. x + x) (3 t

0.1

5)

代数的副作用 [Plotkin & Power ’01]

非決定的選択

確率的選択

大域変数の参照、更新

M t N M t

p

N

update

l,v

(M )

lookup

l

(M

v1

, . . . , M

v|Val|

)

(15)

関数型プログラム + 計算副作用

メモリつきトークンマシン

背景: memoryful GoI [Hoshino, M. & Hasuo ’14]

( x. x + x) (3 t

0.1

5)

副作用つきミーリーマシン

L R

q/3 7! 0.1 q/5 7! 0.9

q/5 7! 1 q/3 7! 1

(16)

memoryful GoI with recursion

概要

memoryful GoI

[Hoshino, M. & Hasuo ’14]

GoI

[Girard ’89]

コンパイラ / 高位合成 [Mackie ’95] [Ghica ’07]

暗黙的計算量理論 [Dal Lago ’06]

(17)

関数型プログラム + 計算副作用 + 再帰

メモリつきトークンマシン

結果: memoryful GoI with recursion

(18)

関数型プログラム + 計算副作用 + 再帰

メモリつきトークンマシン

結果: memoryful GoI with recursion

(19)

関数型プログラム + 計算副作用 + 再帰

メモリつきトークンマシン

結果: memoryful GoI with recursion

Mackie style Girard style

· · ·

fix(F ) = F (F (F ( · · · )))

(20)

Prop. (Girard style as fixed point wrt. “cross connection”)

'

c

A A

N ×A

N ×A

c A A

N× A N× A

c c c . . . c

A A

N × A N × A

c c c . . .

結果: memoryful GoI with recursion

(21)

Muroya (U. Tokyo) 14

Prop. (Girard style as supremum of finite approximations)

c A

B x0

A

B x0

E

c A A

N×A N×A

c c c . . .

A A

N×A N×A

. . . ! c

A A

N×A N×A

. . . ! c

A A

N×A N×A

c . . . ! · · ·

Figure 3.5: The ω-chain of Finite Approximations Fix(i)G (X, c, x)

Proposition 3.3.6. Let (X, c, x) : A + N × A ! A + N × A be a T -transducer.

The family {Fix(i)G (X, c, x) : A ! A}iω of T -transducers forms an ω-chain Fix(0)G (X, c, x) ! Fix(1)G (X, c, x) ! · · ·

as depicted in Figure 3.5, and the T-transducer FixG(X, c, x) : A ! A satisfies the following behavioral equivalence

FixG(X, c, x) sup

iω

(Fix(i)G (X, c, x)) .

Proof. Since the family {(X, c(i)n , x) : A+N×A ! A+N×A}iω forms an ω-chain (X, c(0)n , x) ! (X, c(1)n , x) ! · · ·

and its supremum supiω(X, c(i)n , x) is given by (X, c, x), the statement is an immediate consequence of Lemma 3.3.4, namely continuity of the operators , F , Tr and "n∈N.

3.3.4 Mackie Style Fixed Point Operator FixM

Girard interprets recursion in GoI as a limit of finite approximations in [12], and the Girard style fixed point operator FixG follows his approach in the sense of Proposition 3.3.6. This approach to interpret recursion in GoI is in fact not unique. There is another one by Mackie [24], in which recursion is interpreted as proof nets with a single “box” and feedback loops. In our setting Mackie’s ap- proach corresponds to translate recursion with a single use of the countable copy operator F and the trace operator Tr, and especially without any use of countable parallel composition "n∈N. We introduce another fixed point operator FixM on T -transducers, that follows Mackie’s approach as depicted in Figure 3.3 (c), and therefore call it “Mackie style” fixed point operator.

Definition 3.3.7 (Mackie style fixed point operator FixM). For a T -transducer (X, c, x) : A + N × A ! A + N × A, the T -transducer FixM(X, c, x) : A ! A is defined to be

TrA,AA+A( (J( ˜e′∗A) " J(idA+A)) (J( ˜c′∗A) " JdA))

F (X, c, x)

(J(˜cA) " J( ˜d′∗A)) (J(˜eA) " J′∗A,A)) ) where σ is swapping defined as in Definition 3.3.2.

This Mackie style fixed point operator FixM coincides with the Girard style fixed point operator FixG, therefore both two styles of fixed point operators enjoy

is the supremum of the ω-chain

where

結果: memoryful GoI with recursion

(22)

Thm. (coincidence of Girard style & Mackie style)

Mackie style Girard style

結果: memoryful GoI with recursion

(23)

関数型プログラム + 計算副作用 + 再帰

メモリつきトークンマシン

結果: memoryful GoI with recursion

Mackie style Girard style

· · ·

(24)

Muroya (U. Tokyo) 17

関数型プログラム + 計算副作用 + 再帰

メモリつきトークンマシン

結果: memoryful GoI with recursion

メモリつき

トークンマシンの 実行結果

For a set Loc and a finite set Val, the state monad SX = (1 + ( ) ⇥ ValLoc)ValLoc supports ⌃glstate. Each operation lookupl is modeled by the |Val|-ary algebraic operation lookupl and each operation updatel,v is by the 1-ary algebraic operation updatel,v on S.

Let T be a monad that supports ⌃. We now give a translation L M of terms of L to T -transducers. It is given using depictions such as Figure 3–5. Moreover it is an extension of the translation given by the mGoI framework [16].

Definition 6.3 (translation L M). For each type judgment ` M : ⌧ where = x1 : ⌧1, . . . xm : ⌧m, we inductively define a T - transducer

L ` M : ⌧M = L ` M : M N

N

N N

N . . . N

. . . m m

:

am

i=0

N _

am

i=0

N

as in Figure 7, where labels of edges (either N or N ⇥N) are omitted for visibility.

In translation of recursion depicted in Figure 7 we implicitly use the Mackie style fixed point operator FixM . Due to Theorem 5.7 we can also use the Girard style fixed point operator FixG as depicted in Figure 8.

The Categorical Model Much like the translation of the original mGoI framework in [16], the translation L M of our framework is backed up by a categorical model (whose definition we do not give here). Our translation L M can be extracted by a categorical interpretation on the model Per 0 that is the Kleisli category of the strong monad 0 on the cartesian closed category Per. The model is a modification of the one used in the mGoI framework: the category Per is the same; and the monad 0 is modified to reflect the !-cpo structure of T -transducers. Its construction is done by combination of categorical GoI [2] and realizability techniques, as in [16]. Proposition 5.2 & 5.5 ensures that the Girard style fixed point operator FixG indeed yields a (categorical) fixed point operator in the model Per 0.

6.2 Adequacy of Translation L M

Let T be a monad that supports the algebraic signature ⌃. The statement of adequacy connects operational semantics reviewed in Section 2.2 and the translation L M extracted from denotational semantics. In order to give the statement we start with “collecting”

the execution results of terms of L via both T -transducers and effect values. In this section we restrict ourselves to closed terms of base type nat: we simply say a “term” to indicate such a term, and write LMM for L` M : natM.

For a term M, we can observe that running the T -transducer LMM: N _ N with input in the form ddhi, mi yields output in the form ddhi, ni, where i and m are arbitrary natural numbers and n corresponds to an evaluation result of the term (see Section 4.1 for the notation). Therefore we take the set T N as the collection of evaluation results, fixing a retraction enc : Valnat C N : dec such that

enc(n) = ddh0, ni dec(ddhi, ni) = n .

where ⇡X,0 N : X ⇥ N ! N is the second projection and m denotes a fixed natural number. This procedure ( ) runs a T -transducer and gathers its output. Additionally ( ) ignores the resulting internal states that record the branching history of program execution, or the history of effect occurrences during program execution. Indeed we have the equality (X, c, x) = (Y, d, y) for two behavioral equivalent T -transducers (X, c, x) ' (Y, d, y) : A _ B.

Next we define interpretation of effect values. Recall that effect values for terms are formulated as elements of the free continuous

⌃-algebra CT (Valnat) over the set Valnat. On the other hand, for each operation op 2 ⌃, the monad T has an ar(op)-ary al- gebraic operation op on it. This means that the set T N, which is isomorphic to SetT (1, N), is a continuous ⌃-algebra. Therefore we can lift the function enc : Valnat ! T N to a unique morphism J K: CT (Valnat) ! T N that is a strict continuous function pre- serving the operations specified by ⌃. When the monad T is equal to the powerset monad P, this interpretation corresponds to forget- ting branching structures of effect values (i.e. branching structures of program execution): for example two effect values (1t2)t3 and 1 t (2 t 3) are identified as a set {enc(1), enc(2), enc(3)} ✓ PN where t 2 ⌃ndet is the nondeterministic choice operation.

Now we can state adequacy of the translation L M.

Theorem 6.4 (adequacy). Any closed term M of base type nat satisfies J|M|K = LMM.

6.3 Proof of Adequacy

To prove Theorem 6.4 we introduce a language L following [25].

In this language all occurrences of recursion are restricted to finite depth. Namely L is made from the target language L, by replac- ing the term constructor rec with rec(i) for each i 2 N and by adding a constant ⌦ for each type ⌧. In the definition of the small step operational semantics, transitions

rec(i+1)(f : ! ⌧, x : ). M

! ( x : . M)[rec(i)(f : ! ⌧, x : ). M/f]

rec(0)(f : ! ⌧, x : ). M ! x : . ⌦

replace the one for rec shown in Figure 2. This excludes any infinite sequence M ! M0 ! · · · of pure transitions, hence M * no longer appears in the medium step operational semantics. Effect values are defined in the same way as L, except that we define |E[⌦ ]| to be ⌦.

On the other hand the translation L ` rec(i)(f : ! ⌧, x : ). MM is given like Figure 8 where we use the i-th approximant Fix(i)G of the Girard style fixed point operator instead of FixG.

Theorem 6.4 is a consequence of Lemma 6.5 below that states adequacy of the translation L M with respect to the language L. The proof goes as follows. For a term M of L and i 2 N, let M(i) be a term of L obtained from M by replacing all occurrences of rec with rec(i). For effect values we can prove

J|M|K = sup

i2!J|M(i)|K

in T N as in [25]. On the other hand Proposition 5.5 ensures the behavioral equivalence

LMM ' sup

i2!LM(i)M . Therefore it holds that

J|M|K = supJ|M(i)|K = sup(LM(i)M) = (supLM(i)M) = LMM .

プログラムの 評価結果

(25)

例:再帰的な確率プログラム

H TH TTH TTTH

コイントスの

結果 確率

0.4

0.4 * 0.6

2

0.4 * 0.6

3

0.4 * 0.6

4

0

1 2 3

プログラムの返り値

(26)

プログラムの評価結果

例:再帰的な確率プログラム

(27)

プログラムの評価結果

得られる

メモリつきトークンマシンの

例:再帰的な確率プログラム

(28)

例:再帰的な確率プログラム

(29)

ε, q

例:再帰的な確率プログラム

(30)

ε, q

1: T

例:再帰的な確率プログラム

(31)

⬜ , q

1: T

例:再帰的な確率プログラム

(32)

⬜ , q

1: T 2: T

例:再帰的な確率プログラム

(33)

⬜⬜ , q

1: T 2: T

例:再帰的な確率プログラム

(34)

⬜⬜ , q

1: T 2: T 3: H

例:再帰的な確率プログラム

(35)

⬜⬜⬜ , q

1: T 2: T 3: H

例:再帰的な確率プログラム

(36)

⬜⬜ , 1

1: T 2: T 3: H

例:再帰的な確率プログラム

(37)

⬜ , 2

1: T 2: T 3: H

例:再帰的な確率プログラム

(38)

1: T ε, 2

2: T 3: H

例:再帰的な確率プログラム

(39)

http://koko-m

.github.io/TtT /

可視化ツール TtT

(40)

http://koko-m

.github.io/TtT /

可視化ツール TtT

(41)

memoryful GoI with recursion

概要

memoryful GoI

[Hoshino, M. & Hasuo ’14]

GoI

[Girard ’89]

コンパイラ / 高位合成 [Mackie ’95] [Ghica ’07]

暗黙的計算量理論 [Dal Lago ’06]

(42)

関数型プログラム + 計算副作用 + 再帰

メモリつきトークンマシン

今後の課題

memoryful GoI with recursion

必要なリソース量の見積もり

状態空間

/

トークンのデータ

実行コストの削減

プログラム評価コストとの対応

(43)

論文

Naohiko Hoshino, Koko Muroya & Ichiro Hasuo, “Memoryful Geometry of Interaction: from coalgebraic components to algebraic effects.”

In Proc. of the Joint Meeting of the 23rd EACSL Annual Conference on Computer Science Logic and

the 29th Annual ACM/IEEE Symposium on Logic in Computer Science (CSL-LICS 2014), paper 52, 2014.

Koko Muroya, Naohiko Hoshino & Ichiro Hasuo, “Memoryful Geometry of Interaction II: recursion and adequacy.”

In Proc. of the 43rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL 2016), p. 748–760, 2016.

口頭発表

“Compiling effectful terms to transducers: prototype implementation of memoryful Geometry of Interaction” (preliminary report).

the 5th Workshop on Syntax and Semantics of Low-Level Languages (LOLA 2014), Vienna, Austria, 2014 7 .

25 回代数、論理、幾何と情報科学研究集会 (ALGI 25), 神奈川大学, 2014 8 .

“Memoryful Geometry of Interaction with recursion” (preliminary report).

理論計算機科学と圏論ワークショップ (CSCAT 2015), 鹿児島大学, 2015 3 .

the 6th Workshop on Syntax and Semantics of Low-Level Languages (LOLA 1015),

(44)

Muroya (U. Tokyo) 25

関数型プログラム + 計算副作用 + 再帰

メモリつきトークンマシン

結論: memoryful GoI with recursion

Mackie style Girard style

· · ·

Thm. (coincidence of Girard style & Mackie style)

For a set Loc and a finite set Val, the state monad SX = (1 + ( ) ⇥ ValLoc)ValLoc supports ⌃glstate. Each operation lookupl is modeled by the |Val|-ary algebraic operation lookupl and each operation updatel,v is by the 1-ary algebraic operation updatel,v on S.

Let T be a monad that supports ⌃. We now give a translation L M of terms of L to T -transducers. It is given using depictions such as Figure 3–5. Moreover it is an extension of the translation given by the mGoI framework [16].

Definition 6.3 (translation L M). For each type judgment ` M : ⌧ where = x1 : ⌧1, . . . xm : ⌧m, we inductively define a T - transducer

L ` M : ⌧M = L ` M : M N

N

N N

N . . . N

. . . m m

:

am

i=0

N _

am

i=0

N

as in Figure 7, where labels of edges (either N or N ⇥ N) are omitted for visibility.

In translation of recursion depicted in Figure 7 we implicitly use the Mackie style fixed point operator FixM . Due to Theorem 5.7 we can also use the Girard style fixed point operator FixG as depicted in Figure 8.

The Categorical Model Much like the translation of the original mGoI framework in [16], the translation L M of our framework is backed up by a categorical model (whose definition we do not give here). Our translation L M can be extracted by a categorical interpretation on the model Per 0 that is the Kleisli category of the strong monad 0 on the cartesian closed category Per. The model is a modification of the one used in the mGoI framework: the category Per is the same; and the monad 0 is modified to reflect the !-cpo structure of T -transducers. Its construction is done by combination of categorical GoI [2] and realizability techniques, as in [16]. Proposition 5.2 & 5.5 ensures that the Girard style fixed point operator FixG indeed yields a (categorical) fixed point operator in the model Per 0 .

6.2 Adequacy of Translation L M

Let T be a monad that supports the algebraic signature ⌃. The statement of adequacy connects operational semantics reviewed in Section 2.2 and the translation L M extracted from denotational semantics. In order to give the statement we start with “collecting”

the execution results of terms of L via both T -transducers and effect values. In this section we restrict ourselves to closed terms of base type nat: we simply say a “term” to indicate such a term, and write LMM for L` M : natM.

For a term M, we can observe that running the T -transducer LMM: N _ N with input in the form ddhi, mi yields output in the form ddhi, ni, where i and m are arbitrary natural numbers and n corresponds to an evaluation result of the term (see Section 4.1 for the notation). Therefore we take the set T N as the collection of evaluation results, fixing a retraction enc : Valnat C N : dec such that

enc(n) = ddh0, ni dec(ddhi, ni) = n .

where ⇡X,0 N : X ⇥ N ! N is the second projection and m denotes a fixed natural number. This procedure ( ) runs a T -transducer and gathers its output. Additionally ( ) ignores the resulting internal states that record the branching history of program execution, or the history of effect occurrences during program execution. Indeed we have the equality (X, c, x) = (Y, d, y) for two behavioral equivalent T -transducers (X, c, x) ' (Y, d, y) : A _ B.

Next we define interpretation of effect values. Recall that effect values for terms are formulated as elements of the free continuous

⌃-algebra CT (Valnat) over the set Valnat. On the other hand, for each operation op 2 ⌃, the monad T has an ar(op)-ary al- gebraic operation op on it. This means that the set T N, which is isomorphic to SetT (1, N), is a continuous ⌃-algebra. Therefore we can lift the function enc : Valnat ! T N to a unique morphism J K: CT (Valnat) ! T N that is a strict continuous function pre- serving the operations specified by ⌃. When the monad T is equal to the powerset monad P, this interpretation corresponds to forget- ting branching structures of effect values (i.e. branching structures of program execution): for example two effect values (1t 2)t3 and 1 t (2 t 3) are identified as a set {enc(1), enc(2), enc(3)} ✓ PN where t 2 ⌃ndet is the nondeterministic choice operation.

Now we can state adequacy of the translation L M.

Theorem 6.4 (adequacy). Any closed term M of base type nat satisfies J|M|K = LMM.

6.3 Proof of Adequacy

To prove Theorem 6.4 we introduce a language L following [25].

In this language all occurrences of recursion are restricted to finite depth. Namely L is made from the target language L, by replac- ing the term constructor rec with rec(i) for each i 2 N and by adding a constant ⌦ for each type ⌧. In the definition of the small step operational semantics, transitions

rec(i+1)(f : ! ⌧, x : ). M

! ( x : . M)[rec(i)(f : ! ⌧, x : ). M/f]

rec(0)(f : ! ⌧, x : ). M ! x : . ⌦

replace the one for rec shown in Figure 2. This excludes any infinite sequence M ! M0 ! · · · of pure transitions, hence M * no longer appears in the medium step operational semantics. Effect values are defined in the same way as L, except that we define |E[⌦]| to be ⌦.

On the other hand the translation L ` rec(i)(f : ! ⌧, x : ). MM is given like Figure 8 where we use the i-th approximant Fix(i)G of the Girard style fixed point operator instead of FixG.

Theorem 6.4 is a consequence of Lemma 6.5 below that states adequacy of the translation L M with respect to the language L. The proof goes as follows. For a term M of L and i 2 N, let M(i) be a term of L obtained from M by replacing all occurrences of rec with rec(i). For effect values we can prove

J|M|K = sup

i2!J|M(i)|K

in T N as in [25]. On the other hand Proposition 5.5 ensures the behavioral equivalence

LMM ' sup

i2!LM(i)M . Therefore it holds that

J|M|K = supJ|M(i)|K = sup(LM(i)M) = (supLM(i)M) = LMM .

可視化ツール TtT

http://koko-m.github.io/TtT/

(45)

コンパイラ / 高位合成

研究計画

計算副作用つき関数型プログラムへの GoI による意味論

確率プログラム上の ベイズ推論

プログラム評価コストの反映

(46)

参照

関連したドキュメント

Let X be a smooth projective variety defined over an algebraically closed field k of positive characteristic.. By our assumption the image of f contains

The category of (not necessarily unital) commutative von Neumann regular rings satisfies the amalgamation

Incidentally, it is worth pointing out that an infinite discrete object (such as N) cannot have a weak uniformity since a compact space cannot contain an infinite (uniformly)

It is suggested by our method that most of the quadratic algebras for all St¨ ackel equivalence classes of 3D second order quantum superintegrable systems on conformally flat

Related to this, we examine the modular theory for positive projections from a von Neumann algebra onto a Jordan image of another von Neumann alge- bra, and use such projections

“rough” kernels. For further details, we refer the reader to [21]. Here we note one particular application.. Here we consider two important results: the multiplier theorems

We study the classical invariant theory of the B´ ezoutiant R(A, B) of a pair of binary forms A, B.. We also describe a ‘generic reduc- tion formula’ which recovers B from R(A, B)

We study the theory of representations of a 2-group G in Baez-Crans 2- vector spaces over a field k of arbitrary characteristic, and the corresponding 2-vector spaces of