36
Equivalence of Algebraic λ-calculi Alejandro Díaz-Caro 1 Simon Perdrix 12 Christine Tasson 3 Benoît Valiron 1 1 LIG, Université de Grenoble 2 CNRS 3 CEA-LIST, MeASI HOR July 14th, 2010 Edinburgh

Equivalence of algebraic λ-calculi

Embed Size (px)

DESCRIPTION

Slides of the paper "Equivalence of algebraic λ-calculi" as presented at HOR2010. Edimburgh, UK. 14 July 2010.

Citation preview

Page 1: Equivalence of algebraic λ-calculi

Equivalence of Algebraic λ-calculi

Alejandro Díaz-Caro1 Simon Perdrix12

Christine Tasson3 Benoît Valiron1

1LIG, Université de Grenoble

2CNRS

3CEA-LIST, MeASI

HOR • July 14th, 2010 • Edinburgh

Page 2: Equivalence of algebraic λ-calculi

Algebraic calculi

Algebraic ≡ Module structure

(λx.yx+1

2· λx.y(yx)) λz.z

Two originsλalg −→ differential calculusλlin −→ quantum computation

Differences inthe encoding of the module structurehow the reduction rules apply

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 2 / 25

Page 3: Equivalence of algebraic λ-calculi

λalg and λlin

share the same set of terms

M,N,L ::= V | (M) N |M +N | α ·MU,V,W ::= B | α ·B | V +W | 0

B ::= x | λx.M

closed under associativity and conmutativity

M +N = N +M (M +N) + L = M + (N + L)

base term is either a variable or abstractiona value is either 0 or of the form

∑αi ·Bi ;

a general term can be anything.

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 3 / 25

Page 4: Equivalence of algebraic λ-calculi

Rules for λalgG

roup

E

α · 0 =a 0 0 +M =a Mα · (β ·M) =a (α× β) ·M 0 ·M =a 0

1 ·M =a M α · (M +N) =a α ·M + α ·N

Gro

upF α ·M + β ·M =a (α+ β) ·M

Gro

upA

(M +N) L =a (M) L+ (N) L(α ·M) N =a α · (M) N

(0) M =a 0

Gro

upB

(λx.M) N →a M [x := N ]

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 4 / 25

Page 5: Equivalence of algebraic λ-calculi

Rules for λlinG

roup

E

α · 0 →` 0 0 +M →` Mα · (β ·M) →` (α× β) ·M 0 ·M →` 0

1 ·M →` M α · (M +N) →` α ·M + α ·N

Gro

upF α ·M + β ·M →` (α+ β) ·M

α ·M +M →` (α+ 1) ·MM +M →` (1 + 1) ·M

Gro

upA

(M +N) L→` (M) L+ (N) L (M) (N + L)→` (M) N + (M) L(α ·M) N →` α · (M) N (M) α ·N →` α · (M) N

(0) M →` 0 (M) 0→` 0

Gro

upB

(λx.M) B →a M [x := B]

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 5 / 25

Page 6: Equivalence of algebraic λ-calculi

Context rules

Some common rules

M →M ′

(M) N → (M ′) N

M →M ′

M +N →M ′ +N

N → N ′

M +N →M +N ′

M →M ′

α ·M → α ·M ′

plus one additional rule for λlin

M →` M′

