algebra and coalgebra in the light affine lambda calculus · turing machines lambda calculus ptime...

Post on 17-Jul-2020

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Algebra and Coalgebra in the

Light Affine Lambda Calculus

Marco GaboardiUniversity of Dundee

Romain PéchouxUniversité de Lorraine

ComputabilityComplexity

TuringMachines

Lambda Calculus

ComputabilityComplexity

TuringMachines

Lambda Calculus

PTIME NPTIME

PSPACE

LOGSPACE

BPP

LALC

STAINTML

DLAL

RSLR

ComputabilityComplexity

TuringMachines

Lambda Calculus

PTIME NPTIME

PSPACE

LOGSPACE

BPP

LALC

STAINTML

DLAL

RSLR

ComputabilityComplexity

Implicit Complexity

TuringMachines

Lambda Calculus

PTIME NPTIME

PSPACE

LOGSPACE

BPP

LALC

STAINTML

DLAL

RSLRLALCPTIME

ComputabilityComplexity

(Light Affine Lambda Calculus)

LALC

PTIME

Where these languages could help?

Where these languages could help?

ResourceAnalysis

Where these languages could help?

ResourceAnalysis

Efficient arithmeticimplementation

Where these languages could help?

ComputationalIndistinguishability

ResourceAnalysis

Efficient arithmeticimplementation

Completeness every PTIME Turing Machine can be expressed in LALC.

Soundness: every LALC program can be run in polynomial time.

PTIME LALC

Completeness every PTIME Turing Machine can be expressed in LALC.

Soundness: every LALC program can be run in polynomial time.

Expressivity?

PTIME LALC

Our research question:

Can we express Algebra and Coalgebra in LALC?

Our contribution

Our contributionWeak notions of Algebras and Coalgebras can be encoded in LALC.

1 -

Our contributionWeak notions of Algebras and Coalgebras can be encoded in LALC.

1 -

Data types:

✔ Inductive types✗ Coinductive types

2 -

Our contribution

LALC restrictions can be slightly relaxed to achieve more expressivity for coinductive types.

Weak notions of Algebras and Coalgebras can be encoded in LALC.

1 -

Data types:

✔ Inductive types✗ Coinductive types

2 -

3 -

LALC ⊂ Linear (Affine) System F

Light Affine Lambda Calculus - LALC

LALC ⊂ Linear (Affine) System F

!A §B

A B

A → B =

Main Idea

Light Affine Lambda Calculus - LALC

LALC ⊂ Linear (Affine) System F

!A §B

A B

A → B =

Main Idea

Light Affine Lambda Calculus - LALC

A non iterative function-

A function using its argument only once

LALC ⊂ Linear (Affine) System F

!A §B

A B

A → B =

Main Idea

Light Affine Lambda Calculus - LALC

an iterative function-

! needed for duplication§ placeholder witnessing

duplication

Iterators in LALC

⊸IT : ∀a.!(a a) §(a a)⊸⊸

Iterators in LALC

⊸IT : ∀a.!(a a) §(a a)⊸⊸

IT A (step: A A)⊸✔

Iterators in LALC

⊸IT : ∀a.!(a a) §(a a)⊸⊸

IT A (step: A A)⊸IT A (step: !A §A)⊸

Algebras and Coalgebras

AFA fA FBBgB

Algebra Coalgebra

μX.FXFμX.FX in

AFA fA

Fh h

Weakly Initial Algebra∀A, ∃ h

Algebras and Coalgebras

AFA fA FBBgB

Algebra Coalgebra

μX.FXFμX.FX in

AFA fA

Fh h

Weakly Initial Algebra∀A, ∃ h

FBBgB

νX.FXout

h Fh

Weakly Final Coalgebra∀B, ∃h

FνX.FX

Algebras and Coalgebras

AFA fA FBBgB

Algebra Coalgebra

F(-) = 1+ (-)

F(-) = 1+ A × (-)

F(-) = 1+ A × (-) × (-)

Initial Algebra Final Coalgebra

N N ∪ {∞}

