Open Call-by-Value Beniamino Accattoli1 1 2

Giulio Guerrieri2

´ INRIA, LIX, Ecole Polytechnique

I2M, Aix-Marseille Universit´ e & Dipartimento di Matematica e Fisica, Universit` a Roma Tre

APLAS 2016

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

1 / 39

Call-by-Value

Plotkin’s Call-by-Value (CbV) λ-Calculus models: Programming Languages such as Ocaml or Standard ML; Proof assitants such as Coq. The two settings rely on different hypotheses.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

2 / 39

Flavors of Call-by-Value

Programming Languages rely on Closed CbV, that is: Weak Evaluation, i.e. function bodies are not evaluated; Closed Terms. Proof assitants rely on Strong CbV, that is: Strong Evaluation, i.e. function bodies are evaluated; Open Terms.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

3 / 39

Closed vs Strong CbV

Closed CbV is canonical and much simpler than Strong CbV. 2 Problems: Strong CbV 6= Closed CbV iterated into function bodies; No canonical presentation of Strong CbV.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

4 / 39

Open CbV

Open CbV is halfway Closed and Strong CbV: Weak Evaluation (as in Closed CbV); Open Terms (as in Strong CbV). Open terms ⇒ Open CbV can be iterated into function bodies. Then, Strong CbV = Iterated Open CbV. No canonical presentation of Open CbV, but many equivalent ones.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

5 / 39

Open CbV—Results We compare 4 presentations of Open CbV arising in different contexts: Abstract Machines; Linear Logic Proof Nets; Denotational Semantics; Sequent Calculus. We prove them equivalent with respect to termination. We establish precise quantitative relationships, relating the cost models. Summing Up: many presentations defining the same framework, Open CbV.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

6 / 39

Outline 1

Closed CbV

2

Open CbV 0: Naive Open CbV

3

Open CbV 1: The Fireball Calculus

4

Open CbV 2: The Value Substitution Calculus

5

Open CbV 3: The Shuffling Calculus

6

Open CbV 4: The Value Sequent Calculus

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

7 / 39

Plotkin’s Closed CbV Language: Terms Values

t, u, s v

:= :=

v x

| |

tu λx.t

Weak evaluation contexts: E

:=

h · i | Et

| tE

Small-step Evaluation: Rule at Top Level (λx.t)v 7→βv t{x v }

B. Accattoli, G.Guerrieri

Contextual closure E hti →βv E hui iff t 7→βv u

Open CBV

APLAS 2016

8 / 39

Harmony

Closed CbV harmony property: A closed term t is a →βv -normal forms iff t is a value. Harmony = Internal completeness wrt unconstrained β-reduction. Closed CbV never gets stuck: Every β-redex eventually becomes a βv -redex, unless evaluation diverges.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

9 / 39

Time Cost Model

The study of cost models for λ-calculi is a delicate subject. In Closed CbV the number of βv -steps is a reasonable time cost model. Reasonable = polynomially related to Turing machines. Roughly, one can count 1 for every βv -step. Result first proved by Blelloch and Greiner (1996).

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

10 / 39

Outline 1

Closed CbV

2

Open CbV 0: Naive Open CbV

3

Open CbV 1: The Fireball Calculus

4

Open CbV 2: The Value Substitution Calculus

5

Open CbV 3: The Shuffling Calculus

6

Open CbV 4: The Value Sequent Calculus

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

11 / 39

Adding Open Terms Naively

Open terms break harmony. They introduce stuck β-redexes. Consider t := (λx.u)(yz). t is stuck, it will never reduce to a value nor diverge.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

12 / 39

Adding Open Terms Naively

Stuck β-redexes provide prematures βv -normal forms, e.g. t := (λy .δ)(zz)δ

u := δ((λy .δ)(zz))

where δ := λx.xx

t and u should behave as δδ, i.e. they should diverge: for semantical reasons (empty denotational semantics) for logical reasons (evaluation into linear logic proof-nets) ⇒ Open terms impact on termination and observational equivalences.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

13 / 39

Improving CbV From the start it was clear that something is wrong with CbV. Already Plotkin noted that CPS is sound but not complete for CbV. Many proposals for a better CbV in the literature. Moggi (1989), Sabry & Felleisen (1993), Sabry & Wadler (1997), Maraist et al. (1999), Curien & Herbelin (2000), Dychoff & Lengrand (2007), Herbelin & Zimmermann (2009), ...

They all focus on Strong CbV. We consider 4 representative cases, but on Open CbV.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

14 / 39

Outline 1

Closed CbV

2

Open CbV 0: Naive Open CbV

3

Open CbV 1: The Fireball Calculus

4

Open CbV 2: The Value Substitution Calculus

5

Open CbV 3: The Shuffling Calculus

6

Open CbV 4: The Value Sequent Calculus

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

15 / 39

Fireball Calculus Statically: values are generalized to Fireballs. Dynamically: Call-by-Value ⇒ Call-by-Fireball. History: The Fireball Calculus λfire was introduced as a technical tool. (Paolini and Ronchi della Rocca 1999)

Rediscovered to improve the implementation of Coq. (Gr´ egoire and Leroy 2002)

Rediscovered (and named) to study cost models for CbV. (Accattoli and Sacerdoti Coen 2015)

Fireball is a pun on fire-able term.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

16 / 39

Fireball Calculus Language: Terms Values Fireballs

t, u, s v f

:= := :=

v x v

| | |

tu λx.t xf 1 . . . f n | {z }

n≥1

inert terms i

Weak evaluation contexts (exactly as before): E

:=

h · i | Et

| tE

Small-step Call-by-Fireball Evaluation: Rule at Top Level (λx.t)f 7→βf t{x f }

B. Accattoli, G.Guerrieri

Contextual closure E hti →βf E hui iff t 7→βf u

Open CBV

APLAS 2016

17 / 39

Properties of Fireballs 1

Open Harmony: a term t is a →βf -normal forms iff t is a fireball.

2

Conservative Extension of Closed CbV: if t is closed then t →βv u iff t →βf u.

3

Reasonable Cost Model (Accattoli and Sacerdoti Coen 2015): The number of →βf steps is a reasonable cost model. B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

18 / 39

Properties of Fireballs

1

The calculus is strongly confluent (diamond property).

2

Fireballs remove stuck β-redexes:

3

t := (λy .δ)(zz)δ

→βf

δδ

→βf

...

u := δ((λy .δ)(zz))

→βf

δδ

→βf

...

Problem: not confluent in its strong version.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

19 / 39

Outline 1

Closed CbV

2

Open CbV 0: Naive Open CbV

3

Open CbV 1: The Fireball Calculus

4

Open CbV 2: The Value Substitution Calculus

5

Open CbV 3: The Shuffling Calculus

6

Open CbV 4: The Value Sequent Calculus

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

20 / 39

The Value Substitution Calculus

The Value Substitution Calculus λvsub was introduced by Accattoli and Paolini. (2012) It is a λ-calculus with explicit substitutions. Modern approach to explicit substitutions, called at a distance. Grounded in linear logic.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

21 / 39

Value Substitution Calculus Language: t, u, s

:=

x

|

λx.t

|

|

tu

t[x u]

Evaluation contexts and Lists of substitutions contexts: :=

h·i

|

Et

L :=

h·i

|

L[x t]

E

| tE

| E [x t]

| t[x E ]

Rewriting rules (closed by evaluation contexts E h · i): Lhλx.tiu

→m

Lht[x u]i

exponential t[x Lhv i]

→e

Lht{x v }i

multiplicative

Corresponding to principal (or key) cut-elimination cases. B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

22 / 39

Value Substitution Calculus vs Stuck β-redexes Lists of substitutions contexts: L :=

h·i

|

L[x t]

Rewriting rules: Lhλx.tiu

→m

Lht[x u]i

exponential t[x Lhv i]

→e

Lht{x v }i

multiplicative

Example: (λy .δ)(zz)δ

→m

δ[y zz]δ

→m

(xx)[x δ][y zz] →e

(δδ)[y zz] . . .

(Remember δ := λx.xx). B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

23 / 39

Value Substitution Calculus—Key Properties

1

Elegant and simple rewriting theory: Strongly confluent; The two evaluation rules commute and terminate (separately);

2

Isomorphic to linear logic proof nets.

3

Moggi’s equational theory is contained in the one of λvsub .

4

Our termination equivalences are all proved using λvsub .

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

24 / 39

Fireball and Value Substitutins Termination equivalence: A λ-term t terminates in λfire iff t terminates in λvsub . Moreover: evaluation takes the same number of →βf and →m steps. ⇒ the cost model transfer from λfire to λvsub . The result is trickier than it seems: multiplicative

Lhλx.tiu

→m

Lht[x u]i

Fireball β

(λx.t)f

→βf

t{x f }

→βf requires arguments to be fireballs while →m does not!

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

25 / 39

Outline 1

Closed CbV

2

Open CbV 0: Naive Open CbV

3

Open CbV 1: The Fireball Calculus

4

Open CbV 2: The Value Substitution Calculus

5

Open CbV 3: The Shuffling Calculus

6

Open CbV 4: The Value Sequent Calculus

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

26 / 39

The Shuffling Calculus

The Shuffling Calculus λshuf was introduced by Carraro ad Guerrieri in (2014). It solves the mismatch between denotational semantics and Naive Open CbV. It refines Plotkin’s calculus with rules shuffling constructors. The shuffling rules are CbV variants of Regnier’s σ-rules (for call-by-name).

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

27 / 39

The Shuffling Calculus Language: t, u, s

:=

x

|

λx.t

|

tu

Balanced Evaluation contexts: B ::= h·i | tB | Bt | (λx.B)t Rewriting rules (closed by balanced evaluation contexts Bh · i):

B. Accattoli, G.Guerrieri

CbV β

(λx.t)v

→βv[

t{x v }

Shuffling 1

((λx.t)u)s

→σ1[

(λx.ts)u

Shuffling 3

v ((λx.s)u)

→σ3[

(λx.v s)u

Open CBV

APLAS 2016

28 / 39

Shuffling Calculus Moves Stuck β-redexes Balanced Evaluation contexts: B ::= h·i | tB | Bt | (λx.B)t Rewriting rules: CbV β

(λx.t)v

→βv[

t{x v }

Shuffling 1

((λx.t)u)s

→σ1[

(λx.ts)u

Example: stuck β-redexes are moved by shuffling rules: (λy .δ)(zz)δ

B. Accattoli, G.Guerrieri

→σ1[

(λy .δδ)(zz) →βv[

Open CBV

(λy .δδ)(zz) →βv[ . . .

APLAS 2016

29 / 39

Shuffling Calculus Key Properties

Carraro and Guerrieri show that λshuf is adequate wrt denotational semantics. Denotational semantics = relational semantics induced by linear logic. Adequacy: a term t terminates iff its interpretation is non-empty.

λshuf is not strongly confluent but SN and WN coincide.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

30 / 39

Shuffling vs Value Substitutions

We show how to simulate λshuf in λvsub , obtaining termination equivalence. Quantitatively: the number of →βv[ steps coincide with the number of →e steps. (λx.t)v

→βv[

t{x v }

exponential t[x Lhv i]

→e

Lht{x v }i

CbV β

This result does not allow to transfer the cost model. Termination equivalence ⇒ adequacy transfers to all incarnations of Open CbV.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

31 / 39

Outline 1

Closed CbV

2

Open CbV 0: Naive Open CbV

3

Open CbV 1: The Fireball Calculus

4

Open CbV 2: The Value Substitution Calculus

5

Open CbV 3: The Shuffling Calculus

6

Open CbV 4: The Value Sequent Calculus

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

32 / 39

The Value Sequent Calculus

The Value Sequent Calculus λvseq is a term syntax for sequent calculus. It is a fragment of Curien and Herbelin’s λµ˜ µ. ¯ µ (the CbV variant of λµ˜ Precisely, it is the intuitionistic restriction of λ˜ µ). Key idea: changing the applicative structure of λ-terms. Sequence of applications are looked at from the head value.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

33 / 39

The Value Sequent Calculus

Language: Commands Values Environments

c v e

::= hv | ei ::= x | λx.c ::=  | µ ˜x.c | v ·e

Rewriting rules: Sequent β

hλx.c | v ·ei

→λ¯

hv | (˜ µx.c)@ei

µ ˜-rule

hv | µ ˜x.ci

→µ˜

c{x v }

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

34 / 39

Value Sequent Calculus—Key Properties

Strongly confluent. No need of contextual rewriting rules (rules at a distance). No need of shuffling rules. Drawback: drastic change of syntax.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

35 / 39

Sequent Calculus vs Value Substitution

λvseq is isomorphic to a sub-language of λvsub . The kernel λvsubk of λvsubk is obtained by restricting the application: t, u, s

:=

x

|

λx.t

|

tv

|

t[x u]

Everything else is unchanged. This can be seen as the language of administrivative normal forms of λvsub .

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

36 / 39

Sequent Calculus vs Value Substitution

Termination equivalence of λvsub and λvseq is proved in 2 steps: 1

Showing that λvsub is termination equivalent to its kernel λvsubk ;

2

Showing that the kernel λvsubk is isomorphic to λvseq .

The number of →m steps is preserved (becoming →λ¯ steps). ⇒ the cost model transfers to the value sequent calculus λvseq .

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

37 / 39

Conclusions

4 calculi arising from different perspectives. All termination equivalent. They can be seen as different incarnations of Open CbV. The cost model is stable in 3 out of 4. Adequacy of denotational semantics. Linear logic foundation. Sequent calculus interpretation.

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

38 / 39

THANKS!

B. Accattoli, G.Guerrieri

Open CBV

APLAS 2016

39 / 39

Open Call-by-Value

Plotkin's Call-by-Value (CbV) λ-Calculus models: Programming Languages such as Ocaml or Standard ML;. Proof assitants such as Coq. The two settings rely ...

200KB Sizes 4 Downloads 158 Views

Recommend Documents

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Web Site: http://www.commack-umc.org ..... and drizzle to host a campfire where they had something most homeless ... One of our best selling items is Jewelry.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
will present the program "How Are We. Raced", to ... now home and will be going to Florida for a couple of ... Island Ducks Game, another good time as usual.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Web Site: http://www.commack-umc.org ... may be difficult, even confusing in your own particular life. ... design or drawing that is a visual reminder of the time.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Oct 5, 2008 - Emails: [email protected] [email protected]. CELEBRATING 225 YEARS OF CHRISTIAN SERVICE IN COMMACK. 1783-2008. Rev. ..... Please send cards & good wishes to Phyllis at her new address: c/o ...

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Nov 9, 2006 - Pastor's E-Mail: [email protected]. Rev. Richard C. ... memorial service for Judi in a church in. Columbia ... The list is long of all the things they gave;. Our veterans ... Our veterans—the very best on earth. By Joanna ...

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Email: [email protected]. Pastor's E-Mail: [email protected]. Rev. Richard C. Mills, Pastor (631) 499-4770. November 2005. Open Hearts Open Minds Open Doors .... there are only nine Trustees and it would be impossible for us to do our job wit

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Jun 16, 2007 - Pastor's E-Mail: [email protected]. Rev. Richard C. Mills, Pastor (631) 499-4770. June 2007. Open Hearts .... we will do our best to respond. We wish you all a happy and blessed summer. Anne Tammaro & Gail ... The UMW hosted a cof

Open Hearts Open Minds Open Doors - Commack United Methodist ...
all, I would like to express my deepest gratitude to ... Thank you all again for all your love and support! .... relish dish and assorted deserts, coffee tea and apple.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
At 6:00pm, the 14 members of BSA. Troop 125 arrived, looking great in their uniforms. Joan and Tricia Nehlsen,. Harriet Neuberth, Karen Mallgraf, Tracy.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Emails: [email protected] ... CELEBRATING 225 YEARS OF CHRISTIAN SERVICE IN COMMACK. 1783-2008 ... God is good and it feels like a good gift from God to ... their birth months for this greetings list. ... Everything will be free.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Training; Brazil. Youth Training and Human Rights;. Brazil ... the Confirmation Service on Sunday,. June 4 th ... puppets), Craft Helpers and Games. Leaders as ...

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Oct 5, 2008 - career in the service of the Lord. I recall, gratefully, the warm welcome extended to the bride I brought with me in 1944, with whom I have spent ...

Open Hearts, Open Minds, Open Doors - Commack United Methodist ...
May 20, 2006 - Northport, a Northport Opera Company soprano sang three liturgical .... Apple Bank for Savings in Commack and assistant manager Nancy ...

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Pastor's E-Mail: [email protected]. Rev. ... how many good works are left undone because they were never started. God has called you to his service, it is .... that free item for our food box. .... Everyone needs this list to live by…pass.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Dec 9, 2007 - Pastor's E-Mail: [email protected]. Rev. .... You are invited to add your old or favorite family .... http://www.iGive.com/html/refer.cfm?m.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Jan 1, 2006 - The theme for 2006 is “Preserving. Property; Serving People” and the ... participate! The wearing of your heritage/native dress will add to the.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
it a priority, it all too often falls behind when my schedule is uneven or ... I claimed that a church where folks, all ... Lynda, we will share fellowship in an APPLE.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
May 18, 2008 - Web Site: http://www.commack-umc.org. Emails: [email protected] ... I said yes, but all that I saw and heard was good. I .... Hosting. May 3 rd. Special LI East District Conference. 8:30 am-1:30 pm – Lay Speaker Awards.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Jun 16, 2007 - say good-by to the people called United. Methodists in Commack. It seems that the past nine years has flown by. It seems like yesterday that I began my ministry among you and now it is ending. As we move through the seasons of our live

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Nov 22, 2008 - CELEBRATING 225 YEARS OF CHRISTIAN SERVICE IN COMMACK. 1783-2008. Rev. ... everyday, “Dear God, please help my mom to be a good pastor!” With this prayer .... computer detective work. THRIFT SHOPPE.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Web Site: http://www.commack-umc.org. Email: [email protected]. Pastor's E-Mail: [email protected]. Rev. Dr. John E. Carrington, Pastor (631) ...

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Jun 28, 2008 - CELEBRATING 225 YEARS OF CHRISTIAN SERVICE IN COMMACK. 1783-2008 ... Church. It was one of the best wedding ceremonies and.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Pastor's E-Mail: [email protected]. Rev. ... A merry heart doeth good like a ... The Youth Group is going to host a .... We can only help if you let us know.

Open Hearts Open Minds Open Doors - Commack United Methodist ...
Make sure you add the big dash of love, or the ... continue the Veteran's Day theme. All the kitchen ... Add the fresh fruit and vegetables from the altar together ...