Slides QuAND 2011

43
Confluence via strong normalisation in an algebraic λ-calculus with rewriting – Accepted in LSFA 2011. To appear in EPTCS – Pablo Buiras 1 Alejandro Díaz-Caro 2 Mauro Jaskelioff 1,3 1 Universidad Nacional de Rosario, FCEIA, Argentina 2 Université de Grenoble, LIG, France 3 CIFASIS-CONICET, Argentina Recontre QuAND July 18, 2011 Marseille, France

description

The linear-algebraic λ-calculus and the algebraic λ-calculus are untyped λ-calculi extended with arbitrary linear combinations of terms. The former presents the axioms of linear algebra in the form of a rewrite system, while the latter uses equalities. When given by rewrites, algebraic λ-calculi are not confluent unless further restrictions are added. We provide a type system for the linear-algebraic λ-calculus enforcing strong normalisation, which gives back confluence. The type system allows an interpretation in System F.

Transcript of Slides QuAND 2011

Page 1: Slides QuAND 2011

Confluence via strong normalisation in analgebraic λ-calculus with rewriting

– Accepted in LSFA 2011. To appear in EPTCS –

Pablo Buiras1 Alejandro Díaz-Caro2 Mauro Jaskelioff1,3

1Universidad Nacional de Rosario, FCEIA, Argentina

2Université de Grenoble, LIG, France

3CIFASIS-CONICET, Argentina

Recontre QuAND • July 18, 2011 • Marseille, France

Page 2: Slides QuAND 2011

M,N ::= x | λx .M | (M)N | M + N | α.M | 0

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

“Algebraic” reductions:α.M + β.M → (α + β).M,

(M)(N1 + N2) → (M)N1 + (M)N2,. . .. . .. . .

(oriented version of the axioms of vectorial spaces)

Two origins:I Differential λ-calculus: capturing linearity à la Linear Logic→ Removing the differential operator : Algebraic λ-calculus (λalg) [Vaux’09]

I Quantum computing: superposition of programs→ Linearity as in algebra: Linear-algebraic λ-calculus (λlin)

[Arrighi,Dowek’08]

2 / 15

Page 3: Slides QuAND 2011

M,N ::= x | λx .M | (M)N | M + N | α.M | 0

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

“Algebraic” reductions:α.M + β.M → (α + β).M,

(M)(N1 + N2) → (M)N1 + (M)N2,. . .. . .. . .

(oriented version of the axioms of vectorial spaces)

λalg λlinOrigin Linear Logic Quantum computing

Strategy Call-by-name Call-by-value

2 / 15

Page 4: Slides QuAND 2011

Confluence issues

YB = (λx .(B + (x)x))λx .(B + (x)x)

YB → B + YB → B + B + YB → . . .

YB + (−1).YB −→ (1− 1).YB −→∗ 0↓

B + YB + (−1).YB

↓∗B

Solution 2 (λalg):

Only positive numbers

YB + YB −→ B + YB + YB −→ B + 2.YB

↓2.YB ... and equalities

Solution 1 (λlin):α.M + β.M → (α + β).Monly if M is closed-normaland others similar restrictions

Solution 3:forbid ∞! (type system)

Objective: to forbid ∞−∞

3 / 15

Page 5: Slides QuAND 2011

Confluence issues

YB = (λx .(B + (x)x))λx .(B + (x)x)

YB → B + YB → B + B + YB → . . .

YB + (−1).YB −→ (1− 1).YB −→∗ 0↓

B + YB + (−1).YB

↓∗B

Solution 2 (λalg):

Only positive numbers

YB + YB −→ B + YB + YB −→ B + 2.YB

↓2.YB ... and equalities

Solution 1 (λlin):α.M + β.M → (α + β).Monly if M is closed-normaland others similar restrictions

Solution 3:forbid ∞! (type system)

Objective: to forbid ∞−∞

3 / 15

Page 6: Slides QuAND 2011

Confluence issues

YB = (λx .(B + (x)x))λx .(B + (x)x)

YB → B + YB → B + B + YB → . . .

YB + (−1).YB −→ (1− 1).YB −→∗ 0↓

B + YB + (−1).YB

↓∗B

Solution 2 (λalg):

Only positive numbers

YB + YB −→ B + YB + YB −→ B + 2.YB

↓2.YB ... and equalities

Solution 1 (λlin):α.M + β.M → (α + β).Monly if M is closed-normaland others similar restrictions

Solution 3:forbid ∞! (type system)

Objective: to forbid ∞−∞

3 / 15

Page 7: Slides QuAND 2011

Confluence issues