A* A∞

T*(A) T∞(A)

Examples

(co)algebras in System F

Theorem [Reynolds, Plotkin, Geuvers, …]:Given F expressible in the polymorphic lambda calculus:

- there exists a weakly initial F-Algebra

- there exists a weakly final F-Coalgebra

(co)algebras in System F

Theorem [Reynolds, Plotkin, Geuvers, …]:Given F expressible in the polymorphic lambda calculus:

- there exists a weakly initial F-Algebra

- there exists a weakly final F-Coalgebra

Wraith-Wadler encoding:

μa.Fa = ∀a.(Fa → a) → a

𝛎a.Fa = ∃a.(a → Fa) * a

(co)algebras in System F

Theorem [Reynolds, Plotkin, Geuvers, …]:Given F expressible in the polymorphic lambda calculus:

- there exists a weakly initial F-Algebra

- there exists a weakly final F-Coalgebra

Wraith-Wadler encoding:

μa.Fa = ∀a.(Fa → a) → a

𝛎a.Fa = ∃a.(a → Fa) * a

F-algebra!

(co)algebras in System F

Theorem [Reynolds, Plotkin, Geuvers, …]:Given F expressible in the polymorphic lambda calculus:

- there exists a weakly initial F-Algebra

- there exists a weakly final F-Coalgebra

Wraith-Wadler encoding:

μa.Fa = ∀a.(Fa → a) → a

𝛎a.Fa = ∃a.(a → Fa) * a

F-algebra!

F-coalgebra!

Wraith-Wadler encodingμa.FaF(μa.Fa) in

BFB f

F (fold f) fold f

in : F(μa.Fa) → μa.Fain = λs.λk.k (F (fold k) s)

fold : ∀b. (Fb → b) → μa.Fa → bfold = λf.λt. t f

μa.Fa = ∀a.(Fa→a)→a

in : F(μa.Fa) → μa.Fain = λs.λk. k (F (fold k) s)

fold : ∀b. (Fb → b) → μa.Fa → bfold = λf.λt. t f

μa.Fa =∀a. (Fa → a) → a

Wraith-Wadler encoding in LALC

in : F(μa.Fa) → μa.Fain = λs.λk. k (F (fold k) s)

fold : ∀b. (Fb → b) → μa.Fa → bfold = λf.λt. t f

μa.Fa =∀a. (Fa → a) → a

k need to beduplicated!

Wraith-Wadler encoding in LALC

in : F(μa.Fa) μa.Fain = λs.λk.§k (F (fold !k) s)

fold : ∀b.!(Fb b) μa.Fa §bfold = λf.λt. t !f

μa.Fa =∀a.!(Fa a) §a

Let’s change the type!

Wraith-Wadler encoding in LALC

⊸ ⊸

⊸ ⊸ ⊸

μa.FaF(μa.Fa) in

§BF§B???

F (fold !f) fold !f

in : F(μa.Fa) μa.Fa

fold : ∀b.!(Fb b) μa.Fa §b

⊸⊸ ⊸ ⊸

Wraith-Wadler encoding in LALC

μa.FaF(μa.Fa) in

§BF§B§f

F (fold !f) fold !f

in : F(μa.Fa) μa.FaLF : ∀b. F§b §Fb fold : ∀b.!(Fb b) μa.Fa §b

⊸⊸ ⊸ ⊸

§FBLF

Weakly-Initial algebra under §

μa.FaF(μa.Fa) in

§BF§B§f

F (fold !f) fold !f

in : F(μa.Fa) μa.FaLF : ∀b. F§b §Fb fold : ∀b.!(Fb b) μa.Fa §b

⊸⊸ ⊸ ⊸

§FBLF

Weakly-Initial algebra under §

Left distributivity

out : 𝛎a.Fa F(𝛎a.Fa)RF : ∀b. §Fb F§bunfold:∀b.!(b Fb) §b 𝛎a.Fa

F(𝛎a.Fa)𝛎a.Fa out

F§B§B§f

unfold !f F(unfold !f)