(V ) M →` (V ) M ′

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 6 / 25

Page 7: Equivalence of algebraic λ-calculi

Modifications to the original calculi

The most important

No reduction under lambda (à la Plotkin)

λx.M is a base term for any M

λx.(α ·M + β ·N) 6= α · λx.M + β · λx.N

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 7 / 25

Page 8: Equivalence of algebraic λ-calculi

Confluence

This system is not trivially confluent

ExampleLet Yb = (λx.(b+ (x) x)) (λx.(b+ (x) x)), then

0← Yb − Yb → Yb + b− Yb → b

Several possible solutionsType system→ strong normalisationTake scalars as positive realsRestrict some of the reduction rules

For this talk, we simply assume that confluence holds.

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 8 / 25

Page 9: Equivalence of algebraic λ-calculi

Question

Can we simulate λlin with λalg and λalg with λlin ?

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 9 / 25

Page 10: Equivalence of algebraic λ-calculi

Simulating λalg with λlinThunks

Idea: encapsulating terms M as B = λf.M . So M ≡ (B) f

(|x|)f = (x) f(|0|)f = 0

(|λx.M |)f = λx.(|M |)f(|(M) N |)f = ((|M |)f ) λz.(|N |)f(|M +N |)f = (|M |)f + (|N |)f

(|α ·M |)f = α · (|M |)f

If the encoding λalg → λlin is denoted with (|−|)f , one couldexpect the result

M →∗a N ⇒ (|M |)f →∗` (|N |)f

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 10 / 25

Page 11: Equivalence of algebraic λ-calculi

Simulating λalg with λlinThunks

Idea: encapsulating terms M as B = λf.M . So M ≡ (B) f

(|x|)f = (x) f(|0|)f = 0

(|λx.M |)f = λx.(|M |)f(|(M) N |)f = ((|M |)f ) λz.(|N |)f(|M +N |)f = (|M |)f + (|N |)f

(|α ·M |)f = α · (|M |)f

If the encoding λalg → λlin is denoted with (|−|)f , one couldexpect the result

M →∗a N ⇒ (|M |)f →∗` (|N |)f

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 10 / 25

Page 12: Equivalence of algebraic λ-calculi

Problem

Example(λx.λy.(y) x) I →a λy.(y) I,

(|(λx.λy.(y) x) I|)f = (λx.λy.((y) f) (λz.(x) f)) (λz λx.(x) f)→∗` λy.((y) f) (λz.(λz.λx.(x) f) f),

(|λy.(y) I|)f = λy.((y) f) (λz.λx.(x) f)

“Administrative” redex hidden in the first one

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 11 / 25

Page 13: Equivalence of algebraic λ-calculi

Removing administrative redexes

Adminf 0 = 0

Adminf x = x

Adminf (λf.M) f = Adminf M

Adminf (M) N = (Adminf M) Adminf N

Adminf λx.M = λx.Adminf M (x 6= f)

Adminf M +N = Adminf M + Adminf N

Adminf α ·M = α ·Adminf M

Theorem (Simulation)For any program (i.e. closed term) M , and value V ,if M →∗a V then exists a value W such that

(|M |)f →∗` W and Adminf W = Adminf (|V |)f

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 12 / 25

Page 14: Equivalence of algebraic λ-calculi

First,

M`//

≡Adminf

N

≡Adminf

M ′

LemmaIf Adminf M = Adminf M

′ and M →` N then there exists N ′

such that Adminf N = Adminf N′ and such that M ′ →∗` N ′.

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 13 / 25

Page 15: Equivalence of algebraic λ-calculi

First,

M`//

≡Adminf

N

≡Adminf

M ′`

∗// N ′

LemmaIf Adminf M = Adminf M

′ and M →` N then there exists N ′

such that Adminf N = Adminf N′ and such that M ′ →∗` N ′.

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 13 / 25

Page 16: Equivalence of algebraic λ-calculi

Then,

M

≡Adminf

W

LemmaIf W is a value and M a term such thatAdminf W = Adminf M , then there exists a value V such thatM →∗` V and Adminf W = Adminf V .

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 14 / 25

Page 17: Equivalence of algebraic λ-calculi

Then,

M

≡Adminf

`

∗''OOOOOOOOOOOOOOOOOOOOOOOOOO

W ≡Adminf V

LemmaIf W is a value and M a term such thatAdminf W = Adminf M , then there exists a value V such thatM →∗` V and Adminf W = Adminf V .

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 14 / 25

Page 18: Equivalence of algebraic λ-calculi

Finally,

M

a ��N (|N |)f

`