YB = (λx .(B + (x)x))λx .(B + (x)x)

YB → B + YB → B + B + YB → . . .

YB + (−1).YB −→ (1− 1).YB −→∗ 0↓

B + YB + (−1).YB

↓∗B

Solution 2 (λalg):

Only positive numbers

YB + YB −→ B + YB + YB −→ B + 2.YB

↓2.YB ... and equalities

Solution 1 (λlin):α.M + β.M → (α + β).Monly if M is closed-normaland others similar restrictions

Solution 3:forbid ∞! (type system)

Objective: to forbid ∞−∞

3 / 15

Page 8: Slides QuAND 2011

Confluence issues

YB = (λx .(B + (x)x))λx .(B + (x)x)

YB → B + YB → B + B + YB → . . .

YB + (−1).YB −→ (1− 1).YB −→∗ 0↓

B + YB + (−1).YB

↓∗B

Solution 2 (λalg):

Only positive numbersYB + YB −→ B + YB + YB −→ B + 2.YB

↓2.YB ... and equalities

Solution 1 (λlin):α.M + β.M → (α + β).Monly if M is closed-normaland others similar restrictions

Solution 3:forbid ∞! (type system)

Objective: to forbid ∞−∞

3 / 15

Page 9: Slides QuAND 2011

Confluence issues

YB = (λx .(B + (x)x))λx .(B + (x)x)

YB → B + YB → B + B + YB → . . .

YB + (−1).YB −→ (1− 1).YB −→∗ 0↓

B + YB + (−1).YB

↓∗B

Solution 2 (λalg):

Only positive numbersYB + YB −→ B + YB + YB −→ B + 2.YB

↓2.YB ... and equalities

Solution 1 (λlin):α.M + β.M → (α + β).Monly if M is closed-normaland others similar restrictions

Solution 3:forbid ∞! (type system)

Objective: to forbid ∞−∞

3 / 15

Page 10: Slides QuAND 2011

Confluence issues

YB = (λx .(B + (x)x))λx .(B + (x)x)

YB → B + YB → B + B + YB → . . .

YB + (−1).YB −→ (1− 1).YB −→∗ 0↓

B + YB + (−1).YB

↓∗B

Solution 2 (λalg):

Only positive numbersYB + YB −→ B + YB + YB −→ B + 2.YB

↓2.YB ... and equalities

Solution 1 (λlin):α.M + β.M → (α + β).Monly if M is closed-normaland others similar restrictions

Solution 3:forbid ∞! (type system)

Objective: to forbid ∞−∞

3 / 15

Page 11: Slides QuAND 2011

Possible type systems

Straightforward extension of a classic type system

Γ ` M : T Γ ` N : T+I

Γ ` M + N : T

Γ ` M : TαI

Γ ` α.M : T0I

Γ ` 0 : TPros: Cons:

I Simple I Too restrictive

Scalar type system [Arrighi, Díaz-Caro 2009]

Γ ` M : α.T Γ ` N : β.T+I

Γ ` M + N : (α + β).T

Γ ` M : TαI

Γ ` α.M : α.T0I

Γ ` 0 : 0.T

Pros: Cons:I Characterises the ’amount’

of termsI Still too restrictive

4 / 15

Page 12: Slides QuAND 2011

Possible type systems

Straightforward extension of a classic type system

Γ ` M : T Γ ` N : T+I

Γ ` M + N : T

Γ ` M : TαI

Γ ` α.M : T0I

Γ ` 0 : TPros: Cons:

I Simple I Too restrictive

Scalar type system [Arrighi, Díaz-Caro 2009]

Γ ` M : α.T Γ ` N : β.T+I

Γ ` M + N : (α + β).T

Γ ` M : TαI

Γ ` α.M : α.T0I

Γ ` 0 : 0.T

Pros: Cons:I Characterises the ’amount’

of termsI Still too restrictive

4 / 15

Page 13: Slides QuAND 2011

Possible type systemsAdditive type system [Díaz-Caro, Petit 2010]

Γ ` M : T Γ ` N : R+I

à ` M + N : T + R ������

��XXXXXXXX

Γ ` M : TαI

Γ ` α.M : α.T0I

Γ ` 0 : 0Pros: Cons:

I More versatileI Interpretation in System F

with pairs

I Defined for a fragment(no scalars!)

Vectorial type system [Arrighi, Díaz-Caro, Valiron 2011]

Γ ` M : T Γ ` N : R+I

Γ ` M + N : T + R

Γ ` M : TαI

Γ ` α.M : α.T

Γ ` M : T0I

