On the reduction of the type-free computational -calculus Ugo - - PowerPoint PPT Presentation

on the reduction of the type free computational calculus
SMART_READER_LITE
LIVE PREVIEW

On the reduction of the type-free computational -calculus Ugo - - PowerPoint PPT Presentation

Introduction On the reduction of the type-free computational -calculus Ugo deLiguoro,Riccardo Treglia University of Turin IWC 2020 30/06/2020 Ugo deLiguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. -Calc.


slide-1
SLIDE 1

Introduction

On the reduction of the type-free computational λ-calculus

Ugo de’Liguoro,Riccardo Treglia

University of Turin

IWC 2020 30/06/2020

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 1 / 18

slide-2
SLIDE 2

Introduction

Overview

Moggi Computational Monad Calculus Reduction relation Contexts Confluence Factorization Syntax Semantics via Wadler 1s definition Intersection type assignment Subject convertibility Monadic Interpretation D8 model Soundness and Completeness via filter model Computational λ ´ calculus We study a notion of reduction and prove it is confluent and factorizes; also we relate our calculus to the original work by Moggi.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 1 / 18

slide-3
SLIDE 3

Introduction

Computational Monads (after Wadler)

A monad is a triple pT , unit, ‹q Types D is the type of values; TD is the type of computations (with effects) over D. Operators unitD : D Ñ TD (Haskell: return); ‹D,E : TD Ñ pD Ñ TEq Ñ TE (Haskell: ąą“). Axioms punit dq ‹ f “ f d a ‹ unit “ a pa ‹ f q ‹ g “ a ‹ λ λ d.pf d ‹ gq

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 2 / 18

slide-4
SLIDE 4

Calculus

Untyped computational λ-calculus: λu

c We consider Moggi’s call-by-value reflexive object: D “ D Ñ TD hence there are two types, D and TD, and two kinds of terms: Val : V , W ::“ x | λx.M (values) Com : L, M, N ::“ unit V | M ‹ V (computations) having types: x : D $ x : D x : D $ M : TD $ λx.M : D Ñ TD “ D $ V : D $ unit V : TD $ M : TD $ V : D “ D Ñ TD $ M ‹ V : TD

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 3 / 18

slide-5
SLIDE 5

Calculus

Reduction

