Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas...

49
Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Transcript of Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas...

Page 1: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Category Theoryfor computer scientists

Nicolas Tabareau INRIA, Nantes

Thursday, October 21, 2010

Page 2: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

The denotational semantics trinity

!"#$"%&&'($)

!"#$%

&'()'*+%

*#$'+

,('+-.*%

&'((/%

,%-.$#"/)-0.#"/

012$34%

5('#67%+%

Thursday, October 21, 2010

Page 3: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

The denotational semantics trinity

!"#$"%&&'($)

!"#$%

&'()'*+%

*#$'+

,('+-.*%

&'((/%

,%-.$#"/)-0.#"/

012$34%

5('#67%+%

Curry-Howard Correspondance

Thursday, October 21, 2010

Page 4: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

The simply typed λ-calculusCurry 1958: le !-calcul simplement type

Variablex :A ! x :A

Abstraction!, x :A ! P :B

! ! !x.P :A" B

Application! ! P :A" B " ! Q :A

!," ! PQ :B

Affaiblissement ! ! P :B!, x :A ! P :B

Contraction!, x :A, y :A ! P :B

!, z :A ! P [x, y # z] :B

Permutation!, x :A, y :B," ! P :C

!, y :B, x :A," ! P :C

5

variable

abstraction

application

weakening

contraction

exchange

Thursday, October 21, 2010

Page 5: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Intuitionistic minimal logicCurry-Howard (1) .Logique minimale intuitioniste

Variablex :A ! x :A

Abstraction!, x :A ! P :B

! ! !x.P :A" B

Application! ! P :A" B " ! Q :A

!," ! PQ :B

Affaiblissement ! ! P :B!, x :A ! P :B

Contraction!, x :A, y :A ! P :B

!, z :A ! P [x, y # z] :B

Permutation!, x :A, y :B," ! P :C

!, y :B, x :A," ! P :C

7

axiom

⇒ I

⇒ E

weakening

contraction

exchange

Thursday, October 21, 2010

Page 6: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Intuitionistic minimal logicCurry-Howard (1) .Logique minimale intuitioniste

Variablex :A ! x :A

Abstraction!, x :A ! P :B

! ! !x.P :A" B

Application! ! P :A" B " ! Q :A

!," ! PQ :B

Affaiblissement ! ! P :B!, x :A ! P :B

Contraction!, x :A, y :A ! P :B

!, z :A ! P [x, y # z] :B

Permutation!, x :A, y :B," ! P :C

!, y :B, x :A," ! P :C

7

Curry

Howar

d

axiom

⇒ I

⇒ E

weakening

contraction

exchange

Thursday, October 21, 2010

Page 7: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Other correspondances

Cut elimination ⇔ β-reduction

Thursday, October 21, 2010

Page 8: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Other correspondances

priority to right-hand sidein cut-elimination

⇔call-by-name

Thursday, October 21, 2010

Page 9: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Other correspondances

priority to left-hand sidein cut-elimination

⇔call-by-value

Thursday, October 21, 2010

Page 10: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Other correspondances

Pierce law ((P ⇒ Q) ⇒ P) ⇒ P

⇔call-cc (continuation)

Thursday, October 21, 2010

Page 11: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Other correspondances

double negation translation(Gödel translation)

⇔continuation passing style

translation

Thursday, October 21, 2010

Page 12: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

The denotational semantics trinity

!"#$"%&&'($)

!"#$%

&'()'*+%

*#$'+

,('+-.*%

&'((/%

,%-.$#"/)-0.#"/

012$34%

5('#67%+%

Thursday, October 21, 2010

Page 13: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

The denotational semantics trinity

!"#$"%&&'($)

!"#$%

&'()'*+%

*#$'+

,('+-.*%

&'((/%

,%-.$#"/)-0.#"/

012$34%

5('#67%+%

Thursday, October 21, 2010

Page 14: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

What is a category ?

Thursday, October 21, 2010

Page 15: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

What is a category ?

Une approche des catégories par la dualité de Poincaré

Catégorie : Graphe dont les flèches composent horizontalement+ Identités

A

A

C

C

gf B

f ; g

Tabareau (PPS) Calculer des monoïdes libres Séminaire thésard 4 / 40

Coarsely, a labelled graph whose arrows can be composed

Thursday, October 21, 2010

Page 16: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

What is a category ?

together with basic associativity and identity rules

On fait des maths !

Axiomes : garantir une structure propre

f BAId BA fA

Df ; g C hA

DBf g ; hA

=

=

Tabareau (PPS) Calculer des monoïdes libres Séminaire thésard 5 / 40

Thursday, October 21, 2010

Page 17: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

A first example :

A category with at most one arrow between two objects is

Thursday, October 21, 2010

Page 18: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

A first example :

A category with at most one arrow between two objects is

A preorder

Thursday, October 21, 2010

Page 19: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

A second example :

A category with exactly one object is

Thursday, October 21, 2010

Page 20: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

A second example :

A category with exactly one object is

A monoid

Thursday, October 21, 2010

Page 21: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Lo inevitable

Objects Morphisms

Set sets functions

Bij sets one-to-one function

Vec vector spaces linear applications

Ab abelian groups group morphisms

PO part. order sets monotonic functions

Dom Scott domains continuous function

Thursday, October 21, 2010

Page 22: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

There are also morphisms between categories

Functors

Thursday, October 21, 2010

Page 23: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

There are also morphisms between categories

Functors

Relates two categories in a structure-preserving way

Thursday, October 21, 2010

Page 24: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Example 1:

U : Mon ➝ Set

The forgetful functor from the category of monoids

to the category of sets.

Thursday, October 21, 2010

Page 25: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Example 2:

U’ : Ab ➝ Set

The forgetful functor from the category of abelian groups

to the category of sets.

Thursday, October 21, 2010

Page 26: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Why are categories useful ?

1. Rephrase many structures

with few concepts

Thursday, October 21, 2010

Page 27: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Why are categories useful ?

2. Export abstract theorems

to concrete structures

Thursday, October 21, 2010

Page 28: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

First concept: Adjunction

F: A ➝ B and G: B ➝ A

Fx ➝ y in B

x ➝ Gy in A

as many morphismsin a natural way

Thursday, October 21, 2010

Page 29: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

First concept: Adjunction

F: A ➝ B and G: B ➝ A

In that case, we say that F is left adjoint to G

Thursday, October 21, 2010

Page 30: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Example 1:

U : Mon ➝ Set

as a left adjoint

what is it?

hint : it describes a canonical way to form a monoid from a set

Thursday, October 21, 2010

Page 31: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Example 1:

U : Mon ➝ Set

Answer: the word construction (or free monoid)

Thursday, October 21, 2010

Page 32: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Example 1:

A* ➝ B in Mon

A ➝ U(B) in Set

Proof:

Take f: A ➝ B, construct the function

f*(w1...wn) = f(w1)...f(wn)

Thursday, October 21, 2010

Page 33: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Example 2:

U’ : Ab ➝ Set

The left adjoint constructsthe free abelian group

Thursday, October 21, 2010

Page 34: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Back to the point

What is the categorical structure of the λ-calculus ?

Thursday, October 21, 2010

Page 35: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

1. we need to interpret the “,” in the typing judgment

Thursday, October 21, 2010

Page 36: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

1. we need to interpret the “,” in the typing judgment

This is given by the notionof product ×

Thursday, October 21, 2010

Page 37: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

2. we need to interpret the empty environment in the typing judgment

Thursday, October 21, 2010

Page 38: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

2. we need to interpret the empty environment in the typing judgment

This is given by the notionof terminal object

Thursday, October 21, 2010

Page 39: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

3. we need to interpret the abstraction rule

Curry 1958: le !-calcul simplement type

Variablex :A ! x :A

Abstraction!, x :A ! P :B

! ! !x.P :A" B

Application! ! P :A" B " ! Q :A

!," ! PQ :B

Affaiblissement ! ! P :B!, x :A ! P :B

Contraction!, x :A, y :A ! P :B

!, z :A ! P [x, y # z] :B

Permutation!, x :A, y :B," ! P :C

!, y :B, x :A," ! P :C

5

Thursday, October 21, 2010

Page 40: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

3. we need to interpret the abstraction rule

Γ × A ➝ BΓ ➝ (A ⇒ B)

Thursday, October 21, 2010

Page 41: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

3. we need to interpret the abstraction rule

This says that (A ⇒ -) is

the right adjoint to (- × A)

Γ × A ➝ BΓ ➝ (A ⇒ B)

Thursday, October 21, 2010

Page 42: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

3. we need to interpret the abstraction rule

In category terminology,the right adjoint to the cartesian product is called the

closure

Thursday, October 21, 2010

Page 43: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Cartesian closed category

A category with

1. a product x2. a terminal object 3. a closure ⇒

is a cartesian closed category (CCC)

Thursday, October 21, 2010

Page 44: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

λ-calculus and CCC

We can interpret the λ-calculus in any CCC.

The interpretation is correct:

if M and N are β-equivalentthen [M] = [N]

Thursday, October 21, 2010

Page 45: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

λ-calculus and CCCCurry 1958: le !-calcul simplement type

Variablex :A ! x :A

Abstraction!, x :A ! P :B

! ! !x.P :A" B

Application! ! P :A" B " ! Q :A

!," ! PQ :B

Affaiblissement ! ! P :B!, x :A ! P :B

Contraction!, x :A, y :A ! P :B

!, z :A ! P [x, y # z] :B

Permutation!, x :A, y :B," ! P :C

!, y :B, x :A," ! P :C

5

identity

closure (adjunction)

composition

projection

diagonal of the product

commutativity

Thursday, October 21, 2010

Page 46: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Why introducing CCC ?

Of course, for sets and functions, we don’t really need category theory.

Thursday, October 21, 2010

Page 47: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Why introducing CCC ?

But it is sometimes difficult to say that an interpretation gives rise to a model.

Thursday, October 21, 2010

Page 48: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

Why introducing CCC ?

1. Scott domains and continuous functions

2. Berry domains and stable functions

3. concrete data structures and sequential algorithms

4. opponent starting games and sequential strategies

5. ...

Thursday, October 21, 2010

Page 49: Category Theory for computer scientists - PLEIAD · Category Theory for computer scientists Nicolas Tabareau INRIA, Nantes Thursday, October 21, 2010

To be continued ...

Thursday, October 21, 2010