a bridge between semirings - université sorbonne paris...

26
A bridge between semirings Flavien BREUVART PPS, Paris Denis Diderot & LIPN, Paris Nord 2-4 December 2013 (Work in progress) Flavien BREUVART PPS/LIPN A bridge between semirings 1/1

Upload: others

Post on 19-Oct-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

A bridge between semirings

Flavien BREUVART

PPS, Paris Denis Diderot & LIPN, Paris Nord

2-4 December 2013

(Work in progress)

Flavien BREUVART PPS/LIPN A bridge between semirings 1 / 1

Page 2: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Introduction

Semirings R for resource management

More and more researche projects are using semirings to model ideasof quantitative resources, we are trying to links these approaches.

Ghica’s type system TR

[GhicaSmith13]

Generalization of Girard’s BLLthat are substituting polynomialsby element of given semirings ininferenceable type systems.

Ehrhard’s model RelR![CarraroEhrhardSalibra09]

Generalizations of the relationalccc REL! (known for its resourcemanagement properties) thatrelaxe multisets exponential intosemiring-indexed multisets.

Stratification of RelR! into a model for TR

We will see that rather natural stratifications of Ehrhard’s models givesrise to models for Ghica’s typed calculi.

Flavien BREUVART PPS/LIPN A bridge between semirings 2 / 1

Page 3: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Introduction

The problem: In order to create RelR! , Ehrhard ask for R tohave multiplicities

Introducing the multiplicity

• Given any semiring R,

• any semiring withmultiplicities S,

• a semiring onto morphismφ : S � R,

RelS! can be stratified into a

model of TR.

Expanding semirings to havemultiplicities

Given any semiring R we cancreate

• Nf 〈R〉 that (nearly)has multiplicities

• φ : Nf 〈R〉� Ran onto morphism.

Idea:Resources manager type systems are modeled by

stratifying ccc obtained from differential linear logicwith non-usual exponential.

Flavien BREUVART PPS/LIPN A bridge between semirings 3 / 1

Page 4: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Definition of semirings

Semiring RA semiring is a structure R = (|R|,+, 0, ·, 1) where |R| is a setcontaining 0 and 1 and where + and · are binaries operations verifying:

• + and · are associative,

• + is commutative,

• + distribute over ·,• 0 is neutral for + and absorbing for ·,• 1 is neutral for ·.

Elements of a semiring R are denoted by large Latins letters J,K ...

Examples of semirings

• 1: the trivial Semiring with just one element.

• Poly : the polynomials with their usual addition and multiplication.

• For any commutative monoid (M,+, 0), the automorphisms(Mon(M,M),+, cst0, ◦, idM)

Flavien BREUVART PPS/LIPN A bridge between semirings 4 / 1

Page 5: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

The semimoduleRf 〈A〉

Definition of Rf 〈A〉Given a semiring R and a set A, the space of functions f : A→ R offinite support is denoted Rf 〈A〉. It is a semimodule over R with:

• A commutative sum: (f +g)(x) = f (x)+g(x)

• An external product: (J·f )(x) = J·f (x)

Example: multisets

Nf 〈A〉 correspond to finite multisets over A.

Multiset notationFor very simple functions, multiset notation may be more convenient:

[] := (∀α, α 7→ 0) [J·β] := (β 7→ J ;∀α 6= β, α 7→ 0)

Flavien BREUVART PPS/LIPN A bridge between semirings 5 / 1

Page 6: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

The semiring Nf 〈M〉

Nf 〈M〉Given a monoid M, Nf 〈M〉 is a semiring with:

• A commutative sum: (f +g)(x) = f (x)+g(x)

• A product (Dirichlet convolution):

(f ·g)(x) =∑y ,z

x=y ·z

f (y)·g(z)

Example of such semirings

• N = Nf 〈1〉• Ghica’s Nf 〈Aff c

1 〉• Poly = Nf 〈N+〉

RemarkThis correspond to recurent semirings inimplicit complexity, we will try to explain why.

Flavien BREUVART PPS/LIPN A bridge between semirings 6 / 1

Page 7: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Ghica’s grammar and examples

Ghica’s grammar

