Evaluating functions as processes Beniamino Accattoli Carnegie Mellon University

Accattoli (CMU)

Evaluating functions as processes

1 / 26

Functions as processes λ-calculus model of functional programming. π-calculus model for concurrency. λ-calculus can be simulated in the π-calculus (Milner, 1992). The simulation is subtle, not tight as one would expect. Here refined using: Linear logic; DeYoung-Pfenning-Toninho-Caires session types (but no types here); A novel approach to relate terms and proof nets.

Contribution: Original and simple presentation, revisiting a work by Damiano Mazza. Accattoli (CMU)

Evaluating functions as processes

2 / 26

The simulation The expected simulation: t

β

s

t

β

s

⇒ Pt

* π

Pt

Ps

Does not hold, there is a mismatch about reduction. One gets: t

β

s

⇒ Pt

* π

Q ∼ Ps

where ∼ is strong bisimulation (with respect to the environment). Accattoli (CMU)

Evaluating functions as processes

3 / 26

Improved simulation We refine λ-calculus and (head) β-reduction to a reduction ( s.t.: s

t

s

t

⇒ Pt

Pt

π

Ps

and t

s

t

⇒ ∃s s.t. Pt

π

Q

Pt

π

Q

Novelty: the translation is a strong bisimulation of reductions. Accattoli (CMU)

Evaluating functions as processes

4 / 26

Intuitions

π-calculus evaluates terms in small steps (abstract machine). Small-step evaluation ' λ-calculus + explicit substitutions (ES). λ + ES injects in linear logic (LL). Pfenning-Caires et al.: linear logic injects in the π-calculus. Schema: (λ

⊆)

λ + ES



LL



π

Here: we pull back π-reduction to λ + ES, hiding LL.

Accattoli (CMU)

Evaluating functions as processes

5 / 26

Outline

1

TERM(s and )GRAPH(s)

2

π-calculus

Accattoli (CMU)

Evaluating functions as processes

6 / 26

Explicit substitutions Refine λ-calculus with explicit substitutions: t, s, u

:=

|

x

|

λx.t

|

ts

t[x/s]

Evaluation contexts (weak head contexts): E

:=

L·M

|

|

Es

E [x/s]

Substitution contexts (or Lists of substitutions): L

:=

L·M

|

L[x/s]

Rewriting strategy (closed by evaluation contexts E ·): LLλx.tMs