Γ ` 0 : 0.TPros: Cons:

I Much more versatileI Good characterisation of

terms

I ComplexI Overkill (confluence!)

Idea: extend Additive

5 / 15

Page 14: Slides QuAND 2011

Possible type systemsAdditive type system [Díaz-Caro, Petit 2010]

Γ ` M : T Γ ` N : R+I

à ` M + N : T + R ������

��XXXXXXXX

Γ ` M : TαI

Γ ` α.M : α.T0I

Γ ` 0 : 0Pros: Cons:

I More versatileI Interpretation in System F

with pairs

I Defined for a fragment(no scalars!)

Vectorial type system [Arrighi, Díaz-Caro, Valiron 2011]

Γ ` M : T Γ ` N : R+I

Γ ` M + N : T + R

Γ ` M : TαI

Γ ` α.M : α.T

Γ ` M : T0I

Γ ` 0 : 0.TPros: Cons:

I Much more versatileI Good characterisation of

terms

I ComplexI Overkill (confluence!)

Idea: extend Additive

5 / 15

Page 15: Slides QuAND 2011

Possible type systemsAdditive type system [Díaz-Caro, Petit 2010]

Γ ` M : T Γ ` N : R+I

à ` M + N : T + R ������

��XXXXXXXX

Γ ` M : TαI

Γ ` α.M : α.T0I

Γ ` 0 : 0Pros: Cons:

I More versatileI Interpretation in System F

with pairs

I Defined for a fragment(no scalars!)

Vectorial type system [Arrighi, Díaz-Caro, Valiron 2011]

Γ ` M : T Γ ` N : R+I

Γ ` M + N : T + R

Γ ` M : TαI

Γ ` α.M : α.T

Γ ` M : T0I

Γ ` 0 : 0.TPros: Cons:

I Much more versatileI Good characterisation of

terms

I ComplexI Overkill (confluence!)

Idea: extend Additive

5 / 15

Page 16: Slides QuAND 2011

Idea: λCA - Extend additive

Key idea

Γ ` M : TΓ ` α.M : bαc.T= T + · · ·+ T︸ ︷︷ ︸

bαc

If ` M : T , then ` (0.9).M + (1.1).M : T

(0.9).M + (1.1).M → 2.M and ` 2.M : 2.T

Theorem (weak subject reduction)M → N, Γ ` M : T ⇒ Γ ` N : R with T � R

6 / 15

Page 17: Slides QuAND 2011

Idea: λCA - Extend additive

Key idea

Γ ` M : TΓ ` α.M : bαc.T= T + · · ·+ T︸ ︷︷ ︸

bαc

If ` M : T , then ` (0.9).M + (1.1).M : T

(0.9).M + (1.1).M → 2.M and ` 2.M : 2.T

Theorem (weak subject reduction)M → N, Γ ` M : T ⇒ Γ ` N : R with T � R

6 / 15

Page 18: Slides QuAND 2011

Idea: λCA - Extend additive

Key idea

Γ ` M : TΓ ` α.M : bαc.T= T + · · ·+ T︸ ︷︷ ︸

bαc

If ` M : T , then ` (0.9).M + (1.1).M : T

(0.9).M + (1.1).M → 2.M and ` 2.M : 2.T

Theorem (weak subject reduction)M → N, Γ ` M : T ⇒ Γ ` N : R with T � R

6 / 15

Page 19: Slides QuAND 2011

Unicity of types

Second problem:M + M → 2.M

If Γ ` M : T and Γ ` M : R, Γ ` 2.M :?

Solution: Church style

7 / 15

Page 20: Slides QuAND 2011

Unicity of types

Second problem:M + M → 2.M

If Γ ` M : T and Γ ` M : R, Γ ` 2.M :?

Solution: Church style

7 / 15

Page 21: Slides QuAND 2011

Confluence

Local confluence + Strong normalisation ⇒ Confluence

I Local confluence: Coq proof.I Strong normalisation:

PlanI Translation from λCA to λlin (i.e. remove annotations)I Preservation of reduction by the translationI Typability in λCA ⇒ Typability in VectorialI SN in Vectorial ⇒ SN in λCA

8 / 15

Page 22: Slides QuAND 2011

Confluence

Local confluence + Strong normalisation ⇒ Confluence

I Local confluence: Coq proof.

I Strong normalisation:Plan

I Translation from λCA to λlin (i.e. remove annotations)I Preservation of reduction by the translationI Typability in λCA ⇒ Typability in VectorialI SN in Vectorial ⇒ SN in λCA

8 / 15

Page 23: Slides QuAND 2011

Confluence