∗// V

LemmaFor any program (i.e. closed term) M , if M →a N and(|N |)f →∗` V for a value V, then there exists M ′ such that(|M |)f →∗` M ′ such that Adminf M

′ = Adminf V .

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 15 / 25

Page 19: Equivalence of algebraic λ-calculi

Finally,

M

a ��

(|M |)f`

∗// M ′

≡Adminf

N (|N |)f`

∗// V

LemmaFor any program (i.e. closed term) M , if M →a N and(|N |)f →∗` V for a value V, then there exists M ′ such that(|M |)f →∗` M ′ such that Adminf M

′ = Adminf V .

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 15 / 25

Page 20: Equivalence of algebraic λ-calculi

Now, we want

M a∗// V

(|M |)f (|V |)f

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 16 / 25

Page 21: Equivalence of algebraic λ-calculi

Now, we want

M a∗// V

(|M |)f

`

∗""FFFFFFFF(|V |)f

W

≡Adminf

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 16 / 25

Page 22: Equivalence of algebraic λ-calculi

Base case

V = V

(|V |)f (|V |)f

(|V |)f

==

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 17 / 25

Page 23: Equivalence of algebraic λ-calculi

Inductive case

M ′ a// M a

∗// V

(|M ′|)f (|M |)f

`

∗""EEEEEEEE(|V |)f

W

≡Adminf

Lemma 3

M′

a ��

(|M′|)f`

∗// M′′

≡Adminf

M (|M|)f`

∗// W

Lemma 2

M′′

≡Adminf

`

∗""EEEE

EEEE

EEEE

EEEE

EE

W W ′

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 18 / 25

Page 24: Equivalence of algebraic λ-calculi

Inductive case

M ′ a// M a

∗// V

(|M ′|)f

`

∗##GGGG

GGGG

G(|M |)f

`

∗""EEEEEEEE(|V |)f

M ′′ ≡Adminf W

≡Adminf

Lemma 3

M′

a ��

(|M′|)f`

∗// M′′

≡Adminf

M (|M|)f`

∗// W

Lemma 2

M′′

≡Adminf

`

∗""EEEE

EEEE

EEEE

EEEE

EE

W ≡Adminf W ′

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 18 / 25

Page 25: Equivalence of algebraic λ-calculi

Inductive case

M ′ a// M a

∗// V

(|M ′|)f

`

∗##GGGG

GGGG

G(|M |)f

`

∗""EEEEEEEE(|V |)f

M ′′

`

∗##HHHH

HHHH

H≡Adminf W

≡Adminf

W ′

≡Adminf

Lemma 3

M′

a ��

(|M′|)f`

∗// M′′

≡Adminf

M (|M|)f`

∗// W

Lemma 2

M′′

≡Adminf

`

∗""EEEE

EEEE

EEEE

EEEE

EE

W W ′

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 18 / 25

Page 26: Equivalence of algebraic λ-calculi

Simulating λlin with λalgCPS encoding

We define [|−|] : λlin → λalg

[|x|] = λf. (f) x[|0|] = 0

[|λx.M |] = λf.(f) λx.[|M |][|(M) N |] = λf.([|M |]) λg.([|N |]) λh.((g) h) f

[|α ·M |] = λf.(α · [|M |]) f[|M +N |] = λf.([|M |] + [|N |]) f

Now, given the continuation I = λx.x, if M →` V we want([|M |]) I →a W for some W related to [|V |]

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 19 / 25

Page 27: Equivalence of algebraic λ-calculi

The encoding for values

Ψ(x) = x,Ψ(0) = 0,

Ψ(λx.M) = λx.[|M |],Ψ(α · V ) = α ·Ψ(V ),

Ψ(V +W ) = Ψ(V ) + Ψ(W ).

Ψ(V ) is such that [|V |]→∗a Ψ(V ).

Theorem (Simulation)

M →∗` V ⇒ ([|M |]) λx.x→∗a Ψ(V ).

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 20 / 25