(dB

LLt[x/s]M

E LxM[x/s] (ls E LsM[x/s] Accattoli (CMU)

Evaluating functions as processes

7 / 26

Example of evaluation Rewriting strategy (closed by evaluation contexts E ·): LLλx.tMs (dB LLt[x/s]M E LxM[x/s] (ls E LsM[x/s] is linear weak head reduction (Game semantics, KAM, Bohm’s theorem, Geometry of interaction). Use of contexts in rules = Distance. Example of reduction: (λx.xx)λy .yy

Accattoli (CMU)

(dB (ls (dB (ls (ls

(xx)[x/λy .yy ] ((λy .yy )x)[x/λy .yy ] ((y y )[y /x])[x/λy .yy ] ((xy )[y /x])[x/λy .yy ] (((λy .yy )y )[y /x])[x/λy .yy ] . . .

Evaluating functions as processes

8 / 26

x=

ts =

λx.s =

@

t[x/s] = t

λ x

v x

s

t

x

Γ

*

Γ

o n

t *

x

(

*

d

s

s

*

!

t

!

*

s

x

s

s

x Γ

Γ

NOTE: the hole of an evaluation context is out of all boxes. E Accattoli (CMU)

:=

L·M

|

Es

|

Evaluating functions as processes

E [x/s] 9 / 26

Multiplicative rule o n

* *

*

(

!

x *

(dB

!

x

α

α



(λx.t) u

t[x/u]

rR

*

o n

t

*

*

(

!

t

x *

(dB

u

!

u

x Accattoli (CMU)

Evaluating functions as processes

10 / 26

Distance The translation is not injective, in particular if y ∈ / fv(u): ((λx.t)u)[y /s] = (λx.t)[y /s]u = o n

* *

*

(

!

u

t y x

*

!

s

So, both ((λx.t)u)[y /s] and (λx.t)[y /s]u have a redex! Accattoli (CMU)

Evaluating functions as processes

11 / 26

More on distance

Rule at a distance: LLλx.tMs (dB LLt[x/s]M (λx.t)[·/·] . . . [·/·] u →B−distance t[x/u][·/·] . . . [·/·] Traditionally a configuration like: (λx.t)[y /v ] u is not a redex, as it is blocked by [y /v ]. Here, instead, it is a redex.

Accattoli (CMU)

Evaluating functions as processes

12 / 26

Substitution rule The substitution rule: E LxM[x/s] (ls E LsM[x/s] Corresponds to: ... *

...

d *

* x

*

!

*

!

*

*

S

(ls S

S y1 . . .yk

y1 . . .yk

Note: the substituted variable/dereliction is out of all boxes. Accattoli (CMU)

Evaluating functions as processes

13 / 26

Strong bisimulation ES at a distance and proof nets satisfy: s

t

t

s

Gt

Gs

⇒ Gt

and t

s

Gt

G0

t

⇒ ∃s s.t. Gt

G0

Idea: distance turns terms in an algebraic language for graphs. Accattoli (CMU)

Evaluating functions as processes

14 / 26

Outline

1

TERM(s and )GRAPH(s)

2

π-calculus

Accattoli (CMU)

Evaluating functions as processes

15 / 26

π-calculus Processes: P, Q, R := 0 xhy i xhy , zi νxP x(y , z).P !x(y ).P P | Q Non-blocking contexts: N := L · M N | Q

P |N

νxN

Structural congruence ≡: closure by NL · M of P |0≡P

P | (Q | R) ≡ (P | Q) | R

P |Q≡Q |P

νx0 ≡ 0

x∈ / fn(P) P | νxQ ≡ νx.(P | Q)

νxνyP ≡ νy νxP

Accattoli (CMU)

Evaluating functions as processes

16 / 26

π-calculus

Substitution of y to x in P is P{x/y }. The rewriting rules (closed by NL · M and ≡): xhy , zi | x(y 0 , z 0 ).P →⊗ P{y 0 /y }{z 0 /z} xhy i | !x(z).P

→!

P{z/y } | !x(z).Q

Binary communication = multiplicative cut-elimination Unary communication = exponential cut-elimination Variation on the rules due to Pfenning-Caires et al.

Accattoli (CMU)

Evaluating functions as processes

17 / 26

Milner’s translation with ES

The translation from λ + ES to π is parametrized by a name. Minor variation over Milner’s translation: JxKa Jλx.tKa JtsKa Jt[x/s]Ka

:= := := :=

xhai a(x, b).JtKb νbνx(JtKb | bhx, ai | !x(c).JsKc ) νx(JtKa | !x(b).JsKb )

x is fresh

Red names correspond to multiplicative formulas. Usual names (x,y,...) correspond to exponential formulas.

Accattoli (CMU)

Evaluating functions as processes

18 / 26

Proof nets as processes

JxKa =

JtsKa =

Jλx.sKa =

Jt[x/s]Ka = a

a *

o n

a

d

t

a x

b

t

*

*

(

!

b

x *

!

c

*

s

x

s x Γ

= xhai

s Γ

= νbνx(JtKb | bhx, ai | !x(c).JsKc )

Accattoli (CMU)

b

= a(x, b).JtKb

Evaluating functions as processes

= νx(JtKa | !x(b).JsKb )

19 / 26

Term reductions to process reductions Lemma (action on contexts) JE L · MKa = NLJ·Ka0 M

Proof. Straightforward induction on E L · M.

Theorem (Strong simulation) 1 2

t (dB s implies JtKa ⇒⊗ ≡ JsKa . t (ls s implies JtKa ⇒! ≡ JsKa .

Proof. By induction on t (dB s and t (ls s, using the lemma. Accattoli (CMU)

Evaluating functions as processes

20 / 26

Converse relation and distance

Distance for π ⇒ simpler converse relation. The traditional rewriting rules (closed by NL · M and ≡): xhy , zi | x(y 0 , z 0 ).P →⊗ P{y 0 /y }{z 0 /z} xhy i | !x(z).P

→!

P{z/y } | !x(z).Q

The rewriting rules at a distance (closed by N 0 L · M only): NLxhy , ziM | MLx(y 0 , z 0 ).PM

7→⊗

MLNLP{y 0 /y }{z 0 /z}MM

NLxhy iM | ML!x(z).PM

7→!

MLNLP{z/y } | !x(z).PMM

Accattoli (CMU)

Evaluating functions as processes

21 / 26

Reflecting process reductions

Lemma (reflection of reduction contexts) If NLPM ⇒ NLQM then ∃E L · M s.t. JE L · MKa = NL · M.

Theorem (strong converse simulation) 1 2

If JtKa ⇒⊗ Q then exists s s.t. t (dB s and JsKa ≡ Q. If JtKa ⇒! Q then exists s s.t. t (ls s and JsKa ≡ Q.

Accattoli (CMU)

Evaluating functions as processes

22 / 26

Improved simulation Summing up we obtain: s

t

s

t

⇒ JtKa

JtKa

π

JsKa

and t

s

t

⇒ ∃s s.t. JtKa Accattoli (CMU)

π

Q

JtKa Evaluating functions as processes

π

Q

23 / 26

Call-by-value

The same approach can be applied to the call-by-value λ-calculus. There is a CBV translation of λ-calculus in linear logic. I obtained a calculus strongly bisimilar to CBV proof nets [LSFA’12]. One gets exactly the same strong bisimulation. A notion of CBV linear weak head reduction, which is new.

Accattoli (CMU)

Evaluating functions as processes

24 / 26

Conclusions

Distance = rewriting rules via contexts = Term rewriting matching graph rewriting. General technique, developed for ES, working also for π. Distance provides a simple and elegant re-understanding of λ ,→ π. Catching also the call-by-value case. Unification of λ + ES, linear logic, π-calculus (session types).

Accattoli (CMU)

Evaluating functions as processes

25 / 26

THANKS!

Accattoli (CMU)

Evaluating functions as processes

26 / 26

Evaluating functions as processes

λ-calculus model of functional programming. π-calculus model for concurrency. λ-calculus can be simulated in the π-calculus (Milner, 1992). The simulation is subtle, not tight as one would expect. Here refined using: Linear logic;. DeYoung-Pfenning-Toninho-Caires session types (but no types here);. A novel approach to ...

275KB Sizes 0 Downloads 179 Views

Recommend Documents

Evaluating functions as processes - Semantic Scholar
simultaneously on paper and on a computer screen. ...... By definition of the translation x /∈ fv(v s) and so by Lemma 10 x /∈ fn({|v |}b)∪fn({|s|}z). Consequently ...

Evaluating functions as processes - Semantic Scholar
the call-by-value case, introducing a call-by-value analogous of linear weak .... in the same way as head reduction in λ-calculus [3]—is linear head reduction, ...

Evaluating Functions notes.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Evaluating ...

Lower Functions of Empirical Processes and Brownian Sheets M.A. ...
M.A. Lifshits and Z. Shi. We give a complete characterization of the lower functions for the two-parameter Brownian sheet and for the uniform empirical process.

Evaluating Nancy.pdf
arrived at the door of the Red House, and saw Mr. Godfrey Cass ready. to lift her from the pillion. She wished her sister Priscilla had come up. at the same time ...

Evaluating Nancy.pdf
... sir, I don't mean to say what's ill-natured at all," said Nancy,. looking distractingly prim and pretty. "When gentlemen have so many. pleasures, one dance can ...

Evaluating Trotsky.pdf
Page 1 of 2 ... Page 2 of 2. Evaluating Trotsky.pdf. Evaluating Trotsky.pdf. Open. Extract. Open with. Sign In. Details. Comments. General Info. Type. Dimensions.

Functions and Equations in Two Variables Functions ...
z = f(x, y). Example:ааEvaluate the function for f(4,ан3). f(x, y) = x. 2. + 4y or ... necessary to solve an equation for a variable. ... Pg 486аа585 x 5, 100, 101, 103.

Firebird/InterBase - Date functions
Number of days in month ... get Day of Week by ISO standard, use: .... Because IB5 does not support EXTRACT function, we can just test whether February 29th ...

Perceptual Reward Functions - GitHub
expected discounted cumulative reward an agent will receive after ... Domains. Task Descriptors. Figure 3: Task Descriptors. From left to right: Breakout TG, ...