Orienting monad axioms we get Ý Ñ Ď Com ˆ Com as the compatible closure of: βc unit V ‹ pλx.Mq Ý Ñ MrV {xs id M ‹ λx.unit x Ý Ñ M ass pL ‹ λx.Mq ‹ λy.N Ý Ñ L ‹ λx.pM ‹ λy.Nq for x R FV pNq where MrV {xs denotes the capture avoiding substitution of V for all free

  • ccurrences of x in M.

To have extensionality we add: pηcq unit λx.punit x ‹ V q Ý Ñ unit V if x R FV pV q

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 4 / 18

slide-6
SLIDE 6

wrt Moggi’s calculus

λu

c versus type free λc: translation let is definable: let x “ M in N ” M ‹ λx.N No primitive functional application but pλx.MqV ” punit V q ‹ pλx.Mq VM ” M ‹ V MN ” M ‹ λz.pN ‹ zq for some fresh z By this we retrieve ordinary call-by-value reduction rule: pβvq pλx.MqV ” punit V q ‹ pλx.Mq Ý Ñβc MrV {xs

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 5 / 18

slide-7
SLIDE 7

wrt Moggi’s calculus

λu

c versus type free λc: translation let is definable: let x “ M in N ” M ‹ λx.N No primitive functional application but pλx.MqV ” punit V q ‹ pλx.Mq VM ” M ‹ V MN ” M ‹ λz.pN ‹ zq for some fresh z Bonus track: shuffling calculus V ppλx.LqNq ÞÑσ3 pλx.VLqN that translated pN ‹ λx.Lq ‹ V ÞÑσ3 N ‹ λx.pL ‹ V q and pN ‹ λx.Lq ‹ V ­ÞÑass N ‹ λx.pL ‹ V q if V is a variable

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 5 / 18

slide-8
SLIDE 8

wrt Moggi’s calculus

λu

c versus type free λc: mutual interpretation Theorem There exists an interpretation z¨{ from λC into λu

c that preserves reductions.

There exists an interpretation x¨y from λu

c into λC that preserves the

convertibility relation. The reduction relation λC is confluent. This has been shown by Makoto Hamana, Polymorphic Rewrite Rules: Confluence, Type Inference, and Instance Validation, 2018. It is done by checking critical pair using his tool.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 6 / 18

slide-9
SLIDE 9

Confluence

Confluence

M N ✛ ˚ L ˚ ✲ DP ✛ ˚ ˚ ✲ Reduction in λu

c has three basic rules whose left-hand sides may overlap (not

  • rthogonal).

We split the proof in three steps: 1+2. proving confluence of βc Y id and ass separately,

  • 3. eventually combining by means of the commutativity of these relations.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 7 / 18

slide-10
SLIDE 10

Confluence

Confluence

M N ✛ ˚ L ˚ ✲ DP ✛ ˚ ˚ ✲ Reduction in λu

c has three basic rules whose left-hand sides may overlap (not

  • rthogonal).

We split the proof in three steps: 1+2. proving confluence of βc Y id and ass separately,

  • 3. eventually combining by means of the commutativity of these relations.

Adopted strategy: call-by-need calculi with the let construct (see [2, 6]) variant of call-by-value λ-calculus in [5],

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 7 / 18

slide-11
SLIDE 11

Confluence

Ý Ñβc,id confluence

Define the following relation ˝ Ý Ñ, as in the book [7] ch. 10. Definition The relation ˝ Ý Ñ Ď Term ˆ Term is inductively defined by:

1

x ˝ Ý Ñ x

2

M ˝ Ý Ñ N ñ λx.M ˝ Ý Ñ λx.N

3

V ˝ Ý Ñ V 1 ñ unit V ˝ Ý Ñ unit V 1

4

M ˝ Ý Ñ M1 and V ˝ Ý Ñ V 1 ñ M ‹ V ˝ Ý Ñ M1 ‹ V 1

5

M ˝ Ý Ñ M1 and V ˝ Ý Ñ V 1 ñ unit V ‹ λx.M ˝ Ý Ñ M1rV 1{xs

6

M ˝ Ý Ñ M1 ñ M ‹ λx.unit x ˝ Ý Ñ M1

Lemma (Substitutivity lemma) For M, M1 P Com and V , V 1 P Val and every variable x, if M ˝ Ý Ñ M1 and V ˝ Ý Ñ V 1, then MrV {xs ˝ Ý Ñ M1rV 1{xs.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 8 / 18

slide-12
SLIDE 12

Confluence

Ý Ñβc,id confluence

Define the following relation ˝ Ý Ñ, as in the book [7] ch. 10. Definition The relation ˝ Ý Ñ Ď Term ˆ Term is inductively defined by:

1

x ˝ Ý Ñ x

2

M ˝ Ý Ñ N ñ λx.M ˝ Ý Ñ λx.N

3

V ˝ Ý Ñ V 1 ñ unit V ˝ Ý Ñ unit V 1

4

M ˝ Ý Ñ M1 and V ˝ Ý Ñ V 1 ñ M ‹ V ˝ Ý Ñ M1 ‹ V 1

5

M ˝ Ý Ñ M1 and V ˝ Ý Ñ V 1 ñ unit V ‹ λx.M ˝ Ý Ñ M1rV 1{xs

6

M ˝ Ý Ñ M1 ñ M ‹ λx.unit x ˝ Ý Ñ M1

Lemma (Substitutivity lemma) For M, M1 P Com and V , V 1 P Val and every variable x, if M ˝ Ý Ñ M1 and V ˝ Ý Ñ V 1, then MrV {xs ˝ Ý Ñ M1rV 1{xs. Ý Ñβc,id Ď ˝ Ý Ñ Ď

˚

Ý Ñβc,id

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 8 / 18

slide-13
SLIDE 13

Confluence

Ý Ñβc,id confluence

The next step in the proof is to show that the relation ˝ Ý Ñ satisfies the triangle property TP: P Q ✛ DP˚ ❄ ✲ TP implies the diamond property P N ✛ L ✲ DP1 ✛ ✲ In fact, if TP holds then we can take P1 ” P˚ in DP, since the latter only depends on P. We then define P˚ in terms of P as defining an adapted version of Takahashi translation.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 9 / 18

slide-14
SLIDE 14

Confluence

Ý Ñβc,id confluence

The next step in the proof is to show that the relation ˝ Ý Ñ satisfies the triangle property TP: P Q ✛ DP˚ ❄ ✲ TP implies the diamond property P N ✛ L ✲ DP1 ✛ ✲ In fact, if TP holds then we can take P1 ” P˚ in DP, since the latter only depends on P. We then define P˚ in terms of P as defining an adapted version of Takahashi translation. Lemma For all P, Q P Term, if P ˝ Ý Ñ Q then Q ˝ Ý Ñ P˚, namely ˝ Ý Ñ satisfies TP.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 9 / 18

slide-15
SLIDE 15

Confluence

Ý Ñβc,id confluence

The next step in the proof is to show that the relation ˝ Ý Ñ satisfies the triangle property TP: P Q ✛ DP˚ ❄ ✲ TP implies the diamond property P N ✛ L ✲ DP1 ✛ ✲ In fact, if TP holds then we can take P1 ” P˚ in DP, since the latter only depends on P. We then define P˚ in terms of P as defining an adapted version of Takahashi translation. Proposition Ý Ñβc,id is confluent.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 9 / 18

slide-16
SLIDE 16

Confluence

ass confluence

To prove confluence of ass, we use Newman Lemma (see [4], Prop. 3.1.24). A notion of reduction R is weakly Church-Rosser, shortly WCR, if M N ✛ L ✲ DP ✛ ˚ ˚ ✲ Lemma The notion of reduction ass is WCR.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 10 / 18

slide-17
SLIDE 17

Confluence

ass confluence

Recall that a notion of reduction R is strongly normalizing, shortly SN, if there exists no infinite reduction M Ý ÑR M1 Ý ÑR M2 Ý ÑR ¨ ¨ ¨ out of any M P Com. Lemma The notion of reduction ass is SN.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 11 / 18

slide-18
SLIDE 18

Confluence

ass confluence

Recall that a notion of reduction R is strongly normalizing, shortly SN, if there exists no infinite reduction M Ý ÑR M1 Ý ÑR M2 Ý ÑR ¨ ¨ ¨ out of any M P Com. Lemma The notion of reduction ass is SN. Proof idea Given M P Com. Let’s decorate each

  • ccurrence of ‹ in M with a natural

number. Define ‹i left to ‹j in M iff DpL ‹j V q subterm of M ‹i occurs in L 7M def “ | tpxi, xjq | xi left to xju | It’s easy to see that 7M ą 7N if M Ý Ñass N ‹2 ‹1 N λx L V ‹2 ‹1 N λx L V ass

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 11 / 18

slide-19
SLIDE 19

Confluence

ass confluence

Corollary The notion of reduction ass is CR. Proof. By the previous lemma and by Newman Lemma, stating that a notion of reduction which is WCR and SN is CR.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 12 / 18

slide-20
SLIDE 20

Confluence

Ý Ñβc,id and Ý Ñass commute

The following definitions are from [3], Def. 2.7.9. Relations Ý Ñ1 and Ý Ñ2 strongly commute if, for all M, N, L: M N ✛ 1 L 2 ✲ DP ✛ 1 ˚ 2 “ ✲ where

Ý Ñ2 is Ý Ñ2 Y “, namely at most one reduction step. Lemma Reductions Ý Ñβc,id and Ý Ñass strongly commute, then commute.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 13 / 18

slide-21
SLIDE 21

Confluence

Complete proof recap

# Ý Ñβc,id Ď ˝ Ý ÑĎ

˚

Ý Ñβc,id ˝ Ý Ñ has TP ass is WCR ass is SN

Newman lemma

ass is CR

Parallel reduction Takahashi traslation

βc Y id is CR βc Y id strongly commutes with ass βc Y id and ass commute βc Y id Y ass is CR

Hindley ´ Rosen lemma

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 14 / 18

slide-22
SLIDE 22

Factorization

Factorization

An abstract reduction system pTerm, Ý Ñq factorizes via Ý Ñe, Ý Ñe if Ý Ñ “ Ý Ñe Y Ý Ñe and for all M, N P Term, M

˚

Ý Ñ N implies that there exists L P Term such that M

˚

Ý Ñe L

˚

Ý Ñe N. We abbreviate the last condition by M

˚

Ý Ñe ¨

˚

Ý Ñe N.

Factorized reduction example M ” ppunit λy.unit yq ‹ λw.punit λx.unit xqq ‹ λz.unit z Ý Ñass unit λy.unit y ‹ λw.punit λx.unit x ‹ λz.unit zq Ý Ñβc unit λy.unit y ‹ λw.punit λz.unit zq Ý Ñβc unit λx.unit x M ” ppunit λy.unit yq ‹ λw.punit λx.unit xqq ‹ λz.unit z Ý Ñβc punit λx.unit x ‹ λz.unit zq Ý Ñβc unit λx.unit x

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 15 / 18

slide-23
SLIDE 23

Factorization

Essential vs. Inessential Contexts

Take Ý Ñ “ Ý ÑλC Construct the relations Ý Ñe, Ý Ñe, called the essential and inessential in [1], by closing ÞÑλC under two sorts of contexts: Inessential contexts: E ::“ x¨Cy | unit λx.E | M ‹ λx.E | E ‹ V Essential contexts: E ::“ x¨Cy | E ‹ V where the hole x¨Cy can be filled by terms in Com only. Then Ý Ñe and Ý Ñe are the least relations including ÞÑλC such that for all M, N P Com: M ÞÑλC N ù ñ ExMy Ý Ñe ExNy and M ÞÑλC N ù ñ ExMy Ý Ñe ExNy We highlight that relations Ý Ñe and Ý Ñe are actually not disjoint, as essential steps are also inessential.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 16 / 18

slide-24
SLIDE 24

Factorization

Techniques in between

One of the strengths of the method in [1] is the fact that it does not rely on the DP of the parallel reduction ñλC but on the substitutivity property of an indexed refined

n´1

ù ù ñλC

Definition (Indexed parallel reduction) The relation n ù ñ Ď Term ˆ Term is inductively defined by: 1 x ù ñ x 2 M n ù ñ N ñ λx.M n ù ñ λx.N 3 V n ù ñ V 1 ñ unit V n ù ñ unit V 1 4 M n ù ñ M1 and V m ù ñ V 1 ñ M ‹ V n`m ù ù ù ñ M1 ‹ V 1 5 M n ù ñ M1 and V m ù ñ V 1 ñ unit V ‹ λx.M n`|M1|x ¨m`1 ù ù ù ù ù ù ù ù ù ù ù ñ M1rV 1{xs 6 M n ù ñ M1 ñ M ‹ λx.unit x n ù ñ M1 7 L n ù ñ L1 and M m ù ñ M1 and N p ù ñ N1 ñ pL ‹ λx.Mq ‹ λy.N n`m`p ù ù ù ù ù ù ñ L1 ‹ λx.pM1 ‹ λy.N1q

and of another auxiliary relations ñe, roughly the parallel reduction built over Ý Ñe

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 17 / 18

slide-25
SLIDE 25

Factorization

Factorization proof

Proposition (λC Macro-step system)

1

Merge: if M ñe ¨ Ý Ñe M1 then M ñλC M1

2

Indexed split: if M

n

ù ñ M1, then M ñe M1, or n ą 0 and M Ý Ñe ¨

n´1

ù ù ñ M1

3

Split: If M ñλC M1, then M

˚

Ý Ñe ¨ ñe M1. Then pTerm, Ý Ñe Y Ý Ñeq is a macro-step system with respect to ñλC and ñe.

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 18 / 18

slide-26
SLIDE 26

Factorization

Factorization proof

Proposition (λC Macro-step system)

1

Merge: if M ñe ¨ Ý Ñe M1 then M ñλC M1

2

Indexed split: if M

n

ù ñ M1, then M ñe M1, or n ą 0 and M Ý Ñe ¨

n´1

ù ù ñ M1

3

Split: If M ñλC M1, then M

˚

Ý Ñe ¨ ñe M1. Then pTerm, Ý Ñe Y Ý Ñeq is a macro-step system with respect to ñλC and ñe. By Split and Merge ñλCĎ

˚

Ý Ñe ¨ ñe ñe ¨ Ý ÑeĎ

˚

Ý Ñe ¨ ñe By construction ñλCĎ

˚

Ý ÑλC ñeĎ

˚

Ý Ñe We have pÝ Ñe Y Ý Ñeq˚ Ď

˚

Ý Ñe ¨ ñ˚

e Ď ˚

Ý Ñe ¨

˚

Ý Ñe

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 18 / 18

slide-27
SLIDE 27

Factorization

Factorization proof

Proposition (λC Macro-step system)

1

Merge: if M ñe ¨ Ý Ñe M1 then M ñλC M1

2

Indexed split: if M

n

ù ñ M1, then M ñe M1, or n ą 0 and M Ý Ñe ¨

n´1

ù ù ñ M1

3

Split: If M ñλC M1, then M

˚

Ý Ñe ¨ ñe M1. Then pTerm, Ý Ñe Y Ý Ñeq is a macro-step system with respect to ñλC and ñe. Every Macro-step system satisfies factorization: Theorem (Factorization) The reduction system pTerm, Ý ÑλCq factorizes via Ý Ñe, Ý Ñe M

˚

Ý ÑλC M1 ñ M

˚

Ý Ñe ¨

˚

Ý Ñe M1

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 18 / 18

slide-28
SLIDE 28

Factorization

Factorization proof

Proposition (λC Macro-step system)

1

Merge: if M ñe ¨ Ý Ñe M1 then M ñλC M1

2

Indexed split: if M

n

ù ñ M1, then M ñe M1, or n ą 0 and M Ý Ñe ¨

n´1

ù ù ñ M1

3

Split: If M ñλC M1, then M

˚

Ý Ñe ¨ ñe M1. Then pTerm, Ý Ñe Y Ý Ñeq is a macro-step system with respect to ñλC and ñe. Every Macro-step system satisfies factorization: Theorem (Factorization) The reduction system pTerm, Ý ÑλCq factorizes via Ý Ñe, Ý Ñe M

˚

Ý ÑλC M1 ñ M

˚

Ý Ñe ¨

˚

Ý Ñe M1 Thanks

Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 18 / 18

slide-29
SLIDE 29

Factorization Beniamino Accattoli, Claudia Faggian, and Giulio Guerrieri. Factorization and normalization, essentially. In APLAS 2019: Programming Languages and Systems, volume 11893 of Lecture Notes in Computer Science, page 159–180. Springer Verlag, 12 2019. Zena M. Ariola, Matthias Felleisen, John Maraist, Martin Odersky, and Philip Wadler. The call-by-need lambda calculus. In Ron K. Cytron and Peter Lee, editors, Conference Record of POPL’95: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, USA, January 23-25, 1995, pages 233–246. ACM Press, 1995. Franz Baader and Tobias Nipkow. Term rewriting and all that. Cambridge University Press, 1998.

  • H. Barendregt.

The Lambda Calculus: its Syntax and Semantics. North-Holland, Amsterdam, revised edition, 1984. Alberto Carraro and Giulio Guerrieri. A semantical and operational account of call-by-value solvability. In Anca Muscholl, editor, Foundations of Software Science and Computation Structures - 17th International Conference, FOSSACS 2014, volume 8412 of Lecture Notes in Computer Science, pages 103–118. Springer, 2014. John Maraist, Martin Odersky, David N. Turner, and Philip Wadler. Call-by-name, call-by-value, call-by-need and the linear lambda calculus.

  • Theor. Comput. Sci., 228(1-2):175–210, 1999.

Terese. Term Rewriting Systems, volume 55 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 2003. Ugo de’Liguoro,Riccardo Treglia (University of Turin) On the reduction of Comp. λ-Calc. IWC 2020 18 / 18