Local confluence + Strong normalisation ⇒ Confluence

I Local confluence: Coq proof.I Strong normalisation:

PlanI Translation from λCA to λlin (i.e. remove annotations)I Preservation of reduction by the translationI Typability in λCA ⇒ Typability in VectorialI SN in Vectorial ⇒ SN in λCA

8 / 15

Page 24: Slides QuAND 2011

Strong normalisation

|M| is the term M without type annotations

LemmaIf M → N, then

|M| →=v |N|

where |M| = |N| only when M → N is a type beta reduction.

Lemma

Γ ` M :T ⇒ ∆ `v |M| :R

9 / 15

Page 25: Slides QuAND 2011

Strong normalisation

|M| is the term M without type annotations

LemmaIf M → N, then

|M| →=v |N|

where |M| = |N| only when M → N is a type beta reduction.

Lemma

Γ ` M :T ⇒ ∆ `v |M| :R

9 / 15

Page 26: Slides QuAND 2011

Strong normalisation

|M| is the term M without type annotations

LemmaIf M → N, then

|M| →=v |N|

where |M| = |N| only when M → N is a type beta reduction.

Lemma

Γ ` M :T ⇒ ∆ `v |M| :R

9 / 15

Page 27: Slides QuAND 2011

Strong normalisation

LemmaThere is no infinite sequence reduction consisting only of type beta rules

Proof.Define:

σ(x : U) = 1 σ(ΛX .t) = 1 + σ(t) σ(t@U) =σ(t)σ(λx : U.t) =σ(t) σ((t) r) =σ(t) σ(r) σ(0) = 1

σ(α.t) =σ(t) σ(t + r) =σ(t) + σ(r)

Induction on M: σ((ΛX .M)@T ) > σ(M[X/T ]).

10 / 15

Page 28: Slides QuAND 2011

Strong normalisation

LemmaThere is no infinite sequence reduction consisting only of type beta rules

Proof.Define:

σ(x : U) = 1 σ(ΛX .t) = 1 + σ(t) σ(t@U) =σ(t)σ(λx : U.t) =σ(t) σ((t) r) =σ(t) σ(r) σ(0) = 1

σ(α.t) =σ(t) σ(t + r) =σ(t) + σ(r)

Induction on M: σ((ΛX .M)@T ) > σ(M[X/T ]).

10 / 15

Page 29: Slides QuAND 2011

Strong normalisation

Theorem (Strong normalisation)Γ ` M : T ⇒ M is SN

Proof.Γ ` M : T ⇒ ∆ `v |M| : R ⇒ |M| is SNAssume M not SN:

M → M1 → M2 → · · ·

Then|M| →=

v |M1| →=v |M2| →=

v · · ·

|M| is SN ⇒ ∀i > n |Mi | = |Mi+1|Then Mi → Mi+1 → · · · are type beta reductions.Then Mi must be SN. Absurd.

11 / 15

Page 30: Slides QuAND 2011

Strong normalisation

Theorem (Strong normalisation)Γ ` M : T ⇒ M is SN

Proof.Γ ` M : T ⇒ ∆ `v |M| : R ⇒ |M| is SN

Assume M not SN:

M → M1 → M2 → · · ·

Then|M| →=

v |M1| →=v |M2| →=

v · · ·

|M| is SN ⇒ ∀i > n |Mi | = |Mi+1|Then Mi → Mi+1 → · · · are type beta reductions.Then Mi must be SN. Absurd.

11 / 15

Page 31: Slides QuAND 2011

Strong normalisation

Theorem (Strong normalisation)Γ ` M : T ⇒ M is SN

Proof.Γ ` M : T ⇒ ∆ `v |M| : R ⇒ |M| is SNAssume M not SN:

M → M1 → M2 → · · ·

Then|M| →=

v |M1| →=v |M2| →=

v · · ·

|M| is SN ⇒ ∀i > n |Mi | = |Mi+1|Then Mi → Mi+1 → · · · are type beta reductions.Then Mi must be SN. Absurd.

11 / 15

Page 32: Slides QuAND 2011

Strong normalisation

Theorem (Strong normalisation)Γ ` M : T ⇒ M is SN

Proof.Γ ` M : T ⇒ ∆ `v |M| : R ⇒ |M| is SNAssume M not SN:

M → M1 → M2 → · · ·

Then|M| →=

v |M1| →=v |M2| →=

v · · ·

|M| is SN ⇒ ∀i > n |Mi | = |Mi+1|Then Mi → Mi+1 → · · · are type beta reductions.Then Mi must be SN. Absurd.

11 / 15