Given a semiring R we define typed lambda calculus:

(terms) Λ M,N ::= x | λx .M | M N

(linear types) TR` θ := α | Θ(θ

(types) TR Θ := J·θ J ∈ R

TR` actual types of our terms

TR banged types that count multiplicitiesJ·θ denotes that θ has to be used exactly J times

Some examples (with R = Hom(N))

λxy .y : 0·θ(1·θ′(θ′ λxy .x(xy): 4·(3·θ(θ)(6·θ(θ

λxy .xyy : 1·(2·θ(3·θ(θ′)(5·θ(θ′

λxyz .x(yz): 1·(f ·θ(θ)(f ·(g ·θ(θ)(f ◦g ·θ(θ

λxyz .y(xz): g ·(f ·θ(θ)(1·(g ·θ(θ)(g◦f ·θ(θ

Flavien BREUVART PPS/LIPN A bridge between semirings 7 / 1

Page 8: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Typing judgments

Ghica’s linear type system

Idx :1·θ ` x :θ

Γ ` M:θWeak

Γ, x :0·θ′ ` M:θΓ, x :Θ ` M:θ′

AbsΓ ` λx .M:Θ(θ′

Γ ` M:J·θ(θ′ Γ′ ` N:θ |Γ| = |Γ′|App

Γ+ J·Γ′ ` M N : θ′

where |Γ| = |Γ′| means the equality of contexts except for the multiplicityof the types:

|(xi :Ji ·θi )i≤k | = |(yi :Ki ·θ′i )i≤k′ | ⇔ (k = k ′ ∧ xi = yi ∧ θi = θ′i )

(xi :Ji ·θi )i+(xi :Ki ·θi )i := (xi :(J+K )·θi )i

and where Γ+ J·Γ′ is the context obtain by applying addition andmultiplication to the semiring:

J·(xi :K ·θi )i := (xi :J·K ·θi )i

Flavien BREUVART PPS/LIPN A bridge between semirings 8 / 1

Page 9: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Categorical model

A categorical model of linear logic: RelR

Objects: Sets Morphisms: Relations

Exponential: !A = Rf 〈A〉

We will see later that the semiring R must be a multiplicity semiring.

The co-kleisli category: RelR!Objects: Sets Morphisms: Relations between Rf 〈A〉 and B

Identities: 1A = {([1·α], α)|α ∈ A}Composition: f ; g := {(Σβ∈|b|bβ ·aβ , α)|(b, α) ∈ g , (aβ , β) ∈ f }

Cartesian product:˘

i∈I Ai := {(i , α)|i ∈ I , α ∈ Ai}Exponential object: A⇒ B = Rf 〈A〉 × B

All ccc-diagrams are given by the co-Kleisli construction from theexponential comonad (when R is a multiplicity semiring).

Flavien BREUVART PPS/LIPN A bridge between semirings 9 / 1

Page 10: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Intersection type system

Interpretation of types

[[o]] = 1 [[τ→τ ′]] = Rf 〈[[τ ]]〉 × [[τ ′]]

Ehrhard’s typing rulesαCτ

Idx :[1·α]Cτ ` x :αCτ

Γ ` M:αCτWeak

Γ, x :[]Cτ ′ ` M:αCτ

Γ, x :aCτ ` M:βCτ ′Abs

Γ ` λx .M:a(βCτ→τ ′

Γ ` M:a(βCτ→τ ′∧α∈|a| Γα ` N:αCτ |Γ| = |Γα|

AppΓ + Σα∈|a|aα·Γα ` M N: βCτ ′

|(xi :aiCτi )i≤k | = |(yi :biCτ′i )i≤k | ⇔ (k = k ′ ∧ xi = yi ∧ τi = τ ′i )

(xi :aiCτi )i + (xi :biCτi )i := (xi :(ai+biCτi )iJ·(xi :aiCτi )i := (xi :J·aiCτi )i

Flavien BREUVART PPS/LIPN A bridge between semirings 10 / 1

Page 11: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Comparison

Ehrhard’s typing rules

Idx :[1·α] ` x :α

Γ ` M:αWeak

Γ, x :[] ` M:αΓ, x :a ` M:β

AbsΓ ` λx .M:a(β

Γ ` M:a(β∧α∈|a| Γα ` N:α |Γ| = |Γα|

AppΓ + Σα∈|a|aα·Γα ` M N : β

(xi :ai )i + (xi :bi )i := (xi :(ai+bi )i J·(xi :ai )i := (xi :J·ai )i

Ghica’s typing rules

Idx :1·θ ` x :θ

Γ ` M:θWeak

Γ, x :0·θ′ ` M:θΓ, x :Θ ` M:θ′

AbsΓ ` λx .M:Θ(θ′

Γ ` M:J·θ(θ′ Γ′ ` N:θ |Γ| = |Γ′|App

Γ + J·Γ′ ` M N : θ′

(xi :J i ·θi )i+(xi :Ki ·θi )i := (xi :(J+K )·θi )i J·(xi :K ·θi )i := (xi :J·K ·θi )i

Flavien BREUVART PPS/LIPN A bridge between semirings 11 / 1

Page 12: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

interpretation of the calculus

Intersection type system

αCθId

x :[1·α]C1·θ ` x :αCθΓ ` M:αCθ

WeakΓ, x :(||)C0·θ′ ` M:αCθ

Γ, x :aCΘ ` M:βCθ′Abs

Γ ` λx .M:a(βCΘ(θ

Γ ` M:a(βCJ·θ(θ′∧α∈|a| Γα ` N:αCθ |Γ| = |Γα|

AppΓ + Σα∈|a|aα·Γα ` M N: βCθ′

|(xi :aiCJi ·θi )i≤k | = |(yi :biCKi ·θ′i )i≤k ⇔ (k = k ′ ∧ xi = yi ∧ θi = θ′i )

(xi :aiCJi ·θi )i + (xi :biCKi ·θi )i := (xi :(ai+biC(Ji+Ki )θi )i

J·(xi :aiCKi ·θi )i := (xi :J·aiC(J·Ki )·θi )i

Flavien BREUVART PPS/LIPN A bridge between semirings 12 / 1

Page 13: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Interpretation of types

Interpretation of types

[[o]] = 1 [[Θ(θ]] = [[Θ]]× [[θ]] [[J·θ]] = RJ〈[[θ]]〉

Where RJ〈A〉 are vectors of Rf 〈A〉 whose wedge (in a sort of `1 norm) isexactly J ∈ sR:

||a||`1 := Σα∈|a|aα RJ〈A〉 := {a ∈ Rf 〈A〉 | ||a||`1 = J}

Stratification

![[θ]] =⋃J∈R

[[J·θ]] J 6= K ⇒ [[J·θ]] ∩ [[K ·θ]] = ∅

Flavien BREUVART PPS/LIPN A bridge between semirings 13 / 1

Page 14: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Some intuition

Stratification

![[θ]] =⋃J∈R

[[J·θ]] J 6= K ⇒ [[J·θ]] ∩ [[K ·θ]] = ∅

For Order(τ) < 2:[[τ ]] =

⋃Era(θ)=τ [[θ]]

where Era(θ) is the simple typeobtained by effacing semiringannotations.

For Order(τ) ≥ 2:[[τ ]] 6=

⋃Era(θ)=τ [[θ]]

For exemple[[](∗, [∗](∗](∗ ∈[[(∗→∗)→∗]].

Singleton degeneration

In fact linear types a so restrictive that all types interpretation aresingleton. But this doese not hold for natural generalisations.

Flavien BREUVART PPS/LIPN A bridge between semirings 14 / 1

Page 15: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

A semiring with “some” properties?

A semiring M is said to have multiplicities if:

(Com) M is commutative: n1·n2 = n2·n1

(MS1) M is positive: n1+n2 = 0⇒ n1 = n2 = 0

(MS2) M is discreet: n1+n2 = 0⇒ n1 = 0 or n2 = 0

(MS3) M has additive splitting properties:

n1+n2 = p1+p2 ⇒ ∃r11, r12, r21, r22, pi = r1i+r2i , ni = ri1+r2i

(MS4) M has multiplicative splitting property:

n1+n2 = pm ⇒ ∃p1, p2,m11,m12,m21,m22, p = p1+p2,

m = m11+m12 = m21+m22, ni = p1m1i+p2m2i

Flavien BREUVART PPS/LIPN A bridge between semirings 15 / 1

Page 16: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

A semiring with “some” properties?

A semiring M is said to have multiplicities if:

(Com) M is commutative: n1·n2 = n2·n1

(MS1) M is positive: n1+n2 = 0⇒ n1 = n2 = 0

(MS2) M is discreet: n1+n2 = 0⇒ n1 = 0 or n2 = 0

(MS3) M has additive splitting properties:

n1+n2 = p1+p2 ⇒ ∃r11, r12, r21, r22, pi = r1i+r2i , ni = ri1+r2i

(MS4) M has multiplicative splitting property:

n1+n2 = pm ⇒ ∃p1, p2,m11,m12,m21,m22, p = p1+p2,

m = m11+m12 = m21+m22, ni = p1m1i+p2m2i

Flavien BREUVART PPS/LIPN A bridge between semirings 15 / 1

Page 17: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

A semiring with “some” properties?

A semiring M is said to have multiplicities if:

(Com) M is commutative: n1·n2 = n2·n1

(MS1) M is positive: n1+n2 = 0⇒ n1 = n2 = 0

(MS2) M is discreet: n1+n2 = 0⇒ n1 = 0 or n2 = 0

(MS3) M has additive splitting properties:

n1+n2 = p1+p2 ⇒ ∃r11, r12, r21, r22, pi = r1i+r2i , ni = ri1+r2i

(MS4) M has multiplicative splitting property:

n1+n2 = pm ⇒ ∃p1, p2,m11,m12,m21,m22, p = p1+p2,

m = m11+m12 = m21+m22, ni = p1m1i+p2m2i

Flavien BREUVART PPS/LIPN A bridge between semirings 15 / 1

Page 18: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

A semiring with “some” properties?

A semiring M is said to have multiplicities if:

(Com) M is commutative: n1·n2 = n2·n1

(MS1) M is positive: n1+n2 = 0⇒ n1 = n2 = 0

(MS2) M is discreet: n1+n2 = 0⇒ n1 = 0 or n2 = 0

(MS3) M has additive splitting properties:

n1+n2 = p1+p2 ⇒ ∃r11, r12, r21, r22, pi = r1i+r2i , ni = ri1+r2i

(MS4) M has multiplicative splitting property:

n1+n2 = pm ⇒ ∃p1, p2,m11,m12,m21,m22, p = p1+p2,

m = m11+m12 = m21+m22, ni = p1m1i+p2m2i

Flavien BREUVART PPS/LIPN A bridge between semirings 15 / 1

Page 19: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

A semiring with “some” properties?

A semiring M is said to have multiplicities if:

(Com) M is commutative: n1·n2 = n2·n1

(MS1) M is positive: n1+n2 = 0⇒ n1 = n2 = 0

(MS2) M is discreet: n1+n2 = 0⇒ n1 = 0 or n2 = 0

(MS3) M has additive splitting properties:

n1+n2 = p1+p2 ⇒ ∃r11, r12, r21, r22, pi = r1i+r2i , ni = ri1+r2i

(MS4) M has multiplicative splitting property:

n1+n2 = pm ⇒ ∃p1, p2,m11,m12,m21,m22, p = p1+p2,

m = m11+m12 = m21+m22, ni = p1m1i+p2m2i

Flavien BREUVART PPS/LIPN A bridge between semirings 15 / 1

Page 20: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

A semiring onto morphism:

Given φ : S � R, we can interpret TR in a stratified version of RELS! :

Interpretation of types

[[o]] = 1 [[Θ(θ]] = [[Θ]]× [[θ]] [[J·θ]] = SJ〈[[θ]]〉

Where SJ〈A〉 are vectors of Sf 〈A〉 whose wedge is in φ−1(J):

||a||`1 := Σα∈|a|aα SJ〈A〉 := {a ∈ Sf 〈A〉 | φ(||a||`1) = J}

Example

For R = 1 and S = N: gives the interpretation of simple types in REL!.

For R = Z/2Z and S = N: if θ is a type of TZ/2Z without any 1 thenα ∈ [[θ]] iff α ∈ [[Eff (θ)]] and every bags inside θ are of even size.

Flavien BREUVART PPS/LIPN A bridge between semirings 16 / 1

Page 21: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

A semiring onto morphism:interpretation of the calculus

Intersection type system

αCθId

x :[1·α]C1·θ ` x :αCθΓ ` M:αCθ

WeakΓ, x :(||)C0·θ′ ` M:αCθ

Γ, x :aCΘ ` M:βCθ′Abs

Γ ` λx .M:a(βCΘ(θ

Γ ` M:a(βCJ·θ(θ′∧α∈|a| Γα ` N:αCθ |Γ| = |Γα|

AppΓ + Σα∈|a|aα·Γα ` M N: βCθ′

|(xi :aiCJi ·θi )i≤k | = |(yi :biCJ ′i ·θ′i )i≤k ⇔ (k = k ′ ∧ xi = yi ∧ θi = θ′i )

(xi :aiCJi ·θi )i + (xi :biCJ ′i ·θi )i := (xi :(ai+biC(Ji+J ′i )θi )i

K ·(xi :aiCJi ·θi )i := (xi :K ·aiC(φ(K )·Ji )·θi )i

Flavien BREUVART PPS/LIPN A bridge between semirings 17 / 1

Page 22: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Structuring a semiring

Recalls on Nf 〈R〉Nf 〈R〉 is a semiring with

• A commutative sum: (f +g)(x) = f (x)+g(x)

• A product (Dirichlet convolution):

(f ·g)(x) =∑y ,z

x=y ·z

f (y)·g(z)

The onto morphism

We can define φ : Nf 〈R〉� R by:

φ(f ) = ΣJ∈Rf (J)·J

where n·J is a macro for J+ · · ·n times

+J

Flavien BREUVART PPS/LIPN A bridge between semirings 18 / 1

Page 23: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Does Nf 〈R〉 have multiplicities?

(Com) Nf 〈R〉 is not necessarily commutative: iff M is commutative

(MS1) Nf 〈R〉 is positive: The sum is the one of N(MS2) Nf 〈R〉 is discreet: The sum is the one of N(MS3) Nf 〈R〉 has additive splitting properties:The sum is the one of N(MS4) Nf 〈R〉 does not have multiplicative splitting property:

Flavien BREUVART PPS/LIPN A bridge between semirings 19 / 1

Page 24: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Does Nf 〈R〉 have multiplicities?

But Nf 〈R〉 has generalised multiplicites, i.e. respect:

(MS1) Nf 〈R〉 is positive.

(MS2) Nf 〈R〉 is discreet.

(MS3) Nf 〈R〉 has additive splitting properties.

(MS4’) Nf 〈R〉 has multiplicative k-ary splitting property:

n1+n2 = pm ⇒ ∃k , p1, p2,m11,m12,m21,m22, p =∑j≤k

pj ,

ni =∑j≤k

pjmji ,∀j ≤ k ,m = mj1+mj2

Flavien BREUVART PPS/LIPN A bridge between semirings 20 / 1

Page 25: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

Forgetful adjunction

Semirings > Monoids

U

B

Where U is the forgetful functor and it adjunction B generate from Mthe free semimodule of basis M with the multiplication(Σini ·ai )×B(M) (Σjmj ·bj) = Σi,jnimj ·(ai ×M bj)We have then the properties:

Im(B) ⊆ MSR∗

Φ = der(BU)R : (BU(R)� R)

Flavien BREUVART PPS/LIPN A bridge between semirings 21 / 1

Page 26: A bridge between semirings - Université Sorbonne Paris Nordbreuvart/presentations/fontainebleau.pdf · Semirings Rfor resource management More and more researche projects are using

The conjecture and conclusion

Conjecture

If R has generalised multipliities then RELR is a model of linear logic.

If this conjecture apear to be tru we would have:

General theorem

Every typing system TR has a model obtain by stratification of a certainRELS! .

Flavien BREUVART PPS/LIPN A bridge between semirings 22 / 1