Page 28: Equivalence of algebraic λ-calculi

An auxiliary definition

Note that

([|B|]) K = (λf.(f) Ψ(B)) K →∗a (K) Ψ(B).

We define the term B : K = (K) Ψ(B).We extend this definition to other terms in somenot-so-easy way due to the algebraic properties of thelanguage.It is the main difficulty in this proof.

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 21 / 25

Page 29: Equivalence of algebraic λ-calculi

The auxiliary definition

Let (:) : λlin × λalg → λalg:

B : K = (K) Ψ(B)(M +N) : K = M : K +N : Kα ·M : K = α · (M : K)0 : K = 0(U) B : K = ((Ψ(U)) Ψ(B)) K(U) (V +W ) : K = ((U) V + (U) W ) : K(U) (α ·B) : K = α · (U) B : K(U) 0 : K = 0(U) N : K = N : λf.((Ψ(U)) f) K(M)N : K = M : λg.([|N |]) λh.((g) h) K

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 22 / 25

Page 30: Equivalence of algebraic λ-calculi

Proof

If K is a value:For all M , ([|M |]) K →∗a M : K

If M →` N then M : K →∗a N : K

If V is a value, V : K →∗a (K) Ψ(V )

If M →∗` V ,

([|M |]) (λx.x)

→∗a M : λx.x→∗a V : λx.x→∗a (λx.x) Ψ(V )→a

Ψ(V )

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25

Page 31: Equivalence of algebraic λ-calculi

Proof

If K is a value:For all M , ([|M |]) K →∗a M : K

If M →` N then M : K →∗a N : K

If V is a value, V : K →∗a (K) Ψ(V )

If M →∗` V ,

([|M |]) (λx.x) →∗a M : λx.x

→∗a V : λx.x→∗a (λx.x) Ψ(V )→a

Ψ(V )

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25

Page 32: Equivalence of algebraic λ-calculi

Proof

If K is a value:For all M , ([|M |]) K →∗a M : K

If M →` N then M : K →∗a N : K

If V is a value, V : K →∗a (K) Ψ(V )

If M →∗` V ,

([|M |]) (λx.x) →∗a M : λx.x→∗a V : λx.x

→∗a (λx.x) Ψ(V )→a

Ψ(V )

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25

Page 33: Equivalence of algebraic λ-calculi

Proof

If K is a value:For all M , ([|M |]) K →∗a M : K

If M →` N then M : K →∗a N : K

If V is a value, V : K →∗a (K) Ψ(V )

If M →∗` V ,

([|M |]) (λx.x) →∗a M : λx.x→∗a V : λx.x→∗a (λx.x) Ψ(V )

→a

Ψ(V )

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25

Page 34: Equivalence of algebraic λ-calculi

Proof

If K is a value:For all M , ([|M |]) K →∗a M : K

If M →` N then M : K →∗a N : K

If V is a value, V : K →∗a (K) Ψ(V )

If M →∗` V ,

([|M |]) (λx.x) →∗a M : λx.x→∗a V : λx.x→∗a (λx.x) Ψ(V )→a Ψ(V )

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 23 / 25

Page 35: Equivalence of algebraic λ-calculi

Future and ongoing work

In classical lambda-calculus:CPS can also be done to interpret call-by-name incall-by-value [Plotkin 75].The thunk construction can be related to CPS [Hatcliff andDanvy 96].

Can we relate to these?

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 24 / 25

Page 36: Equivalence of algebraic λ-calculi

Future and ongoing work

Other interesting questionsThe choice between equality and reduction rules seemsarbitrary.

Can we exchange them?Are the simulations still valid?

A. Díaz-Caro, S. Perdrix, C. Tasson, B. Valiron • Equivalence of Algebraic λ-calculi 25 / 25