Page 33: Slides QuAND 2011

Strong normalisation

Theorem (Strong normalisation)Γ ` M : T ⇒ M is SN

Proof.Γ ` M : T ⇒ ∆ `v |M| : R ⇒ |M| is SNAssume M not SN:

M → M1 → M2 → · · ·

Then|M| →=

v |M1| →=v |M2| →=

v · · ·

|M| is SN ⇒ ∀i > n |Mi | = |Mi+1|

Then Mi → Mi+1 → · · · are type beta reductions.Then Mi must be SN. Absurd.

11 / 15

Page 34: Slides QuAND 2011

Strong normalisation

Theorem (Strong normalisation)Γ ` M : T ⇒ M is SN

Proof.Γ ` M : T ⇒ ∆ `v |M| : R ⇒ |M| is SNAssume M not SN:

M → M1 → M2 → · · ·

Then|M| →=

v |M1| →=v |M2| →=

v · · ·

|M| is SN ⇒ ∀i > n |Mi | = |Mi+1|Then Mi → Mi+1 → · · · are type beta reductions.

Then Mi must be SN. Absurd.

11 / 15

Page 35: Slides QuAND 2011

Strong normalisation

Theorem (Strong normalisation)Γ ` M : T ⇒ M is SN

Proof.Γ ` M : T ⇒ ∆ `v |M| : R ⇒ |M| is SNAssume M not SN:

M → M1 → M2 → · · ·

Then|M| →=

v |M1| →=v |M2| →=

v · · ·

|M| is SN ⇒ ∀i > n |Mi | = |Mi+1|Then Mi → Mi+1 → · · · are type beta reductions.Then Mi must be SN. Absurd.

11 / 15

Page 36: Slides QuAND 2011

Abstract interpretation

Translation to additive:

τ(α.M) =

bαc∑i=1

τ(M)

Theorem (Abstract interpretation)

τ(M) ↓a� τ(M ↓)

Lemma (Typing preservation)

Γ ` M : T ⇒ Γ `a τ(M) : T

12 / 15

Page 37: Slides QuAND 2011

Abstract interpretation

Translation to additive:

τ(α.M) =

bαc∑i=1

τ(M)

Theorem (Abstract interpretation)

τ(M) ↓a� τ(M ↓)

Lemma (Typing preservation)

Γ ` M : T ⇒ Γ `a τ(M) : T

12 / 15

Page 38: Slides QuAND 2011

Abstract interpretation

Translation to additive:

τ(α.M) =

bαc∑i=1

τ(M)

Theorem (Abstract interpretation)

τ(M) ↓a� τ(M ↓)

Lemma (Typing preservation)

Γ ` M : T ⇒ Γ `a τ(M) : T

12 / 15

Page 39: Slides QuAND 2011

Abstract interpretation

λCA

��

τ // λadd

↓a

(�) ��

[·] // Fp

↓F

(�) ��λCA

τ// λadd

[·]// Fp

13 / 15

Page 40: Slides QuAND 2011

Contributions

I “Powerful” alternative to Vectorial (extension of Additive)I (weak) Subject reductionI Strong normalisation (via translation to Vectorial)I Confluence (via SN)I Abstract interpretation in System F with pairs (via Additive)

14 / 15

Page 41: Slides QuAND 2011

Possible extensions

I Taking also the ceil to have intervals... [Philippe Jorrand]

` α.M : [bαc, dαe].T

(better approximations)

I pairs to represent negatives... [Simon Perdrix]

` α.M : (bαc, ?).T ` −α.M : (?, bαc).T

I Complexes... [Simon Perdrix]

` (α− βi).M : [(bαc, ?), (?, bβc)].T

I etc.

15 / 15

Page 42: Slides QuAND 2011

Possible extensions

I Taking also the ceil to have intervals... [Philippe Jorrand]

` α.M : [bαc, dαe].T

(better approximations)

I pairs to represent negatives... [Simon Perdrix]

` α.M : (bαc, ?).T ` −α.M : (?, bαc).T

I Complexes... [Simon Perdrix]

` (α− βi).M : [(bαc, ?), (?, bβc)].T

I etc.

15 / 15

Page 43: Slides QuAND 2011

Possible extensions

I Taking also the ceil to have intervals... [Philippe Jorrand]

` α.M : [bαc, dαe].T

(better approximations)

I pairs to represent negatives... [Simon Perdrix]

` α.M : (bαc, ?).T ` −α.M : (?, bαc).T

I Complexes... [Simon Perdrix]

` (α− βi).M : [(bαc, ?), (?, bβc)].T

I etc.

15 / 15