§FBRF

𝛎a.Fa = ∃a.!(a Fa)⨂§a

⊸ ⊸⊸

⊸ ⊸⊸

Weakly-Final coalgebra under §

out : 𝛎a.Fa F(𝛎a.Fa)RF : ∀b. §Fb F§bunfold:∀b.!(b Fb) §b 𝛎a.Fa

F(𝛎a.Fa)𝛎a.Fa out

F§B§B§f

unfold !f F(unfold !f)

§FBRF

𝛎a.Fa = ∃a.!(a Fa)⨂§a

⊸ ⊸⊸

⊸ ⊸⊸

Weakly-Final coalgebra under §

Right distributivity

Expressivity?

F(-) = 1 ⊕ -

F(-) = 1 ⊕ A ⨂ -

F(-) = 1 ⊕ A ⨂ - ⨂ -

• Which Functor satisfies LF:∀b. F§b §Fb ?⊸

Expressivity?

F(-) = 1 ⊕ -

F(-) = 1 ⊕ A ⨂ -

F(-) = 1 ⊕ A ⨂ - ⨂ -

• Which Functor satisfies LF:∀b. F§b §Fb ?

provided ⊢A §A⊸

Expressivity?

F(-) = 1 ⊕ -

F(-) = 1 ⊕ A ⨂ -

F(-) = 1 ⊕ A ⨂ - ⨂ -

• Which Functor satisfies RF: ∀b. §Fb F§b⊸

Expressivity?

F(-) = 1 ⊕ -

F(-) = 1 ⊕ A ⨂ -

F(-) = 1 ⊕ A ⨂ - ⨂ -

• Which Functor satisfies RF: ∀b. §Fb F§b

Where is the problem?

The modality § does not commute with the other type constructions!

Where is the problem?

The modality § does not commute with the other type constructions!

Solution: make § to commute

We can add to LALC the following terms:

dist⊕ : §(A ⊕ B) §A ⊕ §B

dist⨂ : §(A ⨂ B) §A ⨂ §B

⊸⊸

dist⊕ §(inj t) → inj §t

dist⨂ §(<t1,t2>) → <§t1,§t2>

Adding terms for distributivity

We can add to LALC the following terms:

dist⊕ : §(A ⊕ B) §A ⊕ §B

dist⨂ : §(A ⨂ B) §A ⨂ §B

⊸⊸

dist⊕ §(inj t) → inj §t

dist⨂ §(<t1,t2>) → <§t1,§t2>

They require the evaluation of terms inside a §Problem: this breaks polynomial time soundness.

Adding terms for distributivity

We can add to LALC the following terms:

dist⊕ : §(A ⊕ B) §A ⊕ §B

dist⨂ : §(A ⨂ B) §A ⨂ §B

⊸⊸

dist⊕ §(inj t) → inj §t

dist⨂ §(<t1,t2>) → <§t1,§t2>

They require the evaluation of terms inside a §Problem: this breaks polynomial time soundness.

Adding terms for distributivity

New (quite complex) proof in the paper!

Expressivity?

F(-) = 1 ⊕ -

F(-) = 1 ⊕ A ⨂ -

F(-) = 1 ⊕ A ⨂ - ⨂ -

• Which Functor satisfies RF?

Expressivity?

F(-) = 1 ⊕ -

F(-) = 1 ⊕ A ⨂ -

F(-) = 1 ⊕ A ⨂ - ⨂ -

• Which Functor satisfies RF?

provided ⊢§A A⊸

Expressivity?

F(-) = 1 ⊕ -

F(-) = 1 ⊕ A ⨂ -

F(-) = 1 ⊕ A ⨂ - ⨂ -

• Which Functor satisfies RF?

provided ⊢§A A⊸

We can have streams and trees at every finite type

Take out?

• Algebras and Coalgebras encodings make sense also for polynomial time languages,

• Due to the restrictive nature of languages for implicit complexity their definitions can be a bit more tricky,

• The expressivity may still depend on the restrictions of the